summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-09 01:37:18 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-09 01:37:18 +0200
commit80abbf2be25e4c760fe80c9f6694047db6c7cfe4 (patch)
tree55cd74e8163a4afe13467fd024458a5e6a94e261
parent9c990ae801b949de2728bfff4258aa90f9c96a52 (diff)
downloadsolar-80abbf2be25e4c760fe80c9f6694047db6c7cfe4.tar
solar-80abbf2be25e4c760fe80c9f6694047db6c7cfe4.zip
Emit alloc and free functions
-rw-r--r--src/output.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/output.cpp b/src/output.cpp
index e1ca496..7f074ab 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -96,7 +96,12 @@ void output_t::emit_header() {
emit_tokens();
emit_token_value();
- std::fprintf(header_file, "typedef struct %scontext %scontext_t;\n", prefix(), prefix());
+ std::fprintf(header_file, "typedef struct %scontext %scontext_t;\n\n", prefix(), prefix());
+
+ std::fprintf(header_file, "%scontext_t * %salloc(void *(*alloc_func)(size_t));\n", prefix(), prefix());
+ std::fprintf(header_file, "void %sfree(%scontext_t *parser, void (*free_func)(void *));\n\n", prefix(), prefix());
+
+ std::fprintf(header_file, "int %spush(%scontext_t *parser, int token, const %stoken_value_t *value);\n", prefix(), prefix(), prefix());
}
void output_t::emit_reduction(unsigned rule_id) {
@@ -295,7 +300,15 @@ void output_t::emit_source() {
std::fprintf(source_file, "struct %scontext {\n", prefix());
std::fprintf(source_file, "\tunsigned top;\n");
std::fprintf(source_file, "\t%scontext_state_t stack[%u];\n", prefix(), stack_size);
- std::fprintf(source_file, "};\n\n");
+ std::fprintf(source_file, "};\n\n\n");
+
+ std::fprintf(source_file, "%scontext_t * %salloc(void *(*alloc_func)(size_t)) {\n", prefix(), prefix());
+ std::fprintf(source_file, "\treturn (%scontext_t *)alloc_func(sizeof(%scontext_t));\n", prefix(), prefix());
+ std::fprintf(source_file, "}\n\n");
+
+ std::fprintf(source_file, "void %sfree(%scontext_t *parser, void (*free_func)(void *)) {\n", prefix(), prefix());
+ std::fprintf(source_file, "\tfree_func(parser);\n");
+ std::fprintf(source_file, "}\n\n");
emit_reductions();