From 0936ab39c0483c001d24440a0e224b071af83d42 Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 2 Jul 2024 16:43:59 +0200 Subject: [PATCH] fixed: tests --- tests/ast/build_tree.c | 16 ++++++++-------- tests/ast/gen_graph.c | 12 ++++++------ tests/ast/print_graphviz.c | 16 ++++++++-------- tests/ast/print_node.c | 2 +- tests/llvm/CMakeLists.txt | 3 +++ tests/llvm/global_vars.c | 23 ++++++++++------------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/ast/build_tree.c b/tests/ast/build_tree.c index ddc3b66..621345f 100644 --- a/tests/ast/build_tree.c +++ b/tests/ast/build_tree.c @@ -7,22 +7,22 @@ #include void generate_statement(const AST_NODE_PTR stmt) { - const AST_NODE_PTR add = AST_new_node(empty_location(), AST_Add, NULL); + const AST_NODE_PTR add = AST_new_node(empty_location(NULL), AST_Add, NULL); - AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3")); - AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6")); + AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "3")); + AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "6")); AST_push_node(stmt, add); } void generate_branch(const AST_NODE_PTR stmt) { - const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL); - const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL); + const AST_NODE_PTR branch = AST_new_node(empty_location(NULL), AST_If, NULL); + const AST_NODE_PTR gt = AST_new_node(empty_location(NULL), AST_Greater, NULL); AST_push_node(branch, gt); - AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "2.3")); - AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79")); + AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "2.3")); + AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "0.79")); AST_push_node(stmt, branch); @@ -32,7 +32,7 @@ void generate_branch(const AST_NODE_PTR stmt) { int main(void) { mem_init(); - const AST_NODE_PTR root = AST_new_node(empty_location(), AST_Stmt, NULL); + const AST_NODE_PTR root = AST_new_node(empty_location(NULL), AST_Stmt, NULL); generate_branch(root); diff --git a/tests/ast/gen_graph.c b/tests/ast/gen_graph.c index 53ef3cc..e00362a 100644 --- a/tests/ast/gen_graph.c +++ b/tests/ast/gen_graph.c @@ -9,15 +9,15 @@ int main(void) { mem_init(); - struct AST_Node_t* node = AST_new_node(empty_location(), AST_If, NULL); + struct AST_Node_t* node = AST_new_node(empty_location(NULL), AST_If, NULL); - struct AST_Node_t* child = AST_new_node(empty_location(), AST_Add, NULL); - AST_push_node(child, AST_new_node(empty_location(), AST_Int, "43")); - AST_push_node(child, AST_new_node(empty_location(), AST_Int, "9")); + struct AST_Node_t* child = AST_new_node(empty_location(NULL), AST_Add, NULL); + AST_push_node(child, AST_new_node(empty_location(NULL), AST_Int, "43")); + AST_push_node(child, AST_new_node(empty_location(NULL), AST_Int, "9")); AST_push_node(node, child); - AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL)); - AST_push_node(node, AST_new_node(empty_location(), AST_Expr, NULL)); + AST_push_node(node, AST_new_node(empty_location(NULL), AST_Expr, NULL)); + AST_push_node(node, AST_new_node(empty_location(NULL), AST_Expr, NULL)); FILE* out = fopen("ast.gv", "w+"); // convert this file ^^^^^^ diff --git a/tests/ast/print_graphviz.c b/tests/ast/print_graphviz.c index 888a29d..b630eec 100644 --- a/tests/ast/print_graphviz.c +++ b/tests/ast/print_graphviz.c @@ -7,22 +7,22 @@ #include void generate_statement(const AST_NODE_PTR stmt) { - const AST_NODE_PTR add = AST_new_node(empty_location(), AST_Add, NULL); + const AST_NODE_PTR add = AST_new_node(empty_location(NULL), AST_Add, NULL); - AST_push_node(add, AST_new_node(empty_location(), AST_Int, "3")); - AST_push_node(add, AST_new_node(empty_location(), AST_Int, "6")); + AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "3")); + AST_push_node(add, AST_new_node(empty_location(NULL), AST_Int, "6")); AST_push_node(stmt, add); } void generate_branch(const AST_NODE_PTR stmt) { - const AST_NODE_PTR branch = AST_new_node(empty_location(), AST_If, NULL); - const AST_NODE_PTR gt = AST_new_node(empty_location(), AST_Greater, NULL); + const AST_NODE_PTR branch = AST_new_node(empty_location(NULL), AST_If, NULL); + const AST_NODE_PTR gt = AST_new_node(empty_location(NULL), AST_Greater, NULL); AST_push_node(branch, gt); - AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "2.3")); - AST_push_node(gt, AST_new_node(empty_location(), AST_Float, "0.79")); + AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "2.3")); + AST_push_node(gt, AST_new_node(empty_location(NULL), AST_Float, "0.79")); AST_push_node(stmt, branch); @@ -33,7 +33,7 @@ int main(void) { mem_init(); AST_init(); - const AST_NODE_PTR root = AST_new_node(empty_location(), AST_Stmt, NULL); + const AST_NODE_PTR root = AST_new_node(empty_location(NULL), AST_Stmt, NULL); generate_branch(root); diff --git a/tests/ast/print_node.c b/tests/ast/print_node.c index b76285a..7e74590 100644 --- a/tests/ast/print_node.c +++ b/tests/ast/print_node.c @@ -9,7 +9,7 @@ int main(void) { mem_init(); AST_init(); - const AST_NODE_PTR node = AST_new_node(empty_location(), 0, "value"); + const AST_NODE_PTR node = AST_new_node(empty_location(NULL), 0, "value"); for (size_t i = 0; i < AST_ELEMENT_COUNT; i++) { // set kind diff --git a/tests/llvm/CMakeLists.txt b/tests/llvm/CMakeLists.txt index d2d5953..0be9959 100644 --- a/tests/llvm/CMakeLists.txt +++ b/tests/llvm/CMakeLists.txt @@ -36,8 +36,11 @@ add_executable(global_vars ${PROJECT_SOURCE_DIR}/src/codegen/backend.c ${PROJECT_SOURCE_DIR}/src/sys/log.c ${PROJECT_SOURCE_DIR}/src/sys/col.c + ${PROJECT_SOURCE_DIR}/src/set/set.c + ${PROJECT_SOURCE_DIR}/src/ast/ast.c ${PROJECT_SOURCE_DIR}/src/cfg/opt.c ${PROJECT_SOURCE_DIR}/src/io/files.c + ${PROJECT_SOURCE_DIR}/src/mem/cache.c global_vars.c ${SOURCE_FILES}) set_target_properties(global_vars diff --git a/tests/llvm/global_vars.c b/tests/llvm/global_vars.c index 691a64a..135459b 100644 --- a/tests/llvm/global_vars.c +++ b/tests/llvm/global_vars.c @@ -6,8 +6,7 @@ #include [[gnu::always_inline]] -[[clang::always_inline]] -inline Variable* create_variable_decl(const char* name, StorageQualifier qualifier, Type type) { +inline Variable* create_variable_decl(const char* name, StorageQualifier qualifier, Type* type) { Variable* variable = alloca(sizeof(Variable)); variable->name = name; @@ -20,10 +19,8 @@ inline Variable* create_variable_decl(const char* name, StorageQualifier qualifi return variable; } -[[gnu::always_inline]] -[[clang::always_inline]] -inline Module* create_module() { - Module* module = alloca(sizeof(Module)); +Module* create_module() { + Module* module = malloc(sizeof(Module)); module->boxes = g_hash_table_new(g_str_hash, g_str_equal); module->functions = g_hash_table_new(g_str_hash, g_str_equal); @@ -35,7 +32,7 @@ inline Module* create_module() { type_int.kind = TypeKindPrimitive; type_int.impl.primitive = Int; - g_hash_table_insert(module->variables, "a", create_variable_decl("a", Global, type_int)); + g_hash_table_insert(module->variables, "a", create_variable_decl("a", Global, &type_int)); Type type_composite; type_composite.kind = TypeKindComposite; @@ -43,11 +40,11 @@ inline Module* create_module() { type_composite.impl.composite.scale = 2.0; type_composite.impl.composite.sign = Signed; - g_hash_table_insert(module->variables, "b", create_variable_decl("b", Global, type_composite)); + g_hash_table_insert(module->variables, "b", create_variable_decl("b", Global, &type_composite)); Type type_box; type_box.kind = TypeKindBox; - type_box.impl.box.member = g_hash_table_new(g_str_hash, g_str_equal); + type_box.impl.box->member = g_hash_table_new(g_str_hash, g_str_equal); BoxMember* member1 = alloca(sizeof(BoxMember)); member1->box = NULL; @@ -55,7 +52,7 @@ inline Module* create_module() { member1->type = alloca(sizeof(Type)); *(member1->type) = type_int; - g_hash_table_insert(type_box.impl.box.member, "foo", member1); + g_hash_table_insert(type_box.impl.box->member, "foo", member1); Type type_half; type_half.kind = TypeKindComposite; @@ -69,15 +66,15 @@ inline Module* create_module() { member2->type = alloca(sizeof(Type)); *(member2->type) = type_half; - g_hash_table_insert(type_box.impl.box.member, "bar", member2); + g_hash_table_insert(type_box.impl.box->member, "bar", member2); - g_hash_table_insert(module->variables, "c", create_variable_decl("c", Global, type_box)); + g_hash_table_insert(module->variables, "c", create_variable_decl("c", Global, &type_box)); Type type_reference; type_reference.kind = TypeKindReference; type_reference.impl.reference = &type_box; - g_hash_table_insert(module->variables, "d", create_variable_decl("d", Global, type_reference)); + g_hash_table_insert(module->variables, "d", create_variable_decl("d", Global, &type_reference)); return module; }