From f67301e9ecaedc6920470782910f7df79cb68b19 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 14 Nov 2018 18:18:17 +0100 Subject: [PATCH] widl: Always generate files for the target platform only. Signed-off-by: Alexandre Julliard --- tools/widl/client.c | 22 +---------- tools/widl/proxy.c | 24 +---------- tools/widl/register.c | 2 +- tools/widl/server.c | 22 +---------- tools/widl/typelib.c | 2 +- tools/widl/widl.c | 88 +++++++++++++++++++++++++++-------------- tools/widl/widl.h | 9 ++++- tools/widl/widl.man.in | 10 ++--- tools/widl/widltypes.h | 1 - tools/widl/write_msft.c | 4 +- 10 files changed, 75 insertions(+), 109 deletions(-) diff --git a/tools/widl/client.c b/tools/widl/client.c index a3b2bbb6256..30b0dce5b8a 100644 --- a/tools/widl/client.c +++ b/tools/widl/client.c @@ -627,26 +627,6 @@ void write_client(const statement_list_t *stmts) if (!client) return; - if (do_win32 && do_win64) - { - fprintf(client, "#ifndef _WIN64\n\n"); - pointer_size = 4; - write_client_routines( stmts ); - fprintf(client, "\n#else /* _WIN64 */\n\n"); - pointer_size = 8; - write_client_routines( stmts ); - fprintf(client, "\n#endif /* _WIN64 */\n"); - } - else if (do_win32) - { - pointer_size = 4; - write_client_routines( stmts ); - } - else if (do_win64) - { - pointer_size = 8; - write_client_routines( stmts ); - } - + write_client_routines( stmts ); fclose(client); } diff --git a/tools/widl/proxy.c b/tools/widl/proxy.c index 87c27be9759..8d0e8b2cc50 100644 --- a/tools/widl/proxy.c +++ b/tools/widl/proxy.c @@ -942,7 +942,7 @@ static void write_proxy_routines(const statement_list_t *stmts) write_stubdesc(expr_eval_routines); print_proxy( "#if !defined(__RPC_WIN%u__)\n", pointer_size == 8 ? 64 : 32); - print_proxy( "#error Currently only Wine and WIN32 are supported.\n"); + print_proxy( "#error Invalid build platform for this proxy.\n"); print_proxy( "#endif\n"); print_proxy( "\n"); write_procformatstring(proxy, stmts, need_proxy); @@ -1053,26 +1053,6 @@ void write_proxies(const statement_list_t *stmts) init_proxy(stmts); if(!proxy) return; - if (do_win32 && do_win64) - { - fprintf(proxy, "\n#ifndef _WIN64\n\n"); - pointer_size = 4; - write_proxy_routines( stmts ); - fprintf(proxy, "\n#else /* _WIN64 */\n\n"); - pointer_size = 8; - write_proxy_routines( stmts ); - fprintf(proxy, "\n#endif /* _WIN64 */\n"); - } - else if (do_win32) - { - pointer_size = 4; - write_proxy_routines( stmts ); - } - else if (do_win64) - { - pointer_size = 8; - write_proxy_routines( stmts ); - } - + write_proxy_routines( stmts ); fclose(proxy); } diff --git a/tools/widl/register.c b/tools/widl/register.c index 210fb747158..1c369e7c5ee 100644 --- a/tools/widl/register.c +++ b/tools/widl/register.c @@ -325,7 +325,7 @@ void output_typelib_regscript( const typelib_t *typelib ) sprintf(resname, "%s\\%d", typelib_name, expr->cval); } put_str( indent, "'%x' { %s = s '%%MODULE%%%s' }\n", - lcid_expr ? lcid_expr->cval : 0, typelib_kind == SYS_WIN64 ? "win64" : "win32", id_part ); + lcid_expr ? lcid_expr->cval : 0, pointer_size == 8 ? "win64" : "win32", id_part ); put_str( indent, "FLAGS = s '%u'\n", flags ); put_str( --indent, "}\n" ); put_str( --indent, "}\n" ); diff --git a/tools/widl/server.c b/tools/widl/server.c index 783ff900384..d165bbb0490 100644 --- a/tools/widl/server.c +++ b/tools/widl/server.c @@ -544,26 +544,6 @@ void write_server(const statement_list_t *stmts) if (!server) return; - if (do_win32 && do_win64) - { - fprintf(server, "#ifndef _WIN64\n\n"); - pointer_size = 4; - write_server_routines( stmts ); - fprintf(server, "\n#else /* _WIN64 */\n\n"); - pointer_size = 8; - write_server_routines( stmts ); - fprintf(server, "\n#endif /* _WIN64 */\n"); - } - else if (do_win32) - { - pointer_size = 4; - write_server_routines( stmts ); - } - else if (do_win64) - { - pointer_size = 8; - write_server_routines( stmts ); - } - + write_server_routines( stmts ); fclose(server); } diff --git a/tools/widl/typelib.c b/tools/widl/typelib.c index 9b1de2c8c0a..93f8f4de195 100644 --- a/tools/widl/typelib.c +++ b/tools/widl/typelib.c @@ -169,7 +169,7 @@ unsigned short get_type_vt(type_t *t) else return VT_I8; case TYPE_BASIC_INT3264: - if (typelib_kind == SYS_WIN64) + if (pointer_size == 8) { if (type_basic_get_sign(t) > 0) return VT_UI8; diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 7e411cfcf00..8fe8e4c6258 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -43,11 +43,6 @@ #include "wine/wpp.h" #include "header.h" -/* future options to reserve characters for: */ -/* A = ACF input filename */ -/* J = do not search standard include path */ -/* w = select win16/win32 output (?) */ - static const char usage[] = "Usage: widl [options...] infile.idl\n" " or: widl [options...] --dlldata-only name1 [name2...]\n" @@ -63,7 +58,7 @@ static const char usage[] = " -H file Name of header file (default is infile.h)\n" " -I path Set include search dir to path (multiple -I allowed)\n" " --local-stubs=file Write empty stubs for call_as/local methods to file\n" -" -m32, -m64 Set the kind of typelib to build (Win32 or Win64)\n" +" -m32, -m64 Set the target architecture (Win32 or Win64)\n" " -N Do not preprocess input\n" " --oldnames Use old naming conventions\n" " -o, --output=NAME Set the output file name\n" @@ -81,8 +76,7 @@ static const char usage[] = " -u Generate interface identifiers file\n" " -V Print version and exit\n" " -W Enable pedantic warnings\n" -" --win32 Only generate 32-bit code\n" -" --win64 Only generate 64-bit code\n" +" --win32, --win64 Set the target architecture (Win32 or Win64)\n" " --win32-align n Set win32 structure alignment to 'n'\n" " --win64-align n Set win64 structure alignment to 'n'\n" "Debug level 'n' is a bitmask with following meaning:\n" @@ -97,6 +91,20 @@ 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(__powerpc__) +enum target_cpu target_cpu = CPU_POWERPC; +#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 + int debuglevel = DEBUGLEVEL_NONE; int parser_debug, yy_flex_debug; @@ -113,8 +121,6 @@ int do_idfile = 0; int do_dlldata = 0; static int no_preprocess = 0; int old_names = 0; -int do_win32 = 1; -int do_win64 = 1; int win32_packing = 8; int win64_packing = 8; int winrt_mode = 0; @@ -147,7 +153,6 @@ int line_number = 1; static FILE *idfile; unsigned int pointer_size = 0; -syskind_t typelib_kind = sizeof(void*) == 8 ? SYS_WIN64 : SYS_WIN32; time_t now; @@ -187,6 +192,7 @@ static const struct option long_options[] = { { "prefix-client", 1, NULL, PREFIX_CLIENT_OPTION }, { "prefix-server", 1, NULL, PREFIX_SERVER_OPTION }, { "robust", 0, NULL, ROBUST_OPTION }, + { "target", 0, NULL, 'b' }, { "winrt", 0, NULL, RT_OPTION }, { "win32", 0, NULL, WIN32_OPTION }, { "win64", 0, NULL, WIN64_OPTION }, @@ -268,20 +274,24 @@ static void set_target( const char *target ) { static const struct { - const char *name; - syskind_t kind; + const char *name; + enum target_cpu cpu; } cpu_names[] = { - { "i386", SYS_WIN32 }, - { "i486", SYS_WIN32 }, - { "i586", SYS_WIN32 }, - { "i686", SYS_WIN32 }, - { "i786", SYS_WIN32 }, - { "amd64", SYS_WIN64 }, - { "x86_64", SYS_WIN64 }, - { "powerpc", SYS_WIN32 }, - { "arm", SYS_WIN32 }, - { "aarch64", SYS_WIN64 } + { "i386", CPU_x86 }, + { "i486", CPU_x86 }, + { "i586", CPU_x86 }, + { "i686", CPU_x86 }, + { "i786", CPU_x86 }, + { "amd64", CPU_x86_64 }, + { "x86_64", CPU_x86_64 }, + { "powerpc", CPU_POWERPC }, + { "arm", CPU_ARM }, + { "armv5", CPU_ARM }, + { "armv6", CPU_ARM }, + { "armv7", CPU_ARM }, + { "arm64", CPU_ARM64 }, + { "aarch64", CPU_ARM64 }, }; unsigned int i; @@ -295,7 +305,7 @@ static void set_target( const char *target ) { if (!strcmp( cpu_names[i].name, spec )) { - typelib_kind = cpu_names[i].kind; + target_cpu = cpu_names[i].cpu; free( spec ); return; } @@ -605,12 +615,10 @@ int main(int argc,char *argv[]) use_abi_namespace = 1; break; case WIN32_OPTION: - do_win32 = 1; - do_win64 = 0; + pointer_size = 4; break; case WIN64_OPTION: - do_win32 = 0; - do_win64 = 1; + pointer_size = 8; break; case WIN32_ALIGN_OPTION: win32_packing = strtol(optarg, NULL, 0); @@ -663,8 +671,8 @@ int main(int argc,char *argv[]) wpp_add_include_path(optarg); break; case 'm': - if (!strcmp( optarg, "32" )) typelib_kind = SYS_WIN32; - else if (!strcmp( optarg, "64" )) typelib_kind = SYS_WIN64; + if (!strcmp( optarg, "32" )) pointer_size = 4; + else if (!strcmp( optarg, "64" )) pointer_size = 8; break; case 'N': no_preprocess = 1; @@ -728,6 +736,26 @@ int main(int argc,char *argv[]) wpp_add_include_path(DEFAULT_INCLUDE_DIR); #endif + 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_ARM64: + if (pointer_size == 4) error( "Cannot build 32-bit code for this CPU\n" ); + pointer_size = 8; + break; + default: + if (pointer_size == 8) error( "Cannot build 64-bit code for this CPU\n" ); + pointer_size = 4; + break; + } + /* if nothing specified, try to guess output type from the output file name */ if (output_name && do_everything && !do_header && !do_typelib && !do_proxies && !do_client && !do_server && !do_regscript && !do_idfile && !do_dlldata) diff --git a/tools/widl/widl.h b/tools/widl/widl.h index 118e2245c2e..4f4252e3ea3 100644 --- a/tools/widl/widl.h +++ b/tools/widl/widl.h @@ -45,8 +45,6 @@ extern int do_regscript; extern int do_idfile; extern int do_dlldata; extern int old_names; -extern int do_win32; -extern int do_win64; extern int win32_packing; extern int win64_packing; extern int winrt_mode; @@ -76,6 +74,13 @@ extern time_t now; extern int line_number; extern int char_number; +enum target_cpu +{ + CPU_x86, CPU_x86_64, CPU_POWERPC, CPU_ARM, CPU_ARM64, CPU_LAST = CPU_ARM64 +}; + +extern enum target_cpu target_cpu; + enum stub_mode { MODE_Os, /* inline stubs */ diff --git a/tools/widl/widl.man.in b/tools/widl/widl.man.in index 7d89db38faa..ec81488a0e8 100644 --- a/tools/widl/widl.man.in +++ b/tools/widl/widl.man.in @@ -35,10 +35,12 @@ Set the name of the output file. When generating multiple output files, this sets only the base name of the file; the respective output files are then named \fIname\fR.h, \fIname\fR_p.c, etc. If a full file name with extension is specified, only that file is generated. -.IP "\fB-b \fIcpu-manufacturer\fR[\fB-\fIkernel\fR]\fB-\fIos\fR" +.IP "\fB-b, --target=\fIcpu-manufacturer\fR[\fI-kernel\fR]\fI-os\fR" Set the target architecture when cross-compiling. The target specification is in the standard autoconf format as returned by \fBconfig.sub\fR. +.IP "\fB-m32, -m64, --win32, --win64\fR" +Force the target architecture to 32-bit or 64-bit. .PP .B Header options: .IP "\fB-h\fR" @@ -51,8 +53,6 @@ Use old naming conventions. Generate a type library. The default output filename is \fIinfile\fB.tlb\fR. If the output file name ends in \fB.res\fR, a binary resource file containing the type library is generated instead. -.IP "\fB-m32, -m64\fR" -Generate a Win32 or Win64 type library respectively. .PP .B UUID file options: .IP "\fB-u\fR" @@ -78,10 +78,6 @@ Prefix to put on the name of server stubs. .IP "\fB-s\fR" Generate a server stub file. The default output filename is \fIinfile\fB_s.c\fR. -.IP "\fB--win32\fR, \fB--win64\fR" -Only generate 32-bit or 64-bit code respectively (the default is to -generate both 32-bit and 64-bit versions into the same destination -file). .PP .IP "\fB--winrt\fR" Enable Windows Runtime mode. diff --git a/tools/widl/widltypes.h b/tools/widl/widltypes.h index 08584de58e3..37792b24895 100644 --- a/tools/widl/widltypes.h +++ b/tools/widl/widltypes.h @@ -553,7 +553,6 @@ typedef enum { SYS_WIN64 } syskind_t; -extern syskind_t typelib_kind; extern user_type_list_t user_type_list; extern context_handle_list_t context_handle_list; extern generic_handle_list_t generic_handle_list; diff --git a/tools/widl/write_msft.c b/tools/widl/write_msft.c index 88a80d12ed7..cb4f0f38dd7 100644 --- a/tools/widl/write_msft.c +++ b/tools/widl/write_msft.c @@ -2653,8 +2653,6 @@ int create_msft_typelib(typelib_t *typelib) GUID midl_info_guid = {0xde77ba65,0x517c,0x11d1,{0xa2,0xda,0x00,0x00,0xf8,0x77,0x3c,0xe9}}; char info_string[128]; - pointer_size = (typelib_kind == SYS_WIN64) ? 8 : 4; - msft = xmalloc(sizeof(*msft)); memset(msft, 0, sizeof(*msft)); msft->typelib = typelib; @@ -2662,7 +2660,7 @@ int create_msft_typelib(typelib_t *typelib) ctl2_init_header(msft); ctl2_init_segdir(msft); - msft->typelib_header.varflags |= typelib_kind; + msft->typelib_header.varflags |= (pointer_size == 8) ? SYS_WIN64 : SYS_WIN32; /* * The following two calls return an offset or -1 if out of memory. We