diff --git a/src/cfg/opt.c b/src/cfg/opt.c index d0b7718..97dbc02 100644 --- a/src/cfg/opt.c +++ b/src/cfg/opt.c @@ -15,6 +15,85 @@ static GHashTable* args = NULL; static Dependency *new_dependency(); +const char* find_string(const char* haystack, const char** options, size_t size) +{ + const static char* found = NULL; + + for (size_t i = 0; i < size/sizeof(const char*); i++) + { + if (strstr(haystack, options[i])) + { + found = options[i]; + break; + } + } + + return found; +} + +const char* extract_arch_from_triple(const char* triple) +{ + const char* known_archs[] = { + ARCH_X86_64, + ARCH_I386, + ARCH_ARM, + ARCH_THUMB, + ARCH_MIPS + }; + + return find_string(triple, known_archs, sizeof(known_archs)); +} + +const char* extract_sub_from_triple(const char* triple) +{ + const char* known_subs[] = { + SUB_V5, + SUB_V6M, + SUB_V7A, + SUB_V7M + }; + + return find_string(triple, known_subs, sizeof(known_subs)); +} + +const char* extract_vendor_from_triple(const char* triple) +{ + const char* known_subs[] = { + VENDOR_PC, + VENDOR_APPLE, + VENDOR_NVIDIA, + VENDOR_IBM + }; + + return find_string(triple, known_subs, sizeof(known_subs)); +} + +const char* extract_sys_from_triple(const char* triple) +{ + const char* known_sys[] = { + SYS_NONE, + SYS_LINUX, + SYS_WIN32, + SYS_DARWIN, + SYS_CUDA + }; + + return find_string(triple, known_sys, sizeof(known_sys)); +} + +const char* extract_env_from_triple(const char* triple) +{ + const char* known_envs[] = { + ENV_EABI, + ENV_GNU, + ENV_ANDROID, + ENV_MACHO, + ENV_ELF + }; + + return find_string(triple, known_envs, sizeof(known_envs)); +} + static void clean(void) { GHashTableIter iter; gpointer key, value; diff --git a/src/cfg/opt.h b/src/cfg/opt.h index 4583fed..d09de6b 100644 --- a/src/cfg/opt.h +++ b/src/cfg/opt.h @@ -126,6 +126,44 @@ typedef struct Option_t { bool is_opt; } Option; +const char* ARCH_X86_64 = "x86_64"; +const char* ARCH_I386 = "i386"; +const char* ARCH_ARM = "arm"; +const char* ARCH_THUMB = "thumb"; +const char* ARCH_MIPS = "mips"; + +const char* SUB_V5 = "v5"; +const char* SUB_V6M = "v6m"; +const char* SUB_V7A = "v7a"; +const char* SUB_V7M = "v7m"; + +const char* VENDOR_PC = "pc"; +const char* VENDOR_APPLE = "apple"; +const char* VENDOR_NVIDIA = "nvidia"; +const char* VENDOR_IBM = "ibm"; + +const char* SYS_NONE = "none"; +const char* SYS_LINUX = "linux"; +const char* SYS_WIN32 = "win32"; +const char* SYS_DARWIN = "darwin"; +const char* SYS_CUDA = "cuda"; + +const char* ENV_EABI = "eabi"; +const char* ENV_GNU = "gnu"; +const char* ENV_ANDROID = "android"; +const char* ENV_MACHO = "macho"; +const char* ENV_ELF = "elf"; + +const char* extract_arch_from_triple(const char* triple); + +const char* extract_sub_from_triple(const char* triple); + +const char* extract_vendor_from_triple(const char* triple); + +const char* extract_sys_from_triple(const char* triple); + +const char* extract_env_from_triple(const char* triple); + /** * @brief Create the default configuration for targets. * @return A pointer to a new target configuration.