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

« back to all changes in this revision

Viewing changes to modules/parsers/nasm/nasm-token.re

  • 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:
27
27
 * POSSIBILITY OF SUCH DAMAGE.
28
28
 */
29
29
#include <util.h>
30
 
RCSID("$Id: nasm-token.re 2065 2008-04-15 02:53:18Z peter $");
 
30
RCSID("$Id: nasm-token.re 2139 2008-10-08 05:19:47Z peter $");
31
31
 
32
32
#include <libyasm.h>
33
33
 
34
34
#include "modules/parsers/nasm/nasm-parser.h"
 
35
#include "modules/preprocs/nasm/nasm.h"
35
36
 
36
37
 
37
38
#define YYCURSOR        cursor
76
77
{
77
78
    /* check for special non-local labels like ..start */
78
79
    if (tok[zeropos+1] == '.') {
79
 
        lvalp->str_val = yasm__xstrndup(tok+zeropos, toklen-zeropos);
 
80
        lvalp->str_val = yasm__xstrndup(tok+zeropos+(parser_nasm->tasm?2:0),
 
81
            toklen-zeropos-(parser_nasm->tasm?2:0));
80
82
        /* check for special non-local ..@label */
81
83
        if (lvalp->str_val[zeropos+2] == '@')
82
84
            return NONLOCAL_ID;
83
85
        return SPECIAL_ID;
84
86
    }
85
 
 
 
87
    if (parser_nasm->tasm && (!tasm_locals || 
 
88
                (tok[zeropos] == '.' &&
 
89
                 tok[zeropos+1] != '@' && tok[zeropos+2] != '@'))) {
 
90
        /* no locals on Tasm without the 'locals' directive */
 
91
        /* .foo is never local either, but .@@foo may be (local structure
 
92
         * members) */
 
93
        lvalp->str_val = yasm__xstrndup(tok + zeropos, toklen - zeropos);
 
94
        return SPECIAL_ID;
 
95
    }
86
96
    if (!parser_nasm->locallabel_base) {
87
97
        lvalp->str_val = yasm__xstrndup(tok+zeropos, toklen-zeropos);
88
98
        yasm_warn_set(YASM_WARN_GENERAL,
139
149
 
140
150
scan:
141
151
    SCANINIT();
 
152
    if (*cursor == '\0')
 
153
        goto endofinput;
142
154
 
143
155
    /*!re2c
144
156
        /* standard decimal integer */
240
252
        }
241
253
 
242
254
        /* pseudo-instructions */
243
 
        'db'            { lvalp->int_info = 8; RETURN(DECLARE_DATA); }
 
255
        'db'            {
 
256
            lvalp->int_info = 8;
 
257
            parser_nasm->state = INSTRUCTION;
 
258
            RETURN(DECLARE_DATA);
 
259
        }
244
260
        'dhw'           {
245
261
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2;
 
262
            parser_nasm->state = INSTRUCTION;
246
263
            RETURN(DECLARE_DATA);
247
264
        }
248
265
        'dw'            {
249
266
            lvalp->int_info = yasm_arch_wordsize(p_object->arch);
 
267
            parser_nasm->state = INSTRUCTION;
250
268
            RETURN(DECLARE_DATA);
251
269
        }
252
270
        'dd'            {
253
271
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2;
 
272
            parser_nasm->state = INSTRUCTION;
254
273
            RETURN(DECLARE_DATA);
255
274
        }
256
275
        'dq'            {
257
276
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4;
258
 
            RETURN(DECLARE_DATA);
259
 
        }
260
 
        'dt'            { lvalp->int_info = 80; RETURN(DECLARE_DATA); }
 
277
            parser_nasm->state = INSTRUCTION;
 
278
            RETURN(DECLARE_DATA);
 
279
        }
 
280
        'dt'            {
 
281
            lvalp->int_info = 80;
 
282
            parser_nasm->state = INSTRUCTION;
 
283
            RETURN(DECLARE_DATA);
 
284
        }
261
285
        'ddq'           {
262
286
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
 
287
            parser_nasm->state = INSTRUCTION;
263
288
            RETURN(DECLARE_DATA);
264
289
        }
265
290
        'do'           {
266
291
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
 
292
            parser_nasm->state = INSTRUCTION;
267
293
            RETURN(DECLARE_DATA);
268
294
        }
269
295
        'dy'           {
270
296
            lvalp->int_info = 256;
 
297
            parser_nasm->state = INSTRUCTION;
271
298
            RETURN(DECLARE_DATA);
272
299
        }
273
300
 
274
 
        'resb'          { lvalp->int_info = 8; RETURN(RESERVE_SPACE); }
 
301
        'resb'          {
 
302
            lvalp->int_info = 8;
 
303
            parser_nasm->state = INSTRUCTION;
 
304
            RETURN(RESERVE_SPACE);
 
305
        }
275
306
        'reshw'         {
276
307
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)/2;
 
308
            parser_nasm->state = INSTRUCTION;
277
309
            RETURN(RESERVE_SPACE);
278
310
        }
