aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/target.c
diff options
context:
space:
mode:
Diffstat (limited to 'target.c')
-rw-r--r--target.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/target.c b/target.c
index f23ed308..8d2d1058 100644
--- a/target.c
+++ b/target.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <string.h>
#include "symbol.h"
#include "target.h"
@@ -75,6 +76,58 @@ static const struct target *targets[] = {
};
const struct target *arch_target = &target_default;
+enum machine target_parse(const char *name)
+{
+ static const struct arch {
+ const char *name;
+ enum machine mach;
+ char bits;
+ } archs[] = {
+ { "aarch64", MACH_ARM64, 64, },
+ { "arm64", MACH_ARM64, 64, },
+ { "arm", MACH_ARM, 32, },
+ { "i386", MACH_I386, 32, },
+ { "m68k", MACH_M68K, 32, },
+ { "mips", MACH_MIPS32, 0, },
+ { "powerpc", MACH_PPC32, 0, },
+ { "ppc", MACH_PPC32, 0, },
+ { "riscv", MACH_RISCV32, 0, },
+ { "s390x", MACH_S390X, 64, },
+ { "s390", MACH_S390, 32, },
+ { "sparc", MACH_SPARC32, 0, },
+ { "x86_64", MACH_X86_64, 64, },
+ { "x86-64", MACH_X86_64, 64, },
+ { NULL },
+ };
+ const struct arch *p;
+
+ for (p = &archs[0]; p->name; p++) {
+ size_t len = strlen(p->name);
+ if (strncmp(p->name, name, len) == 0) {
+ enum machine mach = p->mach;
+ const char *suf = name + len;
+ int bits = p->bits;
+
+ if (bits == 0) {
+ if (!strcmp(suf, "") || !strcmp(suf, "32")) {
+ ;
+ } else if (!strcmp(suf, "64")) {
+ mach += 1;
+ } else {
+ die("invalid architecture: %s", name);
+ }
+ } else {
+ if (strcmp(suf, ""))
+ die("invalid architecture: %s", name);
+ }
+
+ return mach;
+ }
+ }
+
+ return MACH_UNKNOWN;
+}
+
void target_config(enum machine mach)
{