diff options
-rw-r--r-- | include/apimagic/apimagic.h | 5 | ||||
-rw-r--r-- | project/common.mk | 1 | ||||
-rw-r--r-- | src/driver/amgc_driver_ctx.c | 8 | ||||
-rw-r--r-- | src/driver/amgc_paradigm_meta.c | 53 | ||||
-rw-r--r-- | src/driver/amgc_unit_ctx.c | 2 | ||||
-rw-r--r-- | src/internal/apimagic_driver_impl.h | 1 | ||||
-rw-r--r-- | src/skin/amgc_skin_default.c | 12 |
7 files changed, 81 insertions, 1 deletions
diff --git a/include/apimagic/apimagic.h b/include/apimagic/apimagic.h index f2e7bf5..7d17211 100644 --- a/include/apimagic/apimagic.h +++ b/include/apimagic/apimagic.h @@ -4,6 +4,7 @@ #include <stdint.h> #include <stdio.h> +#include <cparser/driver/c_driver.h> #include <cparser/driver/driver_t.h> #include "apimagic_api.h" @@ -51,6 +52,7 @@ struct amgc_common_ctx { uint64_t actflags; uint64_t fmtflags; struct compilation_env_t * ccenv; + enum lang_standard_t std; }; struct amgc_driver_ctx { @@ -84,6 +86,9 @@ amgc_api void amgc_free_unit_ctx (struct amgc_unit_ctx *); amgc_api int amgc_map_input (int fd, const char * path, int prot, struct amgc_input *); amgc_api int amgc_unmap_input (struct amgc_input *); +/* driver helper api */ +amgc_api int amgc_lang_std_from_string (const char * std); + /* utility api */ #ifdef __cplusplus diff --git a/project/common.mk b/project/common.mk index 25e4e90..a717358 100644 --- a/project/common.mk +++ b/project/common.mk @@ -1,5 +1,6 @@ COMMON_SRCS = \ src/driver/amgc_driver_ctx.c \ + src/driver/amgc_paradigm_meta.c \ src/driver/amgc_unit_ctx.c \ src/logic/amgc_map_input.c \ src/skin/amgc_skin_default.c \ 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) { diff --git a/src/internal/apimagic_driver_impl.h b/src/internal/apimagic_driver_impl.h index ff33a4e..527e1bb 100644 --- a/src/internal/apimagic_driver_impl.h +++ b/src/internal/apimagic_driver_impl.h @@ -10,6 +10,7 @@ enum app_tags { TAG_HELP, TAG_VERSION, + TAG_LANG_STD, }; struct amgc_driver_ctx_impl { diff --git a/src/skin/amgc_skin_default.c b/src/skin/amgc_skin_default.c index 2151b30..865231e 100644 --- a/src/skin/amgc_skin_default.c +++ b/src/skin/amgc_skin_default.c @@ -1,6 +1,15 @@ #include "apimagic_driver_impl.h" #include "argv/argv.h" +#define AMGC_LANG_STD_PARADIGM "c++|c++98|c11|c1x|c89|c90|c99|c9x|" \ + "gnu++98|gnu11|gnu1x|" \ + "gnu89|gnu99|gnu9x|" \ + "iso9899:1990|" \ + "iso9899:199409|" \ + "iso9899:1999|" \ + "iso9899:199x|" \ + "iso9899:2011" + const struct argv_option amgc_default_options[] = { {"version", 'v',TAG_VERSION,ARGV_OPTARG_NONE,0,0, "show version information"}, @@ -8,5 +17,8 @@ const struct argv_option amgc_default_options[] = { {"help", 'h',TAG_HELP,ARGV_OPTARG_OPTIONAL,"short|long",0, "show usage information [listing %s options only]"}, + {"std", 'g',TAG_LANG_STD,ARGV_OPTARG_REQUIRED,AMGC_LANG_STD_PARADIGM,0, + "set language standard"}, + {0} }; |