#ifdef __APPLE__
#include <mach/machine.h>
#define I386_STRING "i386"
#define X86_64_STRING "x86_64"
#define ANY_CPU_STRING "any"
static inline char*
string_for_arch(cpu_type_t arch)
{
switch(arch) {
case CPU_TYPE_I386:
return I386_STRING;
case CPU_TYPE_X86_64:
return X86_64_STRING;
case CPU_TYPE_ANY:
return ANY_CPU_STRING;
default:
return NULL;
}
}
static inline cpu_type_t
arch_for_string(const char* string)
{
if(!strcmp(string, I386_STRING))
return CPU_TYPE_I386;
else if(!strcmp(string, X86_64_STRING))
return CPU_TYPE_X86_64;
else if(!strcmp(string, ANY_CPU_STRING))
return CPU_TYPE_ANY;
else
return (cpu_type_t)0;
}
static inline int needs_swapping(cpu_type_t a, cpu_type_t b)
{
switch(a) {
case CPU_TYPE_I386:
case CPU_TYPE_X86_64:
if(b == CPU_TYPE_POWERPC || b == CPU_TYPE_POWERPC64)
return 1;
else
return 0;
case CPU_TYPE_POWERPC:
case CPU_TYPE_POWERPC64:
if(b == CPU_TYPE_I386 || b == CPU_TYPE_X86_64)
return 1;
else
return 0;
}
return 0;
}
#if defined(__i386__)
#define host_arch CPU_TYPE_I386
#elif defined(__x86_64__)
#define host_arch CPU_TYPE_X86_64
#else
#error Unsupported architecture
#endif
#endif