summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkugwa <kugwa2000@gmail.com>2015-12-30 15:19:51 +0800
committerkugwa <kugwa2000@gmail.com>2015-12-30 15:19:51 +0800
commit0c0c7ab0850b6803c377ad7150305870d75bf3c0 (patch)
treed2bcb8109870d9d3e4254c0f8b6aade427399fa4
parent9cb1a75a6772b2c4bdb895f724b40d00290ffa0d (diff)
downloadcompiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.tar
compiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.tar.gz
compiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.tar.bz2
compiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.tar.lz
compiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.tar.xz
compiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.tar.zst
compiler2015-0c0c7ab0850b6803c377ad7150305870d75bf3c0.zip
Add the code-generation phase
-rw-r--r--Makefile.am2
-rw-r--r--src/code-generation.c13
-rw-r--r--src/code-generation.h14
-rw-r--r--src/main.c9
4 files changed, 38 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 4d45538..f5972eb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,6 +29,8 @@ parser_SOURCES = \
src/common.h \
src/ast.h \
src/ast.c \
+ src/code-generation.h \
+ src/code-generation.c \
src/draw.h \
src/draw.c \
src/semantic-analysis.h \
diff --git a/src/code-generation.c b/src/code-generation.c
new file mode 100644
index 0000000..c0c5874
--- /dev/null
+++ b/src/code-generation.c
@@ -0,0 +1,13 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "code-generation.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void ccmmc_code_generation(CcmmcAst *root, CcmmcSymbolTable *table, FILE *asm_output)
+{
+}
diff --git a/src/code-generation.h b/src/code-generation.h
new file mode 100644
index 0000000..8250695
--- /dev/null
+++ b/src/code-generation.h
@@ -0,0 +1,14 @@
+#ifndef CCMMC_HEADER_CODE_GENERATION_H
+#define CCMMC_HEADER_CODE_GENERATION_H
+
+#include "ast.h"
+#include "symbol-table.h"
+
+#include <stdio.h>
+
+void ccmmc_code_generation (CcmmcAst *root,
+ CcmmcSymbolTable *table,
+ FILE *asm_output);
+
+#endif
+// vim: set sw=4 ts=4 sts=4 et:
diff --git a/src/main.c b/src/main.c
index 6516eab..5f6c169 100644
--- a/src/main.c
+++ b/src/main.c
@@ -5,6 +5,7 @@
typedef void* yyscan_t;
#include "ast.h"
+#include "code-generation.h"
#include "common.h"
#include "draw.h"
#include "semantic-analysis.h"
@@ -95,6 +96,14 @@ int main (int argc, char **argv)
else
exit(1);
+ FILE *asm_output = fopen("output.s", "w");
+ if (asm_output == NULL) {
+ fprintf(stderr, "%s: output.s: %s\n", prog_name, ERR_MSG);
+ exit(1);
+ }
+ ccmmc_code_generation(state->ast, state->table, asm_output);
+ fclose(asm_output);
+
ccmmc_state_fini(state);
fclose(source_handle);
return 0;