From c7e3c72cb7b2da260f72f18006e2f49eaf005161 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 8 Feb 2022 16:33:20 -0500 Subject: [PATCH] added base type definitions for llvm ir --- cerise/backend/ssa/codegen.c | 8 ++++++++ cerise/backend/test/codegen.c | 5 +++++ cerise/inc/cerise.h | 1 + cerise/src/grammar.c | 2 ++ 4 files changed, 16 insertions(+) diff --git a/cerise/backend/ssa/codegen.c b/cerise/backend/ssa/codegen.c index 140d9ec..fc09ae9 100644 --- a/cerise/backend/ssa/codegen.c +++ b/cerise/backend/ssa/codegen.c @@ -40,6 +40,14 @@ void emit_type(Type* type) } } +void codegen_init(Parser* p) +{ + printf("@Bool = type i1\n"); + printf("@Int = type i64\n"); + printf("@Real = type double\n"); + printf("@Void = type void\n"); +} + void codegen_symbol(Parser* p, Symbol* sym) { (void)p; diff --git a/cerise/backend/test/codegen.c b/cerise/backend/test/codegen.c index 7905613..373be44 100644 --- a/cerise/backend/test/codegen.c +++ b/cerise/backend/test/codegen.c @@ -26,6 +26,11 @@ Type StringType = { .size = -1 }; +void codegen_init(Parser* p) +{ + (void)p; +} + void codegen_symbol(Parser* p, Symbol* sym) { (void)p; diff --git a/cerise/inc/cerise.h b/cerise/inc/cerise.h index f2ccfbe..0e9d625 100644 --- a/cerise/inc/cerise.h +++ b/cerise/inc/cerise.h @@ -287,5 +287,6 @@ void ssa_print_asm(Parser* p, SsaBlock* block); *****************************************************************************/ extern Type VoidType, BoolType, IntType, RealType, StringType; +void codegen_init(Parser* p); void codegen_symbol(Parser* p, Symbol* sym); void codegen_block(Parser* p, SsaBlock* block); diff --git a/cerise/src/grammar.c b/cerise/src/grammar.c index 17ad0fa..8b015b0 100644 --- a/cerise/src/grammar.c +++ b/cerise/src/grammar.c @@ -720,6 +720,8 @@ void compile(char* fname) p->types[p->ntypes++] = &RealType; symbol_new(p, 0, "String", SYM_TYPE, 0)->type = &StringType; p->types[p->ntypes++] = &StringType; + + codegen_init(p); module(p); } -- 2.49.0