gas-parser.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * GAS-compatible parser header file
  3. *
  4. * Copyright (C) 2005-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. * 3. Neither the name of the author nor the names of other contributors
  15. * may be used to endorse or promote products derived from this
  16. * software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef YASM_GAS_PARSER_H
  31. #define YASM_GAS_PARSER_H
  32. #define YYCTYPE unsigned char
  33. #define MAX_SAVED_LINE_LEN 80
  34. enum tokentype {
  35. INTNUM = 258,
  36. FLTNUM,
  37. STRING,
  38. REG,
  39. REGGROUP,
  40. SEGREG,
  41. TARGETMOD,
  42. LEFT_OP,
  43. RIGHT_OP,
  44. ID,
  45. LABEL,
  46. CPP_LINE_MARKER,
  47. NASM_LINE_MARKER,
  48. NONE
  49. };
  50. typedef union {
  51. unsigned int int_info;
  52. yasm_intnum *intn;
  53. yasm_floatnum *flt;
  54. yasm_bytecode *bc;
  55. uintptr_t arch_data;
  56. struct {
  57. char *contents;
  58. size_t len;
  59. } str;
  60. } yystype;
  61. #define YYSTYPE yystype
  62. enum gas_parser_state {
  63. INITIAL,
  64. COMMENT,
  65. SECTION_DIRECTIVE,
  66. NASM_FILENAME
  67. };
  68. typedef struct yasm_parser_gas {
  69. /*@only@*/ yasm_object *object;
  70. /* last "base" label for local (.) labels */
  71. /*@null@*/ char *locallabel_base;
  72. size_t locallabel_base_len;
  73. /* .line/.file: we have to see both to start setting linemap versions */
  74. int dir_fileline;
  75. /*@null@*/ char *dir_file;
  76. unsigned long dir_line;
  77. /* Have we seen a line marker? */
  78. int seen_line_marker;
  79. /*@dependent@*/ yasm_preproc *preproc;
  80. /*@dependent@*/ yasm_errwarns *errwarns;
  81. /*@dependent@*/ yasm_linemap *linemap;
  82. /*@null@*/ yasm_bytecode *prev_bc;
  83. yasm_bytecode *temp_bc;
  84. int save_input;
  85. YYCTYPE save_line[2][MAX_SAVED_LINE_LEN];
  86. int save_last;
  87. /* Line data storage used in preproc_input(). */
  88. char *line, *linepos;
  89. size_t lineleft;
  90. yasm_scanner s;
  91. enum gas_parser_state state;
  92. int token; /* enum tokentype or any character */
  93. yystype tokval;
  94. char tokch; /* first character of token */
  95. /* one token of lookahead; used sparingly */
  96. int peek_token; /* NONE if none */
  97. yystype peek_tokval;
  98. char peek_tokch;
  99. /* Index of local labels; what's stored here is the /next/ index,
  100. * so these are all 0 at start.
  101. */
  102. unsigned long local[10];
  103. /* Parser-handled directives HAMT lookup */
  104. HAMT *dirs;
  105. int intel_syntax;
  106. int is_nasm_preproc;
  107. int is_cpp_preproc;
  108. } yasm_parser_gas;
  109. /* shorter access names to commonly used parser_gas fields */
  110. #define p_object (parser_gas->object)
  111. #define p_symtab (parser_gas->object->symtab)
  112. #define cursect (parser_gas->object->cur_section)
  113. #define curtok (parser_gas->token)
  114. #define curval (parser_gas->tokval)
  115. #define INTNUM_val (curval.intn)
  116. #define FLTNUM_val (curval.flt)
  117. #define STRING_val (curval.str)
  118. #define REG_val (curval.arch_data)
  119. #define REGGROUP_val (curval.arch_data)
  120. #define SEGREG_val (curval.arch_data)
  121. #define TARGETMOD_val (curval.arch_data)
  122. #define ID_val (curval.str.contents)
  123. #define ID_len (curval.str.len)
  124. #define LABEL_val (curval.str.contents)
  125. #define LABEL_len (curval.str.len)
  126. #define cur_line (yasm_linemap_get_current(parser_gas->linemap))
  127. #define p_expr_new(l,o,r) yasm_expr_create(o,l,r,cur_line)
  128. #define p_expr_new_tree(l,o,r) yasm_expr_create_tree(l,o,r,cur_line)
  129. #define p_expr_new_branch(o,r) yasm_expr_create_branch(o,r,cur_line)
  130. #define p_expr_new_ident(r) yasm_expr_create_ident(r,cur_line)
  131. yasm_bytecode *parse_instr_intel(yasm_parser_gas *parser_gas);
  132. void gas_parser_parse(yasm_parser_gas *parser_gas);
  133. void gas_parser_cleanup(yasm_parser_gas *parser_gas);
  134. int gas_parser_lex(YYSTYPE *lvalp, yasm_parser_gas *parser_gas);
  135. #endif