nasm-parser.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * NASM-compatible parser header file
  3. *
  4. * Copyright (C) 2002-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. #ifndef YASM_NASM_PARSER_H
  28. #define YASM_NASM_PARSER_H
  29. #include "nasm-parser-struct.h"
  30. #define YYCTYPE unsigned char
  31. #define MAX_SAVED_LINE_LEN 80
  32. enum tokentype {
  33. INTNUM = 258,
  34. FLTNUM,
  35. DIRECTIVE_NAME,
  36. FILENAME,
  37. STRING,
  38. SIZE_OVERRIDE,
  39. OFFSET,
  40. DECLARE_DATA,
  41. RESERVE_SPACE,
  42. LABEL,
  43. INCBIN,
  44. EQU,
  45. TIMES,
  46. DUP,
  47. SEG,
  48. WRT,
  49. ABS,
  50. REL,
  51. NOSPLIT,
  52. STRICT,
  53. INSN,
  54. PREFIX,
  55. REG,
  56. REGGROUP,
  57. SEGREG,
  58. TARGETMOD,
  59. LEFT_OP,
  60. RIGHT_OP,
  61. LOW,
  62. HIGH,
  63. SIGNDIV,
  64. SIGNMOD,
  65. START_SECTION_ID,
  66. ID,
  67. LOCAL_ID,
  68. SPECIAL_ID,
  69. NONLOCAL_ID,
  70. LINE,
  71. NONE /* special token for lookahead */
  72. };
  73. enum nasm_parser_state {
  74. INITIAL,
  75. DIRECTIVE,
  76. SECTION_DIRECTIVE,
  77. DIRECTIVE2,
  78. LINECHG,
  79. LINECHG2,
  80. INSTRUCTION
  81. };
  82. #define YYSTYPE nasm_yystype
  83. /* shorter access names to commonly used parser_nasm fields */
  84. #define p_object (parser_nasm->object)
  85. #define p_symtab (parser_nasm->object->symtab)
  86. #define cursect (parser_nasm->object->cur_section)
  87. #define curtok (parser_nasm->token)
  88. #define curval (parser_nasm->tokval)
  89. #define INTNUM_val (curval.intn)
  90. #define FLTNUM_val (curval.flt)
  91. #define DIRECTIVE_NAME_val (curval.str_val)
  92. #define FILENAME_val (curval.str_val)
  93. #define STRING_val (curval.str)
  94. #define SIZE_OVERRIDE_val (curval.int_info)
  95. #define DECLARE_DATA_val (curval.int_info)
  96. #define RESERVE_SPACE_val (curval.int_info)
  97. #define INSN_val (curval.bc)
  98. #define PREFIX_val (curval.arch_data)
  99. #define REG_val (curval.arch_data)
  100. #define REGGROUP_val (curval.arch_data)
  101. #define SEGREG_val (curval.arch_data)
  102. #define TARGETMOD_val (curval.arch_data)
  103. #define ID_val (curval.str_val)
  104. #define cur_line (yasm_linemap_get_current(parser_nasm->linemap))
  105. #define p_expr_new_tree(l,o,r) yasm_expr_create_tree(l,o,r,cur_line)
  106. #define p_expr_new_branch(o,r) yasm_expr_create_branch(o,r,cur_line)
  107. #define p_expr_new_ident(r) yasm_expr_create_ident(r,cur_line)
  108. void nasm_parser_parse(yasm_parser_nasm *parser_nasm);
  109. void nasm_parser_cleanup(yasm_parser_nasm *parser_nasm);
  110. int nasm_parser_lex(YYSTYPE *lvalp, yasm_parser_nasm *parser_nasm);
  111. #endif