diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-09 01:37:18 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-04-09 01:37:18 +0200 |
commit | 80abbf2be25e4c760fe80c9f6694047db6c7cfe4 (patch) | |
tree | 55cd74e8163a4afe13467fd024458a5e6a94e261 /src | |
parent | 9c990ae801b949de2728bfff4258aa90f9c96a52 (diff) | |
download | solar-80abbf2be25e4c760fe80c9f6694047db6c7cfe4.tar solar-80abbf2be25e4c760fe80c9f6694047db6c7cfe4.zip |
Emit alloc and free functions
Diffstat (limited to 'src')
-rw-r--r-- | src/output.cpp | 17 |
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(); |