From 0f85dc259fe17f8253d851d7fa2d58b7464c70ba Mon Sep 17 00:00:00 2001 From: servostar Date: Tue, 21 May 2024 09:56:41 +0200 Subject: [PATCH] finished type test --- tests/llvm/typedef/test.txt | 15 +++++++++++ tests/llvm/typedef/typedef.c | 49 ++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/tests/llvm/typedef/test.txt b/tests/llvm/typedef/test.txt index dc36998..c9e1fe0 100644 --- a/tests/llvm/typedef/test.txt +++ b/tests/llvm/typedef/test.txt @@ -4,3 +4,18 @@ 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 index 44d8b62..0e2633e 100644 --- a/tests/llvm/typedef/typedef.c +++ b/tests/llvm/typedef/typedef.c @@ -1,4 +1,6 @@ -#include "llvm/types/scope.h" +#include "llvm/types/composite-types.h" +#include +#include #include #include #include @@ -8,8 +10,7 @@ #include #include #include - -#define LOG_LEVEL LOG_LEVEL_DEBUG +#include extern FILE *yyin; AST_NODE_PTR root; @@ -73,12 +74,13 @@ void run_backend_codegen() { err = deinit_backend(); } -void check_typedef(const AST_NODE_PTR node) { - TypeScopeRef scope = type_scope_new(); - - GemstoneTypedefRef typdef = get_type_def_from_ast(scope, node); - - type_scope_delete(scope); +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[]) { @@ -105,9 +107,36 @@ int main(int argc, char *argv[]) { root = AST_new_node(AST_Module, NULL); yyparse(); + TypeScopeRef scope = type_scope_new(); + for (size_t i = 0; i < root->child_count; i++) { - check_typedef(root->children[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;