279
311
        'resw'          {
280
312
            lvalp->int_info = yasm_arch_wordsize(p_object->arch);
 
313
            parser_nasm->state = INSTRUCTION;
281
314
            RETURN(RESERVE_SPACE);
282
315
        }
283
316
        'resd'          {
284
317
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2;
 
318
            parser_nasm->state = INSTRUCTION;
285
319
            RETURN(RESERVE_SPACE);
286
320
        }
287
321
        'resq'          {
288
322
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*4;
289
 
            RETURN(RESERVE_SPACE);
290
 
        }
291
 
        'rest'          { lvalp->int_info = 80; RETURN(RESERVE_SPACE); }
 
323
            parser_nasm->state = INSTRUCTION;
 
324
            RETURN(RESERVE_SPACE);
 
325
        }
 
326
        'rest'          {
 
327
            lvalp->int_info = 80;
 
328
            parser_nasm->state = INSTRUCTION;
 
329
            RETURN(RESERVE_SPACE);
 
330
        }
292
331
        'resdq'         {
293
332
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
 
333
            parser_nasm->state = INSTRUCTION;
294
334
            RETURN(RESERVE_SPACE);
295
335
        }
296
336
        'reso'         {
297
337
            lvalp->int_info = yasm_arch_wordsize(p_object->arch)*8;
 
338
            parser_nasm->state = INSTRUCTION;
298
339
            RETURN(RESERVE_SPACE);
299
340
        }
300
341
        'resy'         {
301
342
            lvalp->int_info = 256;
 
343
            parser_nasm->state = INSTRUCTION;
302
344
            RETURN(RESERVE_SPACE);
303
345
        }
304
346
 
323
365
        "//"                    { RETURN(SIGNDIV); }
324
366
        "%%"                    { RETURN(SIGNMOD); }
325
367
        "$$"                    { RETURN(START_SECTION_ID); }
326
 
        [-+|^*&/%~$():=,\[]     { RETURN(s->tok[0]); }
 
368
        [-+|^*&/%~$():=,\[?]    { RETURN(s->tok[0]); }
327
369
        "]"                     { RETURN(s->tok[0]); }
328
370
 
329
371
        /* local label (.label) */
330
 
        "." [a-zA-Z0-9_$#@~.?]+ {
 
372
        ("." | "@@") [a-zA-Z0-9_$#@~.?]+ {
331
373
            RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 0, parser_nasm));
332
374
        }
333
375
 
334
376
        /* forced identifier */
335
377
        "$" [a-zA-Z0-9_$#@~.?]+ {
336
 
            if (TOK[1] == '.') {
 
378
            if (TOK[1] == '.' ||
 
379
                    (parser_nasm->tasm && TOK[1] == '@' && TOK[2] == '@')) {
337
380
                /* handle like .label */
338
381
                RETURN(handle_dot_label(lvalp, TOK, TOKLEN, 1, parser_nasm));
339
382
            }
374
417
                    s->tok[TOKLEN] = savech;
375
418
                    RETURN(TARGETMOD);
376
419
                default:
377
 
                    s->tok[TOKLEN] = savech;
 
420
                    break;
 
421
            }
 
422
            if (parser_nasm->tasm) {
 
423
                if (!yasm__strcasecmp(TOK, "shl")) {
 
424
                    s->tok[TOKLEN] = savech;
 
425
                    RETURN(LEFT_OP);
 
426
                }
 
427
                if (!yasm__strcasecmp(TOK, "shr")) {
 
428
                    s->tok[TOKLEN] = savech;
 
429
                    RETURN(RIGHT_OP);
 
430
                }
 
431
                if (!yasm__strcasecmp(TOK, "and")) {
 
432
                    s->tok[TOKLEN] = savech;
 
433
                    RETURN('&');
 
434
                }
 
435
                if (!yasm__strcasecmp(TOK, "or")) {
 
436
                    s->tok[TOKLEN] = savech;
 
437
                    RETURN('|');
 
438
                }
 
439
                if (!yasm__strcasecmp(TOK, "low")) {
 
440
                    s->tok[TOKLEN] = savech;
 
441
                    RETURN(LOW);
 
442
                }
 
443
                if (!yasm__strcasecmp(TOK, "high")) {
 
444
                    s->tok[TOKLEN] = savech;
 
445
                    RETURN(HIGH);
 
446
                }
 
447
                if (!yasm__strcasecmp(TOK, "offset")) {
 
448
                    s->tok[TOKLEN] = savech;
 
449
                    RETURN(OFFSET);
 
450
                }
 
451
                if (!yasm__strcasecmp(TOK, "fword")) {
 
452
                    s->tok[TOKLEN] = savech;
 
453
                    lvalp->int_info = yasm_arch_wordsize(p_object->arch)*2;
 
454
                    RETURN(SIZE_OVERRIDE);
 
455
                }
 
456
                if (!yasm__strcasecmp(TOK, "df")) {
 
457
                    s->tok[TOKLEN] = savech;
 
458
                    lvalp->int_info = yasm_arch_wordsize(p_object->arch)*3;
 
459
                    parser_nasm->state = INSTRUCTION;
 
460
                    RETURN(DECLARE_DATA);
 
461
                }
 
462
                if (!yasm__strcasecmp(TOK, "label")) {
 
463
                    s->tok[TOKLEN] = savech;
 
464
                    RETURN(LABEL);
 
465
                }
 
466
                if (!yasm__strcasecmp(TOK, "dup")) {
 
467
                    s->tok[TOKLEN] = savech;
 
468
                    RETURN(DUP);
 
469
                }
378
470
            }
379
471
            /* Propagate errors in case we got a warning from the arch */
380
472
            yasm_errwarn_propagate(parser_nasm->errwarns, cur_line);
381
473
            /* Just an identifier, return as such. */
 
474
            s->tok[TOKLEN] = savech;
382
475
            lvalp->str_val = yasm__xstrndup(TOK, TOKLEN);
383
476
            RETURN(ID);
384
477
        }
387
480
 
388
481
        ws+                     { goto scan; }
389
482
 
390
 
        [\000]                  {
391
 
            parser_nasm->state = INITIAL;
392
 
            RETURN(s->tok[0]);
393
 
        }
 
483
        [\000]                  { goto endofinput; }
394
484
 
395
485
        any {
396
486
            yasm_warn_set(YASM_WARN_UNREC_CHAR,
403
493
    /* %line linenum+lineinc filename */
404
494
linechg:
405
495
    SCANINIT();
 
496
    if (*cursor == '\0')
 
497
        goto endofinput;
406
498
 
407
499
    /*!re2c
408
500
        digit+ {
414
506
            RETURN(INTNUM);
415
507
        }
416
508
 
417
 
        [\000] {
418
 
            parser_nasm->state = INITIAL;
419
 
            RETURN(s->tok[0]);
420
 
        }
 
509
        [\000] { goto endofinput; }
421
510
 
422
511
        "+" {
423
512
            RETURN(s->tok[0]);
441
530
 
442
531
linechg2:
443
532
    SCANINIT();
 
533
    if (*cursor == '\0')
 
534
        goto endofinput;
444
535
 
445
536
    /*!re2c
446
 
        [\000] {
447
 
            parser_nasm->state = INITIAL;
448
 
            RETURN(s->tok[0]);
449
 
        }
 
537
        [\000] { goto endofinput; }
450
538
 
451
 
        "\r" { }
 
539
        "\r" { goto linechg2; }
452
540
 
453
541
        (any \ [\000])+ {
454
542
            parser_nasm->state = LINECHG;
460
548
    /* directive: [name value] */
461
549
directive:
462
550
    SCANINIT();
 
551
    if (*cursor == '\0')
 
552
        goto endofinput;
463
553
 
464
554
    /*!re2c
465
 
        [\]\000] {
466
 
            parser_nasm->state = INITIAL;
467
 
            RETURN(s->tok[0]);
468
 
        }
 
555
        [\]\000] { goto endofinput; }
469
556
 
470
557
        [a-zA-Z_][a-zA-Z_0-9]* {
471
558
            lvalp->str_val = yasm__xstrndup(TOK, TOKLEN);
488
575
    /* section directive (the section name portion thereof) */
489
576
section_directive:
490
577
    SCANINIT();
 
578
    if (*cursor == '\0')
 
579
        goto endofinput;
491
580
 
492
581
    /*!re2c
493
582
        [a-zA-Z0-9_$#@~.?-]+ {
508
597
            goto section_directive;
509
598
        }
510
599
 
511
 
        "]" {
512
 
            parser_nasm->state = INITIAL;
513
 
            RETURN(s->tok[0]);
514
 
        }
515
 
 
516
 
        [\000]          {
517
 
            parser_nasm->state = INITIAL;
518
 
            RETURN(s->tok[0]);
519
 
        }
 
600
        [\]\000]        { goto endofinput; }
520
601
 
521
602
        any {
522
603
            yasm_warn_set(YASM_WARN_UNREC_CHAR,
529
610
    /* inner part of directive */
530
611
directive2:
531
612
    SCANINIT();
 
613
    if (*cursor == '\0')
 
614
        goto endofinput;
532
615
 
533
616
    /*!re2c
534
617
        /* standard decimal integer */
589
672
        [-+|^*&/%~$():=,\[]     { RETURN(s->tok[0]); }
590
673
 
591
674
        /* handle ] for directives */
592
 
        "]" {
593
 
            parser_nasm->state = INITIAL;
594
 
            RETURN(s->tok[0]);
595
 
        }
 
675
        "]"                     { goto endofinput; }
596
676
 
597
677
        /* forced identifier; within directive, don't strip '$', this is
598
678
         * handled later.
625
705
 
626
706
        ws+                     { goto directive2; }
627
707
 
628
 
        [\000]                  {
629
 
            parser_nasm->state = INITIAL;
630
 
            RETURN(s->tok[0]);
631
 
        }
 
708
        [\000]                  { goto endofinput; }
632
709
 
633
710
        any {
634
711
            yasm_warn_set(YASM_WARN_UNREC_CHAR,
646
723
 
647
724
stringconst_scan:
648
725
    SCANINIT();
 
726
    if (*cursor == '\0')
 
727
        goto stringconst_error;
649
728
 
650
729
    /*!re2c
651
 
        [\000]  {
652
 
            yasm_error_set(YASM_ERROR_SYNTAX, N_("unterminated string"));
653
 
            strbuf[count] = '\0';
654
 
            lvalp->str.contents = (char *)strbuf;
655
 
            lvalp->str.len = count;
656
 
            RETURN(STRING);
 
730
        [\000]  { goto stringconst_error; }
 
731
 
 
732
        "''" | '""'     {
 
733
            if (endch != s->tok[0]) {
 
734
                strbuf[count++] = s->tok[0];
 
735
                if (count >= strbuf_size) {
 
736
                    strbuf = yasm_xrealloc(strbuf,
 
737
                                           strbuf_size + STRBUF_ALLOC_SIZE);
 
738
                    strbuf_size += STRBUF_ALLOC_SIZE;
 
739
                }
 
740
            } else if (!parser_nasm->tasm) {
 
741
                YYCURSOR--;
 
742
                goto stringconst_end;
 
743
            }
 
744
            strbuf[count++] = s->tok[0];
 
745
            if (count >= strbuf_size) {
 
746
                strbuf = yasm_xrealloc(strbuf, strbuf_size + STRBUF_ALLOC_SIZE);
 
747
                strbuf_size += STRBUF_ALLOC_SIZE;
 
748
            }
 
749
            goto stringconst_scan;
657
750
        }
658
751
 
659
752
        any     {
660
 
            if (s->tok[0] == endch) {
661
 
                strbuf[count] = '\0';
662
 
                lvalp->str.contents = (char *)strbuf;
663
 
                lvalp->str.len = count;
664
 
                RETURN(STRING);
665
 
            }
 
753
            if (s->tok[0] == endch)
 
754
                goto stringconst_end;
666
755
 
667
756
            strbuf[count++] = s->tok[0];
668
757
            if (count >= strbuf_size) {
673
762
            goto stringconst_scan;
674
763
        }
675
764
    */
 
765
 
 
766
stringconst_error:
 
767
    yasm_error_set(YASM_ERROR_SYNTAX, N_("unterminated string"));
 
768
 
 
769
stringconst_end:
 
770
    strbuf[count] = '\0';
 
771
    lvalp->str.contents = (char *)strbuf;
 
772
    lvalp->str.len = count;
 
773
    RETURN(STRING);
 
774
 
 
775
endofinput:
 
776
    parser_nasm->state = INITIAL;
 
777
    RETURN(s->tok[0]);
676
778
}