summaryrefslogtreecommitdiff
path: root/asm/nasm.c
Commit message (Collapse)AuthorAgeFilesLines
* Make debug info and error messages correctly reflect macros and repsH. Peter Anvin (Intel)2020-07-051-38/+44
| | | | | | | | | | | | | | | 1. Error messages would issue with the line number of %endrep. 2. Debug line information would ignore both macros and reps. This is doubly wrong; macros are semantically equivalent to inline functions, and it is expected that debuggers trace into these functions. These changes finishes the last parts of moving all responsibility for the listing enable/disable into the preprocessor, so remove the way over-complicated macro inhibit facility from the listing module entirely. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392691: errors: issue ERR_PASS2 messages in preproc-only modeH. Peter Anvin (Intel)2020-07-031-4/+19
| | | | | | | | | In preproc-only mode, we only ever execute a single pass, so we need to still issue error messages created during that pass, otherwise we don't even generate %warning or %error messages... Reported-by: Jason Hood <jadoxa@yahoo.com.au> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392648: rename float.[ch] to floats.[ch]H. Peter Anvin (Intel)2020-06-141-1/+1
| | | | | | | | | Haiku apparently wants to include <float.h> rather than "float.h". Rename float.[ch] to floats.[ch] to avoid unnecessary namespace confusion. Reported-by: <alaviss0+nasm@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* %line: quote filenames with double spaces, use unsigned char checkH. Peter Anvin (Intel)2020-06-141-3/+8
| | | | | | | | | | Filenames with double spaces need to be quoted; the preprocessor will otherwise collapse spaces into one. When comparing for control characters and spaces, use an unsigned compare. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc, srcfile: much saner handling of %line directivesH. Peter Anvin (Intel)2020-06-141-25/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | %line directives really need to be preprocessed early, before normal directive processing. In particular, they are *not* affected by such thing as smacro expansion, or deferred into an mmacro expansion. The %line directive is special because it is explicitly indented to be inserted by an external preprocessor, which can happen at any point. For mmacro and rep expansions, store the current file and line for each expansion line. Similarly, let each istk entry contain such information. Don't emit empty lines in preprocessing-only mode when we are already required to issue a %line directive anyway. This cuts down on clutter a fair bit. Quote filenames in %line directives (and accept quoted filenames in %line directives) if and only if it is necessary for disambiguation. This is required if: 1. The filename contains control characters; 2. The filename begins or ends with whitespace or a quotation mark; 3. The filename is empty. Otherwise issue the filename as-is, for backwards compatibility. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Fix missing "here" from error messagesH. Peter Anvin (Intel)2020-06-051-0/+4
| | | | | | | The "here" or "in an unknown location" suffix was inadvertently dropped. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* nasm.c: correctly print errors once committed; assert errhold_stack emptyH. Peter Anvin (Intel)2020-06-041-5/+10
| | | | | | | | | | Properly format the error messages when we print them (oops!) The errhold_stack should be empty after each pass. It may even be worthwhile to make sure it is empty after each *line*, but do this for now. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392652: hold smacro expansion warnings until we are sureH. Peter Anvin (Intel)2020-06-041-32/+125
| | | | | | | | Don't issue smacro expansion warnings until we are sure we are actually *done* with the smacro expansion. The last pass of expand_smacro_noreset() gets to commit warnings. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392667: more reasonable limit for expression descentH. Peter Anvin (Intel)2020-06-011-3/+15
| | | | | | | | Set an expression descent limit to 8192, which is more reasonable to expect to work on most platforms. Furthermore, if getrlimit() exists, then try to use it to see if we need to further limit the size. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* listing: make it possible to flush the listing output after every lineH. Peter Anvin (Intel)2019-10-231-0/+1
| | | | | | | Add the -Lw option to flush the list file after every line output. This is handy for debugging if nasm hangs. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* error: replace nasm_verror() indirection with preproc callbackH. Peter Anvin2019-08-281-4/+8
| | | | | | | | | | Since pp_error_list_macros() was introduced, the only need for pp_verror() is to suppress error messages in certain contexts. Replace this function with a preprocessor callback, preproc->pp_suppress_error(), so we can drop the nasm_verror() function pointer entirely. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* errors: be more robust in handling unexpected fatal errorsH. Peter Anvin2019-08-281-51/+87
| | | | | | | | | | | | | Introduce a new error level, ERR_CRITICAL, beyond which we will minimize the amount of code that will be executed before we die; in particular don't execute any memory allocations, and if we somehow end up recursing, abort() immediately. Basically, "less than panic, more than fatal." At this point this level is used by nasm_alloc_failed(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasm: avoid null pointer reference on VERY early memory allocation failureH. Peter Anvin2019-08-271-1/+2
| | | | | | | | If we get a memory allocation failure before preproc is initialized, we could end up taking a NULL pointer reference while trying to unwind macros. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc: standard macros now C-safe, %aliases off, fix %? recursionH. Peter Anvin2019-08-271-11/+11
| | | | | | | | | | | | | | | | | | | | Enough users expect the namespace starting with underscore to be safe for symbols. Change our private namespace from __foo__ to __?foo?__. Use %defalias to provide backwards compatiblity (by using %defalias instead of %define, we handle the case properly where the user changes the value.) Add a preprocessor directive: %aliases off ... to disable all smacro aliases and thereby making the namespace clean. Finally, fix infinite recursion when seeing %? or %?? due to paste_tokens(). If we don't paste anything, the expansion is done. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc: mmacro argument fixes; listing option for mmacro argsH. Peter Anvin (Intel)2019-08-201-1/+2
| | | | | | | | | | | | | | | | | | Correctly handle empty mmacro arguments that still have preceding whitespace tokens. Default mmacro parameters are obtained by count_mmac_params() so they, too, need to be shifted over by one. Add an option to list mmacro calls with arguments. Name this -Lm; remove the old -Lm option to -Ls since it is related to single-line macros. Trivially optimize the case where an mmacro is called from within itself: if all possible mmacros are excluded by loop removal, there is no need to delve into the mmac processing code. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* listing: add the -L+ option to enable all listing optionsH. Peter Anvin (Intel)2019-08-191-0/+1
| | | | | | | -L+ or %pragma list options ++ will enable all possible listing options. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392576: don't segfault on a bad %pragma limitH. Peter Anvin (Intel)2019-08-161-1/+6
| | | | | | | | Don't segfault on a bad %pragma limit. Instead treat a NULL pointer as an empty string. Reported-by: Ren Kimura <rkx1209dev@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc: fix mmacro nesting preventionH. Peter Anvin (Intel)2019-08-151-1/+2
| | | | | | | BR 3392602: mmacros should not nest unless so explicitly specified. Reported-by: C. Masloch <pushbx@38.de> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* listing: encapsulate the list_options encoding, make more comprehensiveH. Peter Anvin2019-08-101-6/+2
| | | | | | | | | | Encapsulate the list_options() encoding in an inline function. We only ever compute a mask with a non-constant input in two places (command line and pragma parsing), so a slightly more complex mapping is of no consequence; thus map a-z, A-Z and 0-9 as being the most likely characters we may want to use as options. Space is left for two more :) Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Add %pragma list optionsH. Peter Anvin2019-08-101-11/+15
| | | | | | | Add a %pragma to set (or clear) listing options. It only takes effect on the next assembly pass, however! Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc: add listing options to override nolist; some cleanupsH. Peter Anvin2019-08-101-0/+2
| | | | | | | | | | | | | | | | Add listing options: -Lb to show builtin macro packages -Lf to override .nolist Do some cleanups in the process, in particular generalize read_line() between stdmac and file alternatives. When processing stdmac, create an istk entry for it. This means stdmac can be identified by istk->fp == NULL. At some future date there could even be a function pointer to an appropriate read function. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* listing: coalesce TIMES in non-final passes, print <len>, clarify hexH. Peter Anvin2019-08-101-12/+9
| | | | | | | | | | | | | | | Merge TIMES in the nonfinal passes, there is no point in getting <len ...> an arbitrary number of times. Actually print <len> (OUT_RAWDATA without a data pointer), not <res> (OUT_RESERVE). Dropping the zero-fill for the hex format made the listing more manageable, but it also doesn't immediately look like hex, plus there is now the -Ld option. Put an h after hex (shorter than leading 0x) to make it obvious. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Stylistic improvements to help textH. Peter Anvin2019-08-101-9/+6
| | | | | | Trivial stylistic improvements to the help text. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Additional listing options, improve help output, fix macro limitsH. Peter Anvin2019-08-101-100/+179
| | | | | | | | | | | | | | | | | | Additional listing options: -Ld to display counts in decimal -Lp to output a list file in every pass (to make sure one exists) Clean up the help output and make it comprehensive. The -hf and -y options are no longer necessary, although they are supported for backwards compatiblity. Fix macro-levels so it actually count descent levels; a new macro-tokens limit introduced for the actual token limit. Slightly simplify the limits code. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* asm/nasm.c: make --debug=level actually workH. Peter Anvin (Intel)2019-08-091-24/+43
| | | | | | Turns out there was no support for optional arguments at all. [ Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* listing: add -L option for additional listing infoH. Peter Anvin (Intel)2019-08-091-3/+22
| | | | | | | | | | | | | | | | | | | | | | | | Add an -L option for additional listing information. Currently supported is -Le, which emits each line after processing through the preprocessor, and -Lm, which displays each single-line macro defined or undefined. NASM doesn't preserve the names of unused arguments, nor does it have any technical reason to do so. Instead of adding complexity to save them, make unnamed parameters official by specifying an empty string in the argument list. This has the additional advantage that () is now simply considered a single empty argument, which means that NASM should now properly handle things like: %define myreg() eax mov edx,myreg() ... similar to how the C preprocessor allows an empty macro argument list which is distinct from a macro with no arguments whatsoever. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Diagnostics: make debug more dynamic, note -> info, add listmsg levelH. Peter Anvin (Intel)2019-08-091-20/+38
| | | | | | | | | | | | | | | | Make debug messages more dynamic by making it easy to conditionalize the messages. Change ERR_NOTE to ERR_INFO which reflects the usage better. Other compilers use note: for additional information. Don't unwind the macro stack with ERR_HERE; it is only going to give confusing results as it will unwind the wrong macro stack. Add ERR_LISTMSG level which is *always* suppressed, but will still appear in the list file. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Merge empty reservations from TIMES; add counts in listingsH. Peter Anvin2019-08-071-1/+1
| | | | | | | | | | | | For constructs like TIMES xx RESB yy merge the TIMES and RESB and feed a single reservation to the backend; this can (obviously) be dramatically faster. Add byte count in listings for <incbin> and repeat count to <rept>; to make them more reasonable in length shorten to <bin ...> and <rep ...> respectively, and don't require leading zeroes in bin/rep/res count. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Add group aliases for all prefixed warnings.H. Peter Anvin2019-06-061-2/+2
| | | | | | | For example, -w+float will now enable all warnings with names staring with float-*. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* warnings: add [warning push] and [warning pop]H. Peter Anvin (Intel)2019-01-111-20/+17
| | | | | | Add [warning push] and [warning pop] directives. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Remove #includes already provided by "compiler.h"H. Peter Anvin2018-12-271-4/+0
| | | | | | | | "compiler.h" already includes a bunch of common include files. There is absolutely no reason to duplicate them in individual files, and in fact it robs us of central control of how these files are used. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Merge tag 'nasm-2.14.03rc1'H. Peter Anvin2018-12-271-1/+6
|\ | | | | | | | | | | | | | | | | | | NASM 2.14.03rc1 Resolved Conflicts: asm/labels.c include/error.h Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| * BR 3392539: some errors can "cascade". Allow suppressing if dead.H. Peter Anvin2018-12-271-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In BR 3392539, the error: helloW.s:18: error: label `rurt' changed during code generation [-w+error=label-redef-late] ... occurs a number of times after we have already issued an error. This is because the erroring instruction computes to a different size during code generation; this causes each subsequent label to cause a phase error. The phase error simply doesn't make much sense to report: if we are already committed to erroring out, it is more likely an error cascade rather than an error in its own right, so just suppress it in that case. Reported-by: <russvz@comcast.net> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Move <string.h> inclusion to compiler.hH. Peter Anvin2018-12-261-1/+0
| | | | | | | | | | | | | | There is absolutely no reason not to include <string.h> globally, and with the inline function for mempcpy() we need it there anyway. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | assemble_file(): break up this gigantic messH. Peter Anvin2018-12-181-159/+75
| | | | | | | | | | | | Break up this gigantic mess which touches way too many layers. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | With buffered warnings, change the handling of error passesH. Peter Anvin (Intel)2018-12-181-10/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With buffered warnings, most warnings *must* be issued on every pass, so ERR_PASS1 is simply wrong in most cases. ERR_PASS1 now means "force this warning to be output even in pass_first(). This is to be used for the case where the warning is only executed in pass_first() code; this is highly discouraged as it means the warnings will not appear in the list file and subsequent passes may make the warning suddenly vanish. ERR_PASS2 just as before suppresses an error or warning unless we are in pass_final(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Clean up the handling of various passesH. Peter Anvin (Intel)2018-12-181-88/+89
| | | | | | | | | | | | | | | | | | The use of pass0, pass1, pass2, and "pass" passed as an argument is really confusing and already caused a severe bug in the 2.14.01 release cycle. Clean them up and be far more explicit about what various passes mean. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | nasm: Fix condition in skip_this_passCyrill Gorcunov2018-12-161-1/+1
| | | | | | | | | | | | We should not match both condition. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | asm/nasm.c: Drop tabsCyrill Gorcunov2018-12-151-45/+45
| | | | | | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | warnings: make WARN_* constant obligatory for warningsH. Peter Anvin (Intel)2018-12-141-5/+4
| | | | | | | | | | | | Make it an error to have ERR_WARNING without a suppression level. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | nasm_warnf() -> nasm_warn()H. Peter Anvin (Intel)2018-12-141-2/+2
| | | | | | | | | | | | | | | | We want to strongly encourage writers of warnings to create warning categories, so remove the flagless nasm_warn() and change nasm_warnf() to nasm_warn(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Merge tag 'nasm-2.14.01rc5'H. Peter Anvin (Intel)2018-12-141-3/+11
|\ \ | |/ | | | | | | | | | | | | | | NASM 2.14.01rc5 Resolved Conflicts: asm/labels.c asm/nasm.c version
| * Document the -Ov option, minor fix for gcc -OgH. Peter Anvin (Intel)2018-12-141-1/+3
| | | | | | | | | | | | | | | | | | The -Ov option is useful but was undocumented. Add an initialization to keep gcc from complaining at optimization level -Og. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * --no-line: new option to ignore %line directivesH. Peter Anvin (Intel)2018-12-141-1/+8
| | | | | | | | | | | | | | For debugging preprocessed code, it is useful to be able to ignore %line directives rather than having to filter them out externally. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * errors: correct message saying -w+error= ... is in use when it is notH. Peter Anvin (Intel)2018-12-131-1/+1
| | | | | | | | | | | | Correct the test for when -w+error= is the correct thing to print. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | strlist, warnings: improve strlist, buffer warnings until errorH. Peter Anvin (Intel)2018-12-141-6/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Make strlist_free() take a pointer to a pointer, so we can set it to NULL. Buffer warnings on a strlist until we either get an error or we are in pass 2. Hopefully this should let us get rid of a lot of the ERR_PASS* bullshit, which far too often causes messages to get lost. asm/labels.c contains one example of a warning that cannot be made correct with a specific pass number. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | strlist: can be unique or not, add printf functionsH. Peter Anvin (Intel)2018-12-131-2/+2
| | | | | | | | | | | | | | | | | | | | Make it a selectable option at allocation time if a strlist should contain only unique strings or not. If not, we omit the hash table and strlist_find() will not do anything. Add printf()-style functions to a strlist. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | warnings: define warning classes at point of usemkwarningsH. Peter Anvin (Intel)2018-12-131-19/+23
| | | | | | | | | | | | | | | | | | | | | | | | It is extremely desirable to allow the user fine-grained control of warnings, but this has been complicated by the fact that a warning class has had to be defined in no less than three places (error.h, error.c, nasmdoc.src) before it can be used in source code. Instead, use a script to define these via magic comments at the point of use. This hopefully will encourage creating new classes as needed. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | errors: change the severity parameter from "int" to "errflags"H. Peter Anvin (Intel)2018-12-131-9/+9
| | | | | | | | | | | | | | Change the severity parameter to the error function from "int" to an unsigned typedef, currently uint32_t. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Merge remote-tracking branch 'origin/nasm-2.14.xx'H. Peter Anvin (Intel)2018-12-131-3/+3
|\ \ | |/ | | | | | | | | | | | | | | | | | | Resolved Conflicts: Makefile.in Mkfiles/msvc.mak Mkfiles/openwcom.mak asm/nasm.c nasmlib/alloc.c Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>