Commit d969d02e authored by Alexandre Julliard's avatar Alexandre Julliard

tools: Move target CPU and platform handling to the common tools.h header.

parent c70ed78a
......@@ -80,6 +80,23 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
struct target
{
enum { CPU_i386, CPU_x86_64, CPU_ARM, CPU_ARM64 } cpu;
enum
{
PLATFORM_UNSPECIFIED,
PLATFORM_APPLE,
PLATFORM_ANDROID,
PLATFORM_LINUX,
PLATFORM_FREEBSD,
PLATFORM_SOLARIS,
PLATFORM_WINDOWS,
PLATFORM_MINGW,
PLATFORM_CYGWIN
} platform;
};
static inline void *xmalloc( size_t size )
{
......@@ -336,6 +353,217 @@ static inline int make_temp_file( const char *prefix, const char *suffix, char *
}
static inline struct target get_default_target(void)
{
struct target target;
#ifdef __i386__
target.cpu = CPU_i386;
#elif defined(__x86_64__)
target.cpu = CPU_x86_64;
#elif defined(__arm__)
target.cpu = CPU_ARM;
#elif defined(__aarch64__)
target.cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
#ifdef __APPLE__
target.platform = PLATFORM_APPLE;
#elif defined(__ANDROID__)
target.platform = PLATFORM_ANDROID;
#elif defined(__linux__)
target.platform = PLATFORM_LINUX;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
target.platform = PLATFORM_FREEBSD;
#elif defined(__sun)
target.platform = PLATFORM_SOLARIS;
#elif defined(__CYGWIN__)
target.platform = PLATFORM_CYGWIN;
#elif defined(_WIN32)
target.platform = PLATFORM_MINGW;
#else
target.platform = PLATFORM_UNSPECIFIED;
#endif
return target;
}
static inline unsigned int get_target_ptr_size( struct target target )
{
static const unsigned int sizes[] =
{
[CPU_i386] = 4,
[CPU_x86_64] = 8,
[CPU_ARM] = 4,
[CPU_ARM64] = 8,
};
return sizes[target.cpu];
}
static inline void set_target_ptr_size( struct target *target, unsigned int size )
{
switch (target->cpu)
{
case CPU_i386:
if (size == 8) target->cpu = CPU_x86_64;
break;
case CPU_x86_64:
if (size == 4) target->cpu = CPU_i386;
break;
case CPU_ARM:
if (size == 8) target->cpu = CPU_ARM64;
break;
case CPU_ARM64:
if (size == 4) target->cpu = CPU_ARM;
break;
}
}
static inline int get_cpu_from_name( const char *name )
{
static const struct
{
const char *name;
int cpu;
} cpu_names[] =
{
{ "i386", CPU_i386 },
{ "i486", CPU_i386 },
{ "i586", CPU_i386 },
{ "i686", CPU_i386 },
{ "i786", CPU_i386 },
{ "x86_64", CPU_x86_64 },
{ "amd64", CPU_x86_64 },
{ "aarch64", CPU_ARM64 },
{ "arm64", CPU_ARM64 },
{ "arm", CPU_ARM },
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(cpu_names); i++)
if (!strncmp( cpu_names[i].name, name, strlen(cpu_names[i].name) )) return cpu_names[i].cpu;
return -1;
}
static inline int get_platform_from_name( const char *name )
{
static const struct
{
const char *name;
int platform;
} platform_names[] =
{
{ "macos", PLATFORM_APPLE },
{ "darwin", PLATFORM_APPLE },
{ "android", PLATFORM_ANDROID },
{ "linux", PLATFORM_LINUX },
{ "freebsd", PLATFORM_FREEBSD },
{ "solaris", PLATFORM_SOLARIS },
{ "mingw32", PLATFORM_MINGW },
{ "windows-gnu", PLATFORM_MINGW },
{ "winnt", PLATFORM_MINGW },
{ "windows", PLATFORM_WINDOWS },
{ "cygwin", PLATFORM_CYGWIN },
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(platform_names); i++)
if (!strncmp( platform_names[i].name, name, strlen(platform_names[i].name) ))
return platform_names[i].platform;
return -1;
};
static inline const char *get_arch_dir( struct target target )
{
static const char *cpu_names[] =
{
[CPU_i386] = "i386",
[CPU_x86_64] = "x86_64",
[CPU_ARM] = "arm",
[CPU_ARM64] = "aarch64"
};
if (!cpu_names[target.cpu]) return "";
switch (target.platform)
{
case PLATFORM_WINDOWS:
case PLATFORM_CYGWIN:
case PLATFORM_MINGW:
return strmake( "/%s-windows", cpu_names[target.cpu] );
default:
return strmake( "/%s-unix", cpu_names[target.cpu] );
}
}
static inline int parse_target( const char *name, struct target *target )
{
int res;
char *p, *spec = xstrdup( name );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
/* get the CPU part */
if ((p = strchr( spec, '-' )))
{
*p++ = 0;
if ((res = get_cpu_from_name( spec )) == -1)
{
free( spec );
return 0;
}
target->cpu = res;
}
else if (!strcmp( spec, "mingw32" ))
{
target->cpu = CPU_i386;
p = spec;
}
else
{
free( spec );
return 0;
}
/* get the OS part */
target->platform = PLATFORM_UNSPECIFIED; /* default value */
for (;;)
{
if ((res = get_platform_from_name( p )) != -1)
{
target->platform = res;
break;
}
if (!(p = strchr( p, '-' ))) break;
p++;
}
free( spec );
return 1;
}
static inline struct target init_argv0_target( const char *argv0 )
{
char *name = get_basename( argv0 );
struct target target;
if (!strchr( name, '-' ) || !parse_target( name, &target ))
target = get_default_target();
free( name );
return target;
}
/* command-line option parsing */
/* partly based on the Glibc getopt() implementation */
......
......@@ -92,17 +92,7 @@ static const char usage[] =
static const char version_string[] = "Wine IDL Compiler version " PACKAGE_VERSION "\n"
"Copyright 2002 Ove Kaaven\n";
#ifdef __i386__
enum target_cpu target_cpu = CPU_x86;
#elif defined(__x86_64__)
enum target_cpu target_cpu = CPU_x86_64;
#elif defined(__arm__)
enum target_cpu target_cpu = CPU_ARM;
#elif defined(__aarch64__)
enum target_cpu target_cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
static struct target target;
int debuglevel = DEBUGLEVEL_NONE;
int parser_debug, yy_flex_debug;
......@@ -210,28 +200,6 @@ static const struct long_option long_options[] = {
{ NULL }
};
static const struct
{
const char *name;
enum target_cpu cpu;
} cpu_names[] =
{
{ "i386", CPU_x86 },
{ "i486", CPU_x86 },
{ "i586", CPU_x86 },
{ "i686", CPU_x86 },
{ "i786", CPU_x86 },
{ "amd64", CPU_x86_64 },
{ "x86_64", CPU_x86_64 },
{ "arm", CPU_ARM },
{ "armv5", CPU_ARM },
{ "armv6", CPU_ARM },
{ "armv7", CPU_ARM },
{ "armv7a", CPU_ARM },
{ "arm64", CPU_ARM64 },
{ "aarch64", CPU_ARM64 },
};
static void rm_tempfile(void);
enum stub_mode get_stub_mode(void)
......@@ -288,50 +256,6 @@ static void add_widl_version_define(void)
wpp_add_cmdline_define(version_str);
}
static void set_cpu( const char *cpu, int error_out )
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE( cpu_names ); i++)
{
if (!strcmp( cpu_names[i].name, cpu ))
{
target_cpu = cpu_names[i].cpu;
return;
}
}
if (error_out)
error( "Unrecognized CPU '%s'\n", cpu );
}
/* Set the target platform based on a potential prefix of the executable name.
* If not found, or not matching a known CPU name, just proceed silently. */
static void init_argv0_target( const char *argv0 )
{
char *p, *name = get_basename( argv0 );
if (!(p = strchr(name, '-')))
{
free( name );
return;
}
*p = 0;
set_cpu( name, 0 );
free( name );
}
/* set the target platform */
static void set_target( const char *target )
{
char *p, *spec = xstrdup( target );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
if (!(p = strchr( spec, '-' ))) error( "Invalid target specification '%s'\n", target );
*p++ = 0;
set_cpu( spec, 1 );
free( spec );
}
/* clean things up when aborting on a signal */
static void exit_on_signal( int sig )
{
......@@ -648,7 +572,8 @@ static void option_callback( int optc, char *optarg )
/* FIXME: Support robust option */
break;
case 'b':
set_target( optarg );
if (!parse_target( optarg, &target ))
error( "Invalid target specification '%s'\n", optarg );
break;
case 'c':
do_everything = 0;
......@@ -742,22 +667,11 @@ static void option_callback( int optc, char *optarg )
}
}
static const char *get_pe_dir(void)
{
switch (target_cpu)
{
case CPU_x86: return "/i386-windows";
case CPU_x86_64: return "/x86_64-windows";
case CPU_ARM: return "/arm-windows";
case CPU_ARM64: return "/aarch64-windows";
default: return "";
}
}
int open_typelib( const char *name )
{
static const char *default_dirs[] = { DLLDIR, "/usr/lib/wine", "/usr/local/lib/wine" };
const char *pe_dir = get_pe_dir();
struct target win_target = { target.cpu, PLATFORM_WINDOWS };
const char *pe_dir = get_arch_dir( win_target );
int fd;
unsigned int i;
......@@ -809,7 +723,7 @@ int main(int argc,char *argv[])
signal( SIGHUP, exit_on_signal );
#endif
init_argv0_dir( argv[0] );
init_argv0_target( argv[0] );
target = init_argv0_target( argv[0] );
now = time(NULL);
......@@ -832,25 +746,10 @@ int main(int argc,char *argv[])
}
}
switch (target_cpu)
{
case CPU_x86:
if (pointer_size == 8) target_cpu = CPU_x86_64;
else pointer_size = 4;
break;
case CPU_x86_64:
if (pointer_size == 4) target_cpu = CPU_x86;
else pointer_size = 8;
break;
case CPU_ARM:
if (pointer_size == 8) target_cpu = CPU_ARM64;
else pointer_size = 4;
break;
case CPU_ARM64:
if (pointer_size == 4) target_cpu = CPU_ARM;
else pointer_size = 8;
break;
}
if (pointer_size)
set_target_ptr_size( &target, pointer_size );
else
pointer_size = get_target_ptr_size( target );
/* if nothing specified, try to guess output type from the output file name */
if (output_name && do_everything && !do_header && !do_typelib && !do_proxies &&
......
......@@ -75,13 +75,6 @@ extern time_t now;
extern int line_number;
extern int char_number;
enum target_cpu
{
CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64
};
extern enum target_cpu target_cpu;
enum stub_mode
{
MODE_Os, /* inline stubs */
......
......@@ -135,29 +135,17 @@ typedef struct
struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
} DLLSPEC;
enum target_cpu
{
CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64
};
extern char *target_alias;
extern struct target target;
enum target_platform
static inline unsigned int get_ptr_size(void)
{
PLATFORM_UNSPECIFIED,
PLATFORM_APPLE,
PLATFORM_LINUX,
PLATFORM_FREEBSD,
PLATFORM_MINGW,
PLATFORM_SOLARIS,
PLATFORM_WINDOWS
};
extern char *target_alias;
extern enum target_cpu target_cpu;
extern enum target_platform target_platform;
return get_target_ptr_size( target );
}
static inline int is_pe(void)
{
return target_platform == PLATFORM_MINGW || target_platform == PLATFORM_WINDOWS;
return target.platform == PLATFORM_MINGW || target.platform == PLATFORM_WINDOWS;
}
/* entry point flags */
......@@ -178,9 +166,9 @@ static inline int is_pe(void)
#define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
#define FLAG_CPU(cpu) (0x10000 << (cpu))
#define FLAG_CPU_MASK (FLAG_CPU(CPU_LAST + 1) - FLAG_CPU(0))
#define FLAG_CPU_MASK (FLAG_CPU_WIN32 | FLAG_CPU_WIN64)
#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
#define FLAG_CPU_WIN32 (FLAG_CPU_MASK & ~FLAG_CPU_WIN64)
#define FLAG_CPU_WIN32 (FLAG_CPU(CPU_i386) | FLAG_CPU(CPU_ARM))
#define MAX_ORDINALS 65535
......@@ -258,10 +246,8 @@ extern char *make_c_identifier( const char *str );
extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
extern const char *get_link_name( const ORDDEF *odp );
extern int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) );
extern int get_cpu_from_name( const char *name );
extern unsigned int get_alignment(unsigned int align);
extern unsigned int get_page_size(void);
extern unsigned int get_ptr_size(void);
extern unsigned int get_args_size( const ORDDEF *odp );
extern const char *asm_name( const char *func );
extern const char *func_declaration( const char *func );
......
......@@ -757,7 +757,7 @@ int is_undefined( const char *name )
/* output the get_pc thunk if needed */
void output_get_pc_thunk(void)
{
assert( target_cpu == CPU_x86 );
assert( target.cpu == CPU_i386 );
output( "\n\t.text\n" );
output( "\t.align %d\n", get_alignment(4) );
output( "\t%s\n", func_declaration("__wine_spec_get_pc_thunk_eax") );
......@@ -777,9 +777,9 @@ static void output_import_thunk( const char *name, const char *table, int pos )
output( "%s\n", asm_globl(name) );
output_cfi( ".cfi_startproc" );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
if (!UsePIC)
{
output( "\tjmp *(%s+%d)\n", table, pos );
......@@ -1050,9 +1050,9 @@ static void output_delayed_import_thunks( const DLLSPEC *spec )
output( "\t%s\n", func_declaration("__wine_delay_load_asm") );
output( "%s:\n", asm_name("__wine_delay_load_asm") );
output_cfi( ".cfi_startproc" );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
output( "\tpushl %%ecx\n" );
output_cfi( ".cfi_adjust_cfa_offset 4" );
output( "\tpushl %%edx\n" );
......@@ -1137,9 +1137,9 @@ static void output_delayed_import_thunks( const DLLSPEC *spec )
if (thumb_mode) output( "\t.thumb_func\n" );
output( "__wine_delay_imp_%s_%s:\n", import->c_name, name );
output_cfi( ".cfi_startproc" );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
case CPU_x86_64:
output( "\tmovl $%d,%%eax\n", (idx << 16) | j );
output( "\tjmp %s\n", asm_name("__wine_delay_load_asm") );
......@@ -1244,9 +1244,9 @@ void output_stubs( DLLSPEC *spec )
output( "%s:\n", asm_name(name) );
output_cfi( ".cfi_startproc" );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
/* flesh out the stub a bit to make safedisc happy */
output(" \tnop\n" );
output(" \tnop\n" );
......@@ -1398,9 +1398,9 @@ void output_syscalls( DLLSPEC *spec )
output( "\t%s\n", func_declaration(name) );
output( "%s\n", asm_globl(name) );
output_cfi( ".cfi_startproc" );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
if (UsePIC)
{
output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
......@@ -1463,9 +1463,9 @@ void output_syscalls( DLLSPEC *spec )
output_function_size( name );
}
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
if (UsePIC) break;
output( "\t.align %d\n", get_alignment(16) );
output( "\t%s\n", func_declaration("__wine_syscall") );
......@@ -1554,7 +1554,7 @@ static void build_library( const char *output_name, struct strarray files, int c
{
struct strarray args;
if (!create || target_platform != PLATFORM_WINDOWS)
if (!create || target.platform != PLATFORM_WINDOWS)
{
args = find_tool( "ar", NULL );
strarray_add( &args, create ? "rc" : "r" );
......@@ -1571,7 +1571,7 @@ static void build_library( const char *output_name, struct strarray files, int c
if (create) unlink( output_name );
spawn( args );
if (target_platform != PLATFORM_WINDOWS)
if (target.platform != PLATFORM_WINDOWS)
{
struct strarray ranlib = find_tool( "ranlib", NULL );
strarray_add( &ranlib, output_name );
......@@ -1596,9 +1596,9 @@ static void build_windows_import_lib( const char *lib_name, DLLSPEC *spec )
strarray_add( &args, "-d" );
strarray_add( &args, def_file );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
strarray_add( &args, "-m" );
strarray_add( &args, "i386" );
strarray_add( &args, "--as-flags=--32" );
......
......@@ -47,31 +47,7 @@ int unix_lib = 0;
int safe_seh = 0;
int prefer_native = 0;
#ifdef __i386__
enum target_cpu target_cpu = CPU_x86;
#elif defined(__x86_64__)
enum target_cpu target_cpu = CPU_x86_64;
#elif defined(__arm__)
enum target_cpu target_cpu = CPU_ARM;
#elif defined(__aarch64__)
enum target_cpu target_cpu = CPU_ARM64;
#else
#error Unsupported CPU
#endif
#ifdef __APPLE__
enum target_platform target_platform = PLATFORM_APPLE;
#elif defined(__linux__)
enum target_platform target_platform = PLATFORM_LINUX;
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
enum target_platform target_platform = PLATFORM_FREEBSD;
#elif defined(__sun)
enum target_platform target_platform = PLATFORM_SOLARIS;
#elif defined(_WIN32)
enum target_platform target_platform = PLATFORM_MINGW;
#else
enum target_platform target_platform = PLATFORM_UNSPECIFIED;
#endif
struct target target = { 0 };
char *target_alias = NULL;
......@@ -123,22 +99,6 @@ enum exec_mode_values
static enum exec_mode_values exec_mode = MODE_NONE;
static const struct
{
const char *name;
enum target_platform platform;
} platform_names[] =
{
{ "macos", PLATFORM_APPLE },
{ "darwin", PLATFORM_APPLE },
{ "linux", PLATFORM_LINUX },
{ "freebsd", PLATFORM_FREEBSD },
{ "solaris", PLATFORM_SOLARIS },
{ "mingw32", PLATFORM_MINGW },
{ "windows-gnu", PLATFORM_MINGW },
{ "windows", PLATFORM_WINDOWS },
{ "winnt", PLATFORM_MINGW }
};
/* set the dll file name from the input file name */
static void set_dll_file_name( const char *name, DLLSPEC *spec )
......@@ -208,54 +168,12 @@ static void set_syscall_table( const char *id, DLLSPEC *spec )
}
/* set the target CPU and platform */
static void set_target( const char *target )
static void set_target( const char *name )
{
unsigned int i;
char *p, *spec = xstrdup( target );
/* target specification is in the form CPU-MANUFACTURER-OS or CPU-MANUFACTURER-KERNEL-OS */
target_alias = xstrdup( target );
/* get the CPU part */
if ((p = strchr( spec, '-' )))
{
int cpu;
*p++ = 0;
cpu = get_cpu_from_name( spec );
if (cpu == -1) fatal_error( "Unrecognized CPU '%s'\n", spec );
target_cpu = cpu;
}
else if (!strcmp( spec, "mingw32" ))
{
target_cpu = CPU_x86;
p = spec;
}
else
fatal_error( "Invalid target specification '%s'\n", target );
/* get the OS part */
target_platform = PLATFORM_UNSPECIFIED; /* default value */
for (;;)
{
for (i = 0; i < ARRAY_SIZE(platform_names); i++)
{
if (!strncmp( platform_names[i].name, p, strlen(platform_names[i].name) ))
{
target_platform = platform_names[i].platform;
break;
}
}
if (target_platform != PLATFORM_UNSPECIFIED || !(p = strchr( p, '-' ))) break;
p++;
}
target_alias = xstrdup( name );
free( spec );
if (target_cpu == CPU_ARM && is_pe()) thumb_mode = 1;
if (!parse_target( name, &target )) fatal_error( "Unrecognized target '%s'\n", name );
if (target.cpu == CPU_ARM && is_pe()) thumb_mode = 1;
}
/* cleanup on program exit */
......@@ -689,6 +607,9 @@ int main(int argc, char **argv)
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
target = init_argv0_target( argv[0] );
if (target.platform == PLATFORM_CYGWIN) target.platform = PLATFORM_MINGW;
files = parse_options( argc, argv, short_options, long_options, 0, option_callback );
atexit( cleanup ); /* make sure we remove the output file on exit */
......@@ -698,19 +619,7 @@ int main(int argc, char **argv)
strcat( spec->file_name, exec_mode == MODE_EXE ? ".exe" : ".dll" );
init_dll_name( spec );
switch (target_cpu)
{
case CPU_x86:
if (force_pointer_size == 8) target_cpu = CPU_x86_64;
break;
case CPU_x86_64:
if (force_pointer_size == 4) target_cpu = CPU_x86;
break;
default:
if (force_pointer_size == 8)
fatal_error( "Cannot build 64-bit code for this CPU\n" );
break;
}
if (force_pointer_size) set_target_ptr_size( &target, force_pointer_size );
switch(exec_mode)
{
......
......@@ -358,7 +358,7 @@ static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec )
if (odp->type == TYPE_VARARGS)
odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */
if (target_cpu != CPU_x86)
if (target.cpu != CPU_i386)
odp->flags &= ~(FLAG_THISCALL | FLAG_FASTCALL);
if (!(token = GetToken(1)))
......@@ -511,7 +511,7 @@ static const char *parse_spec_flags( DLLSPEC *spec, ORDDEF *odp )
}
else if (!strcmp( token, "i386" )) /* backwards compatibility */
{
odp->flags |= FLAG_CPU(CPU_x86);
odp->flags |= FLAG_CPU(CPU_i386);
}
else
{
......@@ -621,7 +621,7 @@ static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
assert( 0 );
}
if ((odp->flags & FLAG_CPU_MASK) && !(odp->flags & FLAG_CPU(target_cpu)))
if ((odp->flags & FLAG_CPU_MASK) && !(odp->flags & FLAG_CPU(target.cpu)))
{
/* ignore this entry point */
spec->nb_entry_points--;
......
......@@ -685,9 +685,9 @@ void output_res_o_file( DLLSPEC *spec )
strarray_add( &args, res_file );
strarray_add( &args, "-o" );
strarray_add( &args, output_file_name );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
strarray_add( &args, "-F" );
strarray_add( &args, "pe-i386" );
break;
......
......@@ -254,9 +254,9 @@ static void output_relay_debug( DLLSPEC *spec )
if (!needs_relay( odp )) continue;
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
output( "\t.align %d\n", get_alignment(4) );
output( "\t.long 0x90909090,0x90909090\n" );
output( "__wine_spec_relay_entry_point_%d:\n", i );
......@@ -457,7 +457,7 @@ void output_exports( DLLSPEC *spec )
output( "\t%s .L__wine_spec_forwards+%u\n", func_ptr, fwd_size );
fwd_size += strlen(odp->link_name) + 1;
}
else if ((odp->flags & FLAG_IMPORT) && (target_cpu == CPU_x86 || target_cpu == CPU_x86_64))
else if ((odp->flags & FLAG_IMPORT) && (target.cpu == CPU_i386 || target.cpu == CPU_x86_64))
{
name = odp->name ? odp->name : odp->export_name;
if (name) output( "\t%s %s_%s\n", func_ptr, asm_name("__wine_spec_imp"), name );
......@@ -585,9 +585,9 @@ void output_exports( DLLSPEC *spec )
else output( "%s_%u:\n", asm_name("__wine_spec_imp"), i );
output_cfi( ".cfi_startproc" );
switch (target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
output( "\t.byte 0x8b,0xff,0x55,0x8b,0xec,0x5d\n" ); /* hotpatch prolog */
if (UsePIC)
{
......@@ -623,7 +623,7 @@ void output_module( DLLSPEC *spec )
/* Reserve some space for the PE header */
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
......@@ -640,9 +640,9 @@ void output_module( DLLSPEC *spec )
output( "\t.skip %u\n", 65536 + page_size );
break;
default:
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
case CPU_x86_64:
output( "\n\t.section \".init\",\"ax\"\n" );
output( "\tjmp 1f\n" );
......@@ -671,9 +671,9 @@ void output_module( DLLSPEC *spec )
output( ".L__wine_spec_rva_base:\n" );
output( "\t.long 0x4550\n" ); /* Signature */
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
case CPU_i386: machine = IMAGE_FILE_MACHINE_I386; break;
case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
case CPU_ARM: machine = IMAGE_FILE_MACHINE_ARMNT; break;
case CPU_ARM64: machine = IMAGE_FILE_MACHINE_ARM64; break;
......@@ -739,7 +739,7 @@ void output_module( DLLSPEC *spec )
output_data_directories( data_dirs );
if (target_platform == PLATFORM_APPLE)
if (target.platform == PLATFORM_APPLE)
output( "\t.lcomm %s,4\n", asm_name("_end") );
}
......@@ -964,9 +964,9 @@ void output_fake_module( DLLSPEC *spec )
put_data( fakedll_signature, sizeof(fakedll_signature) );
put_dword( 0x4550 ); /* Signature */
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86: put_word( IMAGE_FILE_MACHINE_I386 ); break;
case CPU_i386: put_word( IMAGE_FILE_MACHINE_I386 ); break;
case CPU_x86_64: put_word( IMAGE_FILE_MACHINE_AMD64 ); break;
case CPU_ARM: put_word( IMAGE_FILE_MACHINE_ARMNT ); break;
case CPU_ARM64: put_word( IMAGE_FILE_MACHINE_ARM64 ); break;
......@@ -1105,7 +1105,7 @@ void output_def_file( DLLSPEC *spec, int import_only )
case TYPE_STDCALL:
{
int at_param = get_args_size( odp );
if (!kill_at && target_cpu == CPU_x86) output( "@%d", at_param );
if (!kill_at && target.cpu == CPU_i386) output( "@%d", at_param );
if (import_only) break;
if (odp->flags & FLAG_FORWARD)
output( "=%s", odp->link_name );
......@@ -1114,7 +1114,7 @@ void output_def_file( DLLSPEC *spec, int import_only )
break;
}
case TYPE_STUB:
if (!kill_at && target_cpu == CPU_x86) output( "@%d", get_args_size( odp ));
if (!kill_at && target.cpu == CPU_i386) output( "@%d", get_args_size( odp ));
is_private = 1;
break;
default:
......
......@@ -32,28 +32,6 @@
static struct strarray tmp_files;
static const char *output_file_source_name;
static const struct
{
const char *name;
enum target_cpu cpu;
} cpu_names[] =
{
{ "i386", CPU_x86 },
{ "i486", CPU_x86 },
{ "i586", CPU_x86 },
{ "i686", CPU_x86 },
{ "i786", CPU_x86 },
{ "amd64", CPU_x86_64 },
{ "x86_64", CPU_x86_64 },
{ "arm", CPU_ARM },
{ "armv5", CPU_ARM },
{ "armv6", CPU_ARM },
{ "armv7", CPU_ARM },
{ "armv7a", CPU_ARM },
{ "arm64", CPU_ARM64 },
{ "aarch64", CPU_ARM64 },
};
/* atexit handler to clean tmp files */
void cleanup_tmp_files(void)
{
......@@ -338,7 +316,7 @@ struct strarray get_as_command(void)
if (force_pointer_size)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
strarray_add( &args, "-arch" );
......@@ -369,7 +347,7 @@ struct strarray get_ld_command(void)
if (force_pointer_size)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
strarray_add( &args, "-arch" );
......@@ -391,7 +369,7 @@ struct strarray get_ld_command(void)
}
}
if (target_cpu == CPU_ARM && !is_pe())
if (target.cpu == CPU_ARM && !is_pe())
strarray_add( &args, "--no-wchar-size-warning" );
return args;
......@@ -696,7 +674,7 @@ int remove_stdcall_decoration( char *name )
{
char *p, *end = strrchr( name, '@' );
if (!end || !end[1] || end == name) return -1;
if (target_cpu != CPU_x86) return -1;
if (target.cpu != CPU_i386) return -1;
/* make sure all the rest is digits */
for (p = end + 1; *p; p++) if (!isdigit(*p)) return -1;
*end = 0;
......@@ -822,7 +800,7 @@ const char *get_link_name( const ORDDEF *odp )
static char *buffer;
char *ret;
if (target_cpu != CPU_x86) return odp->link_name;
if (target.cpu != CPU_i386) return odp->link_name;
switch (odp->type)
{
......@@ -877,16 +855,6 @@ int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const
}
/* parse a cpu name and return the corresponding value */
int get_cpu_from_name( const char *name )
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(cpu_names); i++)
if (!strcmp( cpu_names[i].name, name )) return cpu_names[i].cpu;
return -1;
}
/*****************************************************************
* Function: get_alignment
*
......@@ -917,11 +885,11 @@ unsigned int get_alignment(unsigned int align)
assert( !(align & (align - 1)) );
switch(target_cpu)
switch (target.cpu)
{
case CPU_x86:
case CPU_i386:
case CPU_x86_64:
if (target_platform != PLATFORM_APPLE) return align;
if (target.platform != PLATFORM_APPLE) return align;
/* fall through */
case CPU_ARM:
case CPU_ARM64:
......@@ -940,23 +908,6 @@ unsigned int get_page_size(void)
return 0x1000; /* same on all platforms */
}
/* return the size of a pointer on the target CPU */
unsigned int get_ptr_size(void)
{
switch(target_cpu)
{
case CPU_x86:
case CPU_ARM:
return 4;
case CPU_x86_64:
case CPU_ARM64:
return 8;
}
/* unreached */
assert(0);
return 0;
}
/* return the total size in bytes of the arguments on the stack */
unsigned int get_args_size( const ORDDEF *odp )
{
......@@ -968,12 +919,12 @@ unsigned int get_args_size( const ORDDEF *odp )
{
case ARG_INT64:
case ARG_DOUBLE:
if (target_cpu == CPU_ARM) size = (size + 7) & ~7;
if (target.cpu == CPU_ARM) size = (size + 7) & ~7;
size += 8;
break;
case ARG_INT128:
/* int128 is passed as pointer on x86_64 */
if (target_cpu != CPU_x86_64)
if (target.cpu != CPU_x86_64)
{
size += 16;
break;
......@@ -992,11 +943,11 @@ const char *asm_name( const char *sym )
{
static char *buffer;
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
if (target_cpu != CPU_x86) return sym;
if (target.cpu != CPU_i386) return sym;
if (sym[0] == '@') return sym; /* fastcall */
/* fall through */
case PLATFORM_APPLE:
......@@ -1014,7 +965,7 @@ const char *func_declaration( const char *func )
{
static char *buffer;
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
return "";
......@@ -1026,7 +977,7 @@ const char *func_declaration( const char *func )
break;
default:
free( buffer );
switch(target_cpu)
switch (target.cpu)
{
case CPU_ARM:
buffer = strmake( ".type %s,%%function%s", func,
......@@ -1047,7 +998,7 @@ const char *func_declaration( const char *func )
/* output a size declaration for an assembly function */
void output_function_size( const char *name )
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
case PLATFORM_MINGW:
......@@ -1078,7 +1029,7 @@ void output_rva( const char *format, ... )
va_list valist;
va_start( valist, format );
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
......@@ -1098,14 +1049,14 @@ void output_rva( const char *format, ... )
/* output the GNU note for non-exec stack */
void output_gnu_stack_note(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
case PLATFORM_APPLE:
break;
default:
switch(target_cpu)
switch (target.cpu)
{
case CPU_ARM:
case CPU_ARM64:
......@@ -1125,15 +1076,15 @@ const char *asm_globl( const char *func )
static char *buffer;
free( buffer );
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
buffer = strmake( "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
break;
case PLATFORM_MINGW:
case PLATFORM_WINDOWS:
buffer = strmake( "\t.globl %s%s\n%s%s:", target_cpu == CPU_x86 ? "_" : "", func,
target_cpu == CPU_x86 ? "_" : "", func );
buffer = strmake( "\t.globl %s%s\n%s%s:", target.cpu == CPU_i386 ? "_" : "", func,
target.cpu == CPU_i386 ? "_" : "", func );
break;
default:
buffer = strmake( "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
......@@ -1155,7 +1106,7 @@ const char *get_asm_ptr_keyword(void)
const char *get_asm_string_keyword(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
return ".asciz";
......@@ -1166,7 +1117,7 @@ const char *get_asm_string_keyword(void)
const char *get_asm_export_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".data";
case PLATFORM_MINGW:
......@@ -1177,7 +1128,7 @@ const char *get_asm_export_section(void)
const char *get_asm_rodata_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".const";
default: return ".section .rodata";
......@@ -1186,7 +1137,7 @@ const char *get_asm_rodata_section(void)
const char *get_asm_rsrc_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".data";
case PLATFORM_MINGW:
......@@ -1197,7 +1148,7 @@ const char *get_asm_rsrc_section(void)
const char *get_asm_string_section(void)
{
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE: return ".cstring";
default: return ".section .rodata";
......@@ -1208,7 +1159,7 @@ const char *arm64_page( const char *sym )
{
static char *buffer;
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
free( buffer );
......@@ -1224,7 +1175,7 @@ const char *arm64_pageoff( const char *sym )
static char *buffer;
free( buffer );
switch (target_platform)
switch (target.platform)
{
case PLATFORM_APPLE:
buffer = strmake( "%s@PAGEOFF", sym );
......
......@@ -115,10 +115,12 @@ static char* try_lib_path(const char* dir, const char* pre,
return 0;
}
static file_type guess_lib_type(enum target_platform platform, const char* dir,
static file_type guess_lib_type(struct target target, const char* dir,
const char* library, const char *prefix, const char *suffix, char** file)
{
if (platform != PLATFORM_WINDOWS && platform != PLATFORM_MINGW && platform != PLATFORM_CYGWIN)
if (target.platform != PLATFORM_WINDOWS &&
target.platform != PLATFORM_MINGW &&
target.platform != PLATFORM_CYGWIN)
{
/* Unix shared object */
if ((*file = try_lib_path(dir, prefix, library, ".so", file_so)))
......@@ -140,7 +142,7 @@ static file_type guess_lib_type(enum target_platform platform, const char* dir,
return file_na;
}
file_type get_lib_type(enum target_platform platform, struct strarray path, const char *library,
file_type get_lib_type(struct target target, struct strarray path, const char *library,
const char *prefix, const char *suffix, char** file)
{
unsigned int i;
......@@ -148,7 +150,7 @@ file_type get_lib_type(enum target_platform platform, struct strarray path, cons
if (!suffix) suffix = ".a";
for (i = 0; i < path.count; i++)
{
file_type type = guess_lib_type(platform, path.str[i], library, prefix, suffix, file);
file_type type = guess_lib_type(target, path.str[i], library, prefix, suffix, file);
if (type != file_na) return type;
}
return file_na;
......
......@@ -32,22 +32,6 @@
# endif
#endif
enum target_cpu
{
CPU_x86, CPU_x86_64, CPU_ARM, CPU_ARM64
};
enum target_platform
{
PLATFORM_UNSPECIFIED,
PLATFORM_APPLE,
PLATFORM_ANDROID,
PLATFORM_SOLARIS,
PLATFORM_WINDOWS,
PLATFORM_MINGW,
PLATFORM_CYGWIN
};
void DECLSPEC_NORETURN error(const char* s, ...);
typedef enum {
......@@ -57,7 +41,7 @@ typedef enum {
void create_file(const char* name, int mode, const char* fmt, ...);
file_type get_file_type(const char* filename);
file_type get_lib_type(enum target_platform platform, struct strarray path, const char *library,
file_type get_lib_type(struct target target, struct strarray path, const char *library,
const char *prefix, const char *suffix, char** file);
const char *find_binary( struct strarray prefix, const char *name );
int spawn(struct strarray prefix, struct strarray arr, int ignore_errors);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment