- Merge to trunk r37270.
[reactos.git] / reactos / tools / winebuild / spec32.c
1 /*
2 * 32-bit spec files
3 *
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25 #include "config.h"
26 #include "wine/port.h"
27
28 #include <assert.h>
29 #include <ctype.h>
30 #include <stdarg.h>
31 #include <string.h>
32
33 #include "winglue.h"
34 //#include "wine/exception.h"
35 #include "build.h"
36
37
38 /* check if entry point needs a relay thunk */
39 static inline int needs_relay( const ORDDEF *odp )
40 {
41 /* skip nonexistent entry points */
42 if (!odp) return 0;
43 /* skip non-functions */
44 if ((odp->type != TYPE_STDCALL) && (odp->type != TYPE_CDECL)) return 0;
45 /* skip norelay and forward entry points */
46 if (odp->flags & (FLAG_NORELAY|FLAG_FORWARD)) return 0;
47 return 1;
48 }
49
50 /* check if dll will output relay thunks */
51 int has_relays( DLLSPEC *spec )
52 {
53 int i;
54
55 if (target_cpu != CPU_x86) return 0;
56
57 for (i = spec->base; i <= spec->limit; i++)
58 {
59 ORDDEF *odp = spec->ordinals[i];
60 if (needs_relay( odp )) return 1;
61 }
62 return 0;
63 }
64
65 /*******************************************************************
66 * make_internal_name
67 *
68 * Generate an internal name for an entry point. Used for stubs etc.
69 */
70 static const char *make_internal_name( const ORDDEF *odp, DLLSPEC *spec, const char *prefix )
71 {
72 static char buffer[256];
73 if (odp->name || odp->export_name)
74 {
75 char *p;
76 sprintf( buffer, "__wine_%s_%s_%s", prefix, spec->file_name,
77 odp->name ? odp->name : odp->export_name );
78 /* make sure name is a legal C identifier */
79 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
80 if (!*p) return buffer;
81 }
82 sprintf( buffer, "__wine_%s_%s_%d", prefix, make_c_identifier(spec->file_name), odp->ordinal );
83 return buffer;
84 }
85
86
87 /*******************************************************************
88 * output_relay_debug
89 *
90 * Output entry points for relay debugging
91 */
92 static void output_relay_debug( DLLSPEC *spec )
93 {
94 int i;
95 unsigned int j, args, flags;
96
97 /* first the table of entry point offsets */
98
99 output( "\t%s\n", get_asm_rodata_section() );
100 output( "\t.align %d\n", get_alignment(4) );
101 output( ".L__wine_spec_relay_entry_point_offsets:\n" );
102
103 for (i = spec->base; i <= spec->limit; i++)
104 {
105 ORDDEF *odp = spec->ordinals[i];
106
107 if (needs_relay( odp ))
108 output( "\t.long .L__wine_spec_relay_entry_point_%d-__wine_spec_relay_entry_points\n", i );
109 else
110 output( "\t.long 0\n" );
111 }
112
113 /* then the table of argument types */
114
115 output( "\t.align %d\n", get_alignment(4) );
116 output( ".L__wine_spec_relay_arg_types:\n" );
117
118 for (i = spec->base; i <= spec->limit; i++)
119 {
120 ORDDEF *odp = spec->ordinals[i];
121 unsigned int mask = 0;
122
123 if (needs_relay( odp ))
124 {
125 for (j = 0; j < 16 && odp->u.func.arg_types[j]; j++)
126 {
127 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
128 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
129 }
130 }
131 output( "\t.long 0x%08x\n", mask );
132 }
133
134 /* then the relay thunks */
135
136 output( "\t.text\n" );
137 output( "__wine_spec_relay_entry_points:\n" );
138 output( "\tnop\n" ); /* to avoid 0 offset */
139
140 for (i = spec->base; i <= spec->limit; i++)
141 {
142 ORDDEF *odp = spec->ordinals[i];
143
144 if (!needs_relay( odp )) continue;
145
146 output( "\t.align %d\n", get_alignment(4) );
147 output( ".L__wine_spec_relay_entry_point_%d:\n", i );
148
149 if (odp->flags & FLAG_REGISTER)
150 output( "\tpushl %%eax\n" );
151 else
152 output( "\tpushl %%esp\n" );
153
154 args = strlen(odp->u.func.arg_types);
155 flags = 0;
156 if (odp->flags & FLAG_RET64) flags |= 1;
157 if (odp->type == TYPE_STDCALL) flags |= 2;
158 output( "\tpushl $%u\n", (flags << 24) | (args << 16) | (i - spec->base) );
159
160 if (UsePIC)
161 {
162 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
163 output( "1:\tleal .L__wine_spec_relay_descr-1b(%%eax),%%eax\n" );
164 }
165 else output( "\tmovl $.L__wine_spec_relay_descr,%%eax\n" );
166 output( "\tpushl %%eax\n" );
167
168 if (odp->flags & FLAG_REGISTER)
169 {
170 output( "\tcall *8(%%eax)\n" );
171 }
172 else
173 {
174 output( "\tcall *4(%%eax)\n" );
175 if (odp->type == TYPE_STDCALL)
176 output( "\tret $%u\n", args * get_ptr_size() );
177 else
178 output( "\tret\n" );
179 }
180 }
181 }
182
183 /*******************************************************************
184 * output_exports
185 *
186 * Output the export table for a Win32 module.
187 */
188 static void output_exports( DLLSPEC *spec )
189 {
190 int i, fwd_size = 0;
191 int nr_exports = spec->base <= spec->limit ? spec->limit - spec->base + 1 : 0;
192
193 if (!nr_exports) return;
194
195 output( "\n/* export table */\n\n" );
196 output( "\t.data\n" );
197 output( "\t.align %d\n", get_alignment(4) );
198 output( ".L__wine_spec_exports:\n" );
199
200 /* export directory header */
201
202 output( "\t.long 0\n" ); /* Characteristics */
203 output( "\t.long 0\n" ); /* TimeDateStamp */
204 output( "\t.long 0\n" ); /* MajorVersion/MinorVersion */
205 output( "\t.long .L__wine_spec_exp_names-.L__wine_spec_rva_base\n" ); /* Name */
206 output( "\t.long %u\n", spec->base ); /* Base */
207 output( "\t.long %u\n", nr_exports ); /* NumberOfFunctions */
208 output( "\t.long %u\n", spec->nb_names ); /* NumberOfNames */
209 output( "\t.long .L__wine_spec_exports_funcs-.L__wine_spec_rva_base\n" ); /* AddressOfFunctions */
210 if (spec->nb_names)
211 {
212 output( "\t.long .L__wine_spec_exp_name_ptrs-.L__wine_spec_rva_base\n" ); /* AddressOfNames */
213 output( "\t.long .L__wine_spec_exp_ordinals-.L__wine_spec_rva_base\n" ); /* AddressOfNameOrdinals */
214 }
215 else
216 {
217 output( "\t.long 0\n" ); /* AddressOfNames */
218 output( "\t.long 0\n" ); /* AddressOfNameOrdinals */
219 }
220
221 /* output the function pointers */
222
223 output( "\n.L__wine_spec_exports_funcs:\n" );
224 for (i = spec->base; i <= spec->limit; i++)
225 {
226 ORDDEF *odp = spec->ordinals[i];
227 if (!odp) output( "\t%s 0\n", get_asm_ptr_keyword() );
228 else switch(odp->type)
229 {
230 case TYPE_EXTERN:
231 case TYPE_STDCALL:
232 case TYPE_VARARGS:
233 case TYPE_CDECL:
234 if (odp->flags & FLAG_FORWARD)
235 {
236 output( "\t%s .L__wine_spec_forwards+%u\n", get_asm_ptr_keyword(), fwd_size );
237 fwd_size += strlen(odp->link_name) + 1;
238 }
239 else if (odp->flags & FLAG_EXT_LINK)
240 {
241 output( "\t%s %s_%s\n",
242 get_asm_ptr_keyword(), asm_name("__wine_spec_ext_link"), odp->link_name );
243 }
244 else
245 {
246 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
247 }
248 break;
249 case TYPE_STUB:
250 output( "\t%s %s\n", get_asm_ptr_keyword(),
251 asm_name( get_stub_name( odp, spec )) );
252 break;
253 default:
254 assert(0);
255 }
256 }
257
258 if (spec->nb_names)
259 {
260 /* output the function name pointers */
261
262 int namepos = strlen(spec->file_name) + 1;
263
264 output( "\n.L__wine_spec_exp_name_ptrs:\n" );
265 for (i = 0; i < spec->nb_names; i++)
266 {
267 output( "\t.long .L__wine_spec_exp_names+%u-.L__wine_spec_rva_base\n", namepos );
268 namepos += strlen(spec->names[i]->name) + 1;
269 }
270
271 /* output the function ordinals */
272
273 output( "\n.L__wine_spec_exp_ordinals:\n" );
274 for (i = 0; i < spec->nb_names; i++)
275 {
276 output( "\t%s %d\n",
277 get_asm_short_keyword(), spec->names[i]->ordinal - spec->base );
278 }
279 if (spec->nb_names % 2)
280 {
281 output( "\t%s 0\n", get_asm_short_keyword() );
282 }
283 }
284
285 /* output the export name strings */
286
287 output( "\n.L__wine_spec_exp_names:\n" );
288 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
289 for (i = 0; i < spec->nb_names; i++)
290 output( "\t%s \"%s\"\n",
291 get_asm_string_keyword(), spec->names[i]->name );
292
293 /* output forward strings */
294
295 if (fwd_size)
296 {
297 output( "\n.L__wine_spec_forwards:\n" );
298 for (i = spec->base; i <= spec->limit; i++)
299 {
300 ORDDEF *odp = spec->ordinals[i];
301 if (odp && (odp->flags & FLAG_FORWARD))
302 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->link_name );
303 }
304 }
305 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
306 output( ".L__wine_spec_exports_end:\n" );
307
308 /* output relays */
309
310 /* we only support relay debugging on i386 */
311 if (target_cpu != CPU_x86)
312 {
313 output( "\t%s 0\n", get_asm_ptr_keyword() );
314 return;
315 }
316
317 output( ".L__wine_spec_relay_descr:\n" );
318 output( "\t%s 0xdeb90001\n", get_asm_ptr_keyword() ); /* magic */
319 output( "\t%s 0,0\n", get_asm_ptr_keyword() ); /* relay funcs */
320 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* private data */
321 output( "\t%s __wine_spec_relay_entry_points\n", get_asm_ptr_keyword() );
322 output( "\t%s .L__wine_spec_relay_entry_point_offsets\n", get_asm_ptr_keyword() );
323 output( "\t%s .L__wine_spec_relay_arg_types\n", get_asm_ptr_keyword() );
324
325 output_relay_debug( spec );
326 }
327
328
329 /*******************************************************************
330 * output_stub_funcs
331 *
332 * Output the functions for stub entry points
333 */
334 static void output_stub_funcs( DLLSPEC *spec )
335 {
336 int i;
337
338 #if 0
339 for (i = 0; i < spec->nb_entry_points; i++)
340 {
341 ORDDEF *odp = &spec->entry_points[i];
342 if (odp->type != TYPE_STUB) continue;
343 fprintf( outfile, "#ifdef __GNUC__\n" );
344 fprintf( outfile, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func ) __attribute__((noreturn));\n" );
345 fprintf( outfile, "#else\n" );
346 fprintf( outfile, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func );\n" );
347 fprintf( outfile, "#endif\n\n" );
348 break;
349 }
350 #endif
351
352 for (i = 0; i < spec->nb_entry_points; i++)
353 {
354 const ORDDEF *odp = &spec->entry_points[i];
355 if (odp->type != TYPE_STUB) continue;
356 output( "void %s(void) ", make_internal_name( odp, spec, "stub" ) );
357 if (odp->name)
358 output( "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%s\"); }\n", odp->name );
359 else if (odp->export_name)
360 output( "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%s\"); }\n", odp->export_name );
361 else
362 output( "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%d\"); }\n", odp->ordinal );
363 }
364 }
365
366
367 /*******************************************************************
368 * output_asm_constructor
369 *
370 * Output code for calling a dll constructor.
371 */
372 static void output_asm_constructor( const char *constructor )
373 {
374 if (target_platform == PLATFORM_APPLE)
375 {
376 /* Mach-O doesn't have an init section */
377 output( "\n\t.mod_init_func\n" );
378 output( "\t.align %d\n", get_alignment(4) );
379 output( "\t.long %s\n", asm_name(constructor) );
380 }
381 else
382 {
383 output( "\n\t.section \".init\",\"ax\"\n" );
384 switch(target_cpu)
385 {
386 case CPU_x86:
387 case CPU_x86_64:
388 output( "\tcall %s\n", asm_name(constructor) );
389 break;
390 case CPU_SPARC:
391 output( "\tcall %s\n", asm_name(constructor) );
392 output( "\tnop\n" );
393 break;
394 case CPU_ALPHA:
395 output( "\tjsr $26,%s\n", asm_name(constructor) );
396 break;
397 case CPU_POWERPC:
398 output( "\tbl %s\n", asm_name(constructor) );
399 break;
400 }
401 }
402 }
403
404
405 /*******************************************************************
406 * BuildSpec32File
407 *
408 * Build a Win32 C file from a spec file.
409 */
410 void BuildSpec32File( DLLSPEC *spec )
411 {
412 int machine = 0;
413 unsigned int page_size = get_page_size();
414
415 resolve_imports( spec );
416 output_standard_file_header();
417
418 /* Reserve some space for the PE header */
419
420 switch (target_platform)
421 {
422 case PLATFORM_APPLE:
423 output( "\t.text\n" );
424 output( "\t.align %d\n", get_alignment(page_size) );
425 output( "__wine_spec_pe_header:\n" );
426 output( "\t.space 65536\n" );
427 break;
428 case PLATFORM_SOLARIS:
429 output( "\n\t.section \".text\",\"ax\"\n" );
430 output( "__wine_spec_pe_header:\n" );
431 output( "\t.skip %u\n", 65536 + page_size );
432 break;
433 default:
434 output( "\n\t.section \".init\",\"ax\"\n" );
435 switch(target_cpu)
436 {
437 case CPU_x86:
438 case CPU_x86_64:
439 case CPU_ALPHA:
440 case CPU_SPARC:
441 output( "\tjmp 1f\n" );
442 break;
443 case CPU_POWERPC:
444 output( "\tb 1f\n" );
445 break;
446 }
447 output( "__wine_spec_pe_header:\n" );
448 output( "\t.skip %u\n", 65536 + page_size );
449 output( "1:\n" );
450 break;
451 }
452
453 /* Output the NT header */
454
455 output( "\n\t.data\n" );
456 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
457 output( "%s\n", asm_globl("__wine_spec_nt_header") );
458 output( ".L__wine_spec_rva_base:\n" );
459
460 output( "\t.long 0x%04x\n", IMAGE_NT_SIGNATURE ); /* Signature */
461 switch(target_cpu)
462 {
463 case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
464 case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
465 case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break;
466 case CPU_ALPHA: machine = IMAGE_FILE_MACHINE_ALPHA; break;
467 case CPU_SPARC: machine = IMAGE_FILE_MACHINE_UNKNOWN; break;
468 }
469 output( "\t%s 0x%04x\n", /* Machine */
470 get_asm_short_keyword(), machine );
471 output( "\t%s 0\n", /* NumberOfSections */
472 get_asm_short_keyword() );
473 output( "\t.long 0\n" ); /* TimeDateStamp */
474 output( "\t.long 0\n" ); /* PointerToSymbolTable */
475 output( "\t.long 0\n" ); /* NumberOfSymbols */
476 output( "\t%s %d\n", /* SizeOfOptionalHeader */
477 get_asm_short_keyword(),
478 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );
479 output( "\t%s 0x%04x\n", /* Characteristics */
480 get_asm_short_keyword(), spec->characteristics );
481 output( "\t%s 0x%04x\n", /* Magic */
482 get_asm_short_keyword(),
483 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC );
484 output( "\t.byte 0\n" ); /* MajorLinkerVersion */
485 output( "\t.byte 0\n" ); /* MinorLinkerVersion */
486 output( "\t.long 0\n" ); /* SizeOfCode */
487 output( "\t.long 0\n" ); /* SizeOfInitializedData */
488 output( "\t.long 0\n" ); /* SizeOfUninitializedData */
489 /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
490 output( "\t%s %s\n", /* AddressOfEntryPoint */
491 get_asm_ptr_keyword(), asm_name(spec->init_func) );
492 if (get_ptr_size() == 4)
493 {
494 output( "\t.long 0\n" ); /* BaseOfCode */
495 output( "\t.long 0\n" ); /* BaseOfData */
496 }
497 output( "\t%s __wine_spec_pe_header\n", /* ImageBase */
498 get_asm_ptr_keyword() );
499 output( "\t.long %u\n", page_size ); /* SectionAlignment */
500 output( "\t.long %u\n", page_size ); /* FileAlignment */
501 output( "\t%s 1,0\n", /* Major/MinorOperatingSystemVersion */
502 get_asm_short_keyword() );
503 output( "\t%s 0,0\n", /* Major/MinorImageVersion */
504 get_asm_short_keyword() );
505 output( "\t%s %u,%u\n", /* Major/MinorSubsystemVersion */
506 get_asm_short_keyword(), spec->subsystem_major, spec->subsystem_minor );
507 output( "\t.long 0\n" ); /* Win32VersionValue */
508 output( "\t.long %s-.L__wine_spec_rva_base\n", /* SizeOfImage */
509 asm_name("_end") );
510 output( "\t.long %u\n", page_size ); /* SizeOfHeaders */
511 output( "\t.long 0\n" ); /* CheckSum */
512 output( "\t%s 0x%04x\n", /* Subsystem */
513 get_asm_short_keyword(), spec->subsystem );
514 output( "\t%s 0x%04x\n", /* DllCharacteristics */
515 get_asm_short_keyword(), spec->dll_characteristics );
516 output( "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
517 get_asm_ptr_keyword(), (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
518 output( "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
519 get_asm_ptr_keyword(), (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
520 output( "\t.long 0\n" ); /* LoaderFlags */
521 output( "\t.long 16\n" ); /* NumberOfRvaAndSizes */
522
523 if (spec->base <= spec->limit) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
524 output( "\t.long .L__wine_spec_exports-.L__wine_spec_rva_base,"
525 ".L__wine_spec_exports_end-.L__wine_spec_exports\n" );
526 else
527 output( "\t.long 0,0\n" );
528
529 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
530 output( "\t.long .L__wine_spec_imports-.L__wine_spec_rva_base,"
531 ".L__wine_spec_imports_end-.L__wine_spec_imports\n" );
532 else
533 output( "\t.long 0,0\n" );
534
535 if (spec->nb_resources) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
536 output( "\t.long .L__wine_spec_resources-.L__wine_spec_rva_base,"
537 ".L__wine_spec_resources_end-.L__wine_spec_resources\n" );
538 else
539 output( "\t.long 0,0\n" );
540
541 output( "\t.long 0,0\n" ); /* DataDirectory[3] */
542 output( "\t.long 0,0\n" ); /* DataDirectory[4] */
543 output( "\t.long 0,0\n" ); /* DataDirectory[5] */
544 output( "\t.long 0,0\n" ); /* DataDirectory[6] */
545 output( "\t.long 0,0\n" ); /* DataDirectory[7] */
546 output( "\t.long 0,0\n" ); /* DataDirectory[8] */
547 output( "\t.long 0,0\n" ); /* DataDirectory[9] */
548 output( "\t.long 0,0\n" ); /* DataDirectory[10] */
549 output( "\t.long 0,0\n" ); /* DataDirectory[11] */
550 output( "\t.long 0,0\n" ); /* DataDirectory[12] */
551 output( "\t.long 0,0\n" ); /* DataDirectory[13] */
552 output( "\t.long 0,0\n" ); /* DataDirectory[14] */
553 output( "\t.long 0,0\n" ); /* DataDirectory[15] */
554
555 output( "\n\t%s\n", get_asm_string_section() );
556 output( "%s\n", asm_globl("__wine_spec_file_name") );
557 output( ".L__wine_spec_file_name:\n" );
558 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
559 if (target_platform == PLATFORM_APPLE)
560 output( "\t.lcomm %s,4\n", asm_name("_end") );
561
562 output_stubs( spec );
563 output_exports( spec );
564 output_imports( spec );
565 output_resources( spec );
566 output_asm_constructor( "__wine_spec_init_ctor" );
567 output_gnu_stack_note();
568 }
569
570
571 /*******************************************************************
572 * BuildDef32File
573 *
574 * Build a Win32 def file from a spec file.
575 */
576 void BuildDef32File( DLLSPEC *spec )
577 {
578 const char *name;
579 int i, total;
580
581 if (spec_file_name)
582 output( "; File generated automatically from %s; do not edit!\n\n",
583 spec_file_name );
584 else
585 output( "; File generated automatically; do not edit!\n\n" );
586
587 output( "LIBRARY %s\n\n", spec->file_name);
588 output( "EXPORTS\n");
589
590 /* Output the exports and relay entry points */
591
592 for (i = total = 0; i < spec->nb_entry_points; i++)
593 {
594 const ORDDEF *odp = &spec->entry_points[i];
595 int is_data = 0;
596
597 if (!odp) continue;
598
599 if (odp->name) name = odp->name;
600 else if (odp->export_name) name = odp->export_name;
601 else continue;
602
603 if (!(odp->flags & FLAG_PRIVATE)) total++;
604
605 switch(odp->type)
606 {
607 case TYPE_EXTERN:
608 output( " %s", name );
609 is_data = 1;
610 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
611 output( "=%s", odp->link_name );
612 break;
613 case TYPE_VARARGS:
614 case TYPE_CDECL:
615 /* try to reduce output */
616 output( " %s", name );
617 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
618 output( "=%s", odp->link_name );
619 break;
620 case TYPE_STDCALL:
621 {
622 int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
623 output( " %s", name );
624 if (!kill_at) output( "@%d", at_param );
625 if (odp->flags & FLAG_FORWARD)
626 {
627 output( "=%s", odp->link_name );
628 }
629 else if (strcmp(name, odp->link_name)) /* try to reduce output */
630 {
631 output( "=%s", odp->link_name );
632 if (!kill_at) output( "@%d", at_param );
633 }
634 break;
635 }
636 case TYPE_FASTCALL:
637 {
638 int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
639 output( " " );
640 if (!kill_at) output( "@" );
641 output( "%s", name );
642 if (!kill_at) output( "@%d", at_param );
643 if (odp->flags & FLAG_FORWARD)
644 {
645 output( "=" );
646 if (!kill_at) output( "@" );
647 output( "%s", odp->link_name );
648 }
649 else if (strcmp(name, odp->link_name)) /* try to reduce output */
650 {
651 output( "=" );
652 if (!kill_at) output( "@" );
653 output( "%s", odp->link_name );
654 if (!kill_at) output( "@%d", at_param );
655 }
656 break;
657 }
658 case TYPE_STUB:
659 {
660 output( " %s", name );
661 if (!kill_at)
662 {
663 const char *check = name + strlen(name);
664 while (name != check &&
665 '0' <= check[-1] && check[-1] <= '9')
666 {
667 check--;
668 }
669 if (name != check && check != name + strlen(name) &&
670 '@' == check[-1])
671 {
672 output("%s", check - 1);
673 }
674 }
675 if (odp->name || odp->export_name)
676 {
677 output("=%s", make_internal_name( odp, spec, "stub" ));
678 }
679 break;
680 }
681 default:
682 assert(0);
683 }
684 output( " @%d", odp->ordinal );
685 if (!odp->name || (odp->flags & FLAG_ORDINAL)) output( " NONAME" );
686 if (is_data) output( " DATA" );
687 if (odp->flags & FLAG_PRIVATE) output( " PRIVATE" );
688 output( "\n" );
689 }
690 if (!total) warning( "%s: Import library doesn't export anything\n", spec->file_name );
691 }
692
693
694 /*******************************************************************
695 * BuildPedllFile
696 *
697 * Build a PE DLL C file from a spec file.
698 */
699 void BuildPedllFile( DLLSPEC *spec )
700 {
701 int i, has_stubs = 0;
702
703 output_standard_file_header();
704
705 for (i = 0; i < spec->nb_entry_points; i++)
706 {
707 const ORDDEF *odp = &spec->entry_points[i];
708 if (odp->type == TYPE_STUB)
709 {
710 has_stubs = 1;
711 break;
712 }
713 }
714
715 if (!has_stubs)
716 {
717 output( "/* This file is intentionally left blank */\n");
718 return;
719 }
720
721 output( "#include <windows.h>\n");
722 output( "#include <reactos/debug.h>\n");
723
724 output( "DWORD __stdcall __wine_spec_unimplemented_stub( const char *module, const char *function )\n");
725 output( "{\n");
726 output( " DPRINT1(\"%%s hit stub for %%s\\n\",module,function);");
727 output( "\n");
728 output( " SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\n");
729 output( " return -1;\n");
730 output( "}\n");
731
732 output( "static const char __wine_spec_file_name[] = \"%s\";\n\n", spec->file_name );
733
734 /* Output the stub functions */
735 output_stub_funcs( spec );
736 }