sync with trunk head (34904)
[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 output( "\t.text\n" );
421 output( "\t.align %d\n", get_alignment(page_size) );
422 output( "__wine_spec_pe_header:\n" );
423 if (target_platform == PLATFORM_APPLE)
424 output( "\t.space 65536\n" );
425 else
426 output( "\t.skip 65536\n" );
427
428 /* Output the NT header */
429
430 output( "\n\t.data\n" );
431 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
432 output( "%s\n", asm_globl("__wine_spec_nt_header") );
433 output( ".L__wine_spec_rva_base:\n" );
434
435 output( "\t.long 0x%04x\n", IMAGE_NT_SIGNATURE ); /* Signature */
436 switch(target_cpu)
437 {
438 case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
439 case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
440 case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break;
441 case CPU_ALPHA: machine = IMAGE_FILE_MACHINE_ALPHA; break;
442 case CPU_SPARC: machine = IMAGE_FILE_MACHINE_UNKNOWN; break;
443 }
444 output( "\t%s 0x%04x\n", /* Machine */
445 get_asm_short_keyword(), machine );
446 output( "\t%s 0\n", /* NumberOfSections */
447 get_asm_short_keyword() );
448 output( "\t.long 0\n" ); /* TimeDateStamp */
449 output( "\t.long 0\n" ); /* PointerToSymbolTable */
450 output( "\t.long 0\n" ); /* NumberOfSymbols */
451 output( "\t%s %d\n", /* SizeOfOptionalHeader */
452 get_asm_short_keyword(),
453 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );
454 output( "\t%s 0x%04x\n", /* Characteristics */
455 get_asm_short_keyword(), spec->characteristics );
456 output( "\t%s 0x%04x\n", /* Magic */
457 get_asm_short_keyword(),
458 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC );
459 output( "\t.byte 0\n" ); /* MajorLinkerVersion */
460 output( "\t.byte 0\n" ); /* MinorLinkerVersion */
461 output( "\t.long 0\n" ); /* SizeOfCode */
462 output( "\t.long 0\n" ); /* SizeOfInitializedData */
463 output( "\t.long 0\n" ); /* SizeOfUninitializedData */
464 /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
465 output( "\t%s %s\n", /* AddressOfEntryPoint */
466 get_asm_ptr_keyword(), asm_name(spec->init_func) );
467 if (get_ptr_size() == 4)
468 {
469 output( "\t.long 0\n" ); /* BaseOfCode */
470 output( "\t.long 0\n" ); /* BaseOfData */
471 }
472 output( "\t%s __wine_spec_pe_header\n", /* ImageBase */
473 get_asm_ptr_keyword() );
474 output( "\t.long %u\n", page_size ); /* SectionAlignment */
475 output( "\t.long %u\n", page_size ); /* FileAlignment */
476 output( "\t%s 1,0\n", /* Major/MinorOperatingSystemVersion */
477 get_asm_short_keyword() );
478 output( "\t%s 0,0\n", /* Major/MinorImageVersion */
479 get_asm_short_keyword() );
480 output( "\t%s %u,%u\n", /* Major/MinorSubsystemVersion */
481 get_asm_short_keyword(), spec->subsystem_major, spec->subsystem_minor );
482 output( "\t.long 0\n" ); /* Win32VersionValue */
483 output( "\t.long %s-.L__wine_spec_rva_base\n", /* SizeOfImage */
484 asm_name("_end") );
485 output( "\t.long %u\n", page_size ); /* SizeOfHeaders */
486 output( "\t.long 0\n" ); /* CheckSum */
487 output( "\t%s 0x%04x\n", /* Subsystem */
488 get_asm_short_keyword(), spec->subsystem );
489 output( "\t%s 0x%04x\n", /* DllCharacteristics */
490 get_asm_short_keyword(), spec->dll_characteristics );
491 output( "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
492 get_asm_ptr_keyword(), (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
493 output( "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
494 get_asm_ptr_keyword(), (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
495 output( "\t.long 0\n" ); /* LoaderFlags */
496 output( "\t.long 16\n" ); /* NumberOfRvaAndSizes */
497
498 if (spec->base <= spec->limit) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
499 output( "\t.long .L__wine_spec_exports-.L__wine_spec_rva_base,"
500 ".L__wine_spec_exports_end-.L__wine_spec_exports\n" );
501 else
502 output( "\t.long 0,0\n" );
503
504 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
505 output( "\t.long .L__wine_spec_imports-.L__wine_spec_rva_base,"
506 ".L__wine_spec_imports_end-.L__wine_spec_imports\n" );
507 else
508 output( "\t.long 0,0\n" );
509
510 if (spec->nb_resources) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
511 output( "\t.long .L__wine_spec_resources-.L__wine_spec_rva_base,"
512 ".L__wine_spec_resources_end-.L__wine_spec_resources\n" );
513 else
514 output( "\t.long 0,0\n" );
515
516 output( "\t.long 0,0\n" ); /* DataDirectory[3] */
517 output( "\t.long 0,0\n" ); /* DataDirectory[4] */
518 output( "\t.long 0,0\n" ); /* DataDirectory[5] */
519 output( "\t.long 0,0\n" ); /* DataDirectory[6] */
520 output( "\t.long 0,0\n" ); /* DataDirectory[7] */
521 output( "\t.long 0,0\n" ); /* DataDirectory[8] */
522 output( "\t.long 0,0\n" ); /* DataDirectory[9] */
523 output( "\t.long 0,0\n" ); /* DataDirectory[10] */
524 output( "\t.long 0,0\n" ); /* DataDirectory[11] */
525 output( "\t.long 0,0\n" ); /* DataDirectory[12] */
526 output( "\t.long 0,0\n" ); /* DataDirectory[13] */
527 output( "\t.long 0,0\n" ); /* DataDirectory[14] */
528 output( "\t.long 0,0\n" ); /* DataDirectory[15] */
529
530 output( "\n\t%s\n", get_asm_string_section() );
531 output( "%s\n", asm_globl("__wine_spec_file_name") );
532 output( ".L__wine_spec_file_name:\n" );
533 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
534 if (target_platform == PLATFORM_APPLE)
535 output( "\t.lcomm %s,4\n", asm_name("_end") );
536
537 output_stubs( spec );
538 output_exports( spec );
539 output_imports( spec );
540 output_resources( spec );
541 output_asm_constructor( "__wine_spec_init_ctor" );
542 output_gnu_stack_note();
543 }
544
545
546 /*******************************************************************
547 * BuildDef32File
548 *
549 * Build a Win32 def file from a spec file.
550 */
551 void BuildDef32File( DLLSPEC *spec )
552 {
553 const char *name;
554 int i, total;
555
556 if (spec_file_name)
557 output( "; File generated automatically from %s; do not edit!\n\n",
558 spec_file_name );
559 else
560 output( "; File generated automatically; do not edit!\n\n" );
561
562 output( "LIBRARY %s\n\n", spec->file_name);
563 output( "EXPORTS\n");
564
565 /* Output the exports and relay entry points */
566
567 for (i = total = 0; i < spec->nb_entry_points; i++)
568 {
569 const ORDDEF *odp = &spec->entry_points[i];
570 int is_data = 0;
571
572 if (!odp) continue;
573
574 if (odp->name) name = odp->name;
575 else if (odp->export_name) name = odp->export_name;
576 else continue;
577
578 if (!(odp->flags & FLAG_PRIVATE)) total++;
579
580 switch(odp->type)
581 {
582 case TYPE_EXTERN:
583 output( " %s", name );
584 is_data = 1;
585 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
586 output( "=%s", odp->link_name );
587 break;
588 case TYPE_VARARGS:
589 case TYPE_CDECL:
590 /* try to reduce output */
591 output( " %s", name );
592 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
593 output( "=%s", odp->link_name );
594 break;
595 case TYPE_STDCALL:
596 {
597 int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
598 output( " %s", name );
599 if (!kill_at) output( "@%d", at_param );
600 if (odp->flags & FLAG_FORWARD)
601 {
602 output( "=%s", odp->link_name );
603 }
604 else if (strcmp(name, odp->link_name)) /* try to reduce output */
605 {
606 output( "=%s", odp->link_name );
607 if (!kill_at) output( "@%d", at_param );
608 }
609 break;
610 }
611 case TYPE_FASTCALL:
612 {
613 int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
614 output( " @%s", name );
615 if (!kill_at) output( "@%d", at_param );
616 if (odp->flags & FLAG_FORWARD)
617 {
618 output( "=@%s", odp->link_name );
619 }
620 else if (strcmp(name, odp->link_name)) /* try to reduce output */
621 {
622 output( "=@%s", odp->link_name );
623 if (!kill_at) output( "@%d", at_param );
624 }
625 break;
626 }
627 case TYPE_STUB:
628 {
629 output( " %s", name );
630 if (!kill_at)
631 {
632 const char *check = name + strlen(name);
633 while (name != check &&
634 '0' <= check[-1] && check[-1] <= '9')
635 {
636 check--;
637 }
638 if (name != check && check != name + strlen(name) &&
639 '@' == check[-1])
640 {
641 output("%s", check - 1);
642 }
643 }
644 if (odp->name || odp->export_name)
645 {
646 output("=%s", make_internal_name( odp, spec, "stub" ));
647 }
648 break;
649 }
650 default:
651 assert(0);
652 }
653 output( " @%d", odp->ordinal );
654 if (!odp->name || (odp->flags & FLAG_ORDINAL)) output( " NONAME" );
655 if (is_data) output( " DATA" );
656 if (odp->flags & FLAG_PRIVATE) output( " PRIVATE" );
657 output( "\n" );
658 }
659 if (!total) warning( "%s: Import library doesn't export anything\n", spec->file_name );
660 }
661
662
663 /*******************************************************************
664 * BuildPedllFile
665 *
666 * Build a PE DLL C file from a spec file.
667 */
668 void BuildPedllFile( DLLSPEC *spec )
669 {
670 int i, has_stubs = 0;
671
672 output_standard_file_header();
673
674 for (i = 0; i < spec->nb_entry_points; i++)
675 {
676 const ORDDEF *odp = &spec->entry_points[i];
677 if (odp->type == TYPE_STUB)
678 {
679 has_stubs = 1;
680 break;
681 }
682 }
683
684 if (!has_stubs)
685 {
686 output( "/* This file is intentionally left blank */\n");
687 return;
688 }
689
690 output( "#include <windows.h>\n");
691 output( "#include <reactos/debug.h>\n");
692
693 output( "DWORD __wine_spec_unimplemented_stub( const char *module, const char *function )\n");
694 output( "{\n");
695 output( " DPRINT1(\"%%s hit stub for %%s\\n\",module,function);");
696 output( "\n");
697 output( " SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\n");
698 output( " return -1;\n");
699 output( "}\n");
700
701 output( "static const char __wine_spec_file_name[] = \"%s\";\n\n", spec->file_name );
702
703 /* Output the stub functions */
704 output_stub_funcs( spec );
705 }