nasm-parser.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #include <libyasm.h>
  29. #include "nasm-parser.h"
  30. static void
  31. nasm_do_parse(yasm_object *object, yasm_preproc *pp, int save_input,
  32. yasm_linemap *linemap, yasm_errwarns *errwarns, int tasm)
  33. {
  34. yasm_parser_nasm parser_nasm;
  35. parser_nasm.tasm = tasm;
  36. parser_nasm.masm = 0;
  37. parser_nasm.object = object;
  38. parser_nasm.linemap = linemap;
  39. parser_nasm.locallabel_base = (char *)NULL;
  40. parser_nasm.locallabel_base_len = 0;
  41. parser_nasm.preproc = pp;
  42. parser_nasm.errwarns = errwarns;
  43. parser_nasm.prev_bc = yasm_section_bcs_first(object->cur_section);
  44. parser_nasm.save_input = save_input;
  45. parser_nasm.peek_token = NONE;
  46. parser_nasm.absstart = NULL;
  47. parser_nasm.abspos = NULL;
  48. /* initialize scanner structure */
  49. yasm_scanner_initialize(&parser_nasm.s);
  50. parser_nasm.state = INITIAL;
  51. nasm_parser_parse(&parser_nasm);
  52. /*yasm_scanner_delete(&parser_nasm.s);*/
  53. /* Free locallabel base if necessary */
  54. if (parser_nasm.locallabel_base)
  55. yasm_xfree(parser_nasm.locallabel_base);
  56. /* Check for undefined symbols */
  57. yasm_symtab_parser_finalize(object->symtab, 0, errwarns);
  58. }
  59. static void
  60. nasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
  61. int save_input, yasm_linemap *linemap,
  62. yasm_errwarns *errwarns)
  63. {
  64. nasm_do_parse(object, pp, save_input, linemap, errwarns, 0);
  65. }
  66. #include "nasm-macros.c"
  67. /* Define valid preprocessors to use with this parser */
  68. static const char *nasm_parser_preproc_keywords[] = {
  69. "raw",
  70. "nasm",
  71. NULL
  72. };
  73. static const yasm_stdmac nasm_parser_stdmacs[] = {
  74. { "nasm", "nasm", nasm_standard_mac },
  75. { NULL, NULL, NULL }
  76. };
  77. /* Define parser structure -- see parser.h for details */
  78. yasm_parser_module yasm_nasm_LTX_parser = {
  79. "NASM-compatible parser",
  80. "nasm",
  81. nasm_parser_preproc_keywords,
  82. "nasm",
  83. nasm_parser_stdmacs,
  84. nasm_parser_do_parse
  85. };
  86. static void
  87. tasm_parser_do_parse(yasm_object *object, yasm_preproc *pp,
  88. int save_input, yasm_linemap *linemap,
  89. yasm_errwarns *errwarns)
  90. {
  91. yasm_symtab_set_case_sensitive(object->symtab, 0);
  92. yasm_warn_disable(YASM_WARN_IMPLICIT_SIZE_OVERRIDE);
  93. nasm_do_parse(object, pp, save_input, linemap, errwarns, 1);
  94. }
  95. /* Define valid preprocessors to use with this parser */
  96. static const char *tasm_parser_preproc_keywords[] = {
  97. "raw",
  98. "tasm",
  99. NULL
  100. };
  101. static const yasm_stdmac tasm_parser_stdmacs[] = {
  102. { "tasm", "tasm", nasm_standard_mac },
  103. { NULL, NULL, NULL }
  104. };
  105. /* Define parser structure -- see parser.h for details */
  106. yasm_parser_module yasm_tasm_LTX_parser = {
  107. "TASM-compatible parser",
  108. "tasm",
  109. tasm_parser_preproc_keywords,
  110. "tasm",
  111. tasm_parser_stdmacs,
  112. tasm_parser_do_parse
  113. };