From 1fd161942ef2abaaccbda1188a765baf38b7cb82 Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 29 Dec 2015 04:54:34 -0500 Subject: driver: add cparser init/exit routines. --- include/apimagic/apimagic.h | 1 + src/driver/amgc_driver_ctx.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/apimagic/apimagic.h b/include/apimagic/apimagic.h index 167c860..e1ddfb3 100644 --- a/include/apimagic/apimagic.h +++ b/include/apimagic/apimagic.h @@ -25,6 +25,7 @@ extern "C" { #define AMGC_BAD_OPT_VAL 0x03 #define AMGC_IO_ERROR 0xA0 #define AMGC_MAP_ERROR 0xA1 +#define AMGC_INIT_ERROR 0xA2 /* driver flags */ #define AMGC_DRIVER_VERBOSITY_NONE 0x0000 diff --git a/src/driver/amgc_driver_ctx.c b/src/driver/amgc_driver_ctx.c index 65f5b30..bef0c44 100644 --- a/src/driver/amgc_driver_ctx.c +++ b/src/driver/amgc_driver_ctx.c @@ -8,6 +8,14 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + #define ARGV_DRIVER #include @@ -91,6 +99,19 @@ static int amgc_get_driver_ctx_fail(struct argv_meta * meta) return -1; } +static int amgc_init_cparser(void) +{ + init_temp_files(); + init_default_driver(); + init_driver(); + init_preprocessor(); + init_parser(); + init_ast(); + init_gen_firm(); + + return 0; +} + int amgc_get_driver_ctx( const char ** argv, const char ** envp, @@ -133,6 +154,9 @@ int amgc_get_driver_ctx( nunits++; } + if (amgc_init_cparser()) + return amgc_get_driver_ctx_fail(meta); + if (!(ctx = amgc_driver_ctx_alloc(meta,&cctx,nunits))) return amgc_get_driver_ctx_fail(meta); @@ -163,10 +187,23 @@ int amgc_create_driver_ctx( return AMGC_OK; } +static void amgc_exit_cparser(void) +{ + exit_gen_firm(); + exit_ast2firm(); + exit_ast(); + exit_parser(); + exit_preprocessor(); + exit_driver(); + exit_default_driver(); + exit_temp_files(); +} + static void amgc_free_driver_ctx_impl(struct amgc_driver_ctx_alloc * ictx) { argv_free(ictx->meta); free(ictx); + amgc_exit_cparser(); } void amgc_free_driver_ctx(struct amgc_driver_ctx * ctx) -- cgit v1.2.3