From 51b01a27c3630e48bf5bd1e93980ff443046036f Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sun, 12 Jun 2016 22:06:53 +0900 Subject: [PATCH 1/4] Add generate files --- src/code_generator/generate.c | 1 + src/code_generator/generate.h | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 src/code_generator/generate.c create mode 100644 src/code_generator/generate.h diff --git a/src/code_generator/generate.c b/src/code_generator/generate.c new file mode 100644 index 00000000..ac5f04ff --- /dev/null +++ b/src/code_generator/generate.c @@ -0,0 +1 @@ +#include "code_generator/generate.h" diff --git a/src/code_generator/generate.h b/src/code_generator/generate.h new file mode 100644 index 00000000..4a319d40 --- /dev/null +++ b/src/code_generator/generate.h @@ -0,0 +1,4 @@ +#ifndef KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H +#define KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H + +#endif /* KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H */ From 34c53e0835af997d47d4873ef7d5d9e9c9594336 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sat, 18 Jun 2016 12:01:49 +0900 Subject: [PATCH 2/4] Implement generate_code --- src/code_generator/generate.c | 12 ++++++++++++ src/code_generator/generate.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/code_generator/generate.c b/src/code_generator/generate.c index ac5f04ff..c904bcf8 100644 --- a/src/code_generator/generate.c +++ b/src/code_generator/generate.c @@ -1 +1,13 @@ #include "code_generator/generate.h" +#include +#include +#include "ast/ast_impl.h" + +void generate_code(AstRef ast) { + assert(ast); + switch (ast->tag) { + default: + fprintf(stderr, "Unimplemented: %d\n", ast->tag); + break; + } +} diff --git a/src/code_generator/generate.h b/src/code_generator/generate.h index 4a319d40..597e598c 100644 --- a/src/code_generator/generate.h +++ b/src/code_generator/generate.h @@ -1,4 +1,8 @@ #ifndef KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H #define KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H +#include "ast.h" + +void generate_code(AstRef ast); + #endif /* KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H */ From 1712b4871f20b30a1022013fb3cb2b109a331ae6 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sat, 18 Jun 2016 14:31:05 +0900 Subject: [PATCH 3/4] Add error --- src/code_generator/generate.c | 11 +++++++++++ src/code_generator/generate.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/code_generator/generate.c b/src/code_generator/generate.c index c904bcf8..c199adbf 100644 --- a/src/code_generator/generate.c +++ b/src/code_generator/generate.c @@ -1,6 +1,8 @@ #include "code_generator/generate.h" #include +#include #include +#include #include "ast/ast_impl.h" void generate_code(AstRef ast) { @@ -11,3 +13,12 @@ void generate_code(AstRef ast) { break; } } + +void error(const char* message, ...) { + va_list args; + va_start(args, message); + vfprintf(stderr, message, args); + va_end(args); + fprintf(stderr, "\n"); + exit(EXIT_FAILURE); +} diff --git a/src/code_generator/generate.h b/src/code_generator/generate.h index 597e598c..e9cde182 100644 --- a/src/code_generator/generate.h +++ b/src/code_generator/generate.h @@ -4,5 +4,6 @@ #include "ast.h" void generate_code(AstRef ast); +void error(const char* message, ...); #endif /* KMC_C90_COMPILER_CODE_GENERATOR_GENERATE_H */ From fc4f89fd15d76aa1eac64e77d622acef86bced62 Mon Sep 17 00:00:00 2001 From: hatsusato Date: Sat, 18 Jun 2016 14:31:44 +0900 Subject: [PATCH 4/4] Use error --- src/code_generator/generate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code_generator/generate.c b/src/code_generator/generate.c index c199adbf..8be71475 100644 --- a/src/code_generator/generate.c +++ b/src/code_generator/generate.c @@ -9,7 +9,7 @@ void generate_code(AstRef ast) { assert(ast); switch (ast->tag) { default: - fprintf(stderr, "Unimplemented: %d\n", ast->tag); + error("Unimplemented: %d\n", ast->tag); break; } }