summaryrefslogtreecommitdiff
path: root/src/driver
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-12-29 22:27:31 -0500
committermidipix <writeonce@midipix.org>2016-01-01 22:50:24 -0500
commitfd0662520d453add386b48b4e0cc6cd6b566590c (patch)
tree7bad6c7a8e0920c83016176ee4ab2000df325148 /src/driver
parent379519e6def59e4eea6d3a59fc539b34a1c76e60 (diff)
downloadapimagic-fd0662520d453add386b48b4e0cc6cd6b566590c.tar.bz2
apimagic-fd0662520d453add386b48b4e0cc6cd6b566590c.tar.xz
driver: added --std support.
Diffstat (limited to 'src/driver')
-rw-r--r--src/driver/amgc_driver_ctx.c8
-rw-r--r--src/driver/amgc_paradigm_meta.c53
-rw-r--r--src/driver/amgc_unit_ctx.c2
3 files changed, 62 insertions, 1 deletions
diff --git a/src/driver/amgc_driver_ctx.c b/src/driver/amgc_driver_ctx.c
index 7bb59a9..d2bef3f 100644
--- a/src/driver/amgc_driver_ctx.c
+++ b/src/driver/amgc_driver_ctx.c
@@ -8,6 +8,7 @@
#include <unistd.h>
#include <fcntl.h>
+#include <cparser/driver/c_driver.h>
#include <cparser/driver/driver.h>
#include <cparser/driver/driver_t.h>
#include <cparser/driver/target.h>
@@ -143,6 +144,9 @@ int amgc_get_driver_ctx(
if (!argv[1] && (flags & AMGC_DRIVER_VERBOSITY_USAGE))
return amgc_driver_usage(program,0,options,meta);
+ /* compiler defaults */
+ cctx.std = STANDARD_C99;
+
/* get options, count units */
for (entry=meta->entries; entry->fopt || entry->arg; entry++) {
if (entry->fopt) {
@@ -154,6 +158,10 @@ int amgc_get_driver_ctx(
case TAG_VERSION:
cctx.drvflags |= AMGC_DRIVER_VERSION;
break;
+
+ case TAG_LANG_STD:
+ cctx.std = amgc_lang_std_from_string(entry->arg);
+ break;
}
} else
nunits++;
diff --git a/src/driver/amgc_paradigm_meta.c b/src/driver/amgc_paradigm_meta.c
new file mode 100644
index 0000000..82e8dfa
--- /dev/null
+++ b/src/driver/amgc_paradigm_meta.c
@@ -0,0 +1,53 @@
+/**********************************************************/
+/* apimagic: cparser-based API normalization utility */
+/* Copyright (C) 2015--2016 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.APIMAGIC. */
+/**********************************************************/
+
+#include <cparser/driver/c_driver.h>
+
+struct amgc_paradigm_meta {
+ const char * const string;
+ int val;
+};
+
+static const struct amgc_paradigm_meta cparser_lang_std_meta[] = {
+ {"c++", STANDARD_CXX98 },
+ {"c++98", STANDARD_CXX98 },
+ {"c11", STANDARD_C11 },
+ {"c1x", STANDARD_C11 },
+ {"c89", STANDARD_C89 },
+ {"c90", STANDARD_C89 },
+ {"c99", STANDARD_C99 },
+ {"c9x", STANDARD_C99 },
+ {"gnu++98", STANDARD_GNUXX98},
+ {"gnu11", STANDARD_GNU11 },
+ {"gnu1x", STANDARD_GNU11 },
+ {"gnu89", STANDARD_GNU89 },
+ {"gnu99", STANDARD_GNU99 },
+ {"gnu9x", STANDARD_GNU99 },
+ {"iso9899:1990", STANDARD_C89 },
+ {"iso9899:199409", STANDARD_C89AMD1},
+ {"iso9899:1999", STANDARD_C99 },
+ {"iso9899:199x", STANDARD_C99 },
+ {"iso9899:2011", STANDARD_C11},
+ {0,0}
+};
+
+static int amgc_paradigm_member(
+ const struct amgc_paradigm_meta meta[],
+ const char * string)
+{
+ const struct amgc_paradigm_meta * rec;
+
+ for (rec = meta; rec->string; rec++)
+ if (!(strcmp(rec->string,string)))
+ return rec->val;
+
+ return -1;
+}
+
+int amgc_lang_std_from_string(const char * std)
+{
+ return amgc_paradigm_member(cparser_lang_std_meta,std);
+}
diff --git a/src/driver/amgc_unit_ctx.c b/src/driver/amgc_unit_ctx.c
index aed0c65..a37706c 100644
--- a/src/driver/amgc_unit_ctx.c
+++ b/src/driver/amgc_unit_ctx.c
@@ -137,7 +137,7 @@ int amgc_get_unit_ctx(
ctx->ccunit.name = path;
ctx->ccunit.original_name = path;
ctx->ccunit.type = COMPILATION_UNIT_C;
- ctx->ccunit.standard = STANDARD_C99;
+ ctx->ccunit.standard = dctx->cctx->std;
/* parse, generate ast, generate ir */
if ((process_unit(ctx->cctx.ccenv,&ctx->ccunit)) == false) {