listing.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* ----------------------------------------------------------------------- *
  2. *
  3. * Copyright 1996-2019 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. * listing.h header file for listing.c
  35. */
  36. #ifndef NASM_LISTING_H
  37. #define NASM_LISTING_H
  38. #include "nasm.h"
  39. /*
  40. * List-file generators should look like this:
  41. */
  42. struct lfmt {
  43. /*
  44. * Called to initialize the listing file generator. Before this
  45. * is called, the other routines will silently do nothing when
  46. * called. The `char *' parameter is the file name to write the
  47. * listing to.
  48. */
  49. void (*init)(const char *fname);
  50. /*
  51. * Called to clear stuff up and close the listing file.
  52. */
  53. void (*cleanup)(void);
  54. /*
  55. * Called to output binary data. Parameters are: the offset;
  56. * the data; the data type. Data types are similar to the
  57. * output-format interface, only OUT_ADDRESS will _always_ be
  58. * displayed as if it's relocatable, so ensure that any non-
  59. * relocatable address has been converted to OUT_RAWDATA by
  60. * then.
  61. */
  62. void (*output)(const struct out_data *data);
  63. /*
  64. * Called to send a text line to the listing generator. The
  65. * `int' parameter is LIST_READ or LIST_MACRO depending on
  66. * whether the line came directly from an input file or is the
  67. * result of a multi-line macro expansion.
  68. *
  69. * If a line number is provided, print it; if the line number is
  70. * -1 then use the same line number as the previous call.
  71. */
  72. void (*line)(int type, int32_t lineno, const char *line);
  73. /*
  74. * Called to change one of the various levelled mechanisms in the
  75. * listing generator. LIST_INCLUDE and LIST_MACRO can be used to
  76. * increase the nesting level of include files and macro
  77. * expansions; LIST_TIMES and LIST_INCBIN switch on the two
  78. * binary-output-suppression mechanisms for large-scale
  79. * pseudo-instructions; the size argument prints the size or
  80. * repetiiton count.
  81. *
  82. * LIST_MACRO_NOLIST is synonymous with LIST_MACRO except that
  83. * it indicates the beginning of the expansion of a `nolist'
  84. * macro, so anything under that level won't be expanded unless
  85. * it includes another file.
  86. */
  87. void (*uplevel)(int type, int64_t size);
  88. /*
  89. * Reverse the effects of uplevel.
  90. */
  91. void (*downlevel)(int type);
  92. /*
  93. * Called on a warning or error, with the error message.
  94. */
  95. void printf_func_ptr(2, 3) (*error)(errflags severity, const char *fmt, ...);
  96. /*
  97. * Update the current offset. Used to give the listing generator
  98. * an offset to work with when doing things like
  99. * uplevel(LIST_TIMES) or uplevel(LIST_INCBIN); see
  100. * list_set_offset();
  101. */
  102. void (*set_offset)(uint64_t offset);
  103. };
  104. extern const struct lfmt *lfmt;
  105. extern bool user_nolist;
  106. /*
  107. * list_options are the requested options; active_list_options gets
  108. * set when a pass starts.
  109. *
  110. * These are simple bitmasks of ASCII-64 mapping directly to option
  111. * letters.
  112. */
  113. extern uint64_t list_options, active_list_options;
  114. /*
  115. * This maps the characters a-z, A-Z and 0-9 onto a 64-bit bitmask
  116. * (with two bits left over for future use! This isn't particularly
  117. * efficient code, but just about every instance of it should be
  118. * fed a constant, so the entire function can be precomputed at
  119. * compile time. The only cases where the full computation is needed
  120. * is when parsing the -L option or %pragma list options, neither of
  121. * which is in any way performance critical.
  122. *
  123. * The character + represents ALL listing options.
  124. *
  125. * This returns 0 for invalid values, so that no bit is accessed
  126. * for unsupported characters.
  127. */
  128. static inline const_func uint64_t list_option_mask(unsigned char x)
  129. {
  130. if (x >= 'a') {
  131. if (x > 'z')
  132. return 0;
  133. x = x - 'a';
  134. } else if (x >= 'A') {
  135. if (x > 'Z')
  136. return 0;
  137. x = x - 'A' + 26;
  138. } else if (x >= '0') {
  139. if (x > '9')
  140. return 0;
  141. x = x - '0' + 26*2;
  142. } else if (x == '+') {
  143. return ~UINT64_C(0);
  144. } else {
  145. return 0;
  146. }
  147. return UINT64_C(1) << x;
  148. }
  149. static inline pure_func bool list_option(unsigned char x)
  150. {
  151. return unlikely(active_list_options & list_option_mask(x));
  152. }
  153. /* We can't test this using active_list_options for obvious reasons... */
  154. static inline pure_func bool list_on_every_pass(void)
  155. {
  156. return unlikely(list_options & list_option_mask('p'));
  157. }
  158. /* Pragma handler */
  159. enum directive_result list_pragma(const struct pragma *);
  160. #endif