diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 57c4c80..1228d2b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,5 +9,4 @@ set(CTEST_BINARY_DIRECTORY ${PROJECT_BINARY_DIR}/tests) add_subdirectory(logging) add_subdirectory(input_file) add_subdirectory(ast) -add_subdirectory(glib) -add_subdirectory(llvm) \ No newline at end of file +add_subdirectory(glib) \ No newline at end of file diff --git a/tests/llvm/CMakeLists.txt b/tests/llvm/CMakeLists.txt deleted file mode 100644 index fe495c7..0000000 --- a/tests/llvm/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -include(CTest) - -# Provide test to run here or include another CMakeLists.txt - -add_subdirectory(typedef) -add_subdirectory(params) diff --git a/tests/llvm/params/CMakeLists.txt b/tests/llvm/params/CMakeLists.txt deleted file mode 100644 index 712438d..0000000 --- a/tests/llvm/params/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -include(CTest) - -# ------------------------------------------------ # -# Setup Glib 2.0 # -# ------------------------------------------------ # - -find_package(PkgConfig REQUIRED) -pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) - -# ------------------------------------------------ # -# LLVM backend # -# ------------------------------------------------ # - -# Fetch LLVM link configuration -execute_process(COMMAND llvm-config --libs all - OUTPUT_VARIABLE LLVM_LIBS) -# Strip whitespace from output -string(STRIP "${LLVM_LIBS}" LLVM_LIBS) -# Link all targets to LLVM -link_libraries(${LLVM_LIBS}) - -# ------------------------------------------------ # -# Source # -# ------------------------------------------------ # - -include_directories(${PROJECT_SOURCE_DIR}/src) -include_directories(PRIVATE ${GLIB_INCLUDE_DIRS}) - -file(GLOB_RECURSE SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/*.c) -list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/main.c) - -set(LEX_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/lex/lexer.ll.c) -set(YACC_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/yacc/parser.tab.c) - -# ------------------------------------------------------- # -# CTEST 1 -# test parameter declarations - -add_executable(params - ${SOURCE_FILES} - ${LEX_GENERATED_SOURCE_FILE} - ${YACC_GENERATED_SOURCE_FILE} - params.c) -set_target_properties(params - PROPERTIES - OUTPUT_NAME "params" - RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/llvm) -target_link_libraries(params PkgConfig::GLIB) -add_test(NAME params - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/llvm/params - COMMAND ${GEMSTONE_BINARY_DIR}/tests/llvm/params test.txt) diff --git a/tests/llvm/params/params.c b/tests/llvm/params/params.c deleted file mode 100644 index 36a2ea4..0000000 --- a/tests/llvm/params/params.c +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern FILE *yyin; -AST_NODE_PTR root; - -/** - * @brief Log a debug message to inform about beginning exit procedures - * - */ -void notify_exit(void) { DEBUG("Exiting gemstone..."); } - -/** - * @brief Closes File after compiling. - * - */ - -void close_file(void) { - if (NULL != yyin) { - fclose(yyin); - } -} - -/** - * @brief Run compiler setup here - * - */ -void setup(void) { - // setup preample - - log_init(); - DEBUG("starting gemstone..."); - -#if LOG_LEVEL <= LOG_LEVEL_DEBUG - atexit(¬ify_exit); -#endif - - // actual setup - AST_init(); - - col_init(); - - lex_init(); - - DEBUG("finished starting up gemstone..."); -} - -void run_backend_codegen() { - llvm_backend_init(); - - BackendError err; - err = init_backend(); - if (err.kind != Success) { - return; - } - - void* code = NULL; - err = generate_code(root, &code); - if (err.kind != Success) { - return; - } - - err = deinit_backend(); -} - -int main(int argc, char *argv[]) { - - setup(); - atexit(close_file); - - // Check for file input as argument - if (2 != argc) { - INFO("Usage: %s \n", argv[0]); - PANIC("No File could be found"); - } - - // filename as first argument - char *filename = argv[1]; - - FILE *file = fopen(filename, "r"); - - if (NULL == file) { - PANIC("File couldn't be opened!"); - } - yyin = file; - - root = AST_new_node(AST_Module, NULL); - yyparse(); - - TypeScopeRef scope = type_scope_new(); - - AST_NODE_PTR fun = AST_get_node(root, 0); - - GemstoneFunRef function = fun_from_ast(scope, fun); - type_scope_add_fun(scope, function); - assert(function->params->len == 3); - - type_scope_delete(scope); - - AST_delete_node(root); - return 0; -} diff --git a/tests/llvm/params/test.txt b/tests/llvm/params/test.txt deleted file mode 100644 index 1b94e93..0000000 --- a/tests/llvm/params/test.txt +++ /dev/null @@ -1,4 +0,0 @@ - -fun a(in out int: a, in float: b)(out float: c) { - a = 0 -} \ No newline at end of file diff --git a/tests/llvm/typedef/CMakeLists.txt b/tests/llvm/typedef/CMakeLists.txt deleted file mode 100644 index 84646ce..0000000 --- a/tests/llvm/typedef/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -include(CTest) - -# ------------------------------------------------ # -# Setup Glib 2.0 # -# ------------------------------------------------ # - -find_package(PkgConfig REQUIRED) -pkg_search_module(GLIB REQUIRED IMPORTED_TARGET glib-2.0) - -# ------------------------------------------------ # -# LLVM backend # -# ------------------------------------------------ # - -# Fetch LLVM link configuration -execute_process(COMMAND llvm-config --libs all - OUTPUT_VARIABLE LLVM_LIBS) -# Strip whitespace from output -string(STRIP "${LLVM_LIBS}" LLVM_LIBS) -# Link all targets to LLVM -link_libraries(${LLVM_LIBS}) - -# ------------------------------------------------ # -# Source # -# ------------------------------------------------ # - -include_directories(${PROJECT_SOURCE_DIR}/src) -include_directories(PRIVATE ${GLIB_INCLUDE_DIRS}) - -file(GLOB_RECURSE SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/*.c) -list(REMOVE_ITEM SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/main.c) - -set(LEX_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/lex/lexer.ll.c) -set(YACC_GENERATED_SOURCE_FILE ${PROJECT_SOURCE_DIR}/src/yacc/parser.tab.c) - -# ------------------------------------------------------- # -# CTEST 1 -# test typedef - -add_executable(typedef - ${SOURCE_FILES} - ${LEX_GENERATED_SOURCE_FILE} - ${YACC_GENERATED_SOURCE_FILE} - typedef.c) -set_target_properties(typedef - PROPERTIES - OUTPUT_NAME "typedef" - RUNTIME_OUTPUT_DIRECTORY ${GEMSTONE_BINARY_DIR}/tests/llvm) -target_link_libraries(typedef PkgConfig::GLIB) -add_test(NAME typedef - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests/llvm/typedef - COMMAND ${GEMSTONE_BINARY_DIR}/tests/llvm/typedef test.txt) diff --git a/tests/llvm/typedef/test.txt b/tests/llvm/typedef/test.txt deleted file mode 100644 index c9e1fe0..0000000 --- a/tests/llvm/typedef/test.txt +++ /dev/null @@ -1,21 +0,0 @@ - -type unsigned half half int: u8 -type unsigned half int: u16 -type unsigned int: u32 -type unsigned double int: u64 -type unsigned double double int: u128 -type unsigned double double double int: u256 - -type signed half half int: i8 -type signed half int: i16 -type signed int: i32 -type signed double int: i64 -type signed double double int: i128 -type signed double double double int: i256 - -type signed double u8: short_int - -type signed short float: f16 -type signed float: f32 -type signed long float: f64 -type signed long double float: f128 diff --git a/tests/llvm/typedef/typedef.c b/tests/llvm/typedef/typedef.c deleted file mode 100644 index 0e2633e..0000000 --- a/tests/llvm/typedef/typedef.c +++ /dev/null @@ -1,143 +0,0 @@ -#include "llvm/types/composite-types.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern FILE *yyin; -AST_NODE_PTR root; - -/** - * @brief Log a debug message to inform about beginning exit procedures - * - */ -void notify_exit(void) { DEBUG("Exiting gemstone..."); } - -/** - * @brief Closes File after compiling. - * - */ - -void close_file(void) { - if (NULL != yyin) { - fclose(yyin); - } -} - -/** - * @brief Run compiler setup here - * - */ -void setup(void) { - // setup preample - - log_init(); - DEBUG("starting gemstone..."); - -#if LOG_LEVEL <= LOG_LEVEL_DEBUG - atexit(¬ify_exit); -#endif - - // actual setup - AST_init(); - - col_init(); - - lex_init(); - - DEBUG("finished starting up gemstone..."); -} - -void run_backend_codegen() { - llvm_backend_init(); - - BackendError err; - err = init_backend(); - if (err.kind != Success) { - return; - } - - void* code = NULL; - err = generate_code(root, &code); - if (err.kind != Success) { - return; - } - - err = deinit_backend(); -} - -void check_type(const TypeScopeRef scope, const char* name, enum Sign_t sign, enum Scale_t scale, enum Primitive_t prim) { - GemstoneTypedefRef type = type_scope_get_type_from_name(scope, name); - INFO("Expected: %d %d %d Given: %d %d %d", sign, scale, prim, type->type->specs.composite.sign, type->type->specs.composite.scale, type->type->specs.composite.prim); - assert(type->type->kind == TypeComposite); - assert(type->type->specs.composite.prim == prim); - assert(type->type->specs.composite.scale == scale); - assert(type->type->specs.composite.sign == sign); -} - -int main(int argc, char *argv[]) { - - setup(); - atexit(close_file); - - // Check for file input as argument - if (2 != argc) { - INFO("Usage: %s \n", argv[0]); - PANIC("No File could be found"); - } - - // filename as first argument - char *filename = argv[1]; - - FILE *file = fopen(filename, "r"); - - if (NULL == file) { - PANIC("File couldn't be opened!"); - } - yyin = file; - - root = AST_new_node(AST_Module, NULL); - yyparse(); - - TypeScopeRef scope = type_scope_new(); - - for (size_t i = 0; i < root->child_count; i++) { - GemstoneTypedefRef typdef = get_type_def_from_ast(scope, root->children[i]); - - type_scope_append_type(scope, typdef); - } - - check_type(scope, "u8", Unsigned, ATOM, Int); - check_type(scope, "u16", Unsigned, HALF, Int); - check_type(scope, "u32", Unsigned, SINGLE, Int); - check_type(scope, "u64", Unsigned, DOUBLE, Int); - check_type(scope, "u128", Unsigned, QUAD, Int); - check_type(scope, "u256", Unsigned, OCTO, Int); - - check_type(scope, "i8", Signed, ATOM, Int); - check_type(scope, "i16", Signed, HALF, Int); - check_type(scope, "i32", Signed, SINGLE, Int); - check_type(scope, "i64", Signed, DOUBLE, Int); - check_type(scope, "i128", Signed, QUAD, Int); - check_type(scope, "i256", Signed, OCTO, Int); - - check_type(scope, "short_int", Signed, HALF, Int); - - check_type(scope, "f16", Signed, HALF, Float); - check_type(scope, "f32", Signed, SINGLE, Float); - check_type(scope, "f64", Signed, DOUBLE, Float); - check_type(scope, "f128", Signed, QUAD, Float); - - type_scope_delete(scope); - - AST_delete_node(root); - return 0; -}