Home | History | Annotate | Download | only in nasm
      1 /*
      2  * NASM-compatible parser
      3  *
      4  *  Copyright (C) 2001-2007  Peter Johnson
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
     16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
     19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  * POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 #include <util.h>
     28 
     29 #include <libyasm.h>
     30 
     31 #include "nasm-parser.h"
     32 
     33 
     34 static void
     35 nasm_do_parse(yasm_object *object, yasm_preproc *pp, int save_input,
     36               yasm_linemap *linemap, yasm_errwarns *errwarns, int tasm)
     37 {
     38     yasm_parser_nasm parser_nasm;
     39 
     40     parser_nasm.tasm = tasm;
     41     parser_nasm.masm = 0;
     42 
     43     parser_nasm.object = object;
     44     parser_nasm.linemap = linemap;
     45 
     46     parser_nasm.locallabel_base = (char *)NULL;
     47     parser_nasm.locallabel_base_len = 0;
     48 
     49     parser_nasm.preproc = pp;
     50     parser_nasm.errwarns = errwarns;
     51 
     52     parser_nasm.prev_bc = yasm_section_bcs_first(object->cur_section);
     53 
     54     parser_nasm.save_input = save_input;
     55 
     56     parser_nasm.peek_token = NONE;
     57 
     58     parser_nasm.absstart = NULL;
     59     parser_nasm.abspos = NULL;
     60 
     61     /* initialize scanner structure */
     62     yasm_scanner_initialize(&parser_nasm.s);
     63 
     64     parser_nasm.state = INITIAL;
     65 
     66     nasm_parser_parse(&parser_nasm);
     67 
     68     /*yasm_scanner_delete(&parser_nasm.s);*/
     69 
     70     /* Free locallabel base if necessary */
     71     if (parser_nasm.locallabel_base)
     72         yasm_xfree(parser_nasm.locallabel_base);
     73 
     74     /* Check for undefined symbols */
     75     yasm_symtab_parser_finalize(object->symtab, 0, errwarns);
     76 }
     77 
     78 static void
     79 nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
     80                      int save_input, yasm_linemap *linemap,
     81                      yasm_errwarns *errwarns)
     82 {
     83     nasm_do_parse(object, pp, save_input, linemap, errwarns, 0);
     84 }
     85 
     86 #include "nasm-macros.c"
     87 
     88 /* Define valid preprocessors to use with this parser */
     89 static const char *nasm_parser_preproc_keywords[] = {
     90     "raw",
     91     "nasm",
     92     NULL
     93 };
     94 
     95 static const yasm_stdmac nasm_parser_stdmacs[] = {
     96     { "nasm", "nasm", nasm_standard_mac },
     97     { NULL, NULL, NULL }
     98 };
     99 
    100 /* Define parser structure -- see parser.h for details */
    101 yasm_parser_module yasm_nasm_LTX_parser = {
    102     "NASM-compatible parser",
    103     "nasm",
    104     nasm_parser_preproc_keywords,
    105     "nasm",
    106     nasm_parser_stdmacs,
    107     nasm_parser_do_parse
    108 };
    109 
    110 static void
    111 tasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
    112                      int save_input, yasm_linemap *linemap,
    113                      yasm_errwarns *errwarns)
    114 {
    115     yasm_symtab_set_case_sensitive(object->symtab, 0);
    116     yasm_warn_disable(YASM_WARN_IMPLICIT_SIZE_OVERRIDE);
    117     nasm_do_parse(object, pp, save_input, linemap, errwarns, 1);
    118 }
    119 
    120 /* Define valid preprocessors to use with this parser */
    121 static const char *tasm_parser_preproc_keywords[] = {
    122     "raw",
    123     "tasm",
    124     NULL
    125 };
    126 
    127 static const yasm_stdmac tasm_parser_stdmacs[] = {
    128     { "tasm", "tasm", nasm_standard_mac },
    129     { NULL, NULL, NULL }
    130 };
    131 
    132 /* Define parser structure -- see parser.h for details */
    133 yasm_parser_module yasm_tasm_LTX_parser = {
    134     "TASM-compatible parser",
    135     "tasm",
    136     tasm_parser_preproc_keywords,
    137     "tasm",
    138     tasm_parser_stdmacs,
    139     tasm_parser_do_parse
    140 };
    141