From fd0662520d453add386b48b4e0cc6cd6b566590c Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 29 Dec 2015 22:27:31 -0500 Subject: driver: added --std support. --- src/driver/amgc_driver_ctx.c | 8 +++++++ src/driver/amgc_paradigm_meta.c | 53 +++++++++++++++++++++++++++++++++++++++++ src/driver/amgc_unit_ctx.c | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/driver/amgc_paradigm_meta.c (limited to 'src/driver') 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 #include +#include #include #include #include @@ -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 + +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) { -- cgit v1.2.3