Make the handling of messages saner. In particular, regularize the
handling of info and debug messages, so that nasm_info() and
nasm_debug() actually become useful.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Along with C and other languages, the current trend is to be able to
probe for features rather than relying on version numbers. This is
motivated in part by the intent of bumping the major version number to
3.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add the %null(), %note(), %warning(), %error(), and %fatal()
functions. They behave like the corresponding directives, then expands
to nothing.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
$$ is TOKEN_BASE, not a symbol. If this is done incorrectly, ppscan
chokes on $$ as it ends up being an invalid symbol.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
It is possible for m->mstk.mmac to point back to itself. In that case,
don't terminate the macro debug invocation just yet.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The documentation actually states that $ as a hex prefix is only valid
when followed by a digit, which at least makes the syntax conflict
less complicated. Actually match the documentation.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
To avoid repeated warnings, there is no warning issued for when
tokenizing a number starting with $ in the preprocessor, but issue a
warning if such a number is *consumed* (used in arithmetic) in the
preprocessor.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The use of $ prefixes for hexadecimal numbers conflicts with
the use of $ to escape symbols. Add a directive to disable
$ for hexadecimal numbers so that those escapes work OK.
As a result, allow escaped symbols to start with a digit.
Add a warning that this syntax is deprecated.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
- Significantly overhauled the disassembler internals to make
better use of the information already in the instruction template
and to reduce the implementation differences with the assembler
- Add APX support to the disassembler
- Fix problem with disassembler truncating addresses of jumps
- Fix generation of invalid EAs in 16-bit mode
- Fix array overrun for types in a few modules
- Fix invalid ND flag on near JMP
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The late cleanup of macros can cause severe memory hogging with nested
%reps. Instead, implement proper reference counting for mmacros.
Adds some other minor cleanups as well, notably delete_*() are
designed to update or null the pointer that is passed to it.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
It is good to have a way to test for the existence of macro functions,
and since they are really just a special case of single-line macros,
allow %ifdef to test for them instead of coming up with something
entirely new.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The format wasn't actually uleb128 because it was accidentally
bigendian (like UTF-8). That is just begging for confusion in the
future, if and when the uleb128 code gets librarized.
Fix it now.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The very simple compression scheme used for the builtin macro sets no
longer works adequately, and in fact it generates incorrect output
now.
Drop the whole idea of an ad hoc compression scheme and just use
zlib. For the case where there is no system zlib available, include a
(subset of) the zlib distribution. The configure script can be set to
force this included zlib if desired (e.g. for testing.)
Unfortunately this turned out to be a pretty painful can of worms in
terms of complexity. On the other hand having zlib available might be
useful at some point in the future.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add a function to test for the existence of a file, and a function
query the real operating system path, if available.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Implement preprocessor function equivalents of the %pathsearch and
%depend directives.
Simplify the incbin standard macro by using these functions.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This code incorrectly would try to use "path" as the hash key instead
of full->path, causing the key in struct hash_insert to diverge from
the one used in hash_add(). Fix that.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Under some circumstances, such as:
- Certain uses of %exitrep in syntactically invalid code;
- %unmacro of a *alias* to a macro currently being expanded;
... it is possible for an mmacro to get freed while it is still in
use. Although inefficient, the easiest way to avoid this is to not
free mmacros until the end of pass cleanup, when named mmacros are
also freed.
To support this, use the existing ->next field in the MMacro structure
to keep a list of anonymous or removed MMacros. Don't free ->name at
this point, though, since that is currently used to distinguish
between %rep's and %macro's. (This needs to be cleaned up to support
constructs such as %while or %for, but that is for later.)
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Require the second colon before the grouped parameter count; otherwise
the syntax is ambiguous since an expression can start with (.
Update/complete the documentation and the examples.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add the ability to have fixed arguments in %map. This is extremely
useful for parameterizing the invoked macro using arguments to a
surrounding macro.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Separate out counting and parsing smacro parameters into separate
functions. This not only makes the code *way* easier to read, but
these can be re-used e.g. for %map().
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add the %map() function which can apply arguments to a macro from a
list.
Allow the user to specify the desired radix for an evaluated
parameter. It doesn't make any direct difference, but can be nice for
debugging or turning into strings.
As part of this, split expand_one_smacro() into two parts: parameter
parsing and macro expansion. This is a very straightforward splitting
of two mostly unrelated pieces of functionality.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
When expanding %rep blocks, if any of the %rep blocks are empty, there
may be need to unwind the %rep stack multiple times. The code would
not do so -- there was a break; in the loop, which incidentally turned
it into something that wasn't a loop at all.
Reported-by: E. C. Maslock <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Make it possible to add a base prefix to %num().
Add the %hex() function, producing hexadecimal values that are
nevertheless valid NASM numeric constants.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The user would generally expect the parameter number to be counted
from 1 for human purposes, and that is also consistent with %1, %2,
... for multi-line macros.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The fix for BR 3392414 introduced a fairly serious memory
leak. C. Masloch was kind enough to track down the proper root cause
and fix it correctly.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The argument to nasm_new() is the pointer, not the indirection from
the pointer. This code is only relevant when compiled without token
recycling (TOKEN_BLOCKSIZE not set), but it is still wrong...
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add the option of having strings only conditionally quoted (&&) -- do
not quote an already quoted string again -- as opposed to always
quoting a string.
This makes a lot of the string functions way simpler to implement, and
removes the need to share ad hoc parsing code with directives.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add the %abs() function, to produce the absolute value as an
always-positive decimal constant.
Change the order of the arguments for %num().
Refactor the handling of optional arguments, to reduce the amount of
redundant code. This is currently only used for builtin functions, but
might be extended in the future.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add the %num() preprocessor function, which returns a quoted string
with a number formatted in any base between 2 and 64 (using bash
encoding with '@' for 62 and '_' for 63.)
It can specify a fixed number of digits with or without truncation.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Classify all remaining WARN_OTHER warnings in the preprocessor. Move
all preprocessor warnings except "user" under a common pp-* prefix.
Warn for an out-of-range argument to the %sel() function.
Finally, use "dname" in additional places for consistency and future
ease of use.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Implement the %cond() and %sel() functions that expand to a specific
one of the arguments. %cond(x,y,z) is basically a shorthand for
%sel(2-!(x),y,z) used when x is a boolean condition.
Fix a memory leak in %strcat and %strlen.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Allow preprocessor function expansion to recurse. Nearly all the
machinery for recursive smacros was already in place; this merely
activates it for the specific case of preprocessor functions. Making
it a general facility should be deferred to a later relese, though.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Some preprocessor functions have the same name as directives. In those
cases, they should be expanded as functions if and only if they are
followed by a left parenthesis. Although it is not inherently true that
either preprocessor functions require a paren nor that directives
cannot start with one, but it is true and will remain true for all
cases where there is a namespace collision.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
%substr contained a token skip to "skip expanded ID", which is
incorrect, as that has already been skipped at that point. It worked
anyway, accidentally, as this token would always be a whitespace token
-- but we then do skip_white() immediately thereafter.
Delete this to allow this code to be factored.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit adds a check to see if the macro that we want to unmacro exists.
A previous commit, introduced a check to see if the unmacro was undefining a macro being expanded, but that same check included a null pointer dereference if the macro to undefine did not exist.
The following code reproduced the issue:
```asm
%macro baz 0
%unmacro F 0
%endmacro
baz
```
Compile with:
```shell
$ nasm -f elf64 -g -FDWARF -o tmp.o -werror file.asm
```
[hpa: adjusted code to match NASM style]
Fixes bug 3392761
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This reverts commit 8fcc785f95.
This patch causes test a32offs.asm, and in general *any* use of the
"bits" macro, to totally fail.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>