summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-29 04:54:34 -0500
committermidipix <writeonce@midipix.org>2016-01-01 22:50:23 -0500
commit1fd161942ef2abaaccbda1188a765baf38b7cb82 (patch)
treeb43ca038158acc715593b82ba175faececaa6359
parent8b8a8d15174ec92d653cea97ea64dd559a7285e4 (diff)
downloadapimagic-1fd161942ef2abaaccbda1188a765baf38b7cb82.tar.bz2
apimagic-1fd161942ef2abaaccbda1188a765baf38b7cb82.tar.xz
driver: add cparser init/exit routines.
-rw-r--r--include/apimagic/apimagic.h1
-rw-r--r--src/driver/amgc_driver_ctx.c37
2 files changed, 38 insertions, 0 deletions
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 <unistd.h>
#include <fcntl.h>
+#include <cparser/driver/driver.h>
+#include <cparser/driver/driver_t.h>
+#include <cparser/driver/tempfile.h>
+#include <cparser/firm/ast2firm.h>
+#include <cparser/firm/firm_opt.h>
+#include <cparser/parser/parser.h>
+#include <cparser/parser/preprocessor.h>
+
#define ARGV_DRIVER
#include <apimagic/apimagic.h>
@@ -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)