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