~bkerensa/ubuntu/raring/yasm/fix-for-1064341

« back to all changes in this revision

Viewing changes to debian/patches/200_yasm_tasm_source.diff

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar
  • Date: 2009-07-14 08:23:59 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090714082359-10x8mjty41gzkshs
Tags: 0.8.0-1
* New upstream release (Closes: #531047).
* Removed all tasm patches, they’ve been merged upstream.
* debian/control: set debhelper dependency to 5.0 and policy to 3.8.2.
* debian/control: mention TASM in the long description.
* debian/compat: set debhelper level to 5.
* debian/links: link tasm to ytasm and tasm.1.gz to ytasm.1.gz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Index: libyasm/bytecode.c
2
 
===================================================================
3
 
--- old/libyasm/bytecode.c      (r�vision 2128)
4
 
+++ new/libyasm/bytecode.c      (copie de travail)
5
 
@@ -223,6 +223,18 @@
6
 
 }
7
 
 
8
 
 int
9
 
+yasm_bc_elem_size(yasm_bytecode *bc)
10
 
+{
11
 
+    if (!bc->callback) {
12
 
+        yasm_internal_error(N_("got empty bytecode in yasm_bc_elem_size"));
13
 
+        return 0;
14
 
+    } else if (!bc->callback->elem_size)
15
 
+        return 0;
16
 
+    else
17
 
+        return bc->callback->elem_size(bc);
18
 
+}
19
 
+
20
 
+int
21
 
 yasm_bc_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
22
 
                  void *add_span_data)
23
 
 {
24
 
Index: libyasm/symrec.c
25
 
===================================================================
26
 
--- old/libyasm/symrec.c        (r�vision 2128)
27
 
+++ new/libyasm/symrec.c        (copie de travail)
28
 
@@ -28,6 +28,7 @@
29
 
 /*@unused@*/ RCSID("$Id$");
30
 
 
31
 
 #include <limits.h>
32
 
+#include <ctype.h>
33
 
 
34
 
 #include "libyasm-stdint.h"
35
 
 #include "coretype.h"
36
 
@@ -71,6 +72,8 @@
37
 
         /* bytecode immediately preceding a label */
38
 
         /*@dependent@*/ yasm_bytecode *precbc;
39
 
     } value;
40
 
+    unsigned int size;          /* 0 if not user-defined */
41
 
+    const char *segment;        /* for segmented systems like DOS */
42
 
 
43
 
     /* associated data; NULL if none */
44
 
     /*@null@*/ /*@only@*/ yasm__assoc_data *assoc_data;
45
 
@@ -87,6 +90,8 @@
46
 
     /*@only@*/ HAMT *sym_table;
47
 
     /* Symbols not in the table */
48
 
     SLIST_HEAD(nontablesymhead_s, non_table_symrec_s) non_table_syms;
49
 
+
50
 
+    int case_sensitive;
51
 
 };
52
 
 
53
 
 static void
54
 
@@ -132,9 +137,16 @@
55
 
     yasm_symtab *symtab = yasm_xmalloc(sizeof(yasm_symtab));
56
 
     symtab->sym_table = HAMT_create(0, yasm_internal_error_);
57
 
     SLIST_INIT(&symtab->non_table_syms);
58
 
+    symtab->case_sensitive = 1;
59
 
     return symtab;
60
 
 }
61
 
 
62
 
+void
63
 
+yasm_symtab_set_case_sensitive(yasm_symtab *symtab, int sensitive)
64
 
+{
65
 
+    symtab->case_sensitive = sensitive;
66
 
+}
67
 
+
68
 
 static void
69
 
 symrec_destroy_one(/*@only@*/ void *d)
70
 
 {
71
 
@@ -147,15 +159,24 @@
72
 
 }
73
 
 
74
 
 static /*@partial@*/ yasm_symrec *
75
 
-symrec_new_common(/*@keep@*/ char *name)
76
 
+symrec_new_common(/*@keep@*/ char *name, int case_sensitive)
77
 
 {
78
 
     yasm_symrec *rec = yasm_xmalloc(sizeof(yasm_symrec));
79
 
+
80
 
+    if (!case_sensitive) {
81
 
+        char *c;
82
 
+        for (c=name; *c; c++)
83
 
+            *c = tolower(*c);
84
 
+    }
85
 
+
86
 
     rec->name = name;
87
 
     rec->type = SYM_UNKNOWN;
88
 
     rec->def_line = 0;
89
 
     rec->decl_line = 0;
90
 
     rec->use_line = 0;
91
 
     rec->visibility = YASM_SYM_LOCAL;
92
 
+    rec->size = 0;
93
 
+    rec->segment = NULL;
94
 
     rec->assoc_data = NULL;
95
 
     return rec;
96
 
 }
97
 
@@ -163,11 +184,17 @@
98
 
 static /*@partial@*/ /*@dependent@*/ yasm_symrec *
99
 
 symtab_get_or_new_in_table(yasm_symtab *symtab, /*@only@*/ char *name)
100
 
 {
101
 
-    yasm_symrec *rec = symrec_new_common(name);
102
 
+    yasm_symrec *rec = symrec_new_common(name, symtab->case_sensitive);
103
 
     int replace = 0;
104
 
 
105
 
     rec->status = YASM_SYM_NOSTATUS;
106
 
 
107
 
+    if (!symtab->case_sensitive) {
108
 
+        char *c;
109
 
+        for (c=name; *c; c++)
110
 
+            *c = tolower(*c);
111
 
+    }
112
 
+
113
 
     return HAMT_insert(symtab->sym_table, name, rec, &replace,
114
 
                        symrec_destroy_one);
115
 
 }
116
 
@@ -176,7 +203,7 @@
117
 
 symtab_get_or_new_not_in_table(yasm_symtab *symtab, /*@only@*/ char *name)
118
 
 {
119
 
     non_table_symrec *sym = yasm_xmalloc(sizeof(non_table_symrec));
120
 
-    sym->rec = symrec_new_common(name);
121
 
+    sym->rec = symrec_new_common(name, symtab->case_sensitive);
122
 
 
123
 
     sym->rec->status = YASM_SYM_NOTINTABLE;
124
 
 
125
 
@@ -251,7 +278,17 @@
126
 
 yasm_symrec *
127
 
 yasm_symtab_get(yasm_symtab *symtab, const char *name)
128
 
 {
129
 
-    return HAMT_search(symtab->sym_table, name);
130
 
+    if (!symtab->case_sensitive) {
131
 
+        char *_name = yasm__xstrdup(name);
132
 
+        char *c;
133
 
+        yasm_symrec *ret;
134
 
+        for (c=_name; *c; c++)
135
 
+            *c = tolower(*c);
136
 
+        ret = HAMT_search(symtab->sym_table, _name);
137
 
+        yasm_xfree(_name);
138
 
+        return ret;
139
 
+    } else
140
 
+      return HAMT_search(symtab->sym_table, name);
141
 
 }
142
 
 
143
 
 static /*@dependent@*/ yasm_symrec *
144
 
@@ -273,6 +310,8 @@
145
 
         rec->def_line = line;   /* set line number of definition */
146
 
         rec->type = type;
147
 
         rec->status |= YASM_SYM_DEFINED;
148
 
+        rec->size = 0;
149
 
+        rec->segment = NULL;
150
 
     }
151
 
     return rec;
152
 
 }
153
 
@@ -519,7 +558,31 @@
154
 
     return 1;
155
 
 }
156
 
 
157
 
+void
158
 
+yasm_symrec_set_size(yasm_symrec *sym, int size)
159
 
+{
160
 
+    sym->size = size;
161
 
+}
162
 
+
163
 
 int
164
 
+yasm_symrec_get_size(const yasm_symrec *sym)
165
 
+{
166
 
+    return sym->size;
167
 
+}
168
 
+
169
 
+void
170
 
+yasm_symrec_set_segment(yasm_symrec *sym, const char *segment)
171
 
+{
172
 
+    sym->segment = segment;
173
 
+}
174
 
+
175
 
+const char *
176
 
+yasm_symrec_get_segment(const yasm_symrec *sym)
177
 
+{
178
 
+    return sym->segment;
179
 
+}
180
 
+
181
 
+int
182
 
 yasm_symrec_is_abs(const yasm_symrec *sym)
183
 
 {
184
 
     return (sym->def_line == 0 && sym->type == SYM_EQU &&
185
 
Index: libyasm/bytecode.h
186
 
===================================================================
187
 
--- old/libyasm/bytecode.h      (r�vision 2128)
188
 
+++ new/libyasm/bytecode.h      (copie de travail)
189
 
@@ -86,6 +86,14 @@
190
 
      */
191
 
     void (*finalize) (yasm_bytecode *bc, yasm_bytecode *prev_bc);
192
 
 
193
 
+    /** Return elements size of a data bytecode.
194
 
+     * This function should return the size of each elements of a data
195
 
+     * bytecode, for proper dereference of symbols attached to it.
196
 
+     * \param bc            bytecode
197
 
+     * \return 0 if element size is unknown.
198
 
+     */
199
 
+    int (*elem_size) (yasm_bytecode *bc);
200
 
+
201
 
     /** Calculates the minimum size of a bytecode.
202
 
      * Called from yasm_bc_calc_len().
203
 
      * A generic fill-in for this is yasm_bc_calc_len_common(), but as this
204
 
@@ -438,6 +446,14 @@
205
 
 YASM_LIB_DECL
206
 
 unsigned long yasm_bc_next_offset(yasm_bytecode *precbc);
207
 
 
208
 
+/** Return elemens size of a data bytecode.
209
 
+ * Returns the size of each elements of a data bytecode, for proper dereference
210
 
+ * of symbols attached to it.
211
 
+ * \param bc            bytecode
212
 
+ * \return 0 if element size is unknown
213
 
+ */
214
 
+int yasm_bc_elem_size(yasm_bytecode *bc);
215
 
+
216
 
 /** Resolve EQUs in a bytecode and calculate its minimum size.
217
 
  * Generates dependent bytecode spans for cases where, if the length spanned
218
 
  * increases, it could cause the bytecode size to increase.
219
 
@@ -548,11 +565,31 @@
220
 
 yasm_dataval *yasm_dv_create_raw(/*@keep@*/ unsigned char *contents,
221
 
                                  unsigned long len);
222
 
 
223
 
+/** Create a new uninitialized data value.
224
 
+ * \return Newly allocated data value.
225
 
+ */
226
 
+yasm_dataval *yasm_dv_create_reserve(void);
227
 
+
228
 
 #ifndef YASM_DOXYGEN
229
 
 #define yasm_dv_create_string(s, l) yasm_dv_create_raw((unsigned char *)(s), \
230
 
                                                        (unsigned long)(l))
231
 
 #endif
232
 
 
233
 
+/** Set multiple field of a data value.
234
 
+ * A data value can be repeated a number of times when output.  This function
235
 
+ * sets that multiple.
236
 
+ * \param dv    data value
237
 
+ * \param e     multiple (kept, do not free)
238
 
+ */
239
 
+void yasm_dv_set_multiple(yasm_dataval *dv, /*@keep@*/ yasm_expr *e);
240
 
+
241
 
+/** Get the data value multiple value as an unsigned long integer.
242
 
+ * \param dv            data value
243
 
+ * \param multiple      multiple value (output)
244
 
+ * \return 1 on error (set with yasm_error_set), 0 on success.
245
 
+ */
246
 
+int yasm_dv_get_multiple(yasm_dataval *dv, /*@out@*/ unsigned long *multiple);
247
 
+
248
 
 /** Initialize a list of data values.
249
 
  * \param headp list of data values
250
 
  */
251
 
Index: libyasm/symrec.h
252
 
===================================================================
253
 
--- old/libyasm/symrec.h        (r�vision 2128)
254
 
+++ new/libyasm/symrec.h        (copie de travail)
255
 
@@ -73,6 +73,13 @@
256
 
 YASM_LIB_DECL
257
 
 void yasm_symtab_destroy(/*@only@*/ yasm_symtab *symtab);
258
 
 
259
 
+/** Set the symbol table to be case sensitive or not.
260
 
+ * Should be called before adding any symbol.
261
 
+ * \param symtab    symbol table
262
 
+ * \param sensitive whether the symbol table should be case sensitive.
263
 
+ */
264
 
+void yasm_symtab_set_case_sensitive(yasm_symtab *symtab, int sensitive);
265
 
+
266
 
 /** Get a reference to the symbol table's "absolute" symbol.  This is
267
 
  * essentially an EQU with no name and value 0, and is used for relocating
268
 
  * absolute current-position-relative values.
269
 
@@ -318,6 +326,30 @@
270
 
 int yasm_symrec_get_label(const yasm_symrec *sym,
271
 
                           /*@out@*/ yasm_symrec_get_label_bytecodep *precbc);
272
 
 
273
 
+/** Set the size of a symbol.
274
 
+ * \param sym       symbol
275
 
+ * \param size      size to be set
276
 
+ */
277
 
+void yasm_symrec_set_size(yasm_symrec *sym, int size);
278
 
+
279
 
+/** Get the size of a symbol.
280
 
+ * \param sym       symbol
281
 
+ * \return size of the symbol, 0 if none specified by the user.
282
 
+ */
283
 
+int yasm_symrec_get_size(const yasm_symrec *sym);
284
 
+
285
 
+/** Set the segment of a symbol.
286
 
+ * \param sym       symbol
287
 
+ * \param segment   segment to be set
288
 
+ */
289
 
+void yasm_symrec_set_segment(yasm_symrec *sym, const char *segment);
290
 
+
291
 
+/** Get the segment of a symbol.
292
 
+ * \param sym       symbol
293
 
+ * \return segment of the symbol, NULL if none specified by the user.
294
 
+ */
295
 
+const char *yasm_symrec_get_segment(const yasm_symrec *sym);
296
 
+
297
 
 /** Determine if symbol is the "absolute" symbol created by
298
 
  * yasm_symtab_abs_sym().
299
 
  * \param sym       symbol
300
 
Index: libyasm/insn.c
301
 
===================================================================
302
 
--- old/libyasm/insn.c  (r�vision 2128)
303
 
+++ new/libyasm/insn.c  (copie de travail)
304
 
@@ -96,6 +96,7 @@
305
 
     retval->size = 0;
306
 
     retval->deref = 0;
307
 
     retval->strict = 0;
308
 
+    retval->size = ea->data_len * 8;
309
 
 
310
 
     return retval;
311
 
 }
312
 
Index: libyasm/insn.h
313
 
===================================================================
314
 
--- old/libyasm/insn.h  (r�vision 2128)
315
 
+++ new/libyasm/insn.h  (copie de travail)
316
 
@@ -74,6 +74,9 @@
317
 
 
318
 
     /** 1 if effective address is forced non-PC-relative. */
319
 
     unsigned int not_pc_rel:1;
320
 
+
321
 
+    /** length of pointed data (in bytes), 0 if unknown. */
322
 
+    unsigned int data_len;
323
 
 };
324
 
 
325
 
 /** An instruction operand (opaque type). */
326
 
Index: libyasm/bc-align.c
327
 
===================================================================
328
 
--- old/libyasm/bc-align.c      (r�vision 2128)
329
 
+++ new/libyasm/bc-align.c      (copie de travail)
330
 
@@ -66,6 +66,7 @@
331
 
     bc_align_destroy,
332
 
     bc_align_print,
333
 
     bc_align_finalize,
334
 
+    NULL,
335
 
     bc_align_calc_len,
336
 
     bc_align_expand,
337
 
     bc_align_tobytes,
338
 
Index: libyasm/bc-reserve.c
339
 
===================================================================
340
 
--- old/libyasm/bc-reserve.c    (r�vision 2128)
341
 
+++ new/libyasm/bc-reserve.c    (copie de travail)
342
 
@@ -46,6 +46,7 @@
343
 
 static void bc_reserve_destroy(void *contents);
344
 
 static void bc_reserve_print(const void *contents, FILE *f, int indent_level);
345
 
 static void bc_reserve_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc);
346
 
+static int bc_reserve_elem_size(yasm_bytecode *bc);
347
 
 static int bc_reserve_calc_len(yasm_bytecode *bc,
348
 
                                yasm_bc_add_span_func add_span,
349
 
                                void *add_span_data);
350
 
@@ -57,6 +58,7 @@
351
 
     bc_reserve_destroy,
352
 
     bc_reserve_print,
353
 
     bc_reserve_finalize,
354
 
+    bc_reserve_elem_size,
355
 
     bc_reserve_calc_len,
356
 
     yasm_bc_expand_common,
357
 
     bc_reserve_tobytes,
358
 
@@ -96,6 +98,13 @@
359
 
 }
360
 
 
361
 
 static int
362
 
+bc_reserve_elem_size(yasm_bytecode *bc)
363
 
+{
364
 
+    bytecode_reserve *reserve = (bytecode_reserve *)bc->contents;
365
 
+    return reserve->itemsize;
366
 
+}
367
 
+
368
 
+static int
369
 
 bc_reserve_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
370
 
                     void *add_span_data)
371
 
 {
372
 
Index: libyasm/bc-org.c
373
 
===================================================================
374
 
--- old/libyasm/bc-org.c        (r�vision 2128)
375
 
+++ new/libyasm/bc-org.c        (copie de travail)
376
 
@@ -60,6 +60,7 @@
377
 
     bc_org_destroy,
378
 
     bc_org_print,
379
 
     bc_org_finalize,
380
 
+    NULL,
381
 
     bc_org_calc_len,
382
 
     bc_org_expand,
383
 
     bc_org_tobytes,
384
 
Index: libyasm/intnum.c
385
 
===================================================================
386
 
--- old/libyasm/intnum.c        (r�vision 2128)
387
 
+++ new/libyasm/intnum.c        (copie de travail)
388
 
@@ -244,17 +244,65 @@
389
 
         case 0:
390
 
             break;
391
 
         default:
392
 
-            /* >32 bit conversion */
393
 
+            /* >=32 bit conversion */
394
 
             while (len) {
395
 
                 BitVector_Move_Left(conv_bv, 8);
396
 
                 BitVector_Chunk_Store(conv_bv, 8, 0,
397
 
-                                      (unsigned long)str[--len]);
398
 
+                                      ((unsigned long)str[--len]) & 0xff);
399
 
             }
400
 
             intn->val.bv = BitVector_Clone(conv_bv);
401
 
     }
402
 
 
403
 
     return intn;
404
 
 }
405
 
+
406
 
+yasm_intnum *
407
 
+yasm_intnum_create_charconst_tasm(const char *str)
408
 
+{
409
 
+    yasm_intnum *intn = yasm_xmalloc(sizeof(yasm_intnum));
410
 
+    size_t len = strlen(str);
411
 
+    size_t i;
412
 
+
413
 
+    if(len*8 > BITVECT_NATIVE_SIZE)
414
 
+        yasm_error_set(YASM_ERROR_OVERFLOW,
415
 
+                       N_("Character constant too large for internal format"));
416
 
+
417
 
+    /* be conservative in choosing bitvect in case MSB is set */
418
 
+    if (len > 3) {
419
 
+        BitVector_Empty(conv_bv);
420
 
+        intn->type = INTNUM_BV;
421
 
+    } else {
422
 
+        intn->val.l = 0;
423
 
+        intn->type = INTNUM_L;
424
 
+    }
425
 
+
426
 
+    /* tasm uses big endian notation */
427
 
+    i = 0;
428
 
+    switch (len) {
429
 
+        case 3:
430
 
+            intn->val.l |= ((unsigned long)str[i++]) & 0xff;
431
 
+            intn->val.l <<= 8;
432
 
+            /*@fallthrough@*/
433
 
+        case 2:
434
 
+            intn->val.l |= ((unsigned long)str[i++]) & 0xff;
435
 
+            intn->val.l <<= 8;
436
 
+            /*@fallthrough@*/
437
 
+        case 1:
438
 
+            intn->val.l |= ((unsigned long)str[i++]) & 0xff;
439
 
+        case 0:
440
 
+            break;
441
 
+        default:
442
 
+            /* >=32 bit conversion */
443
 
+            while (i < len) {
444
 
+                BitVector_Chunk_Store(conv_bv, 8, (len-i-1)*8,
445
 
+                                      ((unsigned long)str[i]) & 0xff);
446
 
+                i++;
447
 
+            }
448
 
+            intn->val.bv = BitVector_Clone(conv_bv);
449
 
+    }
450
 
+
451
 
+    return intn;
452
 
+}
453
 
 /*@=usedef =compdef =uniondef@*/
454
 
 
455
 
 yasm_intnum *
456
 
Index: libyasm/expr.c
457
 
===================================================================
458
 
--- old/libyasm/expr.c  (r�vision 2128)
459
 
+++ new/libyasm/expr.c  (copie de travail)
460
 
@@ -1444,3 +1444,73 @@
461
 
             fprintf(f, "%s", opstr);
462
 
     }
463
 
 }
464
 
+
465
 
+unsigned int
466
 
+yasm_expr_size(const yasm_expr *e)
467
 
+{
468
 
+    int i;
469
 
+    int seen = 0;
470
 
+    unsigned int size = 0, newsize;
471
 
+
472
 
+    if (e->op == YASM_EXPR_IDENT) {
473
 
+        if (e->terms[0].type == YASM_EXPR_SYM)
474
 
+            return yasm_symrec_get_size(e->terms[0].data.sym);
475
 
+        return 0;
476
 
+    }
477
 
+    if (e->op != YASM_EXPR_ADD && e->op != YASM_EXPR_SUB)
478
 
+        return 0;
479
 
+
480
 
+    for (i=0; i<e->numterms; i++) {
481
 
+        newsize = 0;
482
 
+        switch (e->terms[i].type) {
483
 
+        case YASM_EXPR_EXPR:
484
 
+            newsize = yasm_expr_size(e->terms[i].data.expn);
485
 
+            break;
486
 
+        case YASM_EXPR_SYM:
487
 
+            newsize = yasm_symrec_get_size(e->terms[i].data.sym);
488
 
+            break;
489
 
+        default:
490
 
+            break;
491
 
+        }
492
 
+        if (newsize) {
493
 
+            size = newsize;
494
 
+            if (seen)
495
 
+                /* either sum of idents (?!) or substract of idents */
496
 
+                return 0;
497
 
+            seen = 1;
498
 
+        }
499
 
+    }
500
 
+    /* exactly one offset */
501
 
+    return size;
502
 
+}
503
 
+
504
 
+const char *
505
 
+yasm_expr_segment(const yasm_expr *e)
506
 
+{
507
 
+    int i;
508
 
+    int seen = 0;
509
 
+    const char *segment = NULL;
510
 
+
511
 
+    if (e->op == YASM_EXPR_IDENT) {
512
 
+        if (e->terms[0].type == YASM_EXPR_SYM)
513
 
+            return yasm_symrec_get_segment(e->terms[0].data.sym);
514
 
+        return NULL;
515
 
+    }
516
 
+    if (e->op != YASM_EXPR_ADD && e->op != YASM_EXPR_SUB)
517
 
+        return NULL;
518
 
+
519
 
+    for (i=0; i<e->numterms; i++) {
520
 
+        if ((e->op == YASM_EXPR_ADD || !i) &&
521
 
+                e->terms[i].type == YASM_EXPR_EXPR) {
522
 
+            if ((segment = yasm_expr_segment(e->terms[i].data.expn))) {
523
 
+                if (seen) {
524
 
+                    /* either sum of idents (?!) or substract of idents */
525
 
+                    return NULL;
526
 
+                }
527
 
+                seen = 1;
528
 
+            }
529
 
+        }
530
 
+    }
531
 
+    /* exactly one offset */
532
 
+    return segment;
533
 
+}
534
 
Index: libyasm/intnum.h
535
 
===================================================================
536
 
--- old/libyasm/intnum.h        (r�vision 2128)
537
 
+++ new/libyasm/intnum.h        (copie de travail)
538
 
@@ -76,12 +76,20 @@
539
 
 
540
 
 /** Convert character constant to integer value, using NASM rules.  NASM syntax
541
 
  * supports automatic conversion from strings such as 'abcd' to a 32-bit
542
 
- * integer value.  This function performs those conversions.
543
 
+ * integer value (little endian order).  This function performs those conversions.
544
 
  * \param str       character constant string
545
 
  * \return Newly allocated intnum.
546
 
  */
547
 
 /*@only@*/ yasm_intnum *yasm_intnum_create_charconst_nasm(const char *str);
548
 
 
549
 
+/** Convert character constant to integer value, using TASM rules.  TASM syntax
550
 
+ * supports automatic conversion from strings such as 'abcd' to a 32-bit
551
 
+ * integer value (big endian order).  This function performs those conversions.
552
 
+ * \param str       character constant string
553
 
+ * \return Newly allocated intnum.
554
 
+ */
555
 
+/*@only@*/ yasm_intnum *yasm_intnum_create_charconst_tasm(const char *str);
556
 
+
557
 
 /** Create a new intnum from an unsigned integer value.
558
 
  * \param i         unsigned integer value
559
 
  * \return Newly allocated intnum.
560
 
Index: libyasm/errwarn.c
561
 
===================================================================
562
 
--- old/libyasm/errwarn.c       (r�vision 2128)
563
 
+++ new/libyasm/errwarn.c       (copie de travail)
564
 
@@ -115,7 +115,8 @@
565
 
     warn_class_enabled = 
566
 
         (1UL<<YASM_WARN_GENERAL) | (1UL<<YASM_WARN_UNREC_CHAR) |
567
 
         (1UL<<YASM_WARN_PREPROC) | (0UL<<YASM_WARN_ORPHAN_LABEL) |
568
 
-        (1UL<<YASM_WARN_UNINIT_CONTENTS);
569
 
+        (1UL<<YASM_WARN_UNINIT_CONTENTS) | (0UL<<YASM_WARN_SIZE_OVERRIDE) |
570
 
+        (1UL<<YASM_WARN_IMPLICIT_SIZE_OVERRIDE);
571
 
 
572
 
     yasm_eclass = YASM_ERROR_NONE;
573
 
     yasm_estr = NULL;
574
 
Index: libyasm/expr.h
575
 
===================================================================
576
 
--- old/libyasm/expr.h  (r�vision 2128)
577
 
+++ new/libyasm/expr.h  (copie de travail)
578
 
@@ -297,6 +297,16 @@
579
 
 YASM_LIB_DECL
580
 
 void yasm_expr_print(/*@null@*/ const yasm_expr *e, FILE *f);
581
 
 
582
 
+/** Return the size of an expression, if the user provided it
583
 
+ * \param e     expression
584
 
+ */
585
 
+unsigned int yasm_expr_size(const yasm_expr *e);
586
 
+
587
 
+/** Return the segment of an expression, if the user provided it
588
 
+ * \param e     expression
589
 
+ */
590
 
+const char *yasm_expr_segment(const yasm_expr *e);
591
 
+
592
 
 /** Traverse over expression tree in order (const version).
593
 
  * Calls func for each leaf (non-operation).
594
 
  * \param e     expression
595
 
Index: libyasm/bc-incbin.c
596
 
===================================================================
597
 
--- old/libyasm/bc-incbin.c     (r�vision 2128)
598
 
+++ new/libyasm/bc-incbin.c     (copie de travail)
599
 
@@ -66,6 +66,7 @@
600
 
     bc_incbin_destroy,
601
 
     bc_incbin_print,
602
 
     bc_incbin_finalize,
603
 
+    NULL,
604
 
     bc_incbin_calc_len,
605
 
     yasm_bc_expand_common,
606
 
     bc_incbin_tobytes,
607
 
Index: libyasm/errwarn.h
608
 
===================================================================
609
 
--- old/libyasm/errwarn.h       (r�vision 2128)
610
 
+++ new/libyasm/errwarn.h       (copie de travail)
611
 
@@ -46,7 +46,8 @@
612
 
     YASM_WARN_PREPROC,      /**< Preprocessor warnings */
613
 
     YASM_WARN_ORPHAN_LABEL, /**< Label alone on a line without a colon */
614
 
     YASM_WARN_UNINIT_CONTENTS, /**< Uninitialized space in code/data section */
615
 
-    YASM_WARN_SIZE_OVERRIDE /**< Double size override */
616
 
+    YASM_WARN_SIZE_OVERRIDE,/**< Double size override */
617
 
+    YASM_WARN_IMPLICIT_SIZE_OVERRIDE /**< Implicit size override */
618
 
 } yasm_warn_class;
619
 
 
620
 
 /** Error classes.  Bitmask-based to support limited subclassing. */
621
 
Index: libyasm/bc-data.c
622
 
===================================================================
623
 
--- old/libyasm/bc-data.c       (r�vision 2128)
624
 
+++ new/libyasm/bc-data.c       (copie de travail)
625
 
@@ -42,7 +42,8 @@
626
 
 struct yasm_dataval {
627
 
     /*@reldef@*/ STAILQ_ENTRY(yasm_dataval) link;
628
 
 
629
 
-    enum { DV_EMPTY, DV_VALUE, DV_RAW, DV_ULEB128, DV_SLEB128 } type;
630
 
+    enum { DV_EMPTY, DV_VALUE, DV_RAW, DV_ULEB128, DV_SLEB128, DV_RESERVE }
631
 
+        type;
632
 
 
633
 
     union {
634
 
         yasm_value val;
635
 
@@ -51,16 +52,22 @@
636
 
             unsigned long len;
637
 
         } raw;
638
 
     } data;
639
 
+
640
 
+    /* number of times data is repeated, NULL=1. */
641
 
+    /*@only@*/ /*@null@*/ yasm_expr *multiple;
642
 
 };
643
 
 
644
 
 typedef struct bytecode_data {
645
 
     /* converted data (linked list) */
646
 
     yasm_datavalhead datahead;
647
 
+
648
 
+    int item_size;
649
 
 } bytecode_data;
650
 
 
651
 
 static void bc_data_destroy(void *contents);
652
 
 static void bc_data_print(const void *contents, FILE *f, int indent_level);
653
 
 static void bc_data_finalize(yasm_bytecode *bc, yasm_bytecode *prev_bc);
654
 
+static int bc_data_item_size(yasm_bytecode *bc);
655
 
 static int bc_data_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
656
 
                             void *add_span_data);
657
 
 static int bc_data_tobytes(yasm_bytecode *bc, unsigned char **bufp, void *d,
658
 
@@ -71,6 +78,7 @@
659
 
     bc_data_destroy,
660
 
     bc_data_print,
661
 
     bc_data_finalize,
662
 
+    bc_data_item_size,
663
 
     bc_data_calc_len,
664
 
     yasm_bc_expand_common,
665
 
     bc_data_tobytes,
666
 
@@ -131,37 +139,64 @@
667
 
             default:
668
 
                 break;
669
 
         }
670
 
+        if (dv->multiple) {
671
 
+            yasm_value val;
672
 
+            if (yasm_value_finalize_expr(&val, dv->multiple, prev_bc, 0))
673
 
+                yasm_error_set(YASM_ERROR_TOO_COMPLEX,
674
 
+                               N_("multiple expression too complex"));
675
 
+            else if (val.rel)
676
 
+                yasm_error_set(YASM_ERROR_NOT_ABSOLUTE,
677
 
+                               N_("multiple expression not absolute"));
678
 
+            dv->multiple = val.abs;
679
 
+        }
680
 
     }
681
 
 }
682
 
 
683
 
 static int
684
 
+bc_data_item_size(yasm_bytecode *bc)
685
 
+{
686
 
+    bytecode_data *bc_data = (bytecode_data *)bc->contents;
687
 
+    return bc_data->item_size;
688
 
+}
689
 
+
690
 
+static int
691
 
 bc_data_calc_len(yasm_bytecode *bc, yasm_bc_add_span_func add_span,
692
 
                  void *add_span_data)
693
 
 {
694
 
     bytecode_data *bc_data = (bytecode_data *)bc->contents;
695
 
     yasm_dataval *dv;
696
 
     yasm_intnum *intn;
697
 
+    int len;
698
 
+    unsigned long multiple;
699
 
 
700
 
     /* Count up element sizes, rounding up string length. */
701
 
     STAILQ_FOREACH(dv, &bc_data->datahead, link) {
702
 
         switch (dv->type) {
703
 
             case DV_EMPTY:
704
 
+                len = 0;
705
 
                 break;
706
 
             case DV_VALUE:
707
 
-                bc->len += dv->data.val.size/8;
708
 
+                len = dv->data.val.size/8;
709
 
                 break;
710
 
             case DV_RAW:
711
 
-                bc->len += dv->data.raw.len;
712
 
+                len = dv->data.raw.len;
713
 
                 break;
714
 
             case DV_ULEB128:
715
 
             case DV_SLEB128:
716
 
                 intn = yasm_expr_get_intnum(&dv->data.val.abs, 0);
717
 
                 if (!intn)
718
 
                     yasm_internal_error(N_("non-constant in data_tobytes"));
719
 
-                bc->len +=
720
 
-                    yasm_intnum_size_leb128(intn, dv->type == DV_SLEB128);
721
 
+                len = yasm_intnum_size_leb128(intn, dv->type == DV_SLEB128);
722
 
                 break;
723
 
+            case DV_RESERVE:
724
 
+                len = dv->data.val.size/8;
725
 
+                break;
726
 
         }
727
 
+
728
 
+        if (!yasm_dv_get_multiple(dv, &multiple))
729
 
+            len *= multiple;
730
 
+
731
 
+        bc->len += len;
732
 
     }
733
 
 
734
 
     return 0;
735
 
@@ -177,29 +212,47 @@
736
 
     unsigned char *bufp_orig = *bufp;
737
 
     yasm_intnum *intn;
738
 
     unsigned int val_len;
739
 
+    unsigned long multiple, i;
740
 
 
741
 
     STAILQ_FOREACH(dv, &bc_data->datahead, link) {
742
 
+        if (yasm_dv_get_multiple(dv, &multiple) || multiple == 0)
743
 
+            continue;
744
 
         switch (dv->type) {
745
 
             case DV_EMPTY:
746
 
                 break;
747
 
             case DV_VALUE:
748
 
                 val_len = dv->data.val.size/8;
749
 
-                if (output_value(&dv->data.val, *bufp, val_len,
750
 
-                                 (unsigned long)(*bufp-bufp_orig), bc, 1, d))
751
 
-                    return 1;
752
 
-                *bufp += val_len;
753
 
+                for (i=0; i<multiple; i++) {
754
 
+                    if (output_value(&dv->data.val, *bufp, val_len,
755
 
+                                     (unsigned long)(*bufp-bufp_orig), bc, 1,
756
 
+                                     d))
757
 
+                        return 1;
758
 
+                    *bufp += val_len;
759
 
+                }
760
 
                 break;
761
 
             case DV_RAW:
762
 
-                memcpy(*bufp, dv->data.raw.contents, dv->data.raw.len);
763
 
-                *bufp += dv->data.raw.len;
764
 
+                for (i=0; i<multiple; i++) {
765
 
+                    memcpy(*bufp, dv->data.raw.contents, dv->data.raw.len);
766
 
+                    *bufp += dv->data.raw.len;
767
 
+                }
768
 
                 break;
769
 
             case DV_ULEB128:
770
 
             case DV_SLEB128:
771
 
                 intn = yasm_expr_get_intnum(&dv->data.val.abs, 234);
772
 
                 if (!intn)
773
 
                     yasm_internal_error(N_("non-constant in data_tobytes"));
774
 
-                *bufp +=
775
 
-                    yasm_intnum_get_leb128(intn, *bufp, dv->type == DV_SLEB128);
776
 
+                for (i=0; i<multiple; i++) {
777
 
+                    *bufp +=
778
 
+                        yasm_intnum_get_leb128(intn, *bufp,
779
 
+                                dv->type == DV_SLEB128);
780
 
+                }
781
 
+            case DV_RESERVE:
782
 
+                val_len = dv->data.val.size/8;
783
 
+                for (i=0; i<multiple; i++) {
784
 
+                    memset(*bufp, 0, val_len);
785
 
+                    *bufp += val_len;
786
 
+                }
787
 
+                break;
788
 
         }
789
 
     }
790
 
 
791
 
@@ -218,11 +271,18 @@
792
 
 
793
 
 
794
 
     yasm_dvs_initialize(&data->datahead);
795
 
+    data->item_size = size;
796
 
 
797
 
     /* Prescan input data for length, etc.  Careful: this needs to be
798
 
      * precisely paired with the second loop.
799
 
      */
800
 
     STAILQ_FOREACH(dv, datahead, link) {
801
 
+        if (dv->multiple && dv->type != DV_EMPTY && len > 0) {
802
 
+            /* Flush previous data */
803
 
+            dvo = yasm_dv_create_raw(yasm_xmalloc(len), len);
804
 
+            STAILQ_INSERT_TAIL(&data->datahead, dvo, link);
805
 
+            len = 0;
806
 
+        }
807
 
         switch (dv->type) {
808
 
             case DV_EMPTY:
809
 
                 break;
810
 
@@ -247,6 +307,7 @@
811
 
                     /* Create bytecode for this value */
812
 
                     dvo = yasm_xmalloc(sizeof(yasm_dataval));
813
 
                     STAILQ_INSERT_TAIL(&data->datahead, dvo, link);
814
 
+                    dvo->multiple = dv->multiple;
815
 
                 }
816
 
                 break;
817
 
             case DV_RAW:
818
 
@@ -255,7 +316,19 @@
819
 
                 rlen = (rlen + size - 1) / size;
820
 
                 len += rlen*size;
821
 
                 break;
822
 
+            case DV_RESERVE:
823
 
+                len += size;
824
 
+                break;
825
 
         }
826
 
+
827
 
+        if (dv->multiple && dv->type != DV_EMPTY && len > 0) {
828
 
+            /* Flush this data */
829
 
+            dvo = yasm_dv_create_raw(yasm_xmalloc(len), len);
830
 
+            STAILQ_INSERT_TAIL(&data->datahead, dvo, link);
831
 
+            dvo->multiple = dv->multiple;
832
 
+            len = 0;
833
 
+        }
834
 
+
835
 
         if (append_zero)
836
 
             len++;
837
 
     }
838
 
@@ -271,6 +344,10 @@
839
 
     dvo = STAILQ_FIRST(&data->datahead);
840
 
     len = 0;
841
 
     while (dv && dvo) {
842
 
+        if (dv->multiple && dv->type != DV_EMPTY && len > 0) {
843
 
+            dvo = STAILQ_NEXT(dvo, link);
844
 
+            len = 0;
845
 
+        }
846
 
         switch (dv->type) {
847
 
             case DV_EMPTY:
848
 
                 break;
849
 
@@ -323,7 +400,17 @@
850
 
                         dvo->data.raw.contents[len++] = 0;
851
 
                 }
852
 
                 break;
853
 
+            case DV_RESERVE:
854
 
+                memset(&dvo->data.raw.contents[len], 0, size);
855
 
+                len += size;
856
 
+                break;
857
 
         }
858
 
+
859
 
+        if (dv->multiple && dv->type != DV_EMPTY && len > 0) {
860
 
+            dvo = STAILQ_NEXT(dvo, link);
861
 
+            len = 0;
862
 
+        }
863
 
+
864
 
         if (append_zero)
865
 
             dvo->data.raw.contents[len++] = 0;
866
 
         dv2 = STAILQ_NEXT(dv, link);
867
 
@@ -364,6 +451,7 @@
868
 
 
869
 
     retval->type = DV_VALUE;
870
 
     yasm_value_initialize(&retval->data.val, e, 0);
871
 
+    retval->multiple = NULL;
872
 
 
873
 
     return retval;
874
 
 }
875
 
@@ -376,11 +464,55 @@
876
 
     retval->type = DV_RAW;
877
 
     retval->data.raw.contents = contents;
878
 
     retval->data.raw.len = len;
879
 
+    retval->multiple = NULL;
880
 
 
881
 
     return retval;
882
 
 }
883
 
 
884
 
+yasm_dataval *
885
 
+yasm_dv_create_reserve(void)
886
 
+{
887
 
+    yasm_dataval *retval = yasm_xmalloc(sizeof(yasm_dataval));
888
 
+
889
 
+    retval->type = DV_RESERVE;
890
 
+    retval->multiple = NULL;
891
 
+
892
 
+    return retval;
893
 
+}
894
 
+
895
 
 void
896
 
+yasm_dv_set_multiple(yasm_dataval *dv, yasm_expr *e)
897
 
+{
898
 
+    if (dv->multiple)
899
 
+        dv->multiple = yasm_expr_create_tree( dv->multiple, YASM_EXPR_MUL, e,
900
 
+                                             e->line);
901
 
+    else
902
 
+        dv->multiple = e;
903
 
+}
904
 
+
905
 
+int
906
 
+yasm_dv_get_multiple(yasm_dataval *dv, unsigned long *multiple)
907
 
+{
908
 
+    /*@dependent@*/ /*@null@*/ const yasm_intnum *num;
909
 
+
910
 
+    *multiple = 1;
911
 
+    if (dv->multiple) {
912
 
+        num = yasm_expr_get_intnum(&dv->multiple, 0);
913
 
+        if (!num) {
914
 
+            yasm_error_set(YASM_ERROR_VALUE,
915
 
+                           N_("could not determine multiple"));
916
 
+            return 1;
917
 
+        }
918
 
+        if (yasm_intnum_sign(num) < 0) {
919
 
+            yasm_error_set(YASM_ERROR_VALUE, N_("multiple is negative"));
920
 
+            return 1;
921
 
+        }
922
 
+        *multiple = yasm_intnum_get_uint(num);
923
 
+    }
924
 
+    return 0;
925
 
+}
926
 
+
927
 
+void
928
 
 yasm_dvs_delete(yasm_datavalhead *headp)
929
 
 {
930
 
     yasm_dataval *cur, *next;
931
 
@@ -398,6 +530,8 @@
932
 
             default:
933
 
                 break;
934
 
         }
935
 
+        if (cur->multiple)
936
 
+            yasm_expr_destroy(cur->multiple);
937
 
         yasm_xfree(cur);
938
 
         cur = next;
939
 
     }
940
 
@@ -421,6 +555,11 @@
941
 
     unsigned long i;
942
 
 
943
 
     STAILQ_FOREACH(cur, head, link) {
944
 
+        fprintf(f, "%*sMultiple=", indent_level, "");
945
 
+        if (!cur->multiple)
946
 
+            fprintf(f, "nil (1)");
947
 
+        else
948
 
+            yasm_expr_print(cur->multiple, f);
949
 
         switch (cur->type) {
950
 
             case DV_EMPTY:
951
 
                 fprintf(f, "%*sEmpty\n", indent_level, "");
952
 
@@ -445,6 +584,9 @@
953
 
                 fprintf(f, "%*sSLEB128 value:\n", indent_level, "");
954
 
                 yasm_value_print(&cur->data.val, f, indent_level+1);
955
 
                 break;
956
 
+            case DV_RESERVE:
957
 
+                fprintf(f, "%*sReserved\n", indent_level, "");
958
 
+                break;
959
 
         }
960
 
     }
961
 
 }
962
 
Index: modules/parsers/tasm/tests/lidt.hex
963
 
===================================================================
964
 
--- old/modules/parsers/tasm/tests/lidt.hex     (r�vision 0)
965
 
+++ new/modules/parsers/tasm/tests/lidt.hex     (r�vision 0)
966
 
@@ -0,0 +1,11 @@
967
 
+00 
968
 
+00 
969
 
+00 
970
 
+00 
971
 
+00 
972
 
+00 
973
 
+0f 
974
 
+01 
975
 
+1e 
976
 
+00 
977
 
+00 
978
 
Index: modules/parsers/tasm/tests/macro.asm
979
 
===================================================================
980
 
--- old/modules/parsers/tasm/tests/macro.asm    (r�vision 0)
981
 
+++ new/modules/parsers/tasm/tests/macro.asm    (r�vision 0)
982
 
@@ -0,0 +1,6 @@
983
 
+a macro reg,i
984
 
+  mov reg,i
985
 
+  endm
986
 
+
987
 
+a ax,0
988
 
+a bx,1
989
 
Index: modules/parsers/tasm/tests/segment.asm
990
 
===================================================================
991
 
--- old/modules/parsers/tasm/tests/segment.asm  (r�vision 0)
992
 
+++ new/modules/parsers/tasm/tests/segment.asm  (r�vision 0)
993
 
@@ -0,0 +1,8 @@
994
 
+data segment
995
 
+  a db 0
996
 
+data ends
997
 
+
998
 
+assume es:data
999
 
+code segment
1000
 
+  mov byte ptr [a],1
1001
 
+code ends
1002
 
Index: modules/parsers/tasm/tests/exe/exe.asm
1003
 
===================================================================
1004
 
--- old/modules/parsers/tasm/tests/exe/exe.asm  (r�vision 0)
1005
 
+++ new/modules/parsers/tasm/tests/exe/exe.asm  (r�vision 0)
1006
 
@@ -0,0 +1,4 @@
1007
 
+a db 1
1008
 
+start proc
1009
 
+int 22
1010
 
+start endp
1011
 
Index: modules/parsers/tasm/tests/exe/exe.hex
1012
 
===================================================================
1013
 
--- old/modules/parsers/tasm/tests/exe/exe.hex  (r�vision 0)
1014
 
+++ new/modules/parsers/tasm/tests/exe/exe.hex  (r�vision 0)
1015
 
@@ -0,0 +1,515 @@
1016
 
+4d 
1017
 
+5a 
1018
 
+03 
1019
 
+00 
1020
 
+02 
1021
 
+00 
1022
 
+00 
1023
 
+00 
1024
 
+20 
1025
 
+00 
1026
 
+00 
1027
 
+00 
1028
 
+ff 
1029
 
+ff 
1030
 
+00 
1031
 
+00 
1032
 
+00 
1033
 
+00 
1034
 
+00 
1035
 
+00 
1036
 
+01 
1037
 
+00 
1038
 
+00 
1039
 
+00 
1040
 
+22 
1041
 
+00 
1042
 
+00 
1043
 
+00 
1044
 
+00 
1045
 
+00 
1046
 
+00 
1047
 
+00 
1048
 
+00 
1049
 
+00 
1050
 
+00 
1051
 
+00 
1052
 
+00 
1053
 
+00 
1054
 
+00 
1055
 
+00 
1056
 
+00 
1057
 
+00 
1058
 
+00 
1059
 
+00 
1060
 
+00 
1061
 
+00 
1062
 
+00 
1063
 
+00 
1064
 
+00 
1065
 
+00 
1066
 
+00 
1067
 
+00 
1068
 
+00 
1069
 
+00 
1070
 
+00 
1071
 
+00 
1072
 
+00 
1073
 
+00 
1074
 
+00 
1075
 
+00 
1076
 
+00 
1077
 
+00 
1078
 
+00 
1079
 
+00 
1080
 
+00 
1081
 
+00 
1082
 
+00 
1083
 
+00 
1084
 
+00 
1085
 
+00 
1086
 
+00 
1087
 
+00 
1088
 
+00 
1089
 
+00 
1090
 
+00 
1091
 
+00 
1092
 
+00 
1093
 
+00 
1094
 
+00 
1095
 
+00 
1096
 
+00 
1097
 
+00 
1098
 
+00 
1099
 
+00 
1100
 
+00 
1101
 
+00 
1102
 
+00 
1103
 
+00 
1104
 
+00 
1105
 
+00 
1106
 
+00 
1107
 
+00 
1108
 
+00 
1109
 
+00 
1110
 
+00 
1111
 
+00 
1112
 
+00 
1113
 
+00 
1114
 
+00 
1115
 
+00 
1116
 
+00 
1117
 
+00 
1118
 
+00 
1119
 
+00 
1120
 
+00 
1121
 
+00 
1122
 
+00 
1123
 
+00 
1124
 
+00 
1125
 
+00 
1126
 
+00 
1127
 
+00 
1128
 
+00 
1129
 
+00 
1130
 
+00 
1131
 
+00 
1132
 
+00 
1133
 
+00 
1134
 
+00 
1135
 
+00 
1136
 
+00 
1137
 
+00 
1138
 
+00 
1139
 
+00 
1140
 
+00 
1141
 
+00 
1142
 
+00 
1143
 
+00 
1144
 
+00 
1145
 
+00 
1146
 
+00 
1147
 
+00 
1148
 
+00 
1149
 
+00 
1150
 
+00 
1151
 
+00 
1152
 
+00 
1153
 
+00 
1154
 
+00 
1155
 
+00 
1156
 
+00 
1157
 
+00 
1158
 
+00 
1159
 
+00 
1160
 
+00 
1161
 
+00 
1162
 
+00 
1163
 
+00 
1164
 
+00 
1165
 
+00 
1166
 
+00 
1167
 
+00 
1168
 
+00 
1169
 
+00 
1170
 
+00 
1171
 
+00 
1172
 
+00 
1173
 
+00 
1174
 
+00 
1175
 
+00 
1176
 
+00 
1177
 
+00 
1178
 
+00 
1179
 
+00 
1180
 
+00 
1181
 
+00 
1182
 
+00 
1183
 
+00 
1184
 
+00 
1185
 
+00 
1186
 
+00 
1187
 
+00 
1188
 
+00 
1189
 
+00 
1190
 
+00 
1191
 
+00 
1192
 
+00 
1193
 
+00 
1194
 
+00 
1195
 
+00 
1196
 
+00 
1197
 
+00 
1198
 
+00 
1199
 
+00 
1200
 
+00 
1201
 
+00 
1202
 
+00 
1203
 
+00 
1204
 
+00 
1205
 
+00 
1206
 
+00 
1207
 
+00 
1208
 
+00 
1209
 
+00 
1210
 
+00 
1211
 
+00 
1212
 
+00 
1213
 
+00 
1214
 
+00 
1215
 
+00 
1216
 
+00 
1217
 
+00 
1218
 
+00 
1219
 
+00 
1220
 
+00 
1221
 
+00 
1222
 
+00 
1223
 
+00 
1224
 
+00 
1225
 
+00 
1226
 
+00 
1227
 
+00 
1228
 
+00 
1229
 
+00 
1230
 
+00 
1231
 
+00 
1232
 
+00 
1233
 
+00 
1234
 
+00 
1235
 
+00 
1236
 
+00 
1237
 
+00 
1238
 
+00 
1239
 
+00 
1240
 
+00 
1241
 
+00 
1242
 
+00 
1243
 
+00 
1244
 
+00 
1245
 
+00 
1246
 
+00 
1247
 
+00 
1248
 
+00 
1249
 
+00 
1250
 
+00 
1251
 
+00 
1252
 
+00 
1253
 
+00 
1254
 
+00 
1255
 
+00 
1256
 
+00 
1257
 
+00 
1258
 
+00 
1259
 
+00 
1260
 
+00 
1261
 
+00 
1262
 
+00 
1263
 
+00 
1264
 
+00 
1265
 
+00 
1266
 
+00 
1267
 
+00 
1268
 
+00 
1269
 
+00 
1270
 
+00 
1271
 
+00 
1272
 
+00 
1273
 
+00 
1274
 
+00 
1275
 
+00 
1276
 
+00 
1277
 
+00 
1278
 
+00 
1279
 
+00 
1280
 
+00 
1281
 
+00 
1282
 
+00 
1283
 
+00 
1284
 
+00 
1285
 
+00 
1286
 
+00 
1287
 
+00 
1288
 
+00 
1289
 
+00 
1290
 
+00 
1291
 
+00 
1292
 
+00 
1293
 
+00 
1294
 
+00 
1295
 
+00 
1296
 
+00 
1297
 
+00 
1298
 
+00 
1299
 
+00 
1300
 
+00 
1301
 
+00 
1302
 
+00 
1303
 
+00 
1304
 
+00 
1305
 
+00 
1306
 
+00 
1307
 
+00 
1308
 
+00 
1309
 
+00 
1310
 
+00 
1311
 
+00 
1312
 
+00 
1313
 
+00 
1314
 
+00 
1315
 
+00 
1316
 
+00 
1317
 
+00 
1318
 
+00 
1319
 
+00 
1320
 
+00 
1321
 
+00 
1322
 
+00 
1323
 
+00 
1324
 
+00 
1325
 
+00 
1326
 
+00 
1327
 
+00 
1328
 
+00 
1329
 
+00 
1330
 
+00 
1331
 
+00 
1332
 
+00 
1333
 
+00 
1334
 
+00 
1335
 
+00 
1336
 
+00 
1337
 
+00 
1338
 
+00 
1339
 
+00 
1340
 
+00 
1341
 
+00 
1342
 
+00 
1343
 
+00 
1344
 
+00 
1345
 
+00 
1346
 
+00 
1347
 
+00 
1348
 
+00 
1349
 
+00 
1350
 
+00 
1351
 
+00 
1352
 
+00 
1353
 
+00 
1354
 
+00 
1355
 
+00 
1356
 
+00 
1357
 
+00 
1358
 
+00 
1359
 
+00 
1360
 
+00 
1361
 
+00 
1362
 
+00 
1363
 
+00 
1364
 
+00 
1365
 
+00 
1366
 
+00 
1367
 
+00 
1368
 
+00 
1369
 
+00 
1370
 
+00 
1371
 
+00 
1372
 
+00 
1373
 
+00 
1374
 
+00 
1375
 
+00 
1376
 
+00 
1377
 
+00 
1378
 
+00 
1379
 
+00 
1380
 
+00 
1381
 
+00 
1382
 
+00 
1383
 
+00 
1384
 
+00 
1385
 
+00 
1386
 
+00 
1387
 
+00 
1388
 
+00 
1389
 
+00 
1390
 
+00 
1391
 
+00 
1392
 
+00 
1393
 
+00 
1394
 
+00 
1395
 
+00 
1396
 
+00 
1397
 
+00 
1398
 
+00 
1399
 
+00 
1400
 
+00 
1401
 
+00 
1402
 
+00 
1403
 
+00 
1404
 
+00 
1405
 
+00 
1406
 
+00 
1407
 
+00 
1408
 
+00 
1409
 
+00 
1410
 
+00 
1411
 
+00 
1412
 
+00 
1413
 
+00 
1414
 
+00 
1415
 
+00 
1416
 
+00 
1417
 
+00 
1418
 
+00 
1419
 
+00 
1420
 
+00 
1421
 
+00 
1422
 
+00 
1423
 
+00 
1424
 
+00 
1425
 
+00 
1426
 
+00 
1427
 
+00 
1428
 
+00 
1429
 
+00 
1430
 
+00 
1431
 
+00 
1432
 
+00 
1433
 
+00 
1434
 
+00 
1435
 
+00 
1436
 
+00 
1437
 
+00 
1438
 
+00 
1439
 
+00 
1440
 
+00 
1441
 
+00 
1442
 
+00 
1443
 
+00 
1444
 
+00 
1445
 
+00 
1446
 
+00 
1447
 
+00 
1448
 
+00 
1449
 
+00 
1450
 
+00 
1451
 
+00 
1452
 
+00 
1453
 
+00 
1454
 
+00 
1455
 
+00 
1456
 
+00 
1457
 
+00 
1458
 
+00 
1459
 
+00 
1460
 
+00 
1461
 
+00 
1462
 
+00 
1463
 
+00 
1464
 
+00 
1465
 
+00 
1466
 
+00 
1467
 
+00 
1468
 
+00 
1469
 
+00 
1470
 
+00 
1471
 
+00 
1472
 
+00 
1473
 
+00 
1474
 
+00 
1475
 
+00 
1476
 
+00 
1477
 
+00 
1478
 
+00 
1479
 
+00 
1480
 
+00 
1481
 
+00 
1482
 
+00 
1483
 
+00 
1484
 
+00 
1485
 
+00 
1486
 
+00 
1487
 
+00 
1488
 
+00 
1489
 
+00 
1490
 
+00 
1491
 
+00 
1492
 
+00 
1493
 
+00 
1494
 
+00 
1495
 
+00 
1496
 
+00 
1497
 
+00 
1498
 
+00 
1499
 
+00 
1500
 
+00 
1501
 
+00 
1502
 
+00 
1503
 
+00 
1504
 
+00 
1505
 
+00 
1506
 
+00 
1507
 
+00 
1508
 
+00 
1509
 
+00 
1510
 
+00 
1511
 
+00 
1512
 
+00 
1513
 
+00 
1514
 
+00 
1515
 
+00 
1516
 
+00 
1517
 
+00 
1518
 
+00 
1519
 
+00 
1520
 
+00 
1521
 
+00 
1522
 
+00 
1523
 
+00 
1524
 
+00 
1525
 
+00 
1526
 
+00 
1527
 
+00 
1528
 
+01 
1529
 
+cd 
1530
 
+16 
1531
 
Index: modules/parsers/tasm/tests/exe/tasm_exe_test.sh
1532
 
===================================================================
1533
 
--- old/modules/parsers/tasm/tests/exe/tasm_exe_test.sh (r�vision 0)
1534
 
+++ new/modules/parsers/tasm/tests/exe/tasm_exe_test.sh (r�vision 0)
1535
 
@@ -0,0 +1,4 @@
1536
 
+#! /bin/sh
1537
 
+# $Id: tasm_test.sh 1137 2004-09-04 01:24:57Z peter $
1538
 
+${srcdir}/out_test.sh tasm_test modules/parsers/tasm/tests/exe "tasm-compat parser" "-f dosexe -p tasm" ""
1539
 
+exit $?
1540
 
 
1541
 
Modification de propri�t�s sur modules/parsers/tasm/tests/exe/tasm_exe_test.sh
1542
 
___________________________________________________________________
1543
 
Ajout� : svn:mergeinfo
1544
 
 
1545
 
Index: modules/parsers/tasm/tests/macro.hex
1546
 
===================================================================
1547
 
--- old/modules/parsers/tasm/tests/macro.hex    (r�vision 0)
1548
 
+++ new/modules/parsers/tasm/tests/macro.hex    (r�vision 0)
1549
 
@@ -0,0 +1,6 @@
1550
 
+b8 
1551
 
+00 
1552
 
+00 
1553
 
+bb 
1554
 
+01 
1555
 
+00 
1556
 
Index: modules/parsers/tasm/tests/segment.hex
1557
 
===================================================================
1558
 
--- old/modules/parsers/tasm/tests/segment.hex  (r�vision 0)
1559
 
+++ new/modules/parsers/tasm/tests/segment.hex  (r�vision 0)
1560
 
@@ -0,0 +1,7 @@
1561
 
+00 
1562
 
+26 
1563
 
+c6 
1564
 
+06 
1565
 
+00 
1566
 
+00 
1567
 
+01 
1568
 
Index: modules/parsers/tasm/tests/charstr.asm
1569
 
===================================================================
1570
 
--- old/modules/parsers/tasm/tests/charstr.asm  (r�vision 0)
1571
 
+++ new/modules/parsers/tasm/tests/charstr.asm  (r�vision 0)
1572
 
@@ -0,0 +1 @@
1573
 
+mov eax,"1234"
1574
 
Index: modules/parsers/tasm/tests/charstr.hex
1575
 
===================================================================
1576
 
--- old/modules/parsers/tasm/tests/charstr.hex  (r�vision 0)
1577
 
+++ new/modules/parsers/tasm/tests/charstr.hex  (r�vision 0)
1578
 
@@ -0,0 +1,6 @@
1579
 
+66 
1580
 
+b8 
1581
 
+34 
1582
 
+33 
1583
 
+32 
1584
 
+31 
1585
 
Index: modules/parsers/tasm/tests/array.asm
1586
 
===================================================================
1587
 
--- old/modules/parsers/tasm/tests/array.asm    (r�vision 0)
1588
 
+++ new/modules/parsers/tasm/tests/array.asm    (r�vision 0)
1589
 
@@ -0,0 +1,2 @@
1590
 
+t db 0,1,2
1591
 
+mov al,t[1]
1592
 
Index: modules/parsers/tasm/tests/label.asm
1593
 
===================================================================
1594
 
--- old/modules/parsers/tasm/tests/label.asm    (r�vision 0)
1595
 
+++ new/modules/parsers/tasm/tests/label.asm    (r�vision 0)
1596
 
@@ -0,0 +1,2 @@
1597
 
+a label byte
1598
 
+mov ax,offset a
1599
 
Index: modules/parsers/tasm/tests/array.hex
1600
 
===================================================================
1601
 
--- old/modules/parsers/tasm/tests/array.hex    (r�vision 0)
1602
 
+++ new/modules/parsers/tasm/tests/array.hex    (r�vision 0)
1603
 
@@ -0,0 +1,6 @@
1604
 
+00 
1605
 
+01 
1606
 
+02 
1607
 
+a0 
1608
 
+01 
1609
 
+00 
1610
 
Index: modules/parsers/tasm/tests/label.hex
1611
 
===================================================================
1612
 
--- old/modules/parsers/tasm/tests/label.hex    (r�vision 0)
1613
 
+++ new/modules/parsers/tasm/tests/label.hex    (r�vision 0)
1614
 
@@ -0,0 +1,3 @@
1615
 
+b8 
1616
 
+00 
1617
 
+00 
1618
 
Index: modules/parsers/tasm/tests/offset.asm
1619
 
===================================================================
1620
 
--- old/modules/parsers/tasm/tests/offset.asm   (r�vision 0)
1621
 
+++ new/modules/parsers/tasm/tests/offset.asm   (r�vision 0)
1622
 
@@ -0,0 +1,3 @@
1623
 
+a db 1
1624
 
+mov ax,offset a
1625
 
+mov ax,offset[a]
1626
 
Index: modules/parsers/tasm/tests/offset.hex
1627
 
===================================================================
1628
 
--- old/modules/parsers/tasm/tests/offset.hex   (r�vision 0)
1629
 
+++ new/modules/parsers/tasm/tests/offset.hex   (r�vision 0)
1630
 
@@ -0,0 +1,7 @@
1631
 
+01 
1632
 
+b8 
1633
 
+00 
1634
 
+00 
1635
 
+b8 
1636
 
+00 
1637
 
+00 
1638
 
Index: modules/parsers/tasm/tests/irp.asm
1639
 
===================================================================
1640
 
--- old/modules/parsers/tasm/tests/irp.asm      (r�vision 0)
1641
 
+++ new/modules/parsers/tasm/tests/irp.asm      (r�vision 0)
1642
 
@@ -0,0 +1,3 @@
1643
 
+irp i,<1,2,3>
1644
 
+ mov ax,i
1645
 
+endm
1646
 
Index: modules/parsers/tasm/tests/quote.asm
1647
 
===================================================================
1648
 
--- old/modules/parsers/tasm/tests/quote.asm    (r�vision 0)
1649
 
+++ new/modules/parsers/tasm/tests/quote.asm    (r�vision 0)
1650
 
@@ -0,0 +1,2 @@
1651
 
+a db 'don''t'
1652
 
+b db """"
1653
 
Index: modules/parsers/tasm/tests/tasm_test.sh
1654
 
===================================================================
1655
 
--- old/modules/parsers/tasm/tests/tasm_test.sh (r�vision 0)
1656
 
+++ new/modules/parsers/tasm/tests/tasm_test.sh (r�vision 0)
1657
 
@@ -0,0 +1,5 @@
1658
 
+#! /bin/sh
1659
 
+# $Id: tasm_test.sh 1137 2004-09-04 01:24:57Z peter $
1660
 
+${srcdir}/out_test.sh tasm_test modules/parsers/tasm/tests "tasm-compat parser" "-f bin -p tasm" ""
1661
 
+${srcdir}/out_test.sh tasm_test modules/parsers/tasm/tests/exe "tasm-compat parser" "-f dosexe -p tasm" ""
1662
 
+exit $?
1663
 
 
1664
 
Modification de propri�t�s sur modules/parsers/tasm/tests/tasm_test.sh
1665
 
___________________________________________________________________
1666
 
Ajout� : svn:executable
1667
 
   + *
1668
 
 
1669
 
Index: modules/parsers/tasm/tests/irp.hex
1670
 
===================================================================
1671
 
--- old/modules/parsers/tasm/tests/irp.hex      (r�vision 0)
1672
 
+++ new/modules/parsers/tasm/tests/irp.hex      (r�vision 0)
1673
 
@@ -0,0 +1,9 @@
1674
 
+b8 
1675
 
+01 
1676
 
+00 
1677
 
+b8 
1678
 
+02 
1679
 
+00 
1680
 
+b8 
1681
 
+03 
1682
 
+00 
1683
 
Index: modules/parsers/tasm/tests/struc.asm
1684
 
===================================================================
1685
 
--- old/modules/parsers/tasm/tests/struc.asm    (r�vision 0)
1686
 
+++ new/modules/parsers/tasm/tests/struc.asm    (r�vision 0)
1687
 
@@ -0,0 +1,8 @@
1688
 
+s struc
1689
 
+  a db ?
1690
 
+  b db ?
1691
 
+s ends
1692
 
+
1693
 
+v s <1,?>
1694
 
+
1695
 
+mov al,[v].b
1696
 
Index: modules/parsers/tasm/tests/struc.errwarn
1697
 
===================================================================
1698
 
--- old/modules/parsers/tasm/tests/struc.errwarn        (r�vision 0)
1699
 
+++ new/modules/parsers/tasm/tests/struc.errwarn        (r�vision 0)
1700
 
@@ -0,0 +1 @@
1701
 
+-:6: warning: uninitialized space declared in code/data section: zeroing
1702
 
Index: modules/parsers/tasm/tests/quote.hex
1703
 
===================================================================
1704
 
--- old/modules/parsers/tasm/tests/quote.hex    (r�vision 0)
1705
 
+++ new/modules/parsers/tasm/tests/quote.hex    (r�vision 0)
1706
 
@@ -0,0 +1,6 @@
1707
 
+64 
1708
 
+6f 
1709
 
+6e 
1710
 
+27 
1711
 
+74 
1712
 
+22 
1713
 
Index: modules/parsers/tasm/tests/struc.hex
1714
 
===================================================================
1715
 
--- old/modules/parsers/tasm/tests/struc.hex    (r�vision 0)
1716
 
+++ new/modules/parsers/tasm/tests/struc.hex    (r�vision 0)
1717
 
@@ -0,0 +1,5 @@
1718
 
+01 
1719
 
+00 
1720
 
+a0 
1721
 
+01 
1722
 
+00 
1723
 
Index: modules/parsers/tasm/tests/equal.asm
1724
 
===================================================================
1725
 
--- old/modules/parsers/tasm/tests/equal.asm    (r�vision 0)
1726
 
+++ new/modules/parsers/tasm/tests/equal.asm    (r�vision 0)
1727
 
@@ -0,0 +1 @@
1728
 
+a = byte 1
1729
 
Index: modules/parsers/tasm/tests/size.asm
1730
 
===================================================================
1731
 
--- old/modules/parsers/tasm/tests/size.asm     (r�vision 0)
1732
 
+++ new/modules/parsers/tasm/tests/size.asm     (r�vision 0)
1733
 
@@ -0,0 +1,2 @@
1734
 
+a db 0
1735
 
+mov a,1
1736
 
Index: modules/parsers/tasm/tests/equal.hex
1737
 
===================================================================
1738
 
Index: modules/parsers/tasm/tests/case.asm
1739
 
===================================================================
1740
 
--- old/modules/parsers/tasm/tests/case.asm     (r�vision 0)
1741
 
+++ new/modules/parsers/tasm/tests/case.asm     (r�vision 0)
1742
 
@@ -0,0 +1,3 @@
1743
 
+a db 0
1744
 
+B dw A
1745
 
+c dw b
1746
 
Index: modules/parsers/tasm/tests/size.hex
1747
 
===================================================================
1748
 
--- old/modules/parsers/tasm/tests/size.hex     (r�vision 0)
1749
 
+++ new/modules/parsers/tasm/tests/size.hex     (r�vision 0)
1750
 
@@ -0,0 +1,6 @@
1751
 
+00 
1752
 
+c6 
1753
 
+06 
1754
 
+00 
1755
 
+00 
1756
 
+01 
1757
 
Index: modules/parsers/tasm/tests/expr.asm
1758
 
===================================================================
1759
 
--- old/modules/parsers/tasm/tests/expr.asm     (r�vision 0)
1760
 
+++ new/modules/parsers/tasm/tests/expr.asm     (r�vision 0)
1761
 
@@ -0,0 +1 @@
1762
 
+a db low ((1 shl 2) and (16 shr 2) or (high 0x5034))
1763
 
Index: modules/parsers/tasm/tests/case.hex
1764
 
===================================================================
1765
 
--- old/modules/parsers/tasm/tests/case.hex     (r�vision 0)
1766
 
+++ new/modules/parsers/tasm/tests/case.hex     (r�vision 0)
1767
 
@@ -0,0 +1,5 @@
1768
 
+00 
1769
 
+00 
1770
 
+00 
1771
 
+01 
1772
 
+00 
1773
 
Index: modules/parsers/tasm/tests/expr.hex
1774
 
===================================================================
1775
 
--- old/modules/parsers/tasm/tests/expr.hex     (r�vision 0)
1776
 
+++ new/modules/parsers/tasm/tests/expr.hex     (r�vision 0)
1777
 
@@ -0,0 +1 @@
1778
 
+54 
1779
 
Index: modules/parsers/tasm/tests/les.asm
1780
 
===================================================================
1781
 
--- old/modules/parsers/tasm/tests/les.asm      (r�vision 0)
1782
 
+++ new/modules/parsers/tasm/tests/les.asm      (r�vision 0)
1783
 
@@ -0,0 +1,2 @@
1784
 
+a db 1
1785
 
+les ax,a
1786
 
Index: modules/parsers/tasm/tests/les.hex
1787
 
===================================================================
1788
 
--- old/modules/parsers/tasm/tests/les.hex      (r�vision 0)
1789
 
+++ new/modules/parsers/tasm/tests/les.hex      (r�vision 0)
1790
 
@@ -0,0 +1,5 @@
1791
 
+01 
1792
 
+c4 
1793
 
+06 
1794
 
+00 
1795
 
+00 
1796
 
Index: modules/parsers/tasm/tests/dup.asm
1797
 
===================================================================
1798
 
--- old/modules/parsers/tasm/tests/dup.asm      (r�vision 0)
1799
 
+++ new/modules/parsers/tasm/tests/dup.asm      (r�vision 0)
1800
 
@@ -0,0 +1 @@
1801
 
+a db 10 dup(1)
1802
 
Index: modules/parsers/tasm/tests/res.errwarn
1803
 
===================================================================
1804
 
--- old/modules/parsers/tasm/tests/res.errwarn  (r�vision 0)
1805
 
+++ new/modules/parsers/tasm/tests/res.errwarn  (r�vision 0)
1806
 
@@ -0,0 +1,2 @@
1807
 
+-:1: warning: uninitialized space declared in code/data section: zeroing
1808
 
+-:2: warning: uninitialized space declared in code/data section: zeroing
1809
 
Index: modules/parsers/tasm/tests/res.asm
1810
 
===================================================================
1811
 
--- old/modules/parsers/tasm/tests/res.asm      (r�vision 0)
1812
 
+++ new/modules/parsers/tasm/tests/res.asm      (r�vision 0)
1813
 
@@ -0,0 +1,2 @@
1814
 
+a db ?
1815
 
+b db 2 dup (?)
1816
 
Index: modules/parsers/tasm/tests/lidt.asm
1817
 
===================================================================
1818
 
--- old/modules/parsers/tasm/tests/lidt.asm     (r�vision 0)
1819
 
+++ new/modules/parsers/tasm/tests/lidt.asm     (r�vision 0)
1820
 
@@ -0,0 +1,3 @@
1821
 
+idtr dw 0
1822
 
+     dd 0
1823
 
+lidt fword ptr idtr
1824
 
Index: modules/parsers/tasm/tests/dup.hex
1825
 
===================================================================
1826
 
--- old/modules/parsers/tasm/tests/dup.hex      (r�vision 0)
1827
 
+++ new/modules/parsers/tasm/tests/dup.hex      (r�vision 0)
1828
 
@@ -0,0 +1,10 @@
1829
 
+01 
1830
 
+01 
1831
 
+01 
1832
 
+01 
1833
 
+01 
1834
 
+01 
1835
 
+01 
1836
 
+01 
1837
 
+01 
1838
 
+01 
1839
 
Index: modules/parsers/tasm/tests/res.hex
1840
 
===================================================================
1841
 
--- old/modules/parsers/tasm/tests/res.hex      (r�vision 0)
1842
 
+++ new/modules/parsers/tasm/tests/res.hex      (r�vision 0)
1843
 
@@ -0,0 +1,3 @@
1844
 
+00 
1845
 
+00 
1846
 
+00 
1847
 
Index: modules/parsers/nasm/nasm-token.re
1848
 
===================================================================
1849
 
--- old/modules/parsers/nasm/nasm-token.re      (r�vision 2128)
1850
 
+++ new/modules/parsers/nasm/nasm-token.re      (copie de travail)
1851
 
@@ -32,6 +32,7 @@
1852
 
 #include <libyasm.h>
1853
 
 
1854
 
 #include "modules/parsers/nasm/nasm-parser.h"
1855
 
+#include "modules/preprocs/nasm/nasm.h"
1856
 
 
1857
 
 
1858
 
 #define YYCURSOR        cursor
1859
 
@@ -76,13 +77,22 @@
1860
 
 {
1861
 
     /* check for special non-local labels like ..start */
1862
 
     if (tok[zeropos+1] == '.') {
1863
 
-        lvalp->str_val = yasm__xstrndup(tok+zeropos, toklen-zeropos);
1864
 
+        lvalp->str_val = yasm__xstrndup(tok+zeropos+(parser_nasm->tasm?2:0),
1865
 
+            toklen-zeropos-(parser_nasm->tasm?2:0));
1866
 
         /* check for special non-local ..@label */
1867
 
         if (lvalp->str_val[zeropos+2] == '@')
1868
 
             return NONLOCAL_ID;
1869
 
         return SPECIAL_ID;
1870
 
     }
1871
 
-
1872
 
+    if (parser_nasm->tasm && (!tasm_locals || 
1873
 
+                (tok[zeropos] == '.' &&
1874
 
+                 tok[zeropos+1] != '@' && tok[zeropos+2] != '@'))) {
1875
 
+        /* no locals on Tasm without the 'locals' directive */
1876
 
+        /* .foo is never local either, but .@@foo may be (local structure
1877
 
+         * members) */
1878
 
+        lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos);
1879
 
+        return SPECIAL_ID;
1880
 
+    }
1881
 
     if (!parser_nasm->locallabel_base) {
1882
 
         lvalp->str_val = yasm__xstrndup(tok+zeropos, toklen-zeropos);
1883
 
         yasm_warn_set(YASM_WARN_GENERAL,
1884
 
@@ -242,65 +252,95 @@
1885
 
         }
1886
 
 
1887
 
         /* pseudo-instructions */
1888
 
-        'db'            { lvalp->int_info = 8; RETURN(DECLARE_DATA); }
1889
 
+        'db'            {
1890
 
+            lvalp->int_info = 8;
1891
 
+            parser_nasm->state = INSTRUCTION;
1892
 
+            RETURN(DECLARE_DATA);
1893
 
+        }
1894
 
         'dhw'           {
1895
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2;
1896
 
+            parser_nasm->state = INSTRUCTION;
1897
 
             RETURN(DECLARE_DATA);
1898
 
         }
1899
 
         'dw'            {
1900
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch);
1901
 
+            parser_nasm->state = INSTRUCTION;
1902
 
             RETURN(DECLARE_DATA);
1903
 
         }
1904
 
         'dd'            {
1905
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2;
1906
 
+            parser_nasm->state = INSTRUCTION;
1907
 
             RETURN(DECLARE_DATA);
1908
 
         }
1909
 
         'dq'            {
1910
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4;
1911
 
+            parser_nasm->state = INSTRUCTION;
1912
 
             RETURN(DECLARE_DATA);
1913
 
         }
1914
 
-        'dt'            { lvalp->int_info = 80; RETURN(DECLARE_DATA); }
1915
 
+        'dt'            {
1916
 
+            lvalp->int_info = 80;
1917
 
+            parser_nasm->state = INSTRUCTION;
1918
 
+            RETURN(DECLARE_DATA);
1919
 
+        }
1920
 
         'ddq'           {
1921
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
1922
 
+            parser_nasm->state = INSTRUCTION;
1923
 
             RETURN(DECLARE_DATA);
1924
 
         }
1925
 
         'do'           {
1926
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
1927
 
+            parser_nasm->state = INSTRUCTION;
1928
 
             RETURN(DECLARE_DATA);
1929
 
         }
1930
 
         'dy'           {
1931
 
             lvalp->int_info = 256;
1932
 
+            parser_nasm->state = INSTRUCTION;
1933
 
             RETURN(DECLARE_DATA);
1934
 
         }
1935
 
 
1936
 
-        'resb'          { lvalp->int_info = 8; RETURN(RESERVE_SPACE); }
1937
 
+        'resb'          {
1938
 
+            lvalp->int_info = 8;
1939
 
+            parser_nasm->state = INSTRUCTION;
1940
 
+            RETURN(RESERVE_SPACE);
1941
 
+        }
1942
 
         'reshw'         {
1943
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2;
1944
 
+            parser_nasm->state = INSTRUCTION;
1945
 
             RETURN(RESERVE_SPACE);
1946
 
         }
1947
 
         'resw'          {
1948
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch);
1949
 
+            parser_nasm->state = INSTRUCTION;
1950
 
             RETURN(RESERVE_SPACE);
1951
 
         }
1952
 
         'resd'          {
1953
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2;
1954
 
+            parser_nasm->state = INSTRUCTION;
1955
 
             RETURN(RESERVE_SPACE);
1956
 
         }
1957
 
         'resq'          {
1958
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4;
1959
 
+            parser_nasm->state = INSTRUCTION;
1960
 
             RETURN(RESERVE_SPACE);
1961
 
         }
1962
 
-        'rest'          { lvalp->int_info = 80; RETURN(RESERVE_SPACE); }
1963
 
+        'rest'          {
1964
 
+            lvalp->int_info = 80;
1965
 
+            parser_nasm->state = INSTRUCTION;
1966
 
+            RETURN(RESERVE_SPACE);
1967
 
+        }
1968
 
         'resdq'         {
1969
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
1970
 
+            parser_nasm->state = INSTRUCTION;
1971
 
             RETURN(RESERVE_SPACE);
1972
 
         }
1973
 
         'reso'         {
1974
 
             lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
1975
 
+            parser_nasm->state = INSTRUCTION;
1976
 
             RETURN(RESERVE_SPACE);
1977
 
         }
1978
 
         'resy'         {
1979
 
             lvalp->int_info = 256;
1980
 
+            parser_nasm->state = INSTRUCTION;
1981
 
             RETURN(RESERVE_SPACE);
1982
 
         }
1983
 
 
1984
 
@@ -325,17 +365,18 @@
1985
 
         "//"                    { RETURN(SIGNDIV); }
1986
 
         "%%"                    { RETURN(SIGNMOD); }
1987
 
         "$$"                    { RETURN(START_SECTION_ID); }
1988
 
-        [-+|^*&/%~$():=,\[]     { RETURN(s->tok[0]); }
1989
 
+        [-+|^*&/%~$():=,\[?]    { RETURN(s->tok[0]); }
1990
 
         "]"                     { RETURN(s->tok[0]); }
1991
 
 
1992
 
         /* local label (.label) */
1993
 
-        "." [a-zA-Z0-9_$#@~.?]+ {
1994
 
+        ("." | "@@") [a-zA-Z0-9_$#@~.?]+ {
1995
 
             RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 0, parser_nasm));
1996
 
         }
1997
 
 
1998
 
         /* forced identifier */
1999
 
         "$" [a-zA-Z0-9_$#@~.?]+ {
2000
 
-            if (TOK[1] == '.') {
2001
 
+            if (TOK[1] == '.' ||
2002
 
+                    (parser_nasm->tasm && TOK[1] == '@' && TOK[2] == '@')) {
2003
 
                 /* handle like .label */
2004
 
                 RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 1, parser_nasm));
2005
 
             }
2006
 
@@ -376,11 +417,61 @@
2007
 
                     s->tok[TOKLEN] = savech;
2008
 
                     RETURN(TARGETMOD);
2009
 
                 default:
2010
 
+                    break;
2011
 
+            }
2012
 
+            if (parser_nasm->tasm) {
2013
 
+                if (!strcasecmp(TOK, "shl")) {
2014
 
                     s->tok[TOKLEN] = savech;
2015
 
+                    RETURN(LEFT_OP);
2016
 
+                }
2017
 
+                if (!strcasecmp(TOK, "shr")) {
2018
 
+                    s->tok[TOKLEN] = savech;
2019
 
+                    RETURN(RIGHT_OP);
2020
 
+                }
2021
 
+                if (!strcasecmp(TOK, "and")) {
2022
 
+                    s->tok[TOKLEN] = savech;
2023
 
+                    RETURN('&');
2024
 
+                }
2025
 
+                if (!strcasecmp(TOK, "or")) {
2026
 
+                    s->tok[TOKLEN] = savech;
2027
 
+                    RETURN('|');
2028
 
+                }
2029
 
+                if (!strcasecmp(TOK, "low")) {
2030
 
+                    s->tok[TOKLEN] = savech;
2031
 
+                    RETURN(LOW);
2032
 
+                }
2033
 
+                if (!strcasecmp(TOK, "high")) {
2034
 
+                    s->tok[TOKLEN] = savech;
2035
 
+                    RETURN(HIGH);
2036
 
+                }
2037
 
+                if (!strcasecmp(TOK, "offset")) {
2038
 
+                    s->tok[TOKLEN] = savech;
2039
 
+                    RETURN(OFFSET);
2040
 
+                }
2041
 
+                if (!strcasecmp(TOK, "fword")) {
2042
 
+                    s->tok[TOKLEN] = savech;
2043
 
+                    lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2;
2044
 
+                    RETURN(SIZE_OVERRIDE);
2045
 
+                }
2046
 
+                if (!strcasecmp(TOK, "df")) {
2047
 
+                    s->tok[TOKLEN] = savech;
2048
 
+                    lvalp->int_info = yasm_arch_wordsize(p_object->arch)*3;
2049
 
+                    parser_nasm->state = INSTRUCTION;
2050
 
+                    RETURN(DECLARE_DATA);
2051
 
+                }
2052
 
+                if (!strcasecmp(TOK, "label")) {
2053
 
+                    s->tok[TOKLEN] = savech;
2054
 
+                    RETURN(LABEL);
2055
 
+                }
2056
 
+                if (!strcasecmp(TOK, "dup")) {
2057
 
+                    s->tok[TOKLEN] = savech;
2058
 
+                    RETURN(DUP);
2059
 
+                }
2060
 
             }
2061
 
             /* Propagate errors in case we got a warning from the arch */
2062
 
             yasm_errwarn_propagate(parser_nasm->errwarns, cur_line);
2063
 
             /* Just an identifier, return as such. */
2064
 
+            s->tok[TOKLEN] = savech;
2065
 
             lvalp->str_val = yasm__xstrndup(TOK, TOKLEN);
2066
 
             RETURN(ID);
2067
 
         }
2068
 
@@ -656,6 +747,29 @@
2069
 
             RETURN(STRING);
2070
 
         }
2071
 
 
2072
 
+        "''" | '""'     {
2073
 
+            if (endch != s->tok[0]) {
2074
 
+                strbuf[count++] = s->tok[0];
2075
 
+                if (count >= strbuf_size) {
2076
 
+                    strbuf = yasm_xrealloc(strbuf,
2077
 
+                                           strbuf_size + STRBUF_ALLOC_SIZE);
2078
 
+                    strbuf_size += STRBUF_ALLOC_SIZE;
2079
 
+                }
2080
 
+            } else if (!parser_nasm->tasm) {
2081
 
+                YYCURSOR--;
2082
 
+                strbuf[count] = '\0';
2083
 
+                lvalp->str.contents = (char *)strbuf;
2084
 
+                lvalp->str.len = count;
2085
 
+                RETURN(STRING);
2086
 
+            }
2087
 
+            strbuf[count++] = s->tok[0];
2088
 
+            if (count >= strbuf_size) {
2089
 
+                strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
2090
 
+                strbuf_size += STRBUF_ALLOC_SIZE;
2091
 
+            }
2092
 
+            goto stringconst_scan;
2093
 
+        }
2094
 
+
2095
 
         any     {
2096
 
             if (s->tok[0] == endch) {
2097
 
                 strbuf[count] = '\0';
2098
 
Index: modules/parsers/nasm/nasm-parse.c
2099
 
===================================================================
2100
 
--- old/modules/parsers/nasm/nasm-parse.c       (r�vision 2128)
2101
 
+++ new/modules/parsers/nasm/nasm-parse.c       (copie de travail)
2102
 
@@ -32,6 +32,7 @@
2103
 
 #include <math.h>
2104
 
 
2105
 
 #include "modules/parsers/nasm/nasm-parser.h"
2106
 
+#include "modules/preprocs/nasm/nasm.h"
2107
 
 
2108
 
 typedef enum {
2109
 
     NORM_EXPR,
2110
 
@@ -62,8 +63,24 @@
2111
 
      /*@null@*/ yasm_valparamhead *valparams,
2112
 
      /*@null@*/ yasm_valparamhead *objext_valparams);
2113
 
 static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name,
2114
 
-                         int local);
2115
 
+                         unsigned int size, int local);
2116
 
 
2117
 
+static void yasm_ea_set_implicit_size_segment(yasm_parser_nasm *parser_nasm,
2118
 
+                                              yasm_effaddr *ea, yasm_expr *e)
2119
 
+{
2120
 
+    if (parser_nasm->tasm) {
2121
 
+        const char *segment = yasm_expr_segment(e);
2122
 
+        ea->data_len = yasm_expr_size(e);
2123
 
+        if (segment) {
2124
 
+            const char *segreg = tasm_get_segment_register(segment);
2125
 
+            if (segreg)
2126
 
+                yasm_arch_parse_check_regtmod(p_object->arch, segreg,
2127
 
+                                              strlen(segreg), &ea->segreg);
2128
 
+        }
2129
 
+    }
2130
 
+}
2131
 
+
2132
 
+
2133
 
 #define is_eol_tok(tok) ((tok) == 0)
2134
 
 #define is_eol()        is_eol_tok(curtok)
2135
 
 
2136
 
@@ -242,11 +259,12 @@
2137
 
                 yasm_bc_destroy(bc);
2138
 
             }
2139
 
             temp_bc = NULL;
2140
 
-        } else {
2141
 
+        } else if (bc) {
2142
 
             temp_bc = yasm_section_bcs_append(cursect, bc);
2143
 
             if (temp_bc)
2144
 
                 parser_nasm->prev_bc = temp_bc;
2145
 
-        }
2146
 
+        } else
2147
 
+            temp_bc = NULL;
2148
 
         yasm_errwarn_propagate(parser_nasm->errwarns, cur_line);
2149
 
 
2150
 
         if (parser_nasm->save_input)
2151
 
@@ -355,23 +373,33 @@
2152
 
         case LOCAL_ID:
2153
 
         {
2154
 
             char *name = ID_val;
2155
 
-            int local = (curtok != ID);
2156
 
+            int local = parser_nasm->tasm
2157
 
+                ? (curtok == ID || curtok == LOCAL_ID ||
2158
 
+                        (curtok == SPECIAL_ID && name[0] == '@'))
2159
 
+                : (curtok != ID);
2160
 
+            unsigned int size = 0;
2161
 
 
2162
 
             get_next_token();
2163
 
             if (is_eol()) {
2164
 
                 /* label alone on the line */
2165
 
                 yasm_warn_set(YASM_WARN_ORPHAN_LABEL,
2166
 
                     N_("label alone on a line without a colon might be in error"));
2167
 
-                define_label(parser_nasm, name, local);
2168
 
+                define_label(parser_nasm, name, 0, local);
2169
 
                 return NULL;
2170
 
             }
2171
 
             if (curtok == ':')
2172
 
                 get_next_token();
2173
 
 
2174
 
-            if (curtok == EQU) {
2175
 
+            if (curtok == EQU || (parser_nasm->tasm && curtok == '=')) {
2176
 
                 /* label EQU expr */
2177
 
                 yasm_expr *e;
2178
 
                 get_next_token();
2179
 
+
2180
 
+                if (parser_nasm->tasm && curtok == SIZE_OVERRIDE) {
2181
 
+                    size = SIZE_OVERRIDE_val;
2182
 
+                    get_next_token();
2183
 
+                }
2184
 
+
2185
 
                 e = parse_expr(parser_nasm, NORM_EXPR);
2186
 
                 if (!e) {
2187
 
                     yasm_error_set(YASM_ERROR_SYNTAX,
2188
 
@@ -384,17 +412,30 @@
2189
 
                 return NULL;
2190
 
             }
2191
 
 
2192
 
-            define_label(parser_nasm, name, local);
2193
 
-            if (is_eol())
2194
 
+            if (parser_nasm->tasm && curtok == LABEL)
2195
 
+                get_next_token();
2196
 
+
2197
 
+            if (parser_nasm->tasm && curtok == SIZE_OVERRIDE) {
2198
 
+                size = SIZE_OVERRIDE_val;
2199
 
+                get_next_token();
2200
 
+            }
2201
 
+
2202
 
+            if (is_eol()) {
2203
 
+                define_label(parser_nasm, name, size, local);
2204
 
                 return NULL;
2205
 
+            }
2206
 
             if (curtok == TIMES) {
2207
 
+                define_label(parser_nasm, name, size, local);
2208
 
                 get_next_token();
2209
 
                 return parse_times(parser_nasm);
2210
 
             }
2211
 
             bc = parse_exp(parser_nasm);
2212
 
-            if (!bc)
2213
 
+            if (!parser_nasm->tasm && !bc)
2214
 
                 yasm_error_set(YASM_ERROR_SYNTAX,
2215
 
                                N_("instruction expected after label"));
2216
 
+            if (parser_nasm->tasm && bc && !size)
2217
 
+                size = yasm_bc_elem_size(bc);
2218
 
+            define_label(parser_nasm, name, size, local);
2219
 
             return bc;
2220
 
         }
2221
 
         default:
2222
 
@@ -510,7 +551,7 @@
2223
 
             unsigned int size = DECLARE_DATA_val/8;
2224
 
             yasm_datavalhead dvs;
2225
 
             yasm_dataval *dv;
2226
 
-            yasm_expr *e;
2227
 
+            yasm_expr *e, *e2;
2228
 
 
2229
 
             get_next_token();
2230
 
 
2231
 
@@ -529,14 +570,68 @@
2232
 
                         goto dv_done;
2233
 
                     }
2234
 
                 }
2235
 
-                if ((e = parse_bexpr(parser_nasm, DV_EXPR)))
2236
 
-                    dv = yasm_dv_create_expr(e);
2237
 
-                else {
2238
 
+                if (curtok == '?') {
2239
 
+                    yasm_dvs_delete(&dvs);
2240
 
+                    get_next_token();
2241
 
+                    if (! is_eol_tok(curtok)) {
2242
 
+                        yasm_error_set(YASM_ERROR_SYNTAX,
2243
 
+                                N_("can not handle more than one '?'"));
2244
 
+                        return NULL;
2245
 
+                    }
2246
 
+                    return yasm_bc_create_reserve(
2247
 
+                            p_expr_new_ident(yasm_expr_int(
2248
 
+                                yasm_intnum_create_uint(1))),
2249
 
+                            size, cur_line);
2250
 
+                }
2251
 
+                if (!(e = parse_bexpr(parser_nasm, DV_EXPR))) {
2252
 
                     yasm_error_set(YASM_ERROR_SYNTAX,
2253
 
                                    N_("expression or string expected"));
2254
 
                     yasm_dvs_delete(&dvs);
2255
 
                     return NULL;
2256
 
                 }
2257
 
+                if (curtok == DUP) {
2258
 
+                    get_next_token();
2259
 
+                    if (curtok != '(') {
2260
 
+                        yasm_error_set(YASM_ERROR_SYNTAX,
2261
 
+                                       N_("expected ( after DUP"));
2262
 
+                        goto error;
2263
 
+                    }
2264
 
+                    get_next_token();
2265
 
+                    if (curtok == '?') {
2266
 
+                        get_next_token();
2267
 
+                        if (curtok != ')') {
2268
 
+                            yasm_error_set(YASM_ERROR_SYNTAX,
2269
 
+                                N_("expected ) after DUPlicated expression"));
2270
 
+                            goto error;
2271
 
+                        }
2272
 
+                        get_next_token();
2273
 
+                        if (! is_eol_tok(curtok)) {
2274
 
+                            yasm_error_set(YASM_ERROR_SYNTAX,
2275
 
+                                    N_("can not handle more than one '?'"));
2276
 
+                            goto error;
2277
 
+                        }
2278
 
+                        yasm_dvs_delete(&dvs);
2279
 
+                        return yasm_bc_create_reserve(e, size, cur_line);
2280
 
+                    } else if ((e2 = parse_bexpr(parser_nasm, DV_EXPR))) {
2281
 
+                        if (curtok != ')') {
2282
 
+                            yasm_expr_destroy(e2);
2283
 
+                            yasm_error_set(YASM_ERROR_SYNTAX,
2284
 
+                                N_("expected ) after DUPlicated expression"));
2285
 
+                            goto error;
2286
 
+                        }
2287
 
+                        get_next_token();
2288
 
+                        dv = yasm_dv_create_expr(e2);
2289
 
+                        yasm_dv_set_multiple(dv, e);
2290
 
+                    } else {
2291
 
+                        yasm_error_set(YASM_ERROR_SYNTAX,
2292
 
+                                       N_("expression or string expected"));
2293
 
+error:
2294
 
+                        yasm_expr_destroy(e);
2295
 
+                        yasm_dvs_delete(&dvs);
2296
 
+                        return NULL;
2297
 
+                    }
2298
 
+                } else
2299
 
+                    dv = yasm_dv_create_expr(e);
2300
 
 dv_done:
2301
 
                 yasm_dvs_append(&dvs, dv);
2302
 
                 if (is_eol())
2303
 
@@ -699,12 +794,106 @@
2304
 
                                N_("memory address expected"));
2305
 
                 return NULL;
2306
 
             }
2307
 
+
2308
 
+            if (parser_nasm->tasm && !is_eol() && curtok != ',') {
2309
 
+                yasm_expr *e = NULL, *f;
2310
 
+                yasm_effaddr *ea;
2311
 
+
2312
 
+                switch (op->type) {
2313
 
+                    case YASM_INSN__OPERAND_IMM:
2314
 
+                        e = op->data.val;
2315
 
+                        break;
2316
 
+                    case YASM_INSN__OPERAND_MEMORY:
2317
 
+                        if (op->data.ea->disp.rel) {
2318
 
+                            yasm_error_set(YASM_ERROR_SYNTAX,
2319
 
+                                    N_("relative adressing not supported\n"));
2320
 
+                            return NULL;
2321
 
+                        }
2322
 
+                        e = yasm_expr_copy(op->data.ea->disp.abs);
2323
 
+                        yasm_arch_ea_destroy(p_object->arch, op->data.ea);
2324
 
+                        break;
2325
 
+                    case YASM_INSN__OPERAND_REG:
2326
 
+                    case YASM_INSN__OPERAND_SEGREG:
2327
 
+                        yasm_error_set(YASM_ERROR_SYNTAX,
2328
 
+                                N_("register adressing not supported\n"));
2329
 
+                        return NULL;
2330
 
+                }
2331
 
+                yasm_xfree(op);
2332
 
+                f = parse_bexpr(parser_nasm, NORM_EXPR);
2333
 
+                if (!f) {
2334
 
+                    yasm_expr_destroy(e);
2335
 
+                    yasm_error_set(YASM_ERROR_SYNTAX,
2336
 
+                                   N_("expected expression after ]"));
2337
 
+                    return NULL;
2338
 
+                }
2339
 
+                e = p_expr_new_tree(e, YASM_EXPR_ADD, f);
2340
 
+                ea = yasm_arch_ea_create(p_object->arch, e);
2341
 
+                yasm_ea_set_implicit_size_segment(parser_nasm, ea, e);
2342
 
+                op = yasm_operand_create_mem(ea);
2343
 
+            }
2344
 
             return op;
2345
 
         }
2346
 
+        case OFFSET:
2347
 
+        {
2348
 
+            yasm_insn_operand *op2;
2349
 
+            get_next_token();
2350
 
+            op = parse_operand(parser_nasm);
2351
 
+            if (!op) {
2352
 
+                yasm_error_set(YASM_ERROR_SYNTAX,
2353
 
+                               N_("memory address expected"));
2354
 
+                return NULL;
2355
 
+            }
2356
 
+            if (op->type == YASM_INSN__OPERAND_IMM)
2357
 
+                return op;
2358
 
+            if (op->type != YASM_INSN__OPERAND_MEMORY) {
2359
 
+                yasm_error_set(YASM_ERROR_SYNTAX,
2360
 
+                               N_("OFFSET applied to non-memory operand"));
2361
 
+                return NULL;
2362
 
+            }
2363
 
+            if (op->data.ea->disp.rel) {
2364
 
+                yasm_error_set(YASM_ERROR_SYNTAX,
2365
 
+                               N_("OFFSET applied to non-absolute memory operand"));
2366
 
+                return NULL;
2367
 
+            }
2368
 
+            if (op->data.ea->disp.abs)
2369
 
+                op2 = yasm_operand_create_imm(op->data.ea->disp.abs);
2370
 
+            else
2371
 
+                op2 = yasm_operand_create_imm(p_expr_new_ident(
2372
 
+                        yasm_expr_int(yasm_intnum_create_uint(0))));
2373
 
+            yasm_xfree(op);
2374
 
+            return op2;
2375
 
+        }
2376
 
         case SEGREG:
2377
 
-            op = yasm_operand_create_segreg(SEGREG_val);
2378
 
+        {
2379
 
+            uintptr_t segreg = SEGREG_val;
2380
 
             get_next_token();
2381
 
+            if (parser_nasm->tasm && curtok == ':') {
2382
 
+                get_next_token();
2383
 
+                op = parse_operand(parser_nasm);
2384
 
+                if (!op)
2385
 
+                    return NULL;
2386
 
+                if (op->type == YASM_INSN__OPERAND_IMM) {
2387
 
+                    yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch,
2388
 
+                                                           op->data.val);
2389
 
+                    yasm_insn_operand *op2;
2390
 
+                    yasm_ea_set_implicit_size_segment(parser_nasm, ea,
2391
 
+                                                      op->data.val);
2392
 
+                    op2 = yasm_operand_create_mem(ea);
2393
 
+                    op2->size = op->size;
2394
 
+                    yasm_xfree(op);
2395
 
+                    op = op2;
2396
 
+                }
2397
 
+                if (op->type != YASM_INSN__OPERAND_MEMORY) {
2398
 
+                    yasm_error_set(YASM_ERROR_SYNTAX,
2399
 
+                                   N_("segment applied to non-memory operand"));
2400
 
+                    return NULL;
2401
 
+                }
2402
 
+                yasm_ea_set_segreg(op->data.ea, segreg);
2403
 
+                return op;
2404
 
+            }
2405
 
+            op = yasm_operand_create_segreg(segreg);
2406
 
             return op;
2407
 
+        }
2408
 
         case REG:
2409
 
             op = yasm_operand_create_reg(REG_val);
2410
 
             get_next_token();
2411
 
@@ -756,13 +945,51 @@
2412
 
                 op->targetmod = tmod;
2413
 
             return op;
2414
 
         }
2415
 
+        case ID:
2416
 
+        case LOCAL_ID:
2417
 
+        case NONLOCAL_ID:
2418
 
+            if (parser_nasm->tasm) {
2419
 
+                get_peek_token(parser_nasm);
2420
 
+                if (parser_nasm->peek_token == '[') {
2421
 
+                    yasm_symrec *sym = yasm_symtab_use(p_symtab, ID_val,
2422
 
+                                                       cur_line);
2423
 
+                    yasm_expr *e = p_expr_new_ident(yasm_expr_sym(sym)), *f;
2424
 
+                    yasm_effaddr *ea;
2425
 
+                    yasm_xfree(ID_val);
2426
 
+                    get_next_token();
2427
 
+                    get_next_token();
2428
 
+                    f = parse_bexpr(parser_nasm, NORM_EXPR);
2429
 
+                    if (!f) {
2430
 
+                        yasm_error_set(YASM_ERROR_SYNTAX,
2431
 
+                                       N_("expected expression after ["));
2432
 
+                        return NULL;
2433
 
+                    }
2434
 
+                    e = p_expr_new_tree(e, YASM_EXPR_ADD, f);
2435
 
+                    if (!expect(']')) {
2436
 
+                        yasm_error_set(YASM_ERROR_SYNTAX, N_("missing closing bracket"));
2437
 
+                        return NULL;
2438
 
+                    }
2439
 
+                    get_next_token();
2440
 
+                    ea = yasm_arch_ea_create(p_object->arch, e);
2441
 
+                    yasm_ea_set_implicit_size_segment(parser_nasm, ea, e);
2442
 
+                    op = yasm_operand_create_mem(ea);
2443
 
+                    return op;
2444
 
+                }
2445
 
+            }
2446
 
+            /* Fallthrough */
2447
 
         default:
2448
 
         {
2449
 
             yasm_expr *e = parse_bexpr(parser_nasm, NORM_EXPR);
2450
 
             if (!e)
2451
 
                 return NULL;
2452
 
             if (curtok != ':')
2453
 
-                return yasm_operand_create_imm(e);
2454
 
+                if (parser_nasm->tasm && yasm_expr_size(e)) {
2455
 
+                    yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch, e);
2456
 
+                    yasm_ea_set_implicit_size_segment(parser_nasm, ea, e);
2457
 
+                    op = yasm_operand_create_mem(ea);
2458
 
+                    return op;
2459
 
+                } else
2460
 
+                    return yasm_operand_create_imm(e);
2461
 
             else {
2462
 
                 yasm_expr *off;
2463
 
                 get_next_token();
2464
 
@@ -836,10 +1061,12 @@
2465
 
             yasm_expr *e = parse_bexpr(parser_nasm, NORM_EXPR);
2466
 
             if (!e)
2467
 
                 return NULL;
2468
 
-            if (curtok != ':')
2469
 
-                return yasm_operand_create_mem(
2470
 
-                    yasm_arch_ea_create(p_object->arch, e));
2471
 
-            else {
2472
 
+            if (curtok != ':') {
2473
 
+                yasm_effaddr *ea = yasm_arch_ea_create(p_object->arch, e);
2474
 
+                yasm_ea_set_implicit_size_segment(parser_nasm, ea, e);
2475
 
+                return yasm_operand_create_mem(ea);
2476
 
+            } else {
2477
 
+                yasm_effaddr *ea;
2478
 
                 yasm_expr *off;
2479
 
                 get_next_token();
2480
 
                 off = parse_bexpr(parser_nasm, NORM_EXPR);
2481
 
@@ -847,8 +1074,9 @@
2482
 
                     yasm_expr_destroy(e);
2483
 
                     return NULL;
2484
 
                 }
2485
 
-                op = yasm_operand_create_mem(
2486
 
-                    yasm_arch_ea_create(p_object->arch, off));
2487
 
+                ea = yasm_arch_ea_create(p_object->arch, off);
2488
 
+                yasm_ea_set_implicit_size_segment(parser_nasm, ea, off);
2489
 
+                op = yasm_operand_create_mem(ea);
2490
 
                 op->seg = e;
2491
 
                 return op;
2492
 
             }
2493
 
@@ -1094,6 +1322,30 @@
2494
 
                 return NULL;
2495
 
             }
2496
 
             return p_expr_new_branch(YASM_EXPR_NOT, e);
2497
 
+        case LOW:
2498
 
+            get_next_token();
2499
 
+            e = parse_expr6(parser_nasm, type);
2500
 
+            if (!e) {
2501
 
+                yasm_error_set(YASM_ERROR_SYNTAX,
2502
 
+                               N_("expected expression after %s"), "LOW");
2503
 
+                return NULL;
2504
 
+            }
2505
 
+            return p_expr_new_tree(e, YASM_EXPR_AND,
2506
 
+                p_expr_new_ident(yasm_expr_int(yasm_intnum_create_uint(0xff))));
2507
 
+        case HIGH:
2508
 
+            get_next_token();
2509
 
+            e = parse_expr6(parser_nasm, type);
2510
 
+            if (!e) {
2511
 
+                yasm_error_set(YASM_ERROR_SYNTAX,
2512
 
+                               N_("expected expression after %s"), "HIGH");
2513
 
+                return NULL;
2514
 
+            }
2515
 
+            return p_expr_new_tree(
2516
 
+                p_expr_new_tree(e, YASM_EXPR_SHR,
2517
 
+                    p_expr_new_ident(yasm_expr_int(
2518
 
+                        yasm_intnum_create_uint(8)))),
2519
 
+                YASM_EXPR_AND,
2520
 
+                p_expr_new_ident(yasm_expr_int(yasm_intnum_create_uint(0xff))));
2521
 
         case SEG:
2522
 
             get_next_token();
2523
 
             e = parse_expr6(parser_nasm, type);
2524
 
@@ -1132,10 +1384,16 @@
2525
 
             e = p_expr_new_ident(yasm_expr_reg(REG_val));
2526
 
             break;
2527
 
         case STRING:
2528
 
-            e = p_expr_new_ident(yasm_expr_int(
2529
 
-                yasm_intnum_create_charconst_nasm(STRING_val.contents)));
2530
 
+        {
2531
 
+            yasm_intnum *intn;
2532
 
+            if (parser_nasm->tasm)
2533
 
+                intn = yasm_intnum_create_charconst_tasm(STRING_val.contents);
2534
 
+            else
2535
 
+                intn = yasm_intnum_create_charconst_nasm(STRING_val.contents);
2536
 
+            e = p_expr_new_ident(yasm_expr_int(intn));
2537
 
             yasm_xfree(STRING_val.contents);
2538
 
             break;
2539
 
+        }
2540
 
         case SPECIAL_ID:
2541
 
             sym = yasm_objfmt_get_special_sym(p_object, ID_val+2, "nasm");
2542
 
             if (sym) {
2543
 
@@ -1179,9 +1437,12 @@
2544
 
 }
2545
 
 
2546
 
 static void
2547
 
-define_label(yasm_parser_nasm *parser_nasm, char *name, int local)
2548
 
+define_label(yasm_parser_nasm *parser_nasm, char *name, unsigned int size,
2549
 
+             int local)
2550
 
 {
2551
 
-    if (!local) {
2552
 
+    yasm_symrec *symrec;
2553
 
+
2554
 
+    if ((!parser_nasm->tasm || tasm_locals) && !local) {
2555
 
         if (parser_nasm->locallabel_base)
2556
 
             yasm_xfree(parser_nasm->locallabel_base);
2557
 
         parser_nasm->locallabel_base_len = strlen(name);
2558
 
@@ -1191,11 +1452,16 @@
2559
 
     }
2560
 
 
2561
 
     if (parser_nasm->abspos)
2562
 
-        yasm_symtab_define_equ(p_symtab, name,
2563
 
-                               yasm_expr_copy(parser_nasm->abspos), cur_line);
2564
 
+        symrec = yasm_symtab_define_equ(p_symtab, name,
2565
 
+                                        yasm_expr_copy(parser_nasm->abspos),
2566
 
+                                        cur_line);
2567
 
     else
2568
 
-        yasm_symtab_define_label(p_symtab, name, parser_nasm->prev_bc, 1,
2569
 
-                                 cur_line);
2570
 
+        symrec = yasm_symtab_define_label(p_symtab, name, parser_nasm->prev_bc,
2571
 
+                                          1, cur_line);
2572
 
+
2573
 
+    yasm_symrec_set_size(symrec, size);
2574
 
+    yasm_symrec_set_segment(symrec, tasm_segment);
2575
 
+
2576
 
     yasm_xfree(name);
2577
 
 }
2578
 
 
2579
 
Index: modules/parsers/nasm/nasm-parser.c
2580
 
===================================================================
2581
 
--- old/modules/parsers/nasm/nasm-parser.c      (r�vision 2129)
2582
 
+++ new/modules/parsers/nasm/nasm-parser.c      (r�vision 2137)
2583
 
@@ -33,12 +33,13 @@
2584
 
 
2585
 
 
2586
 
 static void
2587
 
-nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
2588
 
-                     int save_input, yasm_linemap *linemap,
2589
 
-                     yasm_errwarns *errwarns)
2590
 
+nasm_do_parse(yasm_object *object, yasm_preproc *pp, int save_input,
2591
 
+              yasm_linemap *linemap, yasm_errwarns *errwarns, int tasm)
2592
 
 {
2593
 
     yasm_parser_nasm parser_nasm;
2594
 
 
2595
 
+    parser_nasm.tasm = tasm;
2596
 
+
2597
 
     parser_nasm.object = object;
2598
 
     parser_nasm.linemap = linemap;
2599
 
 
2600
 
@@ -77,6 +78,14 @@
2601
 
     yasm_symtab_parser_finalize(object->symtab, 0, errwarns);
2602
 
 }
2603
 
 
2604
 
+static void
2605
 
+nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
2606
 
+                     int save_input, yasm_linemap *linemap,
2607
 
+                     yasm_errwarns *errwarns)
2608
 
+{
2609
 
+    nasm_do_parse(object, pp, save_input, linemap, errwarns, 0);
2610
 
+}
2611
 
+
2612
 
 /* Define valid preprocessors to use with this parser */
2613
 
 static const char *nasm_parser_preproc_keywords[] = {
2614
 
     "raw",
2615
 
@@ -100,3 +109,29 @@
2616
 
     nasm_parser_stdmacs,
2617
 
     nasm_parser_do_parse
2618
 
 };
2619
 
+
2620
 
+static void
2621
 
+tasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
2622
 
+                     int save_input, yasm_linemap *linemap,
2623
 
+                     yasm_errwarns *errwarns)
2624
 
+{
2625
 
+    yasm_symtab_set_case_sensitive(object->symtab, 0);
2626
 
+    yasm_warn_disable(YASM_WARN_IMPLICIT_SIZE_OVERRIDE);
2627
 
+    nasm_do_parse(object, pp, save_input, linemap, errwarns, 1);
2628
 
+}
2629
 
+
2630
 
+/* Define valid preprocessors to use with this parser */
2631
 
+static const char *tasm_parser_preproc_keywords[] = {
2632
 
+    "raw",
2633
 
+    "tasm",
2634
 
+    NULL
2635
 
+};
2636
 
+
2637
 
+/* Define parser structure -- see parser.h for details */
2638
 
+yasm_parser_module yasm_tasm_LTX_parser = {
2639
 
+    "TASM-compatible parser",
2640
 
+    "tasm",
2641
 
+    tasm_parser_preproc_keywords,
2642
 
+    "tasm",
2643
 
+    tasm_parser_do_parse
2644
 
+};
2645
 
Index: modules/parsers/nasm/nasm-parser.h
2646
 
===================================================================
2647
 
--- old/modules/parsers/nasm/nasm-parser.h      (r�vision 2128)
2648
 
+++ new/modules/parsers/nasm/nasm-parser.h      (copie de travail)
2649
 
@@ -38,11 +38,14 @@
2650
 
     FILENAME,
2651
 
     STRING,
2652
 
     SIZE_OVERRIDE,
2653
 
+    OFFSET,
2654
 
     DECLARE_DATA,
2655
 
     RESERVE_SPACE,
2656
 
+    LABEL,
2657
 
     INCBIN,
2658
 
     EQU,
2659
 
     TIMES,
2660
 
+    DUP,
2661
 
     SEG,
2662
 
     WRT,
2663
 
     ABS,
2664
 
@@ -56,6 +59,8 @@
2665
 
     TARGETMOD,
2666
 
     LEFT_OP,
2667
 
     RIGHT_OP,
2668
 
+    LOW,
2669
 
+    HIGH,
2670
 
     SIGNDIV,
2671
 
     SIGNMOD,
2672
 
     START_SECTION_ID,
2673
 
@@ -82,6 +87,8 @@
2674
 
 #define YYSTYPE yystype
2675
 
 
2676
 
 typedef struct yasm_parser_nasm {
2677
 
+    int tasm;
2678
 
+
2679
 
     int debug;
2680
 
 
2681
 
     /*@only@*/ yasm_object *object;
2682
 
Index: modules/objfmts/win64/tests/win64-dataref.hex
2683
 
===================================================================
2684
 
--- old/modules/objfmts/win64/tests/win64-dataref.hex   (r�vision 2128)
2685
 
+++ new/modules/objfmts/win64/tests/win64-dataref.hex   (copie de travail)
2686
 
@@ -1364,7 +1364,7 @@
2687
 
 00 
2688
 
 00 
2689
 
 00 
2690
 
-17 
2691
 
+16 
2692
 
 00 
2693
 
 00 
2694
 
 00 
2695
 
@@ -1374,7 +1374,7 @@
2696
 
 00 
2697
 
 00 
2698
 
 00 
2699
 
-17 
2700
 
+16 
2701
 
 00 
2702
 
 00 
2703
 
 00 
2704
 
@@ -1999,39 +1999,39 @@
2705
 
 03 
2706
 
 00 
2707
 
 78 
2708
 
-70 
2709
 
-74 
2710
 
-72 
2711
 
 00 
2712
 
 00 
2713
 
 00 
2714
 
 00 
2715
 
-40 
2716
 
 00 
2717
 
 00 
2718
 
 00 
2719
 
-02 
2720
 
 00 
2721
 
 00 
2722
 
 00 
2723
 
+00 
2724
 
 03 
2725
 
 00 
2726
 
-78 
2727
 
 00 
2728
 
 00 
2729
 
+03 
2730
 
 00 
2731
 
+78 
2732
 
+70 
2733
 
+74 
2734
 
+72 
2735
 
 00 
2736
 
 00 
2737
 
 00 
2738
 
 00 
2739
 
+40 
2740
 
 00 
2741
 
 00 
2742
 
 00 
2743
 
+02 
2744
 
 00 
2745
 
-03 
2746
 
 00 
2747
 
 00 
2748
 
-00 
2749
 
 03 
2750
 
 00 
2751
 
 78 
2752
 
Index: modules/objfmts/bin/bin-objfmt.c
2753
 
===================================================================
2754
 
--- old/modules/objfmts/bin/bin-objfmt.c        (r�vision 2128)
2755
 
+++ new/modules/objfmts/bin/bin-objfmt.c        (copie de travail)
2756
 
@@ -27,6 +27,9 @@
2757
 
 #include <util.h>
2758
 
 /*@unused@*/ RCSID("$Id$");
2759
 
 
2760
 
+#ifdef HAVE_UNISTD_H
2761
 
+#include <unistd.h>
2762
 
+#endif
2763
 
 #include <libyasm.h>
2764
 
 
2765
 
 
2766
 
@@ -1071,7 +1072,8 @@
2767
 
             yasm_errwarn_propagate(info->errwarns, 0);
2768
 
             return 0;
2769
 
         }
2770
 
-        if (fseek(info->f, yasm_intnum_get_int(info->tmp_intn), SEEK_SET) < 0)
2771
 
+        if (fseek(info->f, yasm_intnum_get_int(info->tmp_intn) + info->start,
2772
 
+                  SEEK_SET) < 0)
2773
 
             yasm__fatal(N_("could not seek on output file"));
2774
 
         yasm_section_bcs_traverse(sect, info->errwarns,
2775
 
                                   info, bin_objfmt_output_bytecode);
2776
 
@@ -1106,6 +1107,8 @@
2777
 
     yasm_intnum *start, *last, *vdelta;
2778
 
     bin_groups unsorted_groups, bss_groups;
2779
 
 
2780
 
+    info.start = ftell(f);
2781
 
+
2782
 
     /* Set ORG to 0 unless otherwise specified */
2783
 
     if (objfmt_bin->org) {
2784
 
         info.origin = yasm_expr_get_intnum(&objfmt_bin->org, 0);
2785
 
@@ -1802,3 +1806,153 @@
2786
 
     bin_objfmt_section_switch,
2787
 
     bin_objfmt_get_special_sym
2788
 
 };
2789
 
+
2790
 
+#define EXE_HEADER_SIZE 0x200
2791
 
+
2792
 
+/* DOS .EXE binaries are just raw binaries with a header */
2793
 
+yasm_objfmt_module yasm_dosexe_LTX_objfmt;
2794
 
+
2795
 
+static yasm_objfmt *
2796
 
+dosexe_objfmt_create(yasm_object *object)
2797
 
+{
2798
 
+    yasm_objfmt_bin *objfmt_bin = (yasm_objfmt_bin *) bin_objfmt_create(object);
2799
 
+    objfmt_bin->objfmt.module = &yasm_dosexe_LTX_objfmt;
2800
 
+    return (yasm_objfmt *)objfmt_bin;
2801
 
+}
2802
 
+
2803
 
+static unsigned long
2804
 
+get_sym(yasm_object *object, const char *name) {
2805
 
+    yasm_symrec *symrec = yasm_symtab_get(object->symtab, name);
2806
 
+    yasm_bytecode *prevbc;
2807
 
+    if (!symrec)
2808
 
+        return 0;
2809
 
+    if (!yasm_symrec_get_label(symrec, &prevbc))
2810
 
+        return 0;
2811
 
+    return prevbc->offset + prevbc->len;
2812
 
+}
2813
 
+
2814
 
+static void
2815
 
+dosexe_objfmt_output(yasm_object *object, FILE *f, /*@unused@*/ int all_syms,
2816
 
+                  yasm_errwarns *errwarns)
2817
 
+{
2818
 
+    unsigned long tot_size, size, bss_size;
2819
 
+    unsigned long start, bss;
2820
 
+    unsigned char c;
2821
 
+
2822
 
+    fseek(f, EXE_HEADER_SIZE, SEEK_SET);
2823
 
+
2824
 
+    bin_objfmt_output(object, f, all_syms, errwarns);
2825
 
+
2826
 
+    tot_size = ftell(f);
2827
 
+
2828
 
+    /* if there is a __bss_start symbol, data after it is 0, no need to write
2829
 
+     * it.  */
2830
 
+    bss = get_sym(object, "__bss_start");
2831
 
+    if (bss)
2832
 
+        size = bss;
2833
 
+    else
2834
 
+        size = tot_size;
2835
 
+    bss_size = tot_size - size;
2836
 
+#ifdef HAVE_FTRUNCATE
2837
 
+    if (size != tot_size)
2838
 
+        ftruncate(fileno(f), EXE_HEADER_SIZE + size);
2839
 
+#endif
2840
 
+    fseek(f, 0, SEEK_SET);
2841
 
+
2842
 
+    /* magic */
2843
 
+    fwrite("MZ", 1, 2, f);
2844
 
+
2845
 
+    /* file size */
2846
 
+    c = size & 0xff;
2847
 
+    fwrite(&c, 1, 1, f);
2848
 
+    c = !!(size & 0x100);
2849
 
+    fwrite(&c, 1, 1, f);
2850
 
+    c = ((size + 511) >> 9) & 0xff;
2851
 
+    fwrite(&c, 1, 1, f);
2852
 
+    c = ((size + 511) >> 17) & 0xff;
2853
 
+    fwrite(&c, 1, 1, f);
2854
 
+
2855
 
+    /* relocation # */
2856
 
+    c = 0;
2857
 
+    fwrite(&c, 1, 1, f);
2858
 
+    fwrite(&c, 1, 1, f);
2859
 
+
2860
 
+    /* header size */
2861
 
+    c = EXE_HEADER_SIZE / 16;
2862
 
+    fwrite(&c, 1, 1, f);
2863
 
+    c = 0;
2864
 
+    fwrite(&c, 1, 1, f);
2865
 
+
2866
 
+    /* minimum paragraph # */
2867
 
+    bss_size = (bss_size + 15) >> 4;
2868
 
+    c = bss_size & 0xff;
2869
 
+    fwrite(&c, 1, 1, f);
2870
 
+    c = (bss_size >> 8) & 0xff;
2871
 
+    fwrite(&c, 1, 1, f);
2872
 
+
2873
 
+    /* maximum paragraph # */
2874
 
+    c = 0xFF;
2875
 
+    fwrite(&c, 1, 1, f);
2876
 
+    fwrite(&c, 1, 1, f);
2877
 
+
2878
 
+    /* relative value of stack segment */
2879
 
+    c = 0;
2880
 
+    fwrite(&c, 1, 1, f);
2881
 
+    fwrite(&c, 1, 1, f);
2882
 
+
2883
 
+    /* SP at start */
2884
 
+    c = 0;
2885
 
+    fwrite(&c, 1, 1, f);
2886
 
+    fwrite(&c, 1, 1, f);
2887
 
+
2888
 
+    /* header checksum */
2889
 
+    c = 0;
2890
 
+    fwrite(&c, 1, 1, f);
2891
 
+    fwrite(&c, 1, 1, f);
2892
 
+
2893
 
+    /* IP at start */
2894
 
+    start = get_sym(object, "start");
2895
 
+    if (!start) {
2896
 
+        yasm_error_set(YASM_ERROR_GENERAL,
2897
 
+                N_("%s: could not find symbol `start'"));
2898
 
+        return;
2899
 
+    }
2900
 
+    c = start & 0xff;
2901
 
+    fwrite(&c, 1, 1, f);
2902
 
+    c = (start >> 8) & 0xff;
2903
 
+    fwrite(&c, 1, 1, f);
2904
 
+
2905
 
+    /* CS start */
2906
 
+    c = 0;
2907
 
+    fwrite(&c, 1, 1, f);
2908
 
+    fwrite(&c, 1, 1, f);
2909
 
+
2910
 
+    /* reloc start */
2911
 
+    c = 0x22;
2912
 
+    fwrite(&c, 1, 1, f);
2913
 
+    c = 0;
2914
 
+    fwrite(&c, 1, 1, f);
2915
 
+
2916
 
+    /* Overlay number */
2917
 
+    c = 0;
2918
 
+    fwrite(&c, 1, 1, f);
2919
 
+    fwrite(&c, 1, 1, f);
2920
 
+}
2921
 
+
2922
 
+
2923
 
+/* Define objfmt structure -- see objfmt.h for details */
2924
 
+yasm_objfmt_module yasm_dosexe_LTX_objfmt = {
2925
 
+    "DOS .EXE format binary",
2926
 
+    "dosexe",
2927
 
+    "exe",
2928
 
+    16,
2929
 
+    bin_objfmt_dbgfmt_keywords,
2930
 
+    "null",
2931
 
+    bin_objfmt_directives,
2932
 
+    dosexe_objfmt_create,
2933
 
+    dosexe_objfmt_output,
2934
 
+    bin_objfmt_destroy,
2935
 
+    bin_objfmt_add_default_section,
2936
 
+    bin_objfmt_section_switch,
2937
 
+    bin_objfmt_get_special_sym
2938
 
+};
2939
 
Index: modules/objfmts/coff/coff-objfmt.c
2940
 
===================================================================
2941
 
--- old/modules/objfmts/coff/coff-objfmt.c      (r�vision 2128)
2942
 
+++ new/modules/objfmts/coff/coff-objfmt.c      (copie de travail)
2943
 
@@ -234,6 +234,7 @@
2944
 
     win32_sxdata_bc_destroy,
2945
 
     win32_sxdata_bc_print,
2946
 
     yasm_bc_finalize_common,
2947
 
+    NULL,
2948
 
     win32_sxdata_bc_calc_len,
2949
 
     yasm_bc_expand_common,
2950
 
     win32_sxdata_bc_tobytes,
2951
 
Index: modules/objfmts/coff/win64-except.c
2952
 
===================================================================
2953
 
--- old/modules/objfmts/coff/win64-except.c     (r�vision 2128)
2954
 
+++ new/modules/objfmts/coff/win64-except.c     (copie de travail)
2955
 
@@ -72,6 +72,7 @@
2956
 
     win64_uwinfo_bc_destroy,
2957
 
     win64_uwinfo_bc_print,
2958
 
     win64_uwinfo_bc_finalize,
2959
 
+    NULL,
2960
 
     win64_uwinfo_bc_calc_len,
2961
 
     win64_uwinfo_bc_expand,
2962
 
     win64_uwinfo_bc_tobytes,
2963
 
@@ -82,6 +83,7 @@
2964
 
     win64_uwcode_bc_destroy,
2965
 
     win64_uwcode_bc_print,
2966
 
     win64_uwcode_bc_finalize,
2967
 
+    NULL,
2968
 
     win64_uwcode_bc_calc_len,
2969
 
     win64_uwcode_bc_expand,
2970
 
     win64_uwcode_bc_tobytes,
2971
 
Index: modules/dbgfmts/codeview/cv-symline.c
2972
 
===================================================================
2973
 
--- old/modules/dbgfmts/codeview/cv-symline.c   (r�vision 2128)
2974
 
+++ new/modules/dbgfmts/codeview/cv-symline.c   (copie de travail)
2975
 
@@ -201,6 +201,7 @@
2976
 
     cv8_symhead_bc_destroy,
2977
 
     cv8_symhead_bc_print,
2978
 
     yasm_bc_finalize_common,
2979
 
+    NULL,
2980
 
     cv8_symhead_bc_calc_len,
2981
 
     yasm_bc_expand_common,
2982
 
     cv8_symhead_bc_tobytes,
2983
 
@@ -211,6 +212,7 @@
2984
 
     cv8_fileinfo_bc_destroy,
2985
 
     cv8_fileinfo_bc_print,
2986
 
     yasm_bc_finalize_common,
2987
 
+    NULL,
2988
 
     cv8_fileinfo_bc_calc_len,
2989
 
     yasm_bc_expand_common,
2990
 
     cv8_fileinfo_bc_tobytes,
2991
 
@@ -221,6 +223,7 @@
2992
 
     cv8_lineinfo_bc_destroy,
2993
 
     cv8_lineinfo_bc_print,
2994
 
     yasm_bc_finalize_common,
2995
 
+    NULL,
2996
 
     cv8_lineinfo_bc_calc_len,
2997
 
     yasm_bc_expand_common,
2998
 
     cv8_lineinfo_bc_tobytes,
2999
 
@@ -231,6 +234,7 @@
3000
 
     cv_sym_bc_destroy,
3001
 
     cv_sym_bc_print,
3002
 
     yasm_bc_finalize_common,
3003
 
+    NULL,
3004
 
     cv_sym_bc_calc_len,
3005
 
     yasm_bc_expand_common,
3006
 
     cv_sym_bc_tobytes,
3007
 
Index: modules/dbgfmts/codeview/cv-type.c
3008
 
===================================================================
3009
 
--- old/modules/dbgfmts/codeview/cv-type.c      (r�vision 2128)
3010
 
+++ new/modules/dbgfmts/codeview/cv-type.c      (copie de travail)
3011
 
@@ -492,6 +492,7 @@
3012
 
     cv_type_bc_destroy,
3013
 
     cv_type_bc_print,
3014
 
     yasm_bc_finalize_common,
3015
 
+    NULL,
3016
 
     cv_type_bc_calc_len,
3017
 
     yasm_bc_expand_common,
3018
 
     cv_type_bc_tobytes,
3019
 
Index: modules/dbgfmts/dwarf2/dwarf2-info.c
3020
 
===================================================================
3021
 
--- old/modules/dbgfmts/dwarf2/dwarf2-info.c    (r�vision 2128)
3022
 
+++ new/modules/dbgfmts/dwarf2/dwarf2-info.c    (copie de travail)
3023
 
@@ -207,6 +207,7 @@
3024
 
     dwarf2_abbrev_bc_destroy,
3025
 
     dwarf2_abbrev_bc_print,
3026
 
     yasm_bc_finalize_common,
3027
 
+    NULL,
3028
 
     dwarf2_abbrev_bc_calc_len,
3029
 
     yasm_bc_expand_common,
3030
 
     dwarf2_abbrev_bc_tobytes,
3031
 
Index: modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c
3032
 
===================================================================
3033
 
--- old/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c  (r�vision 2128)
3034
 
+++ new/modules/dbgfmts/dwarf2/dwarf2-dbgfmt.c  (copie de travail)
3035
 
@@ -55,6 +55,7 @@
3036
 
     dwarf2_head_bc_destroy,
3037
 
     dwarf2_head_bc_print,
3038
 
     yasm_bc_finalize_common,
3039
 
+    NULL,
3040
 
     dwarf2_head_bc_calc_len,
3041
 
     yasm_bc_expand_common,
3042
 
     dwarf2_head_bc_tobytes,
3043
 
Index: modules/dbgfmts/dwarf2/dwarf2-line.c
3044
 
===================================================================
3045
 
--- old/modules/dbgfmts/dwarf2/dwarf2-line.c    (r�vision 2128)
3046
 
+++ new/modules/dbgfmts/dwarf2/dwarf2-line.c    (copie de travail)
3047
 
@@ -149,6 +149,7 @@
3048
 
     dwarf2_spp_bc_destroy,
3049
 
     dwarf2_spp_bc_print,
3050
 
     yasm_bc_finalize_common,
3051
 
+    NULL,
3052
 
     dwarf2_spp_bc_calc_len,
3053
 
     yasm_bc_expand_common,
3054
 
     dwarf2_spp_bc_tobytes,
3055
 
@@ -159,6 +160,7 @@
3056
 
     dwarf2_line_op_bc_destroy,
3057
 
     dwarf2_line_op_bc_print,
3058
 
     yasm_bc_finalize_common,
3059
 
+    NULL,
3060
 
     dwarf2_line_op_bc_calc_len,
3061
 
     yasm_bc_expand_common,
3062
 
     dwarf2_line_op_bc_tobytes,
3063
 
Index: modules/dbgfmts/stabs/stabs-dbgfmt.c
3064
 
===================================================================
3065
 
--- old/modules/dbgfmts/stabs/stabs-dbgfmt.c    (r�vision 2128)
3066
 
+++ new/modules/dbgfmts/stabs/stabs-dbgfmt.c    (copie de travail)
3067
 
@@ -139,6 +139,7 @@
3068
 
     stabs_bc_str_destroy,
3069
 
     stabs_bc_str_print,
3070
 
     yasm_bc_finalize_common,
3071
 
+    NULL,
3072
 
     stabs_bc_str_calc_len,
3073
 
     yasm_bc_expand_common,
3074
 
     stabs_bc_str_tobytes,
3075
 
@@ -149,6 +150,7 @@
3076
 
     stabs_bc_stab_destroy,
3077
 
     stabs_bc_stab_print,
3078
 
     yasm_bc_finalize_common,
3079
 
+    NULL,
3080
 
     stabs_bc_stab_calc_len,
3081
 
     yasm_bc_expand_common,
3082
 
     stabs_bc_stab_tobytes,
3083
 
Index: modules/arch/lc3b/lc3bid.re
3084
 
===================================================================
3085
 
--- old/modules/arch/lc3b/lc3bid.re     (r�vision 2128)
3086
 
+++ new/modules/arch/lc3b/lc3bid.re     (copie de travail)
3087
 
@@ -128,6 +128,7 @@
3088
 
     lc3b_id_insn_destroy,
3089
 
     lc3b_id_insn_print,
3090
 
     lc3b_id_insn_finalize,
3091
 
+    NULL,
3092
 
     yasm_bc_calc_len_common,
3093
 
     yasm_bc_expand_common,
3094
 
     yasm_bc_tobytes_common,
3095
 
Index: modules/arch/lc3b/lc3bbc.c
3096
 
===================================================================
3097
 
--- old/modules/arch/lc3b/lc3bbc.c      (r�vision 2128)
3098
 
+++ new/modules/arch/lc3b/lc3bbc.c      (copie de travail)
3099
 
@@ -53,6 +53,7 @@
3100
 
     lc3b_bc_insn_destroy,
3101
 
     lc3b_bc_insn_print,
3102
 
     yasm_bc_finalize_common,
3103
 
+    NULL,
3104
 
     lc3b_bc_insn_calc_len,
3105
 
     lc3b_bc_insn_expand,
3106
 
     lc3b_bc_insn_tobytes,
3107
 
Index: modules/arch/x86/tests/lds-err.errwarn
3108
 
===================================================================
3109
 
--- old/modules/arch/x86/tests/lds-err.errwarn  (r�vision 2129)
3110
 
+++ new/modules/arch/x86/tests/lds-err.errwarn  (r�vision 2137)
3111
 
@@ -1,4 +0,0 @@
3112
 
--:2: error: invalid size for operand 2
3113
 
--:3: error: invalid size for operand 2
3114
 
--:5: error: invalid size for operand 2
3115
 
--:6: error: invalid size for operand 2
3116
 
Index: modules/arch/x86/tests/lds-err.asm
3117
 
===================================================================
3118
 
--- old/modules/arch/x86/tests/lds-err.asm      (r�vision 2129)
3119
 
+++ new/modules/arch/x86/tests/lds-err.asm      (r�vision 2137)
3120
 
@@ -1,6 +0,0 @@
3121
 
-lds ax,[1]
3122
 
-lds ax,word [1]
3123
 
-lds ax,dword [1]
3124
 
-lds eax,[1]
3125
 
-lds eax,word [1]
3126
 
-lds eax,dword [1]
3127
 
Index: modules/arch/x86/tests/lds.asm
3128
 
===================================================================
3129
 
--- old/modules/arch/x86/tests/lds.asm  (r�vision 0)
3130
 
+++ new/modules/arch/x86/tests/lds.asm  (r�vision 2137)
3131
 
@@ -0,0 +1,6 @@
3132
 
+lds ax,[1]
3133
 
+lds ax,word [1]
3134
 
+lds ax,dword [1]
3135
 
+lds eax,[1]
3136
 
+lds eax,word [1]
3137
 
+lds eax,dword [1]
3138
 
Index: modules/arch/x86/tests/lds.hex
3139
 
===================================================================
3140
 
--- old/modules/arch/x86/tests/lds.hex  (r�vision 0)
3141
 
+++ new/modules/arch/x86/tests/lds.hex  (r�vision 2137)
3142
 
@@ -0,0 +1,27 @@
3143
 
+c5 
3144
 
+06 
3145
 
+01 
3146
 
+00 
3147
 
+c5 
3148
 
+06 
3149
 
+01 
3150
 
+00 
3151
 
+c5 
3152
 
+06 
3153
 
+01 
3154
 
+00 
3155
 
+66 
3156
 
+c5 
3157
 
+06 
3158
 
+01 
3159
 
+00 
3160
 
+66 
3161
 
+c5 
3162
 
+06 
3163
 
+01 
3164
 
+00 
3165
 
+66 
3166
 
+c5 
3167
 
+06 
3168
 
+01 
3169
 
+00 
3170
 
Index: modules/arch/x86/x86id.c
3171
 
===================================================================
3172
 
--- old/modules/arch/x86/x86id.c        (r�vision 2128)
3173
 
+++ new/modules/arch/x86/x86id.c        (copie de travail)
3174
 
@@ -350,6 +350,7 @@
3175
 
     x86_id_insn_destroy,
3176
 
     x86_id_insn_print,
3177
 
     x86_id_insn_finalize,
3178
 
+    NULL,
3179
 
     yasm_bc_calc_len_common,
3180
 
     yasm_bc_expand_common,
3181
 
     yasm_bc_tobytes_common,
3182
 
@@ -1733,6 +1734,9 @@
3183
 
         case X86_PARSER_NASM:
3184
 
             pdata = insnprefix_nasm_find(lcaseid, id_len);
3185
 
             break;
3186
 
+        case X86_PARSER_TASM:
3187
 
+            pdata = insnprefix_nasm_find(lcaseid, id_len);
3188
 
+            break;
3189
 
         case X86_PARSER_GAS:
3190
 
             pdata = insnprefix_gas_find(lcaseid, id_len);
3191
 
             break;
3192
 
Index: modules/arch/x86/x86arch.c
3193
 
===================================================================
3194
 
--- old/modules/arch/x86/x86arch.c      (r�vision 2128)
3195
 
+++ new/modules/arch/x86/x86arch.c      (copie de travail)
3196
 
@@ -71,6 +71,8 @@
3197
 
 
3198
 
     if (yasm__strcasecmp(parser, "nasm") == 0)
3199
 
         arch_x86->parser = X86_PARSER_NASM;
3200
 
+    else if (yasm__strcasecmp(parser, "tasm") == 0)
3201
 
+        arch_x86->parser = X86_PARSER_TASM;
3202
 
     else if (yasm__strcasecmp(parser, "gas") == 0
3203
 
              || yasm__strcasecmp(parser, "gnu") == 0)
3204
 
         arch_x86->parser = X86_PARSER_GAS;
3205
 
Index: modules/arch/x86/x86expr.c
3206
 
===================================================================
3207
 
--- old/modules/arch/x86/x86expr.c      (r�vision 2128)
3208
 
+++ new/modules/arch/x86/x86expr.c      (copie de travail)
3209
 
@@ -422,7 +422,7 @@
3210
 
              * EA.  With no registers, we must have a 16/32 value.
3211
 
              */
3212
 
             if (noreg) {
3213
 
-                yasm_warn_set(YASM_WARN_GENERAL,
3214
 
+                yasm_warn_set(YASM_WARN_IMPLICIT_SIZE_OVERRIDE,
3215
 
                               N_("invalid displacement size; fixed"));
3216
 
                 x86_ea->ea.disp.size = wordsize;
3217
 
             } else
3218
 
Index: modules/arch/x86/x86arch.h
3219
 
===================================================================
3220
 
--- old/modules/arch/x86/x86arch.h      (r�vision 2128)
3221
 
+++ new/modules/arch/x86/x86arch.h      (copie de travail)
3222
 
@@ -82,7 +82,8 @@
3223
 
     unsigned int amd64_machine;
3224
 
     enum {
3225
 
         X86_PARSER_NASM = 0,
3226
 
-        X86_PARSER_GAS = 1
3227
 
+        X86_PARSER_TASM = 1,
3228
 
+        X86_PARSER_GAS = 2
3229
 
     } parser;
3230
 
     unsigned int mode_bits;
3231
 
     unsigned int force_strict;
3232
 
Index: modules/arch/x86/x86bc.c
3233
 
===================================================================
3234
 
--- old/modules/arch/x86/x86bc.c        (r�vision 2128)
3235
 
+++ new/modules/arch/x86/x86bc.c        (copie de travail)
3236
 
@@ -76,6 +76,7 @@
3237
 
     x86_bc_insn_destroy,
3238
 
     x86_bc_insn_print,
3239
 
     yasm_bc_finalize_common,
3240
 
+    NULL,
3241
 
     x86_bc_insn_calc_len,
3242
 
     x86_bc_insn_expand,
3243
 
     x86_bc_insn_tobytes,
3244
 
@@ -86,6 +87,7 @@
3245
 
     x86_bc_jmp_destroy,
3246
 
     x86_bc_jmp_print,
3247
 
     yasm_bc_finalize_common,
3248
 
+    NULL,
3249
 
     x86_bc_jmp_calc_len,
3250
 
     x86_bc_jmp_expand,
3251
 
     x86_bc_jmp_tobytes,
3252
 
@@ -96,6 +98,7 @@
3253
 
     x86_bc_jmpfar_destroy,
3254
 
     x86_bc_jmpfar_print,
3255
 
     yasm_bc_finalize_common,
3256
 
+    NULL,
3257
 
     x86_bc_jmpfar_calc_len,
3258
 
     yasm_bc_expand_common,
3259
 
     x86_bc_jmpfar_tobytes,
3260
 
@@ -192,6 +195,7 @@
3261
 
     x86_ea->ea.segreg = 0;
3262
 
     x86_ea->ea.pc_rel = 0;
3263
 
     x86_ea->ea.not_pc_rel = 0;
3264
 
+    x86_ea->ea.data_len = 0;
3265
 
     x86_ea->modrm = 0;
3266
 
     x86_ea->valid_modrm = 0;
3267
 
     x86_ea->need_modrm = 0;
3268
 
@@ -254,6 +258,8 @@
3269
 
      */
3270
 
     x86_ea->need_sib = 0xff;
3271
 
 
3272
 
+    x86_ea->ea.data_len = 0;
3273
 
+
3274
 
     return (yasm_effaddr *)x86_ea;
3275
 
 }
3276
 
 
3277
 
Index: modules/arch/x86/gen_x86_insn.py
3278
 
===================================================================
3279
 
--- old/modules/arch/x86/gen_x86_insn.py        (r�vision 2128)
3280
 
+++ new/modules/arch/x86/gen_x86_insn.py        (copie de travail)
3281
 
@@ -671,7 +671,7 @@
3282
 
     modifiers=["SpAdd", "Op0Add", "Op1Add"],
3283
 
     opcode=[0x00, 0x00],
3284
 
     spare=0,
3285
 
-    operands=[Operand(type="Mem", dest="EA")])
3286
 
+    operands=[Operand(type="Mem", relaxed=True, dest="EA")])
3287
 
 
3288
 
 #
3289
 
 # mov
3290
 
@@ -1666,7 +1666,7 @@
3291
 
         opersize=sz,
3292
 
         opcode=[0x8D],
3293
 
         operands=[Operand(type="Reg", size=sz, dest="Spare"),
3294
 
-                  Operand(type="Mem", size=sz, relaxed=True, dest="EA")])
3295
 
+                  Operand(type="Mem", relaxed=True, dest="EA")])
3296
 
 
3297
 
 add_insn("lea", "lea")
3298
 
 
3299
 
@@ -1681,7 +1681,7 @@
3300
 
         opersize=sz,
3301
 
         opcode=[0x00],
3302
 
         operands=[Operand(type="Reg", size=sz, dest="Spare"),
3303
 
-                  Operand(type="Mem", dest="EA")])
3304
 
+                  Operand(type="Mem", relaxed=True, dest="EA")])
3305
 
 
3306
 
 add_insn("lds", "ldes", modifiers=[0xC5])
3307
 
 add_insn("les", "ldes", modifiers=[0xC4])
3308
 
@@ -1694,7 +1694,7 @@
3309
 
         opersize=sz,
3310
 
         opcode=[0x0F, 0x00],
3311
 
         operands=[Operand(type="Reg", size=sz, dest="Spare"),
3312
 
-                  Operand(type="Mem", dest="EA")])
3313
 
+                  Operand(type="Mem", relaxed=True, dest="EA")])
3314
 
 
3315
 
 add_insn("lfs", "lfgss", modifiers=[0xB4])
3316
 
 add_insn("lgs", "lfgss", modifiers=[0xB5])
3317
 
Index: modules/preprocs/nasm/nasm.h
3318
 
===================================================================
3319
 
--- old/modules/preprocs/nasm/nasm.h    (r�vision 2128)
3320
 
+++ new/modules/preprocs/nasm/nasm.h    (copie de travail)
3321
 
@@ -276,5 +276,8 @@
3322
 
 #define elements(x)     ( sizeof(x) / sizeof(*(x)) )
3323
 
 
3324
 
 extern int tasm_compatible_mode;
3325
 
+extern int tasm_locals;
3326
 
+extern const char *tasm_segment;
3327
 
+const char *tasm_get_segment_register(const char *segment);
3328
 
 
3329
 
 #endif
3330
 
Index: modules/preprocs/nasm/nasm-preproc.c
3331
 
===================================================================
3332
 
--- old/modules/preprocs/nasm/nasm-preproc.c    (r�vision 2128)
3333
 
+++ new/modules/preprocs/nasm/nasm-preproc.c    (copie de travail)
3334
 
@@ -47,6 +47,8 @@
3335
 
 static yasm_linemap *cur_lm;
3336
 
 static yasm_errwarns *cur_errwarns;
3337
 
 int tasm_compatible_mode = 0;
3338
 
+int tasm_locals;
3339
 
+const char *tasm_segment;
3340
 
 
3341
 
 #include "nasm-version.c"
3342
 
 
3343
 
@@ -314,3 +316,24 @@
3344
 
     nasm_preproc_define_builtin,
3345
 
     nasm_preproc_add_standard
3346
 
 };
3347
 
+
3348
 
+static yasm_preproc *
3349
 
+tasm_preproc_create(const char *in_filename, yasm_symtab *symtab,
3350
 
+                    yasm_linemap *lm, yasm_errwarns *errwarns)
3351
 
+{
3352
 
+    tasm_compatible_mode = 1;
3353
 
+    return nasm_preproc_create(in_filename, symtab, lm, errwarns);
3354
 
+}
3355
 
+
3356
 
+yasm_preproc_module yasm_tasm_LTX_preproc = {
3357
 
+    "Real TASM Preprocessor",
3358
 
+    "tasm",
3359
 
+    tasm_preproc_create,
3360
 
+    nasm_preproc_destroy,
3361
 
+    nasm_preproc_get_line,
3362
 
+    nasm_preproc_get_included_file,
3363
 
+    nasm_preproc_add_include_file,
3364
 
+    nasm_preproc_predefine_macro,
3365
 
+    nasm_preproc_undefine_macro,
3366
 
+    nasm_preproc_define_builtin,
3367
 
+};
3368
 
 
3369
 
Modification de propri�t�s sur modules/preprocs/nasm/nasmlib.h
3370
 
___________________________________________________________________
3371
 
Ajout� : svn:mergeinfo
3372
 
 
3373
 
Index: modules/preprocs/nasm/nasm-pp.c
3374
 
===================================================================
3375
 
--- old/modules/preprocs/nasm/nasm-pp.c (r�vision 2128)
3376
 
+++ new/modules/preprocs/nasm/nasm-pp.c (copie de travail)
3377
 
@@ -324,7 +324,9 @@
3378
 
 enum
3379
 
 {
3380
 
     TM_ARG, TM_ELIF, TM_ELSE, TM_ENDIF, TM_IF, TM_IFDEF, TM_IFDIFI,
3381
 
-    TM_IFNDEF, TM_INCLUDE, TM_LOCAL
3382
 
+    TM_IFNDEF, TM_INCLUDE, TM_LOCAL,
3383
 
+    TM_REPT, TM_IRP, TM_MACRO,
3384
 
+    TM_STRUC, TM_SEGMENT
3385
 
 };
3386
 
 
3387
 
 static const char *tasm_directives[] = {
3388
 
@@ -428,6 +473,7 @@
3389
 
 static Token *new_Token(Token * next, int type, const char *text,
3390
 
                         size_t txtlen);
3391
 
 static Token *delete_Token(Token * t);
3392
 
+static Token *tokenise(char *line);
3393
 
 
3394
 
 /*
3395
 
  * Macros for safe checking of token pointers, avoid *(NULL)
3396
 
@@ -442,69 +488,555 @@
3397
 
  * place to do it for the moment, and it is a hack (ideally it would
3398
 
  * be nice to be able to use the NASM pre-processor to do it).
3399
 
  */
3400
 
+
3401
 
+typedef struct TMEndItem {
3402
 
+    int type;
3403
 
+    void *data;
3404
 
+    struct TMEndItem *next;
3405
 
+} TMEndItem;
3406
 
+
3407
 
+static TMEndItem *EndmStack = NULL, *EndsStack = NULL;
3408
 
+
3409
 
+char **TMParameters;
3410
 
+
3411
 
+struct TStrucField {
3412
 
+    char *name;
3413
 
+    char *type;
3414
 
+    struct TStrucField *next;
3415
 
+};
3416
 
+struct TStruc {
3417
 
+    char *name;
3418
 
+    struct TStrucField *fields, *lastField;
3419
 
+    struct TStruc *next;
3420
 
+};
3421
 
+static struct TStruc *TStrucs = NULL;
3422
 
+static int inTstruc = 0;
3423
 
+
3424
 
+struct TSegmentAssume {
3425
 
+    char *segreg;
3426
 
+    char *segment;
3427
 
+};
3428
 
+struct TSegmentAssume *TAssumes;
3429
 
+
3430
 
+const char *tasm_get_segment_register(const char *segment)
3431
 
+{
3432
 
+    struct TSegmentAssume *assume;
3433
 
+    if (!TAssumes)
3434
 
+        return NULL;
3435
 
+    for (assume = TAssumes; assume->segreg; assume++) {
3436
 
+        if (!strcmp(assume->segment, segment))
3437
 
+            break;
3438
 
+    }
3439
 
+    return assume->segreg;
3440
 
+}
3441
 
+
3442
 
 static char *
3443
 
 check_tasm_directive(char *line)
3444
 
 {
3445
 
     int i, j, k, m;
3446
 
-    size_t len;
3447
 
-    char *p = line, *oldline, oldchar;
3448
 
+    size_t len, len2;
3449
 
+    char *p, *oldline, oldchar, *q, oldchar2;
3450
 
+    TMEndItem *end;
3451
 
 
3452
 
+    if ((p = strchr(line, ';')))
3453
 
+        *p = '\0';
3454
 
+
3455
 
+    p = line;
3456
 
+
3457
 
     /* Skip whitespace */
3458
 
     while (isspace(*p) && *p != 0)
3459
 
         p++;
3460
 
 
3461
 
+    /* Ignore nasm directives */
3462
 
+    if (*p == '%')
3463
 
+        return line;
3464
 
+
3465
 
     /* Binary search for the directive name */
3466
 
-    i = -1;
3467
 
-    j = elements(tasm_directives);
3468
 
     len = 0;
3469
 
     while (!isspace(p[len]) && p[len] != 0)
3470
 
         len++;
3471
 
-    if (len)
3472
 
+    if (!len)
3473
 
+        return line;
3474
 
+
3475
 
+    oldchar = p[len];
3476
 
+    p[len] = 0;
3477
 
+    i = -1;
3478
 
+    j = elements(tasm_directives);
3479
 
+    while (j - i > 1)
3480
 
     {
3481
 
-        oldchar = p[len];
3482
 
-        p[len] = 0;
3483
 
-        while (j - i > 1)
3484
 
+        k = (j + i) / 2;
3485
 
+        m = nasm_stricmp(p, tasm_directives[k]);
3486
 
+        if (m == 0)
3487
 
         {
3488
 
-            k = (j + i) / 2;
3489
 
-            m = nasm_stricmp(p, tasm_directives[k]);
3490
 
-            if (m == 0)
3491
 
+            /* We have found a directive, so jam a % in front of it
3492
 
+             * so that NASM will then recognise it as one if it's own.
3493
 
+             */
3494
 
+            p[len] = oldchar;
3495
 
+            len = strlen(p);
3496
 
+            oldline = line;
3497
 
+            if (k == TM_IFDIFI)
3498
 
             {
3499
 
-                /* We have found a directive, so jam a % in front of it
3500
 
-                 * so that NASM will then recognise it as one if it's own.
3501
 
+                /* NASM does not recognise IFDIFI, so we convert it to
3502
 
+                 * %ifdef BOGUS. This is not used in NASM comaptible
3503
 
+                 * code, but does need to parse for the TASM macro
3504
 
+                 * package.
3505
 
                  */
3506
 
-                p[len] = oldchar;
3507
 
+                line = nasm_malloc(13);
3508
 
+                strcpy(line, "%ifdef BOGUS");
3509
 
+            }
3510
 
+            else if (k == TM_INCLUDE)
3511
 
+            {
3512
 
+                /* add double quotes around file name */
3513
 
+                p += 7 + 1;
3514
 
+                while (isspace(*p) && *p)
3515
 
+                    p++;
3516
 
                 len = strlen(p);
3517
 
-                oldline = line;
3518
 
+                line = nasm_malloc(1 + 7 + 1 + 1 + len + 1 + 1);
3519
 
+                sprintf(line, "%%include \"%s\"", p);
3520
 
+            }
3521
 
+            else
3522
 
+            {
3523
 
                 line = nasm_malloc(len + 2);
3524
 
                 line[0] = '%';
3525
 
-                if (k == TM_IFDIFI)
3526
 
-                {
3527
 
-                    /* NASM does not recognise IFDIFI, so we convert it to
3528
 
-                     * %ifdef BOGUS. This is not used in NASM comaptible
3529
 
-                     * code, but does need to parse for the TASM macro
3530
 
-                     * package.
3531
 
-                     */
3532
 
-                    strcpy(line + 1, "ifdef BOGUS");
3533
 
+                memcpy(line + 1, p, len + 1);
3534
 
+            }
3535
 
+            nasm_free(oldline);
3536
 
+            return line;
3537
 
+        }
3538
 
+        else if (m < 0)
3539
 
+        {
3540
 
+            j = k;
3541
 
+        }
3542
 
+        else
3543
 
+            i = k;
3544
 
+    }
3545
 
+
3546
 
+    /* Not a simple directive */
3547
 
+
3548
 
+    if (!nasm_stricmp(p, "endm")) {
3549
 
+        /* handle end of endm directive */
3550
 
+        char **parameter;
3551
 
+        end = EndmStack;
3552
 
+        /* undef parameters */
3553
 
+        if (!end) {
3554
 
+            error(ERR_FATAL, "ENDM: not in an endm context");
3555
 
+            return line;
3556
 
+        }
3557
 
+        EndmStack = EndmStack->next;
3558
 
+        nasm_free(line);
3559
 
+        switch (end->type) {
3560
 
+        case TM_MACRO:
3561
 
+            len = 0;
3562
 
+            for (parameter = end->data; *parameter; parameter++)
3563
 
+                len += 6 + 1 + strlen(*parameter) + 1;
3564
 
+            len += 5 + 1;
3565
 
+            line = nasm_malloc(len);
3566
 
+            p = line;
3567
 
+            for (parameter = end->data; *parameter; parameter++) {
3568
 
+                p += sprintf(p, "%%undef %s\n", *parameter);
3569
 
+                nasm_free(*parameter);
3570
 
+            }
3571
 
+            nasm_free(end->data);
3572
 
+            nasm_free(end);
3573
 
+            sprintf(p, "%%endm");
3574
 
+            return line;
3575
 
+        case TM_REPT:
3576
 
+            nasm_free(end);
3577
 
+            return nasm_strdup("%endrep");
3578
 
+        case TM_IRP: {
3579
 
+            char **data;
3580
 
+            const char *irp_format = 
3581
 
+                "%%undef %s\n"
3582
 
+                "%%rotate 1\n"
3583
 
+                "%%endrep\n"
3584
 
+                "%%endm\n"
3585
 
+                "irp %s\n"
3586
 
+                "%%undef irp";
3587
 
+            data = end->data;
3588
 
+            line = nasm_malloc(strlen(irp_format) - 4 + strlen(data[0])
3589
 
+                   + strlen(data[1]));
3590
 
+            sprintf(line, irp_format, data[0], data[1]);
3591
 
+            nasm_free(data[0]);
3592
 
+            nasm_free(data[1]);
3593
 
+            nasm_free(data);
3594
 
+            return line;
3595
 
+            }
3596
 
+        default:
3597
 
+            error(ERR_FATAL, "ENDM: bogus endm context type %d\n",end->type);
3598
 
+            return NULL;
3599
 
+        }
3600
 
+    } else if (!nasm_stricmp(p, "end")) {
3601
 
+        nasm_free(line);
3602
 
+        return strdup("");
3603
 
+    } else if (!nasm_stricmp(p, "rept")) {
3604
 
+        /* handle repeat directive */
3605
 
+        end = nasm_malloc(sizeof(*end));
3606
 
+        end->type = TM_REPT;
3607
 
+        end->next = EndmStack;
3608
 
+        EndmStack = end;
3609
 
+        memcpy(p, "%rep", 4);
3610
 
+        p[len] = oldchar;
3611
 
+        return line;
3612
 
+    } else if (!nasm_stricmp(p, "locals")) {
3613
 
+        tasm_locals = 1;
3614
 
+        nasm_free(line);
3615
 
+        return strdup("");
3616
 
+    }
3617
 
+
3618
 
+    if (!oldchar)
3619
 
+        return line;
3620
 
+
3621
 
+    /* handle two-words directives */
3622
 
+    q = p + len + 1;
3623
 
+    /* Skip whitespaces */
3624
 
+    while (isspace(*q) && *q)
3625
 
+        q++;
3626
 
+
3627
 
+    len2 = 0;
3628
 
+    while (!isspace(q[len2]) && q[len2]!=',' && q[len2] != 0)
3629
 
+        len2++;
3630
 
+    oldchar2 = q[len2];
3631
 
+    q[len2] = '\0';
3632
 
+
3633
 
+    if (!nasm_stricmp(p, "irp")) {
3634
 
+        /* handle indefinite repeat directive */
3635
 
+        const char *irp_format = 
3636
 
+            "%%imacro irp 0-*\n"
3637
 
+            "%%rep %%0\n"
3638
 
+            "%%define %s %%1\n";
3639
 
+        char **data;
3640
 
+
3641
 
+        data = malloc(2*sizeof(char*));
3642
 
+        oldline = line;
3643
 
+        line = nasm_malloc(strlen(irp_format) - 2 + len2 + 1);
3644
 
+        sprintf(line,irp_format,q);
3645
 
+        data[0] = nasm_strdup(q);
3646
 
+
3647
 
+        if (!oldchar2)
3648
 
+            error(ERR_FATAL, "%s: expected <values>", q + len2);
3649
 
+        p = strchr(q + len2 + 1, '<');
3650
 
+        if (!p)
3651
 
+            error(ERR_FATAL, "%s: expected <values>", q + len2);
3652
 
+        p++;
3653
 
+        q = strchr(p, '>');
3654
 
+        data[1] = nasm_strndup(p, q - p);
3655
 
+
3656
 
+        end = nasm_malloc(sizeof(*end));
3657
 
+        end->type = TM_IRP;
3658
 
+        end->next = EndmStack;
3659
 
+        end->data = data;
3660
 
+        EndmStack = end;
3661
 
+
3662
 
+        nasm_free(oldline);
3663
 
+        return line;
3664
 
+    } else if (!nasm_stricmp(q, "macro")) {
3665
 
+        char *name = p;
3666
 
+        /* handle MACRO */
3667
 
+        /* count parameters */
3668
 
+        j = 1;
3669
 
+        i = 0;
3670
 
+        TMParameters = nasm_malloc(j*sizeof(*TMParameters));
3671
 
+        len = 0;
3672
 
+        p = q + len2 + 1;
3673
 
+        /* Skip whitespaces */
3674
 
+        while (isspace(*p) && *p)
3675
 
+            p++;
3676
 
+        while (*p) {
3677
 
+            /* Get parameter name */
3678
 
+            for (q = p; !isspace(*q) && *q != ',' && *q; q++);
3679
 
+            len2 = q-p;
3680
 
+            if (len2 == 0)
3681
 
+                error(ERR_FATAL, "'%s': expected parameter name", p);
3682
 
+            TMParameters[i] = nasm_malloc(len2 + 1);
3683
 
+            memcpy(TMParameters[i], p, len2);
3684
 
+            TMParameters[i][len2] = '\0';
3685
 
+            len += len2;
3686
 
+            i++;
3687
 
+            if (i + 1 > j) {
3688
 
+                j *= 2;
3689
 
+                TMParameters = nasm_realloc(TMParameters,
3690
 
+                                               j*sizeof(*TMParameters));
3691
 
+            }
3692
 
+            if (i == 1000)
3693
 
+                error(ERR_FATAL, "too many parameters for macro %s", name);
3694
 
+            p = q;
3695
 
+            while (isspace(*p) && *p)
3696
 
+                p++;
3697
 
+            if (!*p)
3698
 
+                break;
3699
 
+            if (*p != ',')
3700
 
+                error(ERR_FATAL, "expected comma");
3701
 
+            p++;
3702
 
+            while (isspace(*p) && *p)
3703
 
+                p++;
3704
 
+        }
3705
 
+        TMParameters[i] = NULL;
3706
 
+        TMParameters = nasm_realloc(TMParameters,
3707
 
+                                        (i+1)*sizeof(*TMParameters));
3708
 
+        len += 1 + 6 + 1 + strlen(name) + 1 + 3; /* macro definition */
3709
 
+        len += i * (1 + 9 + 1 + 1 + 1 + 3 + 2); /* macro parameter definition */
3710
 
+        oldline = line;
3711
 
+        p = line = nasm_malloc(len + 1);
3712
 
+        p += sprintf(p, "%%imacro %s 0-*", name);
3713
 
+        nasm_free(oldline);
3714
 
+        for (j = 0; TMParameters[j]; j++) {
3715
 
+            p += sprintf(p, "\n%%idefine %s %%{%-u}", TMParameters[j], j + 1);
3716
 
+        }
3717
 
+        end = nasm_malloc(sizeof(*end));
3718
 
+        end->type = TM_MACRO;
3719
 
+        end->next = EndmStack;
3720
 
+        end->data = TMParameters;
3721
 
+        EndmStack = end;
3722
 
+        return line;
3723
 
+    } else if (!nasm_stricmp(q, "proc")) {
3724
 
+        /* handle PROC */
3725
 
+        oldline = line;
3726
 
+        line = nasm_malloc(2 + len + 1);
3727
 
+        sprintf(line, "..%s",p);
3728
 
+        nasm_free(oldline);
3729
 
+        return line;
3730
 
+    } else if (!nasm_stricmp(q, "struc")) {
3731
 
+        /* handle struc */
3732
 
+        struct TStruc *struc;
3733
 
+        if (inTstruc) {
3734
 
+            error(ERR_FATAL, "STRUC: already in a struc context");
3735
 
+            return line;
3736
 
+        }
3737
 
+        oldline = line;
3738
 
+        line = nasm_malloc(5 + 1 + len + 1);
3739
 
+        sprintf(line, "struc %s", p);
3740
 
+        struc = malloc(sizeof(*struc));
3741
 
+        struc->name = strdup(p);
3742
 
+        struc->fields = NULL;
3743
 
+        struc->lastField = NULL;
3744
 
+        struc->next = TStrucs;
3745
 
+        TStrucs = struc;
3746
 
+        inTstruc = 1;
3747
 
+        nasm_free(oldline);
3748
 
+        end = nasm_malloc(sizeof(*end));
3749
 
+        end->type = TM_STRUC;
3750
 
+        end->next = EndsStack;
3751
 
+        EndsStack = end;
3752
 
+        return line;
3753
 
+    } else if (!nasm_stricmp(q, "segment")) {
3754
 
+        /* handle SEGMENT */
3755
 
+        oldline = line;
3756
 
+        line = strdup(oldchar2?q+len2+1:"");
3757
 
+        if (tasm_segment) {
3758
 
+            error(ERR_FATAL, "SEGMENT: already in a segment context");
3759
 
+            return line;
3760
 
+        }
3761
 
+        tasm_segment = strdup(p);
3762
 
+        nasm_free(oldline);
3763
 
+        end = nasm_malloc(sizeof(*end));
3764
 
+        end->type = TM_SEGMENT;
3765
 
+        end->next = EndsStack;
3766
 
+        EndsStack = end;
3767
 
+        return line;
3768
 
+    } else if (!nasm_stricmp(p, "ends") || !nasm_stricmp(q, "ends")) {
3769
 
+        /* handle end of ends directive */
3770
 
+        end = EndsStack;
3771
 
+        /* undef parameters */
3772
 
+        if (!end) {
3773
 
+            error(ERR_FATAL, "ENDS: not in an ends context");
3774
 
+            return line;
3775
 
+        }
3776
 
+        EndsStack = EndsStack->next;
3777
 
+        nasm_free(line);
3778
 
+        switch (end->type) {
3779
 
+        case TM_STRUC:
3780
 
+            inTstruc = 0;
3781
 
+            return strdup("endstruc");
3782
 
+        case TM_SEGMENT:
3783
 
+            /* XXX: yes, we leak memory here, but that permits labels
3784
 
+             * to avoid strduping... */
3785
 
+            tasm_segment = NULL;
3786
 
+            return strdup("");
3787
 
+        default:
3788
 
+            error(ERR_FATAL, "ENDS: bogus ends context type %d",end->type);
3789
 
+            return NULL;
3790
 
+        }
3791
 
+    } else if (!nasm_stricmp(p, "endp") || !nasm_stricmp(q, "endp")) {
3792
 
+        nasm_free(line);
3793
 
+        return strdup("");
3794
 
+    } else if (!nasm_stricmp(p, "assume")) {
3795
 
+        struct TSegmentAssume *assume;
3796
 
+        /* handle ASSUME */
3797
 
+        if (!TAssumes) {
3798
 
+            TAssumes = nasm_malloc(sizeof(*TAssumes));
3799
 
+            TAssumes[0].segreg = NULL;
3800
 
+        }
3801
 
+        i = 0;
3802
 
+        q[len2] = oldchar2;
3803
 
+        /* Skip whitespaces */
3804
 
+        while (isspace(*q) && *q)
3805
 
+            q++;
3806
 
+        while (*q) {
3807
 
+            p = q;
3808
 
+            for (; *q && *q != ':' && !isspace(*q); q++);
3809
 
+            if (!*q)
3810
 
+                break;
3811
 
+            /* segment register name */
3812
 
+            for (assume = TAssumes; assume->segreg; assume++)
3813
 
+                if (strlen(assume->segreg) == (size_t)(q-p) &&
3814
 
+                    !strncasecmp(assume->segreg, p, q-p))
3815
 
+                    break;
3816
 
+            if (!assume->segreg) {
3817
 
+                i = assume - TAssumes + 1;
3818
 
+                TAssumes = nasm_realloc(TAssumes, (i+1)*sizeof(*TAssumes));
3819
 
+                assume = TAssumes + i - 1;
3820
 
+                assume->segreg = nasm_strndup(p, q-p);
3821
 
+                assume[1].segreg = NULL;
3822
 
+            }
3823
 
+            for (; *q && *q != ':' && isspace(*q); q++);
3824
 
+            if (*q != ':')
3825
 
+                error(ERR_FATAL, "expected `:' instead of `%c'", *q);
3826
 
+            for (q++; *q && isspace(*q); q++);
3827
 
+
3828
 
+            /* segment name */
3829
 
+            p = q;
3830
 
+            for (; *q && *q != ',' && !isspace(*q); q++);
3831
 
+            assume->segment = nasm_strndup(p, q-p);
3832
 
+            for (; *q && isspace(*q); q++);
3833
 
+            if (*q && *q != ',')
3834
 
+                error(ERR_FATAL, "expected `,' instead of `%c'", *q);
3835
 
+        
3836
 
+            for (q++; *q && isspace(*q); q++);
3837
 
+        }
3838
 
+        TAssumes[i].segreg = NULL;
3839
 
+        TAssumes = nasm_realloc(TAssumes, (i+1)*sizeof(*TAssumes));
3840
 
+        nasm_free(line);
3841
 
+        return strdup("");
3842
 
+    } else if (inTstruc) {
3843
 
+        struct TStrucField *field;
3844
 
+        /* TODO: handle unnamed data */
3845
 
+        field = nasm_malloc(sizeof(*field));
3846
 
+        field->name = strdup(p);
3847
 
+        /* TODO: type struc ! */
3848
 
+        field->type = strdup(q);
3849
 
+        field->next = NULL;
3850
 
+        if (!TStrucs->fields)
3851
 
+                TStrucs->fields = field;
3852
 
+        else if (TStrucs->lastField)
3853
 
+                TStrucs->lastField->next = field;
3854
 
+        TStrucs->lastField = field;
3855
 
+        if (!oldchar2) {
3856
 
+            error(ERR_FATAL, "Expected struc field initializer after %s %s", p, q);
3857
 
+            return line;
3858
 
+        }
3859
 
+        oldline = line;
3860
 
+        line = nasm_malloc(1 + len + 1 + len2 + 1 + strlen(q+len2+1) + 1);
3861
 
+        sprintf(line, ".%s %s %s", p, q, q+len2+1);
3862
 
+        nasm_free(oldline);
3863
 
+        return line;
3864
 
+    }
3865
 
+    {
3866
 
+        struct TStruc *struc;
3867
 
+        for (struc = TStrucs; struc; struc = struc->next) {
3868
 
+            if (!strcasecmp(q, struc->name)) {
3869
 
+                char *r = q + len2 + 1, *s, *t, tasm_param[6];
3870
 
+                struct TStrucField *field = struc->fields;
3871
 
+                int size, n;
3872
 
+                if (!oldchar2) {
3873
 
+                    error(ERR_FATAL, "Expected struc field initializer after %s %s", p, q);
3874
 
+                    return line;
3875
 
                 }
3876
 
-                else
3877
 
-                {
3878
 
-                    memcpy(line + 1, p, len + 1);
3879
 
+                r = strchr(r, '<');
3880
 
+                if (!r) {
3881
 
+                    error(ERR_FATAL, "Expected < for struc field initializer in %s %s %s", p, q, r);
3882
 
+                    return line;
3883
 
                 }
3884
 
+                t = strchr(r + 1, '>');
3885
 
+                if (!t) {
3886
 
+                    error(ERR_FATAL, "Expected > for struc field initializer in %s %s %s", p, q, r);
3887
 
+                    return line;
3888
 
+                }
3889
 
+                *t = 0;
3890
 
+                oldline = line;
3891
 
+                size = len + len2 + 128;
3892
 
+                line = nasm_malloc(size);
3893
 
+                if (defining)
3894
 
+                    for (n=0;TMParameters[n];n++)
3895
 
+                        if (!strcmp(TMParameters[n],p)) {
3896
 
+                            sprintf(tasm_param,"%%{%d}",n+1);
3897
 
+                            p = tasm_param;
3898
 
+                            break;
3899
 
+                        }
3900
 
+                n = sprintf(line, "%s: istruc %s\n", p, q);
3901
 
+                /* use initialisers */
3902
 
+                while ((s = strchr(r + 1, ','))) {
3903
 
+                    if (!field) {
3904
 
+                        error(ERR_FATAL, "Too many initializers in structure %s %s", p, q);
3905
 
+                        return oldline;
3906
 
+                    }
3907
 
+                    *s = 0;
3908
 
+                    while (1) {
3909
 
+                            m = snprintf(line + n, size - n, "%s.%s: at .%s, %s %s\n", p, field->name, field->name, field->type, r + 1);
3910
 
+                        if (m + 1 <= size - n)
3911
 
+                                break;
3912
 
+                        size *= 2;
3913
 
+                        line = nasm_realloc(line, size);
3914
 
+                    }
3915
 
+                    n += m;
3916
 
+                    r = s;
3917
 
+                    field = field->next;
3918
 
+                }
3919
 
+                /* complete with last initializer and '?' */
3920
 
+                while(field) {
3921
 
+                    while (1) {
3922
 
+                            m = snprintf(line + n, size - n, "%s.%s: at .%s, %s %s\n", p, field->name, field->name, field->type, r ? r + 1: "?");
3923
 
+                        if (m + 1 <= size - n)
3924
 
+                                break;
3925
 
+                        size *= 2;
3926
 
+                        line = nasm_realloc(line, size);
3927
 
+                    }
3928
 
+                    n += m;
3929
 
+                    r = NULL;
3930
 
+                    field = field->next;
3931
 
+                }
3932
 
+                line = nasm_realloc(line, n + 5);
3933
 
+                sprintf(line + n, "iend");
3934
 
                 nasm_free(oldline);
3935
 
                 return line;
3936
 
             }
3937
 
-            else if (m < 0)
3938
 
-            {
3939
 
-                j = k;
3940
 
-            }
3941
 
-            else
3942
 
-                i = k;
3943
 
         }
3944
 
-        p[len] = oldchar;
3945
 
     }
3946
 
+
3947
 
+    q[len2] = oldchar2;
3948
 
+    p[len] = oldchar;
3949
 
+    
3950
 
     return line;
3951
 
 }
3952
 
 
3953
 
+static Token * tasm_join_tokens(Token *tline)
3954
 
+{
3955
 
+    Token *t, *prev, *next;
3956
 
+    for (prev = NULL, t = tline; t; prev = t, t = next) {
3957
 
+        next = t->next;
3958
 
+        if (t->type == TOK_OTHER && !strcmp(t->text,"&")) {
3959
 
+            if (!prev)
3960
 
+                error(ERR_FATAL, "no token before &");
3961
 
+            else if (!next)
3962
 
+                error(ERR_FATAL, "no token after &");
3963
 
+            else if (prev->type != next->type)
3964
 
+                error(ERR_FATAL, "can't handle different types of token around &");
3965
 
+            else if (!prev->text || !next->text)
3966
 
+                error(ERR_FATAL, "can't handle empty token around &");
3967
 
+            else {
3968
 
+                int lenp = strlen(prev->text);
3969
 
+                int lenn = strlen(next->text);
3970
 
+                prev->text = nasm_realloc(prev->text, lenp + lenn + 1);
3971
 
+                strncpy(prev->text + lenp, next->text, lenn + 1);
3972
 
+                (void) delete_Token(t);
3973
 
+                prev->next = delete_Token(next);
3974
 
+                t = prev;
3975
 
+                next = t->next;
3976
 
+            }
3977
 
+        }
3978
 
+    }
3979
 
+    return tline;
3980
 
+}
3981
 
+
3982
 
 /*
3983
 
  * The pre-preprocessing stage... This function translates line
3984
 
  * number indications as they emerge from GNU cpp (`# lineno "file"
3985
 
@@ -517,6 +1049,8 @@
3986
 
     int lineno;
3987
 
     size_t fnlen;
3988
 
     char *fname, *oldline;
3989
 
+    char *c, *d, *ret;
3990
 
+    Line *l, **lp;
3991
 
 
3992
 
     if (line[0] == '#' && line[1] == ' ')
3993
 
     {
3994
 
@@ -532,8 +1066,30 @@
3995
 
         nasm_free(oldline);
3996
 
     }
3997
 
     if (tasm_compatible_mode)
3998
 
-        return check_tasm_directive(line);
3999
 
-    return line;
4000
 
+        line = check_tasm_directive(line);
4001
 
+
4002
 
+    if (!(c = strchr(line, '\n')))
4003
 
+        return line;
4004
 
+
4005
 
+    /* Turn multiline macros into several lines */
4006
 
+    *c = '\0';
4007
 
+    ret = nasm_strdup(line);
4008
 
+
4009
 
+    lp = &istk->expansion;
4010
 
+    do {
4011
 
+        d = strchr(c+1, '\n');
4012
 
+        if (d)
4013
 
+            *d = '\0';
4014
 
+        l = malloc(sizeof(*l));
4015
 
+        l -> first = tokenise(c+1);
4016
 
+        l -> finishes = NULL;
4017
 
+        l -> next = *lp;
4018
 
+        *lp = l;
4019
 
+        c = d;
4020
 
+        lp = &l -> next;
4021
 
+    } while (c);
4022
 
+    nasm_free(line);
4023
 
+    return ret;
4024
 
 }
4025
 
 
4026
 
 /*
4027
 
@@ -1231,7 +1787,7 @@
4028
 
 inc_fopen(char *file, char **newname)
4029
 
 {
4030
 
     FILE *fp;
4031
 
-    char *combine = NULL;
4032
 
+    char *combine = NULL, *c;
4033
 
     char *pb, *p1, *p2, *file2 = NULL;
4034
 
 
4035
 
     /* Try to expand all %ENVVAR% in filename.  Warn, and leave %string%
4036
 
@@ -1281,6 +1837,27 @@
4037
 
 
4038
 
     fp = yasm_fopen_include(file2 ? file2 : file, nasm_src_get_fname(), "r",
4039
 
                             &combine);
4040
 
+    if (!fp && tasm_compatible_mode)
4041
 
+    {
4042
 
+        char *thefile = file2 ? file2 : file;
4043
 
+        /* try a few case combinations */
4044
 
+        do {
4045
 
+            for (c = thefile; *c; c++)
4046
 
+                *c = toupper(*c);
4047
 
+            fp = yasm_fopen_include(thefile, nasm_src_get_fname(), "r", &combine);
4048
 
+            if (fp) break;
4049
 
+            *thefile = tolower(*thefile);
4050
 
+            fp = yasm_fopen_include(thefile, nasm_src_get_fname(), "r", &combine);
4051
 
+            if (fp) break;
4052
 
+            for (c = thefile; *c; c++)
4053
 
+                *c = tolower(*c);
4054
 
+            fp = yasm_fopen_include(thefile, nasm_src_get_fname(), "r", &combine);
4055
 
+            if (fp) break;
4056
 
+            *thefile = toupper(*thefile);
4057
 
+            fp = yasm_fopen_include(thefile, nasm_src_get_fname(), "r", &combine);
4058
 
+            if (fp) break;
4059
 
+        } while (0);
4060
 
+    }
4061
 
     if (!fp)
4062
 
         error(ERR_FATAL, "unable to open include file `%s'",
4063
 
               file2 ? file2 : file);
4064
 
@@ -4420,6 +4997,9 @@
4065
 
                 /*
4066
 
                  * De-tokenise the line again, and emit it.
4067
 
                  */
4068
 
+                if (tasm_compatible_mode)
4069
 
+                    tline = tasm_join_tokens(tline);
4070
 
+
4071
 
                 line = detoken(tline, TRUE);
4072
 
                 free_tlist(tline);
4073
 
                 break;
4074
 
Index: frontends/tasm/tasm-options.h
4075
 
===================================================================
4076
 
--- old/frontends/tasm/tasm-options.h   (r�vision 0)
4077
 
+++ new/frontends/tasm/tasm-options.h   (r�vision 0)
4078
 
@@ -0,0 +1,69 @@
4079
 
+/* $Id: tasm-options.h 1137 2004-09-04 01:24:57Z peter $
4080
 
+ * Generic Options Support Header File
4081
 
+ *
4082
 
+ * Copyright (c) 2001  Stanislav Karchebny <berk@madfire.net>
4083
 
+ *
4084
 
+ * Redistribution and use in source and binary forms, with or without
4085
 
+ * modification, are permitted provided that the following conditions
4086
 
+ * are met:
4087
 
+ * 1. Redistributions of source code must retain the above copyright
4088
 
+ *    notice, this list of conditions and the following disclaimer.
4089
 
+ * 2. Redistributions in binary form must reproduce the above copyright
4090
 
+ *    notice, this list of conditions and the following disclaimer in the
4091
 
+ *    documentation and/or other materials provided with the distribution.
4092
 
+ *
4093
 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
4094
 
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4095
 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4096
 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
4097
 
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4098
 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4099
 
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4100
 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4101
 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4102
 
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4103
 
+ * POSSIBILITY OF SUCH DAMAGE.
4104
 
+ */
4105
 
+#ifndef TASM_OPTIONS_H
4106
 
+#define TASM_OPTIONS_H
4107
 
+
4108
 
+/* an option structure
4109
 
+ * operate on either -sopt, --lopt, -sopt <val> or --lopt=<val>
4110
 
+ */
4111
 
+typedef struct opt_option_s
4112
 
+{
4113
 
+    /* option */
4114
 
+    const char *opt;
4115
 
+
4116
 
+    /* !=0 if option requires parameter, 0 if not */
4117
 
+    int takes_param;
4118
 
+
4119
 
+    int (*handler) (char *cmd, /*@null@*/ char *param, int extra);
4120
 
+    int extra;                 /* extra value for handler */
4121
 
+
4122
 
+    /* description to use in help_msg() */
4123
 
+    /*@observer@*/ const char *description;
4124
 
+
4125
 
+    /* optional description for the param taken (NULL if not present) */
4126
 
+    /*  (short - will be printed after option sopt/lopt) */
4127
 
+    /*@observer@*/ /*@null@*/ const char *param_desc;
4128
 
+} opt_option;
4129
 
+
4130
 
+/* handle everything that is not an option */
4131
 
+int not_an_option_handler(char *param);
4132
 
+
4133
 
+/* parse command line calling handlers when appropriate
4134
 
+ * argc, argv - pass directly from main(argc,argv)
4135
 
+ * options - array of options
4136
 
+ * nopts - options count
4137
 
+ */
4138
 
+int parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts,
4139
 
+                  void (*print_error) (const char *fmt, ...));
4140
 
+
4141
 
+/* display help message msg followed by list of options in options and followed
4142
 
+ * by tail
4143
 
+ */
4144
 
+void help_msg(const char *msg, const char *tail, opt_option *options,
4145
 
+              size_t nopts);
4146
 
+
4147
 
+#endif
4148
 
Index: frontends/tasm/tasm.c
4149
 
===================================================================
4150
 
--- old/frontends/tasm/tasm.c   (r�vision 0)
4151
 
+++ new/frontends/tasm/tasm.c   (r�vision 0)
4152
 
@@ -0,0 +1,1003 @@
4153
 
+/*
4154
 
+ * Program entry point, command line parsing
4155
 
+ *
4156
 
+ *  Copyright (C) 2001-2008  Peter Johnson
4157
 
+ *  Copyright (C) 2007-2008  Samuel Thibault
4158
 
+ *
4159
 
+ * Redistribution and use in source and binary forms, with or without
4160
 
+ * modification, are permitted provided that the following conditions
4161
 
+ * are met:
4162
 
+ * 1. Redistributions of source code must retain the above copyright
4163
 
+ *    notice, this list of conditions and the following disclaimer.
4164
 
+ * 2. Redistributions in binary form must reproduce the above copyright
4165
 
+ *    notice, this list of conditions and the following disclaimer in the
4166
 
+ *    documentation and/or other materials provided with the distribution.
4167
 
+ *
4168
 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
4169
 
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4170
 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4171
 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
4172
 
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
4173
 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
4174
 
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
4175
 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
4176
 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4177
 
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4178
 
+ * POSSIBILITY OF SUCH DAMAGE.
4179
 
+ */
4180
 
+#include <util.h>
4181
 
+/*@unused@*/ RCSID("$Id: tasm.c 1523 2006-05-06 16:11:56Z peter $");
4182
 
+
4183
 
+#include <ctype.h>
4184
 
+#include <unistd.h>
4185
 
+#include <libyasm/compat-queue.h>
4186
 
+#include <libyasm/bitvect.h>
4187
 
+#include <libyasm.h>
4188
 
+
4189
 
+#ifdef HAVE_LIBGEN_H
4190
 
+#include <libgen.h>
4191
 
+#endif
4192
 
+
4193
 
+#include "tasm-options.h"
4194
 
+
4195
 
+#ifdef CMAKE_BUILD
4196
 
+#include "yasm-plugin.h"
4197
 
+#endif
4198
 
+
4199
 
+#include "license.c"
4200
 
+
4201
 
+#define DEFAULT_OBJFMT_MODULE   "bin"
4202
 
+
4203
 
+/*@null@*/ /*@only@*/ static char *obj_filename = NULL, *in_filename = NULL;
4204
 
+/*@null@*/ /*@only@*/ static char *list_filename = NULL, *xref_filename = NULL;
4205
 
+/*@null@*/ /*@only@*/ static char *machine_name = NULL;
4206
 
+static int special_options = 0;
4207
 
+static int segment_ordering = 0;
4208
 
+static int cross_reference = 0;
4209
 
+static int floating_point = 0;
4210
 
+static int listing = 0;
4211
 
+static int expanded_listing = 0;
4212
 
+static int case_sensitivity = 0;
4213
 
+static int valid_length = -1;
4214
 
+/*@null@*/ /*@dependent@*/ static yasm_arch *cur_arch = NULL;
4215
 
+/*@null@*/ /*@dependent@*/ static const yasm_arch_module *
4216
 
+    cur_arch_module = NULL;
4217
 
+/*@null@*/ /*@dependent@*/ static const yasm_parser_module *
4218
 
+    cur_parser_module = NULL;
4219
 
+/*@null@*/ /*@dependent@*/ static yasm_preproc *cur_preproc = NULL;
4220
 
+/*@null@*/ /*@dependent@*/ static const yasm_preproc_module *
4221
 
+    cur_preproc_module = NULL;
4222
 
+/*@null@*/ static char *objfmt_keyword = NULL;
4223
 
+/*@null@*/ /*@dependent@*/ static const yasm_objfmt_module *
4224
 
+    cur_objfmt_module = NULL;
4225
 
+/*@null@*/ /*@dependent@*/ static const yasm_dbgfmt_module *
4226
 
+    cur_dbgfmt_module = NULL;
4227
 
+/*@null@*/ /*@dependent@*/ static yasm_listfmt *cur_listfmt = NULL;
4228
 
+/*@null@*/ /*@dependent@*/ static const yasm_listfmt_module *
4229
 
+    cur_listfmt_module = NULL;
4230
 
+static int warning_error = 0;   /* warnings being treated as errors */
4231
 
+static FILE *errfile;
4232
 
+/*@null@*/ /*@only@*/ static char *error_filename = NULL;
4233
 
+
4234
 
+/*@null@*/ /*@dependent@*/ static FILE *open_file(const char *filename,
4235
 
+                                                  const char *mode);
4236
 
+static void check_errors(/*@only@*/ yasm_errwarns *errwarns,
4237
 
+                         /*@only@*/ yasm_object *object,
4238
 
+                         /*@only@*/ yasm_linemap *linemap);
4239
 
+static void cleanup(/*@null@*/ /*@only@*/ yasm_object *object);
4240
 
+
4241
 
+/* Forward declarations: cmd line parser handlers */
4242
 
+static int opt_special_handler(char *cmd, /*@null@*/ char *param, int extra);
4243
 
+static int opt_segment_ordering_handler(char *cmd, /*@null@*/ char *param, int extra);
4244
 
+static int opt_cross_reference_handler(char *cmd, /*@null@*/ char *param, int extra);
4245
 
+static int opt_floating_point_handler(char *cmd, /*@null@*/ char *param, int extra);
4246
 
+static int opt_ignore(char *cmd, /*@null@*/ char *param, int extra);
4247
 
+static int opt_listing_handler(char *cmd, /*@null@*/ char *param, int extra);
4248
 
+static int opt_case_handler(char *cmd, /*@null@*/ char *param, int extra);
4249
 
+static int opt_valid_length_handler(char *cmd, /*@null@*/ char *param, int extra);
4250
 
+
4251
 
+static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
4252
 
+static int opt_preproc_option(char *cmd, /*@null@*/ char *param, int extra);
4253
 
+static int opt_exe_handler(char *cmd, /*@null@*/ char *param, int extra);
4254
 
+
4255
 
+static /*@only@*/ char *replace_extension(const char *orig, /*@null@*/
4256
 
+                                          const char *ext, const char *def);
4257
 
+static void print_error(const char *fmt, ...);
4258
 
+
4259
 
+static /*@exits@*/ void handle_yasm_int_error(const char *file,
4260
 
+                                              unsigned int line,
4261
 
+                                              const char *message);
4262
 
+static /*@exits@*/ void handle_yasm_fatal(const char *message, va_list va);
4263
 
+static const char *handle_yasm_gettext(const char *msgid);
4264
 
+static void print_yasm_error(const char *filename, unsigned long line,
4265
 
+                             const char *msg, /*@null@*/ const char *xref_fn,
4266
 
+                             unsigned long xref_line,
4267
 
+                             /*@null@*/ const char *xref_msg);
4268
 
+static void print_yasm_warning(const char *filename, unsigned long line,
4269
 
+                               const char *msg);
4270
 
+
4271
 
+static void apply_preproc_builtins(void);
4272
 
+static void apply_preproc_standard_macros(const yasm_stdmac *stdmacs);
4273
 
+static void apply_preproc_saved_options(void);
4274
 
+static void print_list_keyword_desc(const char *name, const char *keyword);
4275
 
+
4276
 
+/* values for special_options */
4277
 
+#define SPECIAL_SHOW_HELP 0x01
4278
 
+#define SPECIAL_SHOW_VERSION 0x02
4279
 
+#define SPECIAL_SHOW_LICENSE 0x04
4280
 
+
4281
 
+#define SEGMENT_ORDERING_ALPHABETIC 0x01
4282
 
+#define SEGMENT_ORDERING_SOURCE 0x02
4283
 
+
4284
 
+#define FP_EMULATED 0x01
4285
 
+#define FP_REAL 0x02
4286
 
+
4287
 
+#define CASE_ALL 0x01
4288
 
+#define CASE_GLOBALS 0x02
4289
 
+#define CASE_NONE 0x04
4290
 
+
4291
 
+#define DEBUG_FULL 0x01
4292
 
+#define DEBUG_LINES 0x02
4293
 
+#define DEBUG_NONE 0x04
4294
 
+
4295
 
+/* command line options */
4296
 
+static opt_option options[] =
4297
 
+{
4298
 
+    { "version", 0, opt_special_handler, SPECIAL_SHOW_VERSION,
4299
 
+      N_("show version text"), NULL },
4300
 
+    { "license", 0, opt_special_handler, SPECIAL_SHOW_LICENSE,
4301
 
+      N_("show license text"), NULL },
4302
 
+    { "a", 0, opt_segment_ordering_handler, SEGMENT_ORDERING_ALPHABETIC,
4303
 
+      N_("Alphabetic segment ordering"), NULL },
4304
 
+    { "s", 0, opt_segment_ordering_handler, SEGMENT_ORDERING_SOURCE,
4305
 
+      N_("Source segment ordering"), NULL },
4306
 
+
4307
 
+    { "c", 0, opt_cross_reference_handler, 0,
4308
 
+      N_("Generate cross-reference in listing"), NULL },
4309
 
+
4310
 
+    { "d", 1, opt_preproc_option, 2,
4311
 
+      N_("pre-define a macro, optionally to value"), N_("macro[=value]") },
4312
 
+
4313
 
+    { "e", 0, opt_floating_point_handler, FP_EMULATED,
4314
 
+      N_("Emulated floating-point instructions (not supported)"), NULL },
4315
 
+    { "r", 0, opt_floating_point_handler, FP_REAL,
4316
 
+      N_("Real floating-point instructions"), NULL },
4317
 
+
4318
 
+    { "h", 0, opt_special_handler, SPECIAL_SHOW_HELP,
4319
 
+      N_("show help text"), NULL },
4320
 
+    { "?", 0, opt_special_handler, SPECIAL_SHOW_HELP,
4321
 
+      N_("show help text"), NULL },
4322
 
+
4323
 
+    { "i", 1, opt_preproc_option, 0,
4324
 
+      N_("add include path"), N_("path") },
4325
 
+
4326
 
+    { "j", 1, opt_ignore, 0,
4327
 
+      N_("Jam in an assemble directive CMD (eg. /jIDEAL) (not supported)"), NULL },
4328
 
+
4329
 
+    { "k", 1, opt_ignore, 0,
4330
 
+      N_("Hash table capacity (ignored)"), N_("# symbols") },
4331
 
+
4332
 
+    { "l", 0, opt_listing_handler, 0,
4333
 
+      N_("Generate listing"), N_("l=normal listing, la=expanded listing") },
4334
 
+
4335
 
+    { "ml", 0, opt_case_handler, CASE_ALL,
4336
 
+      N_("Case sensitivity on all symbols"), NULL },
4337
 
+    { "mx", 0, opt_case_handler, CASE_GLOBALS,
4338
 
+      N_("Case sensitivity on global symbols"), NULL },
4339
 
+    { "mu", 0, opt_case_handler, CASE_NONE,
4340
 
+      N_("No case sensitivity on symbols"), NULL },
4341
 
+    { "mv", 0, opt_valid_length_handler, 0,
4342
 
+      N_("Set maximum valid length for symbols"), N_("length") },
4343
 
+
4344
 
+    { "m", 1, opt_ignore, 0,
4345
 
+      N_("Allow multiple passes to resolve forward reference (ignored)"), N_("number of passes") },
4346
 
+
4347
 
+    { "n", 0, opt_ignore, 0,
4348
 
+      N_("Suppress symbol tables in listing"), NULL },
4349
 
+
4350
 
+    { "o", 0, opt_ignore, 0,
4351
 
+      N_("Object code"), N_("os: standard, o: standard w/overlays, op: Phar Lap, oi: IBM") },
4352
 
+
4353
 
+    { "p", 0, opt_ignore, 0,
4354
 
+      N_("Check for code segment overrides in protected mode"), NULL },
4355
 
+    { "q", 0, opt_ignore, 0,
4356
 
+      N_("Suppress OBJ records not needed for linking (ignored)"), NULL },
4357
 
+    { "t", 0, opt_ignore, 0,
4358
 
+      N_("Suppress messages if successful assembly"), NULL },
4359
 
+    { "u", 0, opt_ignore, 0,
4360
 
+      N_("Set version emulation"), N_("Version") },
4361
 
+    { "w", 1, opt_warning_handler, 0,
4362
 
+      N_("Set warning level"), N_("w0=none, w1=w2=warnings on, w-xxx/w+xxx=disable/enable warning xxx") },
4363
 
+    { "x", 0, opt_ignore, 0,
4364
 
+      N_("Include false conditionals in listing"), NULL },
4365
 
+    { "zi", 0, opt_ignore, DEBUG_FULL,
4366
 
+      N_("Full debug info"), NULL },
4367
 
+    { "zd", 0, opt_ignore, DEBUG_LINES,
4368
 
+      N_("Line numbers debug info"), NULL },
4369
 
+    { "zn", 0, opt_ignore, DEBUG_NONE,
4370
 
+      N_("No debug info"), NULL },
4371
 
+    { "z", 0, opt_ignore, 0,
4372
 
+      N_("Display source line with error message (ignored)"), NULL },
4373
 
+
4374
 
+    { "b", 0, opt_exe_handler, 0,
4375
 
+      N_("Build a (very) basic .exe file"), NULL },
4376
 
+};
4377
 
+
4378
 
+/* version message */
4379
 
+/*@observer@*/ static const char *version_msg[] = {
4380
 
+    PACKAGE_NAME " " PACKAGE_INTVER "." PACKAGE_BUILD,
4381
 
+    "Compiled on " __DATE__ ".",
4382
 
+    "Copyright (c) 2001-2008 Peter Johnson and other Yasm developers.",
4383
 
+    "Run yasm --license for licensing overview and summary."
4384
 
+};
4385
 
+
4386
 
+/* help messages */
4387
 
+/*@observer@*/ static const char *help_head = N_(
4388
 
+    "usage: tasm [option]* source [,object] [,listing] [,xref] \n"
4389
 
+    "Options:\n");
4390
 
+/*@observer@*/ static const char *help_tail = N_(
4391
 
+    "\n"
4392
 
+    "source is asm source to be assembled.\n"
4393
 
+    "\n"
4394
 
+    "Sample invocation:\n"
4395
 
+    "   tasm /zi source.asm\n"
4396
 
+    "\n"
4397
 
+    "Report bugs to bug-yasm@tortall.net\n");
4398
 
+
4399
 
+/* parsed command line storage until appropriate modules have been loaded */
4400
 
+typedef STAILQ_HEAD(constcharparam_head, constcharparam) constcharparam_head;
4401
 
+
4402
 
+typedef struct constcharparam {
4403
 
+    STAILQ_ENTRY(constcharparam) link;
4404
 
+    const char *param;
4405
 
+    int id;
4406
 
+} constcharparam;
4407
 
+
4408
 
+static constcharparam_head preproc_options;
4409
 
+
4410
 
+static int
4411
 
+do_assemble(void)
4412
 
+{
4413
 
+    yasm_object *object;
4414
 
+    const char *base_filename;
4415
 
+    /*@null@*/ FILE *obj = NULL;
4416
 
+    yasm_arch_create_error arch_error;
4417
 
+    yasm_linemap *linemap;
4418
 
+    yasm_errwarns *errwarns = yasm_errwarns_create();
4419
 
+    int i, matched;
4420
 
+
4421
 
+    /* Initialize line map */
4422
 
+    linemap = yasm_linemap_create();
4423
 
+    yasm_linemap_set(linemap, in_filename, 1, 1);
4424
 
+
4425
 
+    /* determine the object filename if not specified */
4426
 
+    if (!obj_filename) {
4427
 
+        if (in_filename == NULL)
4428
 
+            /* Default to yasm.out if no obj filename specified */
4429
 
+            obj_filename = yasm__xstrdup("yasm.out");
4430
 
+        else {
4431
 
+            /* replace (or add) extension to base filename */
4432
 
+            yasm__splitpath(in_filename, &base_filename);
4433
 
+            if (base_filename[0] == '\0')
4434
 
+                obj_filename = yasm__xstrdup("yasm.out");
4435
 
+            else
4436
 
+                obj_filename = replace_extension(base_filename,
4437
 
+                                                 "obj",
4438
 
+                                                 "yasm.out");
4439
 
+        }
4440
 
+    }
4441
 
+
4442
 
+    cur_arch = yasm_arch_create(cur_arch_module, machine_name,
4443
 
+                                cur_parser_module->keyword, &arch_error);
4444
 
+    if (!cur_arch) {
4445
 
+        switch (arch_error) {
4446
 
+            case YASM_ARCH_CREATE_BAD_MACHINE:
4447
 
+                print_error(_("%s: `%s' is not a valid %s for %s `%s'"),
4448
 
+                            _("FATAL"), machine_name, _("machine"),
4449
 
+                            _("architecture"), cur_arch_module->keyword);
4450
 
+                break;
4451
 
+            case YASM_ARCH_CREATE_BAD_PARSER:
4452
 
+                print_error(_("%s: `%s' is not a valid %s for %s `%s'"),
4453
 
+                            _("FATAL"), cur_parser_module->keyword,
4454
 
+                            _("parser"), _("architecture"),
4455
 
+                            cur_arch_module->keyword);
4456
 
+                break;
4457
 
+            default:
4458
 
+                print_error(_("%s: unknown architecture error"), _("FATAL"));
4459
 
+        }
4460
 
+
4461
 
+        return EXIT_FAILURE;
4462
 
+    }
4463
 
+
4464
 
+    /* Create object */
4465
 
+    object = yasm_object_create(in_filename, obj_filename, cur_arch,
4466
 
+                                cur_objfmt_module, cur_dbgfmt_module);
4467
 
+    if (!object) {
4468
 
+        yasm_error_class eclass;
4469
 
+        unsigned long xrefline;
4470
 
+        /*@only@*/ /*@null@*/ char *estr, *xrefstr;
4471
 
+
4472
 
+        yasm_error_fetch(&eclass, &estr, &xrefline, &xrefstr);
4473
 
+        print_error("%s: %s", _("FATAL"), estr);
4474
 
+        yasm_xfree(estr);
4475
 
+        yasm_xfree(xrefstr);
4476
 
+
4477
 
+        cleanup(object);
4478
 
+        return EXIT_FAILURE;
4479
 
+    }
4480
 
+
4481
 
+    /* Get a fresh copy of objfmt_module as it may have changed. */
4482
 
+    cur_objfmt_module = ((yasm_objfmt_base *)object->objfmt)->module;
4483
 
+
4484
 
+    /* Check to see if the requested preprocessor is in the allowed list
4485
 
+     * for the active parser.
4486
 
+     */
4487
 
+    matched = 0;
4488
 
+    for (i=0; cur_parser_module->preproc_keywords[i]; i++)
4489
 
+        if (yasm__strcasecmp(cur_parser_module->preproc_keywords[i],
4490
 
+                             cur_preproc_module->keyword) == 0)
4491
 
+            matched = 1;
4492
 
+    if (!matched) {
4493
 
+        print_error(_("%s: `%s' is not a valid %s for %s `%s'"), _("FATAL"),
4494
 
+                    cur_preproc_module->keyword, _("preprocessor"),
4495
 
+                    _("parser"), cur_parser_module->keyword);
4496
 
+        cleanup(object);
4497
 
+        return EXIT_FAILURE;
4498
 
+    }
4499
 
+
4500
 
+    cur_preproc = yasm_preproc_create(cur_preproc_module, in_filename,
4501
 
+                                      object->symtab, linemap, errwarns);
4502
 
+
4503
 
+    apply_preproc_builtins();
4504
 
+    apply_preproc_standard_macros(cur_parser_module->stdmacs);
4505
 
+    apply_preproc_standard_macros(cur_objfmt_module->stdmacs);
4506
 
+    apply_preproc_saved_options();
4507
 
+
4508
 
+    /* Get initial x86 BITS setting from object format */
4509
 
+    if (strcmp(cur_arch_module->keyword, "x86") == 0) {
4510
 
+        yasm_arch_set_var(cur_arch, "mode_bits",
4511
 
+                          cur_objfmt_module->default_x86_mode_bits);
4512
 
+    }
4513
 
+
4514
 
+    /* Parse! */
4515
 
+    cur_parser_module->do_parse(object, cur_preproc, list_filename != NULL,
4516
 
+                                linemap, errwarns);
4517
 
+
4518
 
+    check_errors(errwarns, object, linemap);
4519
 
+
4520
 
+    /* Finalize parse */
4521
 
+    yasm_object_finalize(object, errwarns);
4522
 
+    check_errors(errwarns, object, linemap);
4523
 
+
4524
 
+    /* Optimize */
4525
 
+    yasm_object_optimize(object, errwarns);
4526
 
+    check_errors(errwarns, object, linemap);
4527
 
+
4528
 
+    /* generate any debugging information */
4529
 
+    yasm_dbgfmt_generate(object, linemap, errwarns);
4530
 
+    check_errors(errwarns, object, linemap);
4531
 
+
4532
 
+    /* open the object file for output (if not already opened by dbg objfmt) */
4533
 
+    if (!obj && strcmp(cur_objfmt_module->keyword, "dbg") != 0) {
4534
 
+        obj = open_file(obj_filename, "wb");
4535
 
+        if (!obj) {
4536
 
+            cleanup(object);
4537
 
+            return EXIT_FAILURE;
4538
 
+        }
4539
 
+    }
4540
 
+
4541
 
+    /* Write the object file */
4542
 
+    yasm_objfmt_output(object, obj?obj:stderr,
4543
 
+                       strcmp(cur_dbgfmt_module->keyword, "null"), errwarns);
4544
 
+
4545
 
+    /* Close object file */
4546
 
+    if (obj)
4547
 
+        fclose(obj);
4548
 
+
4549
 
+    /* If we had an error at this point, we also need to delete the output
4550
 
+     * object file (to make sure it's not left newer than the source).
4551
 
+     */
4552
 
+    if (yasm_errwarns_num_errors(errwarns, warning_error) > 0)
4553
 
+        remove(obj_filename);
4554
 
+    check_errors(errwarns, object, linemap);
4555
 
+
4556
 
+    /* Open and write the list file */
4557
 
+    if (list_filename) {
4558
 
+        FILE *list = open_file(list_filename, "wt");
4559
 
+        if (!list) {
4560
 
+            cleanup(object);
4561
 
+            return EXIT_FAILURE;
4562
 
+        }
4563
 
+        /* Initialize the list format */
4564
 
+        cur_listfmt = yasm_listfmt_create(cur_listfmt_module, in_filename,
4565
 
+                                          obj_filename);
4566
 
+        yasm_listfmt_output(cur_listfmt, list, linemap, cur_arch);
4567
 
+        fclose(list);
4568
 
+    }
4569
 
+
4570
 
+    yasm_errwarns_output_all(errwarns, linemap, warning_error,
4571
 
+                             print_yasm_error, print_yasm_warning);
4572
 
+
4573
 
+    yasm_linemap_destroy(linemap);
4574
 
+    yasm_errwarns_destroy(errwarns);
4575
 
+    cleanup(object);
4576
 
+    return EXIT_SUCCESS;
4577
 
+}
4578
 
+
4579
 
+/* main function */
4580
 
+/*@-globstate -unrecog@*/
4581
 
+int
4582
 
+main(int argc, char *argv[])
4583
 
+{
4584
 
+    size_t i;
4585
 
+
4586
 
+    errfile = stderr;
4587
 
+
4588
 
+#if defined(HAVE_SETLOCALE) && defined(HAVE_LC_MESSAGES)
4589
 
+    setlocale(LC_MESSAGES, "");
4590
 
+#endif
4591
 
+#if defined(LOCALEDIR)
4592
 
+    bindtextdomain(PACKAGE, LOCALEDIR);
4593
 
+#endif
4594
 
+    textdomain(PACKAGE);
4595
 
+
4596
 
+    /* Initialize errwarn handling */
4597
 
+    yasm_internal_error_ = handle_yasm_int_error;
4598
 
+    yasm_fatal = handle_yasm_fatal;
4599
 
+    yasm_gettext_hook = handle_yasm_gettext;
4600
 
+    yasm_errwarn_initialize();
4601
 
+
4602
 
+    /* Initialize BitVector (needed for intnum/floatnum). */
4603
 
+    if (BitVector_Boot() != ErrCode_Ok) {
4604
 
+        print_error(_("%s: could not initialize BitVector"), _("FATAL"));
4605
 
+        return EXIT_FAILURE;
4606
 
+    }
4607
 
+
4608
 
+    /* Initialize intnum and floatnum */
4609
 
+    yasm_intnum_initialize();
4610
 
+    yasm_floatnum_initialize();
4611
 
+
4612
 
+#ifdef CMAKE_BUILD
4613
 
+    /* Load standard modules */
4614
 
+    if (!load_plugin("yasmstd")) {
4615
 
+        print_error(_("%s: could not load standard modules"), _("FATAL"));
4616
 
+        return EXIT_FAILURE;
4617
 
+    }
4618
 
+#endif
4619
 
+
4620
 
+    /* Initialize parameter storage */
4621
 
+    STAILQ_INIT(&preproc_options);
4622
 
+
4623
 
+    if (parse_cmdline(argc, argv, options, NELEMS(options), print_error))
4624
 
+        return EXIT_FAILURE;
4625
 
+
4626
 
+    switch (special_options) {
4627
 
+        case SPECIAL_SHOW_HELP:
4628
 
+            /* Does gettext calls internally */
4629
 
+            help_msg(help_head, help_tail, options, NELEMS(options));
4630
 
+            return EXIT_SUCCESS;
4631
 
+        case SPECIAL_SHOW_VERSION:
4632
 
+            for (i=0; i<NELEMS(version_msg); i++)
4633
 
+                printf("%s\n", version_msg[i]);
4634
 
+            return EXIT_SUCCESS;
4635
 
+        case SPECIAL_SHOW_LICENSE:
4636
 
+            for (i=0; i<NELEMS(license_msg); i++)
4637
 
+                printf("%s\n", license_msg[i]);
4638
 
+            return EXIT_SUCCESS;
4639
 
+    }
4640
 
+
4641
 
+    /* Open error file if specified. */
4642
 
+    if (error_filename) {
4643
 
+        errfile = open_file(error_filename, "wt");
4644
 
+        if (!errfile)
4645
 
+            return EXIT_FAILURE;
4646
 
+    }
4647
 
+
4648
 
+    /* If not already specified, default to bin as the object format. */
4649
 
+    if (!cur_objfmt_module) {
4650
 
+        if (!objfmt_keyword)
4651
 
+            objfmt_keyword = yasm__xstrdup(DEFAULT_OBJFMT_MODULE);
4652
 
+        cur_objfmt_module = yasm_load_objfmt(objfmt_keyword);
4653
 
+        if (!cur_objfmt_module) {
4654
 
+            print_error(_("%s: could not load default %s"), _("FATAL"),
4655
 
+                        _("object format"));
4656
 
+            return EXIT_FAILURE;
4657
 
+        }
4658
 
+    }
4659
 
+
4660
 
+    /* TASM's architecture is x86 */
4661
 
+    cur_arch_module = yasm_load_arch("x86");
4662
 
+    if (!cur_arch_module) {
4663
 
+        print_error(_("%s: could not load %s"), _("FATAL"),
4664
 
+                    _("architecture"));
4665
 
+        return EXIT_FAILURE;
4666
 
+    }
4667
 
+    machine_name =
4668
 
+        yasm__xstrdup(cur_arch_module->default_machine_keyword);
4669
 
+
4670
 
+    /* Check for arch help */
4671
 
+    if (machine_name && strcmp(machine_name, "help") == 0) {
4672
 
+        const yasm_arch_machine *m = cur_arch_module->machines;
4673
 
+        printf(_("Available %s for %s `%s':\n"), _("machines"),
4674
 
+               _("architecture"), cur_arch_module->keyword);
4675
 
+        while (m->keyword && m->name) {
4676
 
+            print_list_keyword_desc(m->name, m->keyword);
4677
 
+            m++;
4678
 
+        }
4679
 
+        return EXIT_SUCCESS;
4680
 
+    }
4681
 
+
4682
 
+    cur_parser_module = yasm_load_parser("tasm");
4683
 
+    if (!cur_parser_module) {
4684
 
+        print_error(_("%s: could not load %s"), _("FATAL"),
4685
 
+                    _("parser"));
4686
 
+        cleanup(NULL);
4687
 
+        return EXIT_FAILURE;
4688
 
+    }
4689
 
+
4690
 
+    /* If not already specified, default to the parser's default preproc. */
4691
 
+    if (!cur_preproc_module) {
4692
 
+        cur_preproc_module =
4693
 
+            yasm_load_preproc(cur_parser_module->default_preproc_keyword);
4694
 
+        if (!cur_preproc_module) {
4695
 
+            print_error(_("%s: could not load default %s"), _("FATAL"),
4696
 
+                        _("preprocessor"));
4697
 
+            cleanup(NULL);
4698
 
+            return EXIT_FAILURE;
4699
 
+        }
4700
 
+    }
4701
 
+
4702
 
+    /* Determine input filename and open input file. */
4703
 
+    if (!in_filename) {
4704
 
+        print_error(_("No input files specified"));
4705
 
+        return EXIT_FAILURE;
4706
 
+    }
4707
 
+
4708
 
+    /* If list file enabled, make sure we have a list format loaded. */
4709
 
+    if (list_filename) {
4710
 
+        /* use nasm as the list format. */
4711
 
+        cur_listfmt_module = yasm_load_listfmt("nasm");
4712
 
+    }
4713
 
+
4714
 
+    /* If not already specified, default to null as the debug format. */
4715
 
+    if (!cur_dbgfmt_module) {
4716
 
+        cur_dbgfmt_module = yasm_load_dbgfmt("null");
4717
 
+        if (!cur_dbgfmt_module) {
4718
 
+            print_error(_("%s: could not load default %s"), _("FATAL"),
4719
 
+                        _("debug format"));
4720
 
+            return EXIT_FAILURE;
4721
 
+        }
4722
 
+    }
4723
 
+
4724
 
+    return do_assemble();
4725
 
+}
4726
 
+/*@=globstate =unrecog@*/
4727
 
+
4728
 
+/* Open the object file.  Returns 0 on failure. */
4729
 
+static FILE *
4730
 
+open_file(const char *filename, const char *mode)
4731
 
+{
4732
 
+    FILE *f;
4733
 
+
4734
 
+    f = fopen(filename, mode);
4735
 
+    if (!f)
4736
 
+        print_error(_("could not open file `%s'"), filename);
4737
 
+    return f;
4738
 
+}
4739
 
+
4740
 
+static void
4741
 
+check_errors(yasm_errwarns *errwarns, yasm_object *object,
4742
 
+             yasm_linemap *linemap)
4743
 
+{
4744
 
+    if (yasm_errwarns_num_errors(errwarns, warning_error) > 0) {
4745
 
+        yasm_errwarns_output_all(errwarns, linemap, warning_error,
4746
 
+                                 print_yasm_error, print_yasm_warning);
4747
 
+        yasm_linemap_destroy(linemap);
4748
 
+        yasm_errwarns_destroy(errwarns);
4749
 
+        cleanup(object);
4750
 
+        exit(EXIT_FAILURE);
4751
 
+    }
4752
 
+}
4753
 
+
4754
 
+/* Define DO_FREE to 1 to enable deallocation of all data structures.
4755
 
+ * Useful for detecting memory leaks, but slows down execution unnecessarily
4756
 
+ * (as the OS will free everything we miss here).
4757
 
+ */
4758
 
+#define DO_FREE 1
4759
 
+
4760
 
+/* Cleans up all allocated structures. */
4761
 
+static void
4762
 
+cleanup(yasm_object *object)
4763
 
+{
4764
 
+    if (DO_FREE) {
4765
 
+        if (cur_listfmt)
4766
 
+            yasm_listfmt_destroy(cur_listfmt);
4767
 
+        if (cur_preproc)
4768
 
+            yasm_preproc_destroy(cur_preproc);
4769
 
+        if (object)
4770
 
+            yasm_object_destroy(object);
4771
 
+
4772
 
+        yasm_floatnum_cleanup();
4773
 
+        yasm_intnum_cleanup();
4774
 
+
4775
 
+        yasm_errwarn_cleanup();
4776
 
+
4777
 
+        BitVector_Shutdown();
4778
 
+    }
4779
 
+
4780
 
+    if (DO_FREE) {
4781
 
+        if (in_filename)
4782
 
+            yasm_xfree(in_filename);
4783
 
+        if (obj_filename)
4784
 
+            yasm_xfree(obj_filename);
4785
 
+        if (list_filename)
4786
 
+            yasm_xfree(list_filename);
4787
 
+        if (xref_filename)
4788
 
+            yasm_xfree(xref_filename);
4789
 
+        if (machine_name)
4790
 
+            yasm_xfree(machine_name);
4791
 
+        if (objfmt_keyword)
4792
 
+            yasm_xfree(objfmt_keyword);
4793
 
+    }
4794
 
+
4795
 
+    if (errfile != stderr && errfile != stdout)
4796
 
+        fclose(errfile);
4797
 
+#ifdef CMAKE_BUILD
4798
 
+    unload_plugins();
4799
 
+#endif
4800
 
+}
4801
 
+
4802
 
+/*
4803
 
+ *  Command line options handlers
4804
 
+ */
4805
 
+static char ** const filenames[] = {
4806
 
+    &in_filename, &obj_filename, &list_filename, &xref_filename, NULL
4807
 
+}, ** const * cur_filename = &filenames[0];
4808
 
+
4809
 
+static int filename_handler(char *param) {
4810
 
+    if (!*cur_filename) {
4811
 
+        print_error(_("error: too many files on command line."));
4812
 
+        return 1;
4813
 
+    }
4814
 
+
4815
 
+    if (*param)
4816
 
+            **cur_filename = yasm__xstrdup(param);
4817
 
+
4818
 
+    return 0;
4819
 
+}
4820
 
+int
4821
 
+not_an_option_handler(char *param) {
4822
 
+    char *c, *d = param;
4823
 
+
4824
 
+    while ((c = strchr(d, ','))) {
4825
 
+        *c = '\0';
4826
 
+        if (filename_handler(d))
4827
 
+            return 1;
4828
 
+        d = c + 1;
4829
 
+        cur_filename++;
4830
 
+    }
4831
 
+    filename_handler(d);
4832
 
+    return 0;
4833
 
+}
4834
 
+
4835
 
+static int
4836
 
+opt_special_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4837
 
+{
4838
 
+    if (special_options == 0)
4839
 
+        special_options = extra;
4840
 
+    return 0;
4841
 
+}
4842
 
+
4843
 
+static int
4844
 
+opt_segment_ordering_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4845
 
+{
4846
 
+    segment_ordering = extra;
4847
 
+    return 0;
4848
 
+}
4849
 
+
4850
 
+static int
4851
 
+opt_cross_reference_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4852
 
+{
4853
 
+    cross_reference = 1;
4854
 
+    return 0;
4855
 
+}
4856
 
+
4857
 
+static int
4858
 
+opt_floating_point_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4859
 
+{
4860
 
+    floating_point = extra;
4861
 
+    return 0;
4862
 
+}
4863
 
+
4864
 
+static int
4865
 
+opt_ignore(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4866
 
+{
4867
 
+    return 0;
4868
 
+}
4869
 
+
4870
 
+static int
4871
 
+opt_listing_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4872
 
+{
4873
 
+    if (param && param[0]) {
4874
 
+        if (param[0] != 'a')
4875
 
+            return 1;
4876
 
+        expanded_listing = 1;
4877
 
+    }
4878
 
+    listing = 1;
4879
 
+    return 0;
4880
 
+}
4881
 
+
4882
 
+static int
4883
 
+opt_case_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4884
 
+{
4885
 
+    case_sensitivity = extra;
4886
 
+    return 0;
4887
 
+}
4888
 
+
4889
 
+static int
4890
 
+opt_valid_length_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param, int extra)
4891
 
+{
4892
 
+    valid_length = atoi(param);
4893
 
+    return 0;
4894
 
+}
4895
 
+
4896
 
+static int
4897
 
+opt_warning_handler(char *cmd, /*@unused@*/ char *param, int extra)
4898
 
+{
4899
 
+    /* is it disabling the warning instead of enabling? */
4900
 
+    void (*action)(yasm_warn_class wclass) = NULL;
4901
 
+
4902
 
+    if (cmd[0] == '0') {
4903
 
+        /* /w0, disable warnings */
4904
 
+        yasm_warn_disable_all();
4905
 
+        return 0;
4906
 
+    }
4907
 
+
4908
 
+    if (cmd[0] == '1' || cmd[0] == '2') {
4909
 
+        /* /w[12], enable warnings */
4910
 
+        yasm_warn_enable(YASM_WARN_UNREC_CHAR);
4911
 
+        yasm_warn_enable(YASM_WARN_ORPHAN_LABEL);
4912
 
+        yasm_warn_enable(YASM_WARN_UNINIT_CONTENTS);
4913
 
+        return 0;
4914
 
+    }
4915
 
+
4916
 
+    /* detect no- prefix to disable the warning */
4917
 
+    if (cmd[0] == '-') {
4918
 
+        action = yasm_warn_disable;
4919
 
+    } else if (cmd[0] == '+') {
4920
 
+        action = yasm_warn_enable;
4921
 
+    } else return 1;
4922
 
+
4923
 
+    /* skip past '+/-' */
4924
 
+    cmd++;
4925
 
+
4926
 
+    if (cmd[0] == '\0')
4927
 
+        /* just /w- or /w+, so definitely not valid */
4928
 
+        return 1;
4929
 
+    else if (strcmp(cmd, "error") == 0)
4930
 
+        warning_error = (action == yasm_warn_enable);
4931
 
+    else if (strcmp(cmd, "unrecognized-char") == 0)
4932
 
+        action(YASM_WARN_UNREC_CHAR);
4933
 
+    else if (strcmp(cmd, "orphan-labels") == 0)
4934
 
+        action(YASM_WARN_ORPHAN_LABEL);
4935
 
+    else if (strcmp(cmd, "uninit-contents") == 0)
4936
 
+        action(YASM_WARN_UNINIT_CONTENTS);
4937
 
+    else if (strcmp(cmd, "size-override") == 0)
4938
 
+        action(YASM_WARN_SIZE_OVERRIDE);
4939
 
+    else
4940
 
+        return 1;
4941
 
+
4942
 
+    return 0;
4943
 
+}
4944
 
+
4945
 
+static int
4946
 
+opt_preproc_option(/*@unused@*/ char *cmd, char *param, int extra)
4947
 
+{
4948
 
+    constcharparam *cp;
4949
 
+    cp = yasm_xmalloc(sizeof(constcharparam));
4950
 
+    cp->param = param;
4951
 
+    cp->id = extra;
4952
 
+    STAILQ_INSERT_TAIL(&preproc_options, cp, link);
4953
 
+    return 0;
4954
 
+}
4955
 
+
4956
 
+static int
4957
 
+opt_exe_handler(char *cmd, /*@unused@*/ char *param, int extra)
4958
 
+{
4959
 
+    objfmt_keyword = yasm__xstrdup("dosexe");
4960
 
+    return 0;
4961
 
+}
4962
 
+
4963
 
+static void
4964
 
+apply_preproc_builtins()
4965
 
+{
4966
 
+    char *predef;
4967
 
+
4968
 
+    if (!objfmt_keyword)
4969
 
+        objfmt_keyword = yasm__xstrdup(DEFAULT_OBJFMT_MODULE);
4970
 
+
4971
 
+    /* Define standard YASM assembly-time macro constants */
4972
 
+    predef = yasm_xmalloc(strlen("__YASM_OBJFMT__=")
4973
 
+                          + strlen(objfmt_keyword) + 1);
4974
 
+    strcpy(predef, "__YASM_OBJFMT__=");
4975
 
+    strcat(predef, objfmt_keyword);
4976
 
+    yasm_preproc_define_builtin(cur_preproc, predef);
4977
 
+    yasm_xfree(predef);
4978
 
+}
4979
 
+
4980
 
+static void
4981
 
+apply_preproc_standard_macros(const yasm_stdmac *stdmacs)
4982
 
+{
4983
 
+    int i, matched;
4984
 
+
4985
 
+    if (!stdmacs)
4986
 
+        return;
4987
 
+
4988
 
+    matched = -1;
4989
 
+    for (i=0; stdmacs[i].parser; i++)
4990
 
+        if (yasm__strcasecmp(stdmacs[i].parser,
4991
 
+                             cur_parser_module->keyword) == 0 &&
4992
 
+            yasm__strcasecmp(stdmacs[i].preproc,
4993
 
+                             cur_preproc_module->keyword) == 0)
4994
 
+            matched = i;
4995
 
+    if (matched >= 0 && stdmacs[matched].macros)
4996
 
+        yasm_preproc_add_standard(cur_preproc, stdmacs[matched].macros);
4997
 
+}
4998
 
+
4999
 
+static void
5000
 
+apply_preproc_saved_options()
5001
 
+{
5002
 
+    constcharparam *cp, *cpnext;
5003
 
+
5004
 
+    void (*funcs[3])(yasm_preproc *, const char *);
5005
 
+    funcs[0] = cur_preproc_module->add_include_file;
5006
 
+    funcs[1] = cur_preproc_module->predefine_macro;
5007
 
+    funcs[2] = cur_preproc_module->undefine_macro;
5008
 
+
5009
 
+    STAILQ_FOREACH(cp, &preproc_options, link) {
5010
 
+        if (0 <= cp->id && cp->id < 3 && funcs[cp->id])
5011
 
+            funcs[cp->id](cur_preproc, cp->param);
5012
 
+    }
5013
 
+
5014
 
+    cp = STAILQ_FIRST(&preproc_options);
5015
 
+    while (cp != NULL) {
5016
 
+        cpnext = STAILQ_NEXT(cp, link);
5017
 
+        yasm_xfree(cp);
5018
 
+        cp = cpnext;
5019
 
+    }
5020
 
+    STAILQ_INIT(&preproc_options);
5021
 
+}
5022
 
+
5023
 
+/* Replace extension on a filename (or append one if none is present).
5024
 
+ * If output filename would be identical to input (same extension out as in),
5025
 
+ * returns (copy of) def.
5026
 
+ * A NULL ext means the trailing '.' should NOT be included, whereas a "" ext
5027
 
+ * means the trailing '.' should be included.
5028
 
+ */
5029
 
+static char *
5030
 
+replace_extension(const char *orig, /*@null@*/ const char *ext,
5031
 
+                  const char *def)
5032
 
+{
5033
 
+    char *out, *outext;
5034
 
+    size_t deflen, outlen;
5035
 
+
5036
 
+    /* allocate enough space for full existing name + extension */
5037
 
+    outlen = strlen(orig) + 2;
5038
 
+    if (ext)
5039
 
+        outlen += strlen(ext) + 1;
5040
 
+    deflen = strlen(def) + 1;
5041
 
+    if (outlen < deflen)
5042
 
+        outlen = deflen;
5043
 
+    out = yasm_xmalloc(outlen);
5044
 
+
5045
 
+    strcpy(out, orig);
5046
 
+    outext = strrchr(out, '.');
5047
 
+    if (outext) {
5048
 
+        /* Existing extension: make sure it's not the same as the replacement
5049
 
+         * (as we don't want to overwrite the source file).
5050
 
+         */
5051
 
+        outext++;   /* advance past '.' */
5052
 
+        if (ext && strcmp(outext, ext) == 0) {
5053
 
+            outext = NULL;  /* indicate default should be used */
5054
 
+            print_error(
5055
 
+                _("file name already ends in `.%s': output will be in `%s'"),
5056
 
+                ext, def);
5057
 
+        }
5058
 
+    } else {
5059
 
+        /* No extension: make sure the output extension is not empty
5060
 
+         * (again, we don't want to overwrite the source file).
5061
 
+         */
5062
 
+        if (!ext)
5063
 
+            print_error(
5064
 
+                _("file name already has no extension: output will be in `%s'"),
5065
 
+                def);
5066
 
+        else {
5067
 
+            outext = strrchr(out, '\0');    /* point to end of the string */
5068
 
+            *outext++ = '.';                    /* append '.' */
5069
 
+        }
5070
 
+    }
5071
 
+
5072
 
+    /* replace extension or use default name */
5073
 
+    if (outext) {
5074
 
+        if (!ext) {
5075
 
+            /* Back up and replace '.' with string terminator */
5076
 
+            outext--;
5077
 
+            *outext = '\0';
5078
 
+        } else
5079
 
+            strcpy(outext, ext);
5080
 
+    } else
5081
 
+        strcpy(out, def);
5082
 
+
5083
 
+    return out;
5084
 
+}
5085
 
+
5086
 
+void
5087
 
+print_list_keyword_desc(const char *name, const char *keyword)
5088
 
+{
5089
 
+    printf("%4s%-12s%s\n", "", keyword, name);
5090
 
+}
5091
 
+
5092
 
+static void
5093
 
+print_error(const char *fmt, ...)
5094
 
+{
5095
 
+    va_list va;
5096
 
+    fprintf(errfile, "tasm: ");
5097
 
+    va_start(va, fmt);
5098
 
+    vfprintf(errfile, fmt, va);
5099
 
+    va_end(va);
5100
 
+    fputc('\n', errfile);
5101
 
+}
5102
 
+
5103
 
+static /*@exits@*/ void
5104
 
+handle_yasm_int_error(const char *file, unsigned int line, const char *message)
5105
 
+{
5106
 
+    fprintf(stderr, _("INTERNAL ERROR at %s, line %u: %s\n"), file, line,
5107
 
+            gettext(message));
5108
 
+#ifdef HAVE_ABORT
5109
 
+    abort();
5110
 
+#else
5111
 
+    exit(EXIT_FAILURE);
5112
 
+#endif
5113
 
+}
5114
 
+
5115
 
+static /*@exits@*/ void
5116
 
+handle_yasm_fatal(const char *fmt, va_list va)
5117
 
+{
5118
 
+    fprintf(errfile, "**%s**: ", _("Fatal"));
5119
 
+    vfprintf(errfile, gettext(fmt), va);
5120
 
+    fputc('\n', errfile);
5121
 
+    exit(EXIT_FAILURE);
5122
 
+}
5123
 
+
5124
 
+static const char *
5125
 
+handle_yasm_gettext(const char *msgid)
5126
 
+{
5127
 
+    return gettext(msgid);
5128
 
+}
5129
 
+
5130
 
+static void
5131
 
+print_yasm_error(const char *filename, unsigned long line, const char *msg,
5132
 
+                 const char *xref_fn, unsigned long xref_line,
5133
 
+                 const char *xref_msg)
5134
 
+{
5135
 
+    if (line)
5136
 
+        fprintf(errfile, "**%s** %s(%lu) %s\n", _("Error"), filename, line, msg);
5137
 
+    else
5138
 
+        fprintf(errfile, "**%s** %s %s\n", _("Error"), filename, msg);
5139
 
+
5140
 
+    if (/* xref_fn && */ xref_msg) {
5141
 
+        if (xref_line)
5142
 
+            fprintf(errfile, "**%s** %s(%lu) %s\n", _("Error"), filename, xref_line, xref_msg);
5143
 
+        else
5144
 
+            fprintf(errfile, "**%s** %s %s\n", _("Error"), filename, xref_msg);
5145
 
+    }
5146
 
+}
5147
 
+
5148
 
+static void
5149
 
+print_yasm_warning(const char *filename, unsigned long line, const char *msg)
5150
 
+{
5151
 
+    if (line)
5152
 
+        fprintf(errfile, "*%s* %s(%lu) %s\n", _("Warning"), filename, line, msg);
5153
 
+    else
5154
 
+        fprintf(errfile, "*%s* %s %s\n", _("Warning"), filename, msg);
5155
 
+}
5156
 
Index: frontends/tasm/tasm-options.c
5157
 
===================================================================
5158
 
--- old/frontends/tasm/tasm-options.c   (r�vision 0)
5159
 
+++ new/frontends/tasm/tasm-options.c   (r�vision 2137)
5160
 
@@ -0,0 +1,129 @@
5161
 
+/*
5162
 
+ * Generic Options Support Header File
5163
 
+ *
5164
 
+ * Copyright (c) 2001  Stanislav Karchebny <berk@madfire.net>
5165
 
+ *
5166
 
+ * Redistribution and use in source and binary forms, with or without
5167
 
+ * modification, are permitted provided that the following conditions
5168
 
+ * are met:
5169
 
+ * 1. Redistributions of source code must retain the above copyright
5170
 
+ *    notice, this list of conditions and the following disclaimer.
5171
 
+ * 2. Redistributions in binary form must reproduce the above copyright
5172
 
+ *    notice, this list of conditions and the following disclaimer in the
5173
 
+ *    documentation and/or other materials provided with the distribution.
5174
 
+ * 3. Neither the name of the author nor the names of other contributors
5175
 
+ *    may be used to endorse or promote products derived from this
5176
 
+ *    software without specific prior written permission.
5177
 
+ *
5178
 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
5179
 
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5180
 
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5181
 
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
5182
 
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5183
 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5184
 
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5185
 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
5186
 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
5187
 
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
5188
 
+ * POSSIBILITY OF SUCH DAMAGE.
5189
 
+ */
5190
 
+#include <util.h>
5191
 
+#include <ctype.h>
5192
 
+/*@unused@*/ RCSID("$Id: tasm-options.c 1197 2005-01-24 06:44:25Z peter $");
5193
 
+
5194
 
+#include "tasm-options.h"
5195
 
+
5196
 
+
5197
 
+#ifdef __DEBUG__
5198
 
+#define DEBUG(x) fprintf ## x ;
5199
 
+#else
5200
 
+#define DEBUG(x)
5201
 
+#endif
5202
 
+
5203
 
+
5204
 
+/* Options Parser */
5205
 
+int
5206
 
+parse_cmdline(int argc, char **argv, opt_option *options, size_t nopts,
5207
 
+              void (*print_error) (const char *fmt, ...))
5208
 
+{
5209
 
+    int errors = 0, warnings = 0;
5210
 
+    size_t i;
5211
 
+    int got_it;
5212
 
+
5213
 
+    DEBUG((stderr, "parse_cmdline: entered\n"));
5214
 
+
5215
 
+  fail:
5216
 
+    while (--argc) {
5217
 
+        argv++;
5218
 
+
5219
 
+        if (argv[0][0] == '/' && argv[0][1]) {        /* opt */
5220
 
+            got_it = 0;
5221
 
+            for (i = 0; i < nopts; i++) {
5222
 
+                    char *cmd = &argv[0][1];
5223
 
+                size_t len = strlen(options[i].opt);
5224
 
+                if (yasm__strncasecmp(cmd, options[i].opt, len) == 0) {
5225
 
+                    char *param;
5226
 
+
5227
 
+                    param = &argv[0][1+len];
5228
 
+                    if (options[i].takes_param) {
5229
 
+                        if (param[0] == '\0') {
5230
 
+                            print_error(
5231
 
+                                _("option `-%c' needs an argument!"),
5232
 
+                                options[i].opt);
5233
 
+                            errors++;
5234
 
+                            goto fail;
5235
 
+                        } else {
5236
 
+                            argc--;
5237
 
+                            argv++;
5238
 
+                        }
5239
 
+                    } else
5240
 
+                        param = NULL;
5241
 
+
5242
 
+                    if (!options[i].handler(cmd, param, options[i].extra))
5243
 
+                        got_it = 1;
5244
 
+                    break;
5245
 
+                }
5246
 
+            }
5247
 
+            if (!got_it) {
5248
 
+                print_error(_("warning: unrecognized option `%s'"),
5249
 
+                            argv[0]);
5250
 
+                warnings++;
5251
 
+            }
5252
 
+        } else {    /* not an option, then it should be a file or something */
5253
 
+
5254
 
+            if (not_an_option_handler(argv[0]))
5255
 
+                errors++;
5256
 
+        }
5257
 
+    }
5258
 
+
5259
 
+    DEBUG((stderr, "parse_cmdline: finished\n"));
5260
 
+    return errors;
5261
 
+}
5262
 
+
5263
 
+void
5264
 
+help_msg(const char *msg, const char *tail, opt_option *options, size_t nopts)
5265
 
+{
5266
 
+    char optbuf[100], optopt[100];
5267
 
+    size_t i;
5268
 
+
5269
 
+    printf("%s", gettext(msg));
5270
 
+
5271
 
+    for (i = 0; i < nopts; i++) {
5272
 
+        optbuf[0] = 0;
5273
 
+        optopt[0] = 0;
5274
 
+
5275
 
+        if (options[i].takes_param) {
5276
 
+            if (options[i].opt)
5277
 
+                sprintf(optbuf, "/%s <%s>", options[i].opt,
5278
 
+                        options[i].param_desc ? options[i].
5279
 
+                        param_desc : _("param"));
5280
 
+        } else {
5281
 
+            if (options[i].opt)
5282
 
+                sprintf(optbuf, "/%s", options[i].opt);
5283
 
+        }
5284
 
+
5285
 
+        printf("    %-22s  %s\n", optbuf, gettext(options[i].description));
5286
 
+    }
5287
 
+
5288
 
+    printf("%s", gettext(tail));
5289
 
+}
5290
 
--- old/modules/preprocs/nasm/standard.mac      2008-04-16 05:29:59.000000000 +0200
5291
 
+++ new/modules/preprocs/nasm/standard.mac      2008-10-06 19:21:36.000000000 +0200
5292
 
@@ -5,10 +5,53 @@
5293
 
 
5294
 
     %idefine IDEAL
5295
 
     %idefine JUMPS
5296
 
-    %idefine P386
5297
 
-    %idefine P486
5298
 
-    %idefine P586
5299
 
     %idefine END
5300
 
+    %idefine P8086     CPU 8086
5301
 
+    %idefine P186      CPU 186
5302
 
+    %idefine P286      CPU 286
5303
 
+    %idefine P286N     CPU 286
5304
 
+    %idefine P286P     CPU 286 Priv
5305
 
+    %idefine P386      CPU 386
5306
 
+    %idefine P386N     CPU 386
5307
 
+    %idefine P386P     CPU 386 Priv
5308
 
+    %idefine P486      CPU 486
5309
 
+    %idefine P586      CPU 586
5310
 
+    %idefine .8086     CPU 8086
5311
 
+    %idefine .186      CPU 186
5312
 
+    %idefine .286      CPU 286
5313
 
+    %idefine .286C     CPU 286
5314
 
+    %idefine .286P     CPU 286
5315
 
+    %idefine .386      CPU 386
5316
 
+    %idefine .386C     CPU 386
5317
 
+    %idefine .386P     CPU 386
5318
 
+    %idefine .486      CPU 486
5319
 
+    %idefine .486C     CPU 486
5320
 
+    %idefine .486P     CPU 486
5321
 
+    %idefine .586      CPU 586
5322
 
+    %idefine .586C     CPU 586
5323
 
+    %idefine .586P     CPU 586
5324
 
+    
5325
 
+    %imacro TITLE 1
5326
 
+    %endm
5327
 
+    %imacro NAME 1
5328
 
+    %endm
5329
 
+    
5330
 
+    %imacro EXTRN 1-*.nolist
5331
 
+    %rep %0
5332
 
+    [extern %1]
5333
 
+    %rotate 1
5334
 
+    %endrep
5335
 
+    %endmacro
5336
 
+    
5337
 
+    %imacro PUBLIC 1-*.nolist
5338
 
+    %rep %0
5339
 
+    [global %1]
5340
 
+    %rotate 1
5341
 
+    %endrep
5342
 
+    %endmacro
5343
 
+    
5344
 
+    ; this is not needed
5345
 
+    %idefine PTR
5346
 
 
5347
 
 ; This is a magic token which indicates the end of the TASM macros
5348
 
 *END*TASM*MACROS*