error.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2018 The NASM Authors - All Rights Reserved
  4. * See the file AUTHORS included with the NASM distribution for
  5. * the specific copyright holders.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following
  9. * conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  19. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  20. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * ----------------------------------------------------------------------- */
  33. /*
  34. * Error reporting functions for the assembler
  35. */
  36. #ifndef NASM_ERROR_H
  37. #define NASM_ERROR_H 1
  38. #include "compiler.h"
  39. /*
  40. * File pointer for error messages
  41. */
  42. extern FILE *error_file; /* Error file descriptor */
  43. /*
  44. * An error reporting function should look like this.
  45. */
  46. void printf_func(2, 3) nasm_error(int severity, const char *fmt, ...);
  47. fatal_func printf_func(2, 3) nasm_fatal(int flags, const char *fmt, ...);
  48. fatal_func printf_func(2, 3) nasm_panic(int flags, const char *fmt, ...);
  49. fatal_func nasm_panic_from_macro(const char *file, int line);
  50. #define panic() nasm_panic_from_macro(__FILE__, __LINE__);
  51. typedef void (*vefunc) (int severity, const char *fmt, va_list ap);
  52. extern vefunc nasm_verror;
  53. static inline vefunc nasm_set_verror(vefunc ve)
  54. {
  55. vefunc old_verror = nasm_verror;
  56. nasm_verror = ve;
  57. return old_verror;
  58. }
  59. /*
  60. * These are the error severity codes which get passed as the first
  61. * argument to an efunc.
  62. */
  63. #define ERR_DEBUG 0x00000000 /* put out debugging message */
  64. #define ERR_NOTE 0x00000001 /* additional error information */
  65. #define ERR_WARNING 0x00000002 /* warn only: no further action */
  66. #define ERR_NONFATAL 0x00000003 /* terminate assembly after phase */
  67. #define ERR_FATAL 0x00000006 /* instantly fatal: exit with error */
  68. #define ERR_PANIC 0x00000007 /* internal error: panic instantly
  69. * and dump core for reference */
  70. #define ERR_MASK 0x00000007 /* mask off the above codes */
  71. #define ERR_NOFILE 0x00000010 /* don't give source file name/line */
  72. #define ERR_HERE 0x00000020 /* point to a specific source location */
  73. #define ERR_USAGE 0x00000040 /* print a usage message */
  74. #define ERR_PASS1 0x00000080 /* only print this error on pass 1 */
  75. #define ERR_PASS2 0x00000100 /* only print this error on pass 2 */
  76. #define ERR_NO_SEVERITY 0x00000200 /* suppress printing severity */
  77. #define ERR_PP_PRECOND 0x00000400 /* for preprocessor use */
  78. #define ERR_PP_LISTMACRO 0x00000800 /* from preproc->error_list_macros() */
  79. /*
  80. * These codes define specific types of suppressible warning.
  81. * They are assumed to occupy the most significant bits of the
  82. * severity code.
  83. */
  84. #define WARN_SHR 12 /* how far to shift right */
  85. #define WARN(x) ((x) << WARN_SHR)
  86. #define WARN_MASK WARN(~0)
  87. #define WARN_IDX(x) ((x) >> WARN_SHR)
  88. #define WARN_MNP WARN( 1) /* macro-num-parameters warning */
  89. #define WARN_MSR WARN( 2) /* macro self-reference */
  90. #define WARN_MDP WARN( 3) /* macro default parameters check */
  91. #define WARN_OL WARN( 4) /* orphan label (no colon, and alone on line) */
  92. #define WARN_NOV WARN( 5) /* numeric overflow */
  93. #define WARN_GNUELF WARN( 6) /* using GNU ELF extensions */
  94. #define WARN_FL_OVERFLOW WARN( 7) /* FP overflow */
  95. #define WARN_FL_DENORM WARN( 8) /* FP denormal */
  96. #define WARN_FL_UNDERFLOW WARN( 9) /* FP underflow */
  97. #define WARN_FL_TOOLONG WARN(10) /* FP too many digits */
  98. #define WARN_USER WARN(11) /* %warning directives */
  99. #define WARN_LOCK WARN(12) /* bad LOCK prefixes */
  100. #define WARN_HLE WARN(13) /* bad HLE prefixes */
  101. #define WARN_BND WARN(14) /* bad BND prefixes */
  102. #define WARN_ZEXTRELOC WARN(15) /* relocation zero-extended */
  103. #define WARN_PTR WARN(16) /* not a NASM keyword */
  104. #define WARN_BAD_PRAGMA WARN(17) /* malformed pragma */
  105. #define WARN_UNKNOWN_PRAGMA WARN(18) /* unknown pragma */
  106. #define WARN_NOTMY_PRAGMA WARN(19) /* pragma inapplicable */
  107. #define WARN_UNK_WARNING WARN(20) /* unknown warning */
  108. #define WARN_NEG_REP WARN(21) /* negative repeat count */
  109. #define WARN_PHASE WARN(22) /* phase error in pass 1 */
  110. #define WARN_LABEL_REDEF WARN(23) /* label redefined, but consistent */
  111. #define WARN_LABEL_LATE WARN(24) /* label (re)defined during code generation */
  112. /* These two should come last */
  113. #define WARN_ALL (24+2) /* Do not use WARN() here */
  114. #define WARN_OTHER WARN(WARN_ALL-1) /* any noncategorized warning */
  115. /* This is a bitmask */
  116. #define WARN_ST_ENABLED 1 /* Warning is currently enabled */
  117. #define WARN_ST_ERROR 2 /* Treat this warning as an error */
  118. struct warning {
  119. const char *name;
  120. const char *help;
  121. uint8_t state; /* Default state for this warning */
  122. };
  123. extern const struct warning warnings[WARN_ALL+1];
  124. extern uint8_t warning_state[WARN_ALL];
  125. extern uint8_t warning_state_init[WARN_ALL];
  126. /* Process a warning option or directive */
  127. bool set_warning_status(const char *);
  128. #endif /* NASM_ERROR_H */