gas-eval.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* eval.h header file for eval.c
  2. *
  3. * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  4. * Julian Hall. All rights reserved. The software is
  5. * redistributable under the licence given in the file "Licence"
  6. * distributed in the NASM archive.
  7. */
  8. #ifndef YASM_EVAL_H
  9. #define YASM_EVAL_H
  10. /*
  11. * -------------------------
  12. * Error reporting functions
  13. * -------------------------
  14. */
  15. /*
  16. * An error reporting function should look like this.
  17. */
  18. typedef void (*efunc) (void *private_data, int severity, const char *fmt, ...);
  19. /*
  20. * These are the error severity codes which get passed as the first
  21. * argument to an efunc.
  22. */
  23. #define ERR_DEBUG 0x00000008 /* put out debugging message */
  24. #define ERR_WARNING 0x00000000 /* warn only: no further action */
  25. #define ERR_NONFATAL 0x00000001 /* terminate assembly after phase */
  26. #define ERR_FATAL 0x00000002 /* instantly fatal: exit with error */
  27. #define ERR_PANIC 0x00000003 /* internal error: panic instantly
  28. * and dump core for reference */
  29. #define ERR_MASK 0x0000000F /* mask off the above codes */
  30. #define ERR_NOFILE 0x00000010 /* don't give source file name/line */
  31. #define ERR_USAGE 0x00000020 /* print a usage message */
  32. #define ERR_PASS1 0x00000040 /* only print this error on pass one */
  33. /*
  34. * These codes define specific types of suppressible warning.
  35. */
  36. #define ERR_WARN_MASK 0x0000FF00 /* the mask for this feature */
  37. #define ERR_WARN_SHR 8 /* how far to shift right */
  38. #define ERR_WARN_MNP 0x00000100 /* macro-num-parameters warning */
  39. #define ERR_WARN_MSR 0x00000200 /* macro self-reference */
  40. #define ERR_WARN_OL 0x00000300 /* orphan label (no colon, and
  41. * alone on line) */
  42. #define ERR_WARN_NOV 0x00000400 /* numeric overflow */
  43. #define ERR_WARN_GNUELF 0x00000500 /* using GNU ELF extensions */
  44. #define ERR_WARN_MAX 5 /* the highest numbered one */
  45. /*
  46. * The expression evaluator must be passed a scanner function; a
  47. * standard scanner is provided as part of nasmlib.c. The
  48. * preprocessor will use a different one. Scanners, and the
  49. * token-value structures they return, look like this.
  50. *
  51. * The return value from the scanner is always a copy of the
  52. * `t_type' field in the structure.
  53. */
  54. struct tokenval {
  55. int t_type;
  56. yasm_intnum *t_integer, *t_inttwo;
  57. char *t_charptr;
  58. };
  59. typedef int (*scanner) (void *private_data, struct tokenval *tv);
  60. /*
  61. * Token types returned by the scanner, in addition to ordinary
  62. * ASCII character values, and zero for end-of-string.
  63. */
  64. enum { /* token types, other than chars */
  65. TOKEN_INVALID = -1, /* a placeholder value */
  66. TOKEN_EOS = 0, /* end of string */
  67. TOKEN_EQ = '=', TOKEN_GT = '>', TOKEN_LT = '<', /* aliases */
  68. TOKEN_ID = 256, TOKEN_NUM, TOKEN_REG, TOKEN_INSN, /* major token types */
  69. TOKEN_ERRNUM, /* numeric constant with error in */
  70. TOKEN_HERE, TOKEN_BASE, /* $ and $$ */
  71. TOKEN_SPECIAL, /* BYTE, WORD, DWORD, FAR, NEAR, etc */
  72. TOKEN_PREFIX, /* A32, O16, LOCK, REPNZ, TIMES, etc */
  73. TOKEN_SHL, TOKEN_SHR, /* << and >> */
  74. TOKEN_SDIV, TOKEN_SMOD, /* // and %% */
  75. TOKEN_GE, TOKEN_LE, TOKEN_NE, /* >=, <= and <> (!= is same as <>) */
  76. TOKEN_DBL_AND, TOKEN_DBL_OR, TOKEN_DBL_XOR, /* &&, || and ^^ */
  77. TOKEN_SEG, TOKEN_WRT, /* SEG and WRT */
  78. TOKEN_FLOAT /* floating-point constant */
  79. };
  80. /*
  81. * The actual expression evaluator function looks like this. When
  82. * called, it expects the first token of its expression to already
  83. * be in `*tv'; if it is not, set tv->t_type to TOKEN_INVALID and
  84. * it will start by calling the scanner.
  85. *
  86. * `critical' is non-zero if the expression may not contain forward
  87. * references. The evaluator will report its own error if this
  88. * occurs; if `critical' is 1, the error will be "symbol not
  89. * defined before use", whereas if `critical' is 2, the error will
  90. * be "symbol undefined".
  91. *
  92. * If `critical' has bit 8 set (in addition to its main value: 0x101
  93. * and 0x102 correspond to 1 and 2) then an extended expression
  94. * syntax is recognised, in which relational operators such as =, <
  95. * and >= are accepted, as well as low-precedence logical operators
  96. * &&, ^^ and ||.
  97. */
  98. #define CRITICAL 0x100
  99. typedef yasm_expr *(*evalfunc) (scanner sc, void *scprivate, struct tokenval *tv,
  100. int critical, efunc error, yasm_symtab *symtab);
  101. /*
  102. * The evaluator itself.
  103. */
  104. yasm_expr *evaluate (scanner sc, void *scprivate, struct tokenval *tv,
  105. void *eprivate, int critical, efunc report_error,
  106. yasm_symtab *symtab);
  107. #endif