summaryrefslogtreecommitdiff
path: root/asm/parser.c
Commit message (Collapse)AuthorAgeFilesLines
* Change unused -> unused_func to remove special caseH. Peter Anvin (Intel)2020-07-011-1/+1
| | | | | | | | | The autoconf process automatically generates macros for function attributes, including empty placeholders. Said empty placeholders also propagate automatically into config/unconfig.h for the compilers which don't support autoconf. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Make empty db statement a suppressable warningH. Peter Anvin (Intel)2020-06-301-2/+9
| | | | | | Add a "db-empty" warning class to allow suppressing warnings. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* clang: mark inline functions unused and add warning optionsH. Peter Anvin (Intel)2020-06-301-1/+2
| | | | | | | | | | | | | clang, unlike gcc, will warn on inline functions which are unused. This can happen if a function is either intended to be used in the future, or it is only used under certain config options. Mark those functions with the "unused" attribute; not only does it quiet the warning, but it also documents it for the user. Shuffle around the warning options in configure and add a few more that are specific to clang. 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>
* Implement an enhanced version of MASM's dup() and "db ?" syntax.H. Peter Anvin (Intel)2019-10-161-158/+278
| | | | | | | | | Add support for complex data (Dx) statement expressions involving both initialized and uninitialized data. In addition, we have support for overriding the size of each element on an individual item and/or list basis. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* warnings: do a line break before enabled/disabled noteH. Peter Anvin2019-10-031-1/+0
| | | | | | | | We need to create a separate paragraph if the help text had used \c anyway. Putting the enabled/disabled separately for all entries makes it read a lot cleaner anyway. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* warnings: make it possible to put blank lines in doc textH. Peter Anvin2019-10-031-1/+2
| | | | | | | rdsrc.pl requires blank lines around \c paragraph, but warnings.pl would strip them. Create a *!- prefix to force a blank line. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* masm.mac, parser: VERY limited MASM emulation packageH. Peter Anvin (Intel)2019-08-141-142/+170
| | | | | | | | | | Very limited MASM emulation. The parser has been extended to emulate the PTR keyword if the corresponding macro is enabled, and the syntax displacement[index] for memory operations is now recognized. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Add implicitly sized versions of the K instructionsH. Peter Anvin (Intel)2019-08-091-3/+24
| | | | | | | | | This allows the K instructions to be specified without a size suffix as long as the operands are sized; this matches the way most other x86 instructions work. As this is not the syntax specified in the SDM, don't use it for disassembly. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Add group aliases for all prefixed warnings.H. Peter Anvin2019-06-061-2/+3
| | | | | | | For example, -w+float will now enable all warnings with names staring with float-*. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* strfunc: better error messages if a string transform failsH. Peter Anvin2019-06-061-2/+2
| | | | | | Let the user know what string transform actually failed on them. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Remove #includes already provided by "compiler.h"H. Peter Anvin2018-12-271-3/+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>
* Replace <ctype.h> includes with "nctype.h"H. Peter Anvin2018-12-271-1/+1
| | | | | | | For almost everything we should use "nctype.h". Right now we don't have a nasm_toupper() to use <ctype.h> for things that need toupper(). 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>
* Factor out size tokens and annotate with the corresponding sizeH. Peter Anvin2018-12-241-3/+6
| | | | | | | There is space in the token table to explicitly encode the size corresponding to a size token. We might as well do so... Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Don't convert the various RESx instructions to RESBH. Peter Anvin2018-12-181-10/+0
| | | | | | | All it does is complicate things; instead leave the opcode where it is. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* With buffered warnings, change the handling of error passesH. Peter Anvin (Intel)2018-12-181-4/+4
| | | | | | | | | | | | | | | | 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-8/+4
| | | | | | | | | 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>
* warnings: make WARN_* constant obligatory for warningsH. Peter Anvin (Intel)2018-12-141-3/+3
| | | | | | 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-4/+4
| | | | | | | | 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>
* warnings: define warning classes at point of usemkwarningsH. Peter Anvin (Intel)2018-12-131-0/+6
| | | | | | | | | | | | 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>
* warnings: Make WARN_ constants consistent with -w optionsH. Peter Anvin (Intel)2018-12-121-1/+1
| | | | | | Not only does this make it consistent, but allows for automation. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* warnings: rename ERR_WARN_* to WARN_*H. Peter Anvin (Intel)2018-12-121-1/+1
| | | | | | | | | | The prefix ERR_WARN_ is unnecessarily long and may be a disincentive to create new warning categories. Change it to WARN_*, it is still plenty distinctive. This is equivalent to nasm-2.14.xx checkin 77f53ba6d4cb90e5a7e09b33357ed7c1fe9f6b9d. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* parser: Use nasm_error helpersCyrill Gorcunov2018-12-011-84/+58
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Merge branch 'nasm-2.14.xx'Cyrill Gorcunov2018-10-151-7/+47
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * nasm-2.14.xx: (83 commits) NASM 2.14rc16 doc: Update changes preproc: expand_smacro -- Fix nil dereference on error path eval: Eliminate division by zero doc: Update changes opflags: Convert is_class and is_reg_class to helpers preproc: Fix out of range access in expand mmacro doc: Update changes parser: Fix sigsegv on certain equ instruction parsing labels: Make sure nil label is never passed labels: Don't nil dereference if no label provided macho: Add warning message in macho_output() macho/reloc: Fix addr size sensitive conditions macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc() macho/reloc: Fixed offset adjustment in add_reloc() macho/reloc: Allow absolute relocation when forcing a symbol reference macho/reloc: Adjust SUB relocation information macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations macho/reloc: Simplified relocation for REL/BRANCH macho/sym: Record initial symbol number always ... Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
| * parser: Fix sigsegv on certain equ instruction parsingCyrill Gorcunov2018-10-131-0/+17
| | | | | | | | | | | | | | | | | | | | We should check for bounds when accessing nasm_reg_flags. Seems this bug was for long time already. https://bugzilla.nasm.us/show_bug.cgi?id=3392516 Reported-by: Jordan Zebor <j.zebor@f5.com> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
| * optimization: Introduce new flag to turn-off selectivelyChang S. Bae2018-08-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | While configuring optimization in a level is conventional, a certain optimization tends to conflict with some pragma. For example, jump match conflicts with Mach-O's "subsections-via-symbols" macro. This configurability will workaround such conflicts. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
| * asm: support the +n syntax for register setsH. Peter Anvin2018-06-251-4/+26
| | | | | | | | | | | | | | Support the +n syntax for multiple contiguous registers, and emit it in the output from ndisasm as well. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * absolute: in absolute space, need to use absolute.segmentH. Peter Anvin (Intel)2018-06-251-1/+2
| | | | | | | | | | | | | | | | | | We can be in absolute space and still end up with segment-relative references. This is in fact the meaning of absolute.segment. Make sure we define the labels appropriately. Reported-by: Cyrill Gorcunov <gorcunov@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | errors: simplify nasm_fatal() and nasm_panic()H. Peter Anvin2018-06-151-1/+1
|/ | | | | | | | | | | | | | | Nearly all instances of nasm_fatal() and nasm_panic() take a flags argument of zero. Simplify the code by making nasm_fatal and nasm_panic default to no flags, and add an alternate version if flags really are desired. This also means that every call site doesn't have to initialize a zero argument. Furthermore, ERR_NOFILE is now often not necessary, as the error code will no longer cause a null reference if there is no current file. Therefore, we can remove many instances of ERR_NOFILE which only deprives the user of information. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* gcc: fix mistakes discovered by recent gccH. Peter Anvin2018-06-021-1/+2
| | | | | | | Recent versions of gcc issue a couple of warnings, which may be real bugs. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Cleanup of label renaming infrastructure, add subsection supportH. Peter Anvin2018-06-011-4/+4
| | | | | | | | | | | | | | In order to support Mach-O better, add support for subsections, as used by Mach-O "subsections_via_symbols". We also want to add infrastructure to support this by downcalling to the backend to indicate if a new subsection is needed. Currently this supports a maximum of 2^14 subsections per section for Mach-O; this can be addressed by adding a level of indirection (or cleaning up the handling of sections so we have an actual data structure.) Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* Merge remote-tracking branch 'origin/nasm-2.13.xx'H. Peter Anvin2017-11-011-3/+2
|\ | | | | | | | | | | | | Resolved conflicts: version Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
| * BR 3392437: Fix diagnostic for negative value in TIMESH. Peter Anvin2017-09-271-3/+2
| | | | | | | | | | | | | | Issue a diagnostic and don't panic for invalid TIMES values. Reported-by: C. Masloch <pushbx@38.de> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* | Don't sort opcodes; move all pseudo-ops to the beginningH. Peter Anvin2017-05-011-2/+2
|/ | | | | | | | | | | | We don't need to sort opcodes anymore, since we are using an O(1) hash and not binary search. Instead, sort them in the order they first appear in insns.dat; this lets us move all the pseudo-ops to a contiguous range at the start of the file, for more efficient handling. Change the functions that process pseudo-ops accordingly. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* a) Fix handling of DZ/ZWORD; b) don't crash on TIMES JMPH. Peter Anvin2017-05-011-39/+8
| | | | | | | | | | | | | | | a) Fix a number of missing instances of DZ and ZWORD. b) NASM would crash if TIMES was used on an instruction which varies in size, e.g. JMP. Fix this by moving the handling of TIMES at a higher level, so we generate the instruction "de novo" for each iteration. The exception is INCBIN, so we can avoid reading the included file over and over. c) When using the RESx instructions, just fold TIMES into the reserved space size; there is absolutely no point to iterate over it. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* BR3392392: fix broadcast decorators and improve error messagesH. Peter Anvin2017-04-021-28/+32
| | | | | | | | | | | Checkin c33d95fde9f8ae6252c8ecf4d66c543dfa914d83: BR 3392370: {z} decorator allowed on MOVDQ* memory operands ... inadvertently broke broadcast operations, which only apply to memory operands and therefore were only handled in one of the two brace-parser implementations. Fix that. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* BR 3392363: clear the operands when making an artificial I_RESBH. Peter Anvin2017-03-311-0/+1
| | | | | | | | | | When we make an artificial RESB instructions (due to isolated prefixes) we need to make sure there isn't any crap left in the operands structure. The easiest way to guarantee that is to force it to zero. Reported-by: Henrik <henrik@gramner.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* BR 3392370: {z} decorator allowed on MOVDQ* memory operandsH. Peter Anvin2017-03-311-18/+4
| | | | | | | | | | The spec says very clearly the {z} decorator is allowed on memory operands for the MOVDQ* instructions. Remove special cases from the code to disallow this case, which had the unfortunate effect of generating a very uninformative error message. Reported-by: Agner <agner@agner.org> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* asm/*: Move directive processing to its own file, refactor error handlingH. Peter Anvin2017-03-071-5/+4
| | | | | | | | Move directive processing to its own file, and move nasmlib/error.c to asm/error.c (it was not used by the disassembler); remove some extern declarations from .c files, and do some general code cleanups. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* Remove casts in switch statements only meant to keep OpenWatcom happyH. Peter Anvin2017-03-011-3/+3
| | | | | | | | Remove casts in switch statements that were intended to keep OpenWatcom happy. It didn't work, and now we have a more general solution for the problem, which also ought to be less dangerous. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* asm/parser.c: don't call reloc_value() twice, minor cleanupsH. Peter Anvin2017-02-281-6/+6
| | | | | | | | | There is absolutely no reason to call reloc_value() twice while processing an immediate. Doing so is both expensive and unnecessary. Make some more deliberate decorations to try to avoid miscompilation on OpenWatcom, but I'm not sure this will help enough. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* We can have a WRT for a relative referenceH. Peter Anvin2017-02-211-1/+1
| | | | | | It isn't illegal to have WRT for a relative reference. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Support self-relative expressions in offsets and immediatesH. Peter Anvin2017-02-201-40/+37
| | | | | | | | | | Handle, hopefully correctly, self-relative expressions (that is, expressions of the form X - Y where Y is a symbol in the current segment, possibly $ or $$) used as offsets or immediates, as opposed to arguments to Dx statements (which have already been supported for a while.) Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasm_build_assert() -> nasm_static_assert()H. Peter Anvin2017-01-241-1/+1
| | | | | | | The C11 standard calls this concept a static assert, so go with that terminology. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* parser: Get rid of global variableMartin Lindhe2017-01-051-1/+1
| | | | | | | | | | fixes pvs-studio error 'V707 Giving short names to global variables is considered to be bad practice. It is suggested to rename 'i' variable. gorcunov@: Simply define it as local variable. Signed-off-by: Martin Lindhe <martin-commit@ubique.se> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* If we have new features introduced by C11, use themH. Peter Anvin2016-12-201-1/+1
| | | | | | | Instead of using hacks or compiler-specific features, if we have standard features as defined in ISO C11, use them. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* asm/parser.c -- Fix typo in testing for registerCyrill Gorcunov2016-11-291-1/+1
| | | | | | | | | | | It should be EXPR_REG_END referred when testing for register present. A typo in 472a7c1d17e0212b3cbf5302a9f5cdb358be4425 https://bugzilla.nasm.us/show_bug.cgi?id=3392375 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Allow relative references to external symbols in dataH. Peter Anvin2016-10-311-14/+58
| | | | | | | | | | | Allow constructs like: dd foo - $ ... where foo is an external symbol. Currently this is only implemented for extops, i.e. dx opcodes. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Reorganize the source code into subdirectoriesH. Peter Anvin2016-05-251-0/+1168
Make the source code easier to understand and keep track of by organizing it into subdirectories depending on the function. Signed-off-by: H. Peter Anvin <hpa@zytor.com>