summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChristoph Mallon <christoph.mallon@gmx.de>2019-03-19 21:39:45 +0100
committerChristoph Mallon <christoph.mallon@gmx.de>2019-03-19 22:50:33 +0100
commitcf3a98dc451528b30eb1b91324cee30c0f320fb2 (patch)
treefd18b916c8a34f34a17c13d5479762e3f69601bc
parente34236f2c2acf733549a7e42f7a092ffe7a66e3a (diff)
driver: The target triple can also be set by prefixing the executable name, e.g. `x86_64-unknown-elf-cparser`.
-rw-r--r--NEWS.md1
-rw-r--r--cparser.15
-rw-r--r--src/driver/options.c2
-rw-r--r--src/driver/options.h2
-rw-r--r--src/main.c13
5 files changed, 20 insertions, 3 deletions
diff --git a/NEWS.md b/NEWS.md
index 2b907fa..613b056 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -19,6 +19,7 @@ cparser 1.22.1 (2016-01-23)
* Add target `riscv32`
* Accept asm qualifiers in arbitrary order
* Accept (and ignore) the asm qualifier `inline`
+* The target triple can also be set by prefixing the executable name, e.g. `x86_64-unknown-elf-cparser`
* Bugfixes
cparser 1.22.0 (2015-12-31)
diff --git a/cparser.1 b/cparser.1
index 4f666bd..5341280 100644
--- a/cparser.1
+++ b/cparser.1
@@ -4,7 +4,7 @@
.Nm cparser
.Nd C compiler
.Sh SYNOPSIS
-.Nm
+.Oo Ar architecture Ns Oo Oo Cm - Ns Ar vendor Oc Ns Cm - Ns Ar system Oc Ns Cm - Oc Ns Nm
.Op Fl c | S | E | -print-ast | dumpmachine
.Op Fl -print-implicit-cast
.Op Fl -print-parenthesis
@@ -62,8 +62,9 @@ Output the abstract syntax tree of the parsed input file as C again.
Use the integrated preprocessor instead of an external one.
.No This is the default if no Fl target No is specified .
.No Otherwise the external preprocessor Ar architecture Ns Cm - Ns Ar vendor Ns Cm - Ns Ar system Ns Cm -gcc No is used .
-.It Fl target Ar architecture Ns Op Oo Cm - Ns Ar vendor Oc Ns Cm - Ns Ar system
+.It Fl target Ar architecture Ns Oo Oo Cm - Ns Ar vendor Oc Ns Cm - Ns Ar system Oc , Oo Ar architecture Ns Oo Oo Cm - Ns Ar vendor Oc Ns Cm - Ns Ar system Oc Ns Cm - Oc Ns Nm
Set target, for which code is generated.
+The target can also be set by prefixing the executable name.
.No The default target triple is determined by the host when building Nm .
.No Supported Ar architecture Ns s are:
.Bl -dash -compact
diff --git a/src/driver/options.c b/src/driver/options.c
index 35eee9d..d62c79f 100644
--- a/src/driver/options.c
+++ b/src/driver/options.c
@@ -653,7 +653,7 @@ bool options_parse_help(options_state_t *s)
return true;
}
-static bool parse_target_triple(const char *arg)
+bool parse_target_triple(char const *const arg)
{
ir_machine_triple_t *triple = ir_parse_machine_triple(arg);
if (triple == NULL) {
diff --git a/src/driver/options.h b/src/driver/options.h
index 3a10057..4b9b9de 100644
--- a/src/driver/options.h
+++ b/src/driver/options.h
@@ -37,4 +37,6 @@ void setup_target_machine(void);
char const *spaced_arg(char const *arg, options_state_t *s);
bool simple_arg(const char *arg, options_state_t *s);
+bool parse_target_triple(char const *arg);
+
#endif
diff --git a/src/main.c b/src/main.c
index 17958ab..e1526d8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -313,6 +313,19 @@ int main(int argc, char **argv)
init_ast();
init_parser();
+ /* Optionally set target by executable name prefix. */
+ char const *const full_name = argv[0];
+ if (full_name) {
+ char const *const slash = strrchr(full_name, '/');
+ char const *const name = slash ? slash + 1 : full_name;
+ char const *const dash = strstr(name, "-cparser");
+ if (dash) {
+ char *const triple = strndup(name, dash - name);
+ parse_target_triple(triple);
+ free(triple);
+ }
+ }
+
options_state_t state;
memset(&state, 0, sizeof(state));
state.argc = argc;