finished type test
This commit is contained in:
parent
cc1dc790e1
commit
0f85dc259f
|
@ -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
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "llvm/types/scope.h"
|
||||
#include "llvm/types/composite-types.h"
|
||||
#include <llvm/types/structs.h>
|
||||
#include <llvm/types/scope.h>
|
||||
#include <ast/ast.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/log.h>
|
||||
|
@ -8,8 +10,7 @@
|
|||
#include <llvm/backend.h>
|
||||
#include <codegen/backend.h>
|
||||
#include <llvm/types/type.h>
|
||||
|
||||
#define LOG_LEVEL LOG_LEVEL_DEBUG
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue