diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-05 00:09:04 +0100 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2019-11-05 00:09:04 +0100 |
| commit | fdc1539d3c42e114c90805cde8cfabd132cc7944 (patch) | |
| tree | 278ed0b3ae9de7c327252529021e39990aad3dd2 /lib.c | |
| parent | 41a1e45b6e9141a1a914f0ffbd5eb18436516159 (diff) | |
| parent | fba1931d2c2779b0b84e4837c51187d9d2fe0226 (diff) | |
| download | sparse-dev-fdc1539d3c42e114c90805cde8cfabd132cc7944.tar.gz | |
Merge branch 'option-arch'
* add new option, --arch=ARCH, allowing to specify the target arch.
Diffstat (limited to 'lib.c')
| -rw-r--r-- | lib.c | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -459,6 +459,8 @@ static char **handle_switch_m(char *arg, char **next) arch_m64 = ARCH_LP64; } else if (!strcmp(arg, "m32") || !strcmp(arg, "m16")) { arch_m64 = ARCH_LP32; + } else if (!strcmp(arg, "m31")) { + arch_m64 = ARCH_LP32; } else if (!strcmp(arg, "mx32")) { arch_m64 = ARCH_X32; } else if (!strcmp(arg, "msize-llp64")) { @@ -1094,6 +1096,73 @@ static char **handle_switch_x(char *arg, char **next) } +static char **handle_arch(char *arg, char **next) +{ + static const struct arch { + const char *name; + char mach; + char bits; + bool big_endian:1; + } archs[] = { + { "aarch64", MACH_ARM64, 64, 0 }, + { "arm64", MACH_ARM64, 64, 0 }, + { "arm", MACH_ARM, 32, 0 }, + { "i386", MACH_I386, 32, 0 }, + { "m68k", MACH_M68K, 32, 0 }, + { "mips", MACH_MIPS32, 0, 1 }, + { "powerpc", MACH_PPC32, 0, 1 }, + { "ppc", MACH_PPC32, 0, 1 }, + { "riscv", MACH_RISCV32, 0, 0 }, + { "s390x", MACH_S390X, 64, 1 }, + { "s390", MACH_S390, 32, 1 }, + { "sparc", MACH_SPARC32, 0, 1 }, + { "x86_64", MACH_X86_64, 64, 0 }, + { "x86-64", MACH_X86_64, 64, 0 }, + { NULL }, + }; + const struct arch *p; + + if (*arg++ != '=') + die("missing argument for --arch option"); + + for (p = &archs[0]; p->name; p++) { + size_t len = strlen(p->name); + if (strncmp(p->name, arg, len) == 0) { + const char *suf = arg + len; + int bits = p->bits; + + arch_mach = p->mach; + if (bits == 0) { + if (!strcmp(suf, "")) { + bits = 32; + } else if (!strcmp(suf, "32")) { + bits = 32; + } else if (!strcmp(suf, "64")) { + bits = 64; + arch_mach += 1; + } else { + die("invalid architecture: %s", arg); + } + } else { + if (strcmp(suf, "")) + die("invalid architecture: %s", arg); + } + + // adjust the arch size (but keep x32 & llp64) + if (bits == 32) + arch_m64 = ARCH_LP32; + else if (bits == 64 && arch_m64 == ARCH_LP32) + arch_m64 = ARCH_LP64; + if (p->big_endian) + arch_big_endian = 1; + + break; + } + } + + return next; +} + static char **handle_version(char *arg, char **next) { printf("%s\n", SPARSE_VERSION); @@ -1126,6 +1195,7 @@ struct switches { static char **handle_long_options(char *arg, char **next) { static struct switches cmd[] = { + { "arch", handle_arch, 1 }, { "param", handle_param, 1 }, { "version", handle_version }, { NULL, NULL } @@ -1428,6 +1498,7 @@ static void predefined_macros(void) predefine("__mips64", 1, "64"); /* fall-through */ case MACH_MIPS32: + predefine("__mips__", 1, "1"); predefine("__mips", 1, "%d", ptr_ctype.bit_size); predefine("_MIPS_SZINT", 1, "%d", int_ctype.bit_size); predefine("_MIPS_SZLONG", 1, "%d", long_ctype.bit_size); @@ -1454,6 +1525,7 @@ static void predefined_macros(void) case MACH_S390X: predefine("__zarch__", 1, "1"); predefine("__s390x__", 1, "1"); + case MACH_S390: predefine("__s390__", 1, "1"); break; case MACH_SPARC64: |
