Commit Graph

314 Commits

Author SHA1 Message Date
H. Peter Anvin
6d9b2b59b5 preproc: add %ifenv
Add %ifenv to test for the presence of an environment variable.  The
environment variable can, but does not have to be, prefixed with %!.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-07-13 12:00:58 -07:00
H. Peter Anvin
5b00bf4d49 BR3028880: Revert to nonfatal, better error message, cleanup
Revert to issuing a nonfatal error (it makes no sense to make it a
fatal error, but it probably makes sense for it to be an error instead
of a warning, especially since a lot of prior versions would crash and
apparently noone noticed.)  We might have to revisit this based on
user requirements, and/or provide a method for the user to detect an
existing environment variable (%ifenv?).

Issue a better error message, indicating the nature of the failure.

Simplify the code by just updating the string in "p".

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-07-13 11:46:37 -07:00
Cyrill Gorcunov
41c5c6c36d BR3028880: Make nonexistent environment variable being fatal error
Frank suggested to just print out an error if environment
variable is not there. Agreed.

Suggested-by: Frank Kotler <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-13 21:17:49 +04:00
Cyrill Gorcunov
385d3e9c53 BR3028880: Fix NULL dereference on nonexistent environment variable
Frank reported we hit NULL dereference on nonexistent
environment variables. Fix it by leaving empty string
in text field of such token and yielding warning.

Reported-by: Frank Kotler <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-13 21:17:24 +04:00
Cyrill Gorcunov
c6360a757b tokenize: Fix wrong string index in indirect strings
At moment of calling the nasm_skip_string the string pointer
is already incremented which makes tokenize fail on correct
indirect strings.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-13 21:17:16 +04:00
Cyrill Gorcunov
15bdc51187 preproc: Extract reading line from predefined macros from read_line
It makes read_line less complex

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-13 21:17:10 +04:00
Cyrill Gorcunov
984279b1dd BR3026808: Assign to local preprocessor variable does not work in 2.09
The commits

20a94ad7fe
29c96651de
13dbfad76b
6f5f7ef417
ddd08c3ccc

seems to do the tricks we need. Eventually
get rid of commented "case".

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-13 21:13:24 +04:00
Cyrill Gorcunov
adabc1576b preproc.c: Fix NULL deref on token pasting
In case if there is a whitespace before
'paste' token we may reach NULL dereference
in strlen since paste_head will point to
TOK_WHITESPACE. Fix it.

[test: paste.asm]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-10 02:14:24 +04:00
H. Peter Anvin
20a94ad7fe preproc: don't paste TOK_PREPROC_ID
Trying to deal with bug reports 3005117 and 3026808: don't paste after
TOK_PREPROC_ID.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-07-08 11:52:57 -07:00
H. Peter Anvin
29c96651de Revert "BR3005117: Expland local single macro before pasting tokens"
This reverts commit ec88c1beac.

Revert due to BR 3026808.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-08 08:35:32 -07:00
H. Peter Anvin
13dbfad76b Revert "expand_mmac_params: Don't forget to handle TOK_OTHER"
This reverts commit 51fd86e0fe.

Revert due to BR 3026808.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-08 08:34:41 -07:00
H. Peter Anvin
6f5f7ef417 Revert "expand_mmac_params: Expand local single macros unconditionally"
This reverts commit 1f6741fc78.

Revert due to BR 3026808.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-08 08:33:47 -07:00
H. Peter Anvin
ddd08c3ccc Revert "expand_mmac_params: Expand local single macros unconditionally"
This reverts commit 985d880c15.

Revert due to BR 3026808.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-08 08:33:14 -07:00
Cyrill Gorcunov
efb358339d preproc.c: Get rid of signed/unsigned comparison warning
We need mac->nparam being explicictly int'fied otherwise
compiler issue a warning. Note that we might have been
using unsigned int but it would break an ability to pass
negative indices.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-20 01:52:19 +04:00
Cyrill Gorcunov
985d880c15 expand_mmac_params: Expand local single macros unconditionally
Peter proposed to expand local single macros unconditionally.
This should not hurt but give us more cleaner code in result.

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-08 18:45:06 +04:00
Cyrill Gorcunov
1f6741fc78 expand_mmac_params: Expand local single macros unconditionally
Peter proposed to expand local single macros unconditionally.
This should not hurt but give us more cleaner code in result.

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-08 18:39:56 +04:00
Cyrill Gorcunov
2f40375077 expand_mmac_params_range: Simplify condition
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-05 10:47:10 +04:00
Cyrill Gorcunov
c57eb51527 preproc.c: Fix argument indices checking in parameters range
Otherwise %{-1:-1} fails.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-05 01:58:10 +04:00
Cyrill Gorcunov
c29404d7ba preproc.c: Introduce macros parameters range expansion
Introduce an ability to expand multi-line macros parameters in
a range/sequence manner.

For this purpose a special form is introduced %{x:y} which means to
expand %{x:y} to %{x},%{x+1},%{x+2},...,%{y}.

Both arguments could be negative or positive but MUST NOT be zero.

The arguments take into account possible %rotate as well.

Note that unlike the approach implemented in yasm we refer :-1 as
_last_ argument passed to a macro call, this makes possible to refer
the last element from macro via record as %{-1:-1} which could be
a convenient trick.

Also you can refer the argument in reverse order, ie it's legitime
to write %{5:4}, or even to reverse the all arguments %{-1:1}.

An example

 |
 | %macro mpar 1-*
 |     db %{1:-2}
 | %endmacro
 |
 | mpar 1,2,3,4,5,6

in result we'll get the sequence of 1,2,3,4,5

Reported-by: nasm64developer <nasm64developer@users.sf.net>
Inspired-by: Mathieu Monnier <mathieu.monnier@polytechnique.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-05 01:50:59 +04:00
Cyrill Gorcunov
ca61119a01 expand_mmac_params: Format condition
It's much easier to read aligned

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-04 22:16:54 +04:00
Cyrill Gorcunov
a731924978 nasmlib: Rename elements() macro to ARRAY_SIZE
ARRAY_SIZE is a well known name pointing out that
we're dealing with array in macro argument.

Also to be on a safe side prefix_name helper should
check the index been in bounds more precisely.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-03 23:17:21 +04:00
Cyrill Gorcunov
3b4e86b1dd preproc.c: Use list_ helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-02 20:31:53 +04:00
Cyrill Gorcunov
51fd86e0fe expand_mmac_params: Don't forget to handle TOK_OTHER
TOK_OTHER is legitime to follow TOK_PREPROC_ID so don't forget to handle it as well.

[ An addition to commit ec88c1beac ]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-02 20:31:46 +04:00
Cyrill Gorcunov
ec88c1beac BR3005117: Expland local single macro before pasting tokens
When we have switched to unified token pasting code we loose
backward compatibility. Restore it.

Note that new code MUST not expluatate this facility but rather
use paste macro %+ explicitly.

N.B. this patch is probably the candidate for revert, though
to give it a chance I commit it.

Reported-by: Alexey Dokuchaev
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-02 01:05:37 +04:00
Cyrill Gorcunov
367d59e272 expand_mmacro: Use list helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:13:57 +04:00
Cyrill Gorcunov
f32ed14ebd detoken: Use list_for_each helpers
And a few style nits.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:13:53 +04:00
Cyrill Gorcunov
ed4a805b0a expand_smacro: stylish nits
- no need to split functions even if it a bit longer
  then 80 characters, it becomes hard to read it

- initialize "thead" before "tail" is more natural

- use more simple while() instead of for() with a
  long initializer

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:13:49 +04:00
Victor van den Elzen
35eb2ea2ee preproc.c: Fix regression introduced in bebf0d215 2010-03-10 22:33:48 +01:00
Cyrill Gorcunov
f09116f445 preproc.c: Turn off rmacro,exitmacro support
We've a problem in supporting [i]rmacro, exitmacro
facilities at moment.

In a sake of not holding new NASM release any longer these
directives are just marked as being "forbidden".

This allow us to not squash much changes in current source
code base but remain on a safe side same time.

Reviewed-by: Keith Kanios <keith@kanios.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-28 12:24:20 +03:00
Cyrill Gorcunov
8e48edb68a preproc.c: Eliminate parasite comment on PP_STACKSIZE
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-17 00:11:07 +03:00
Cyrill Gorcunov
accda195a3 preproc.c: Fix tab\space mess
It's really hard to read the code which is
terribly messed in tabs\spaces. Fix it all
at once. It's dirty work but has to be done
once.

No change on binary level.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-17 00:11:01 +03:00
Cyrill Gorcunov
a327c65d28 preproc.c: Fix SIGSEV on missed %endm
In case if EOF is reached (or due to any
other case pp_cleanup is being called) we
do free "defining" macro but forgot to set
pointer to NULL itself which leads to attempt
to free memory again for this macro on further
pp_cleanup calls.
2010-02-14 17:27:10 +03:00
Cyrill Gorcunov
bebf0d2157 preproc.c: Fix NULL dereference on package absence
If package can't be retrieved we should not attempt
to dereference NULL'ed pointer which leads to segmentation
fault.

Reported-by: Serge
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-12 22:00:18 +03:00
Cyrill Gorcunov
c56d9ad350 expand_smacro: Don't search for ID in global context
The corner case is the code like

%define foo 1
%push bar
%$foo:
%pop

for which v2.07 ends up with "foo = 1" while 0.98.39
issue an error.

hpa said that ideally we may need to create a context
structure for the global context but this seems to be
too agressive for 2.08.

Based on patch from nasm64developer

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:41 +03:00
Cyrill Gorcunov
9b66d8e4c3 Use ALIGN helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:30 +03:00
Per Jessen
53252e0cc3 preproc.c: Use 16 byte offset in "flat64" stack model
The first argument passed on stack with "flat64" stack model
(stack frame with base pointer) should be pointed by
[rbp + 16].

Signed-off-by: Per Jessen <per@computer.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:22 +03:00
Cyrill Gorcunov
bd38c8f231 preproc.c: expand_smacro -- break endless loop for interminable macro recursion
Frank reported:
|
| From the "expert questions" forum comes this:
|
| ---------------------
| By: jasper_neumann
|
| How can I delegate %undef?
|
| In the example below the assembler (called with "nasm.exe -t -f rdf q.asm")
| bemoans my code, displays
|
| "q.asm:19: error: interminable macro recursion"
|
| and hangs.
|
| q.asm
| -----
| bits 32
| CPU P4
|
| %macro my_def 2
|  %xdefine %1 esp+%2
| %endmacro
|
| %macro my_undef 1
|  %undef %1
| %endmacro
|
| global check_it
| check_it:
|  my_def x,4
|  mov eax,[x]
|  my_undef x
|
|  my_def x,8
|  add eax,[x]
|  my_undef x
|  ret
|

So in case of interminable macro recursion we should break
the expansion procedure that way to not return back and start
expand macro again.

This address a part of the original problem.
Nasm64developer pointed out:
|
| Btw, after you manage to fix this recursion problem, the code
| in question still faces the same fundamental issue -- the arg
| to the my_undef invocations (i.e. x) gets expanded first; thus
| the %undef inside the macro sees esp+4 and esp+8 instead
| of x, and fails. What you'd need is a means to prevent the ex-
| pansion -- look for e.g. %# in 4.1.4 of the manual.txt which is
| attached to SF #1842438; it implements exactly that -- I once
| filed SF #829879 for this feature.
|

In turn Keith Kanios said:
|
| Anon is also correct in that we would need a special directive to instruct
| the delay of macro expansion, although I don't see this as critical or even
| high priority at the moment. The intermediate solution for this is, don't
| use indirection if it is not needed... an inline %undef should be
| sufficient.
|

Reported-by: Frank Kotler <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Keith Kanios <keith@kanios.net>
2009-11-21 11:11:29 +03:00
Keith Kanios
3c0d91f3d5 preproc.c: fix exitmacro to account for if/endif blocks 2009-10-25 13:28:03 -05:00
Cyrill Gorcunov
f66ac7deb0 preproc.c: use string helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:42:10 +04:00
Cyrill Gorcunov
10b4a18d7f preproc.c - remove redundant assignment
There is no need for tline assignment right
before it'll be assigned again in for() cycle.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-20 17:59:00 +04:00
H. Peter Anvin
dbb640b846 Drop efunc and evalfunc as input to the preprocessor
We only ever invoked the preprocessor with fixed values for efunc and
evalfunc, so call nasm_error() and evaluate() directly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-18 18:57:16 -07:00
H. Peter Anvin
89cee57ad0 preproc: style cleanups
Fix indentation, space between if and (, and prefer (foo) and (!foo)
to (foo != NULL) and (foo == NULL).

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-15 09:16:54 -04:00
H. Peter Anvin
db8f96e0e6 preproc: formatting cleanups
Fix inconsistent indentation, and legacy use of partial directives
instead of simply pp_directives[i].

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-15 09:07:29 -04:00
Keith Kanios
d37a38c359 pptok: change %rimacro to %irmacro
preproc: change PP_RIMACRO to PP_IRMACRO
nasmdoc: add entries for %[i]deftok and %[i]rmacro
2009-07-14 21:00:40 -05:00
H. Peter Anvin
cd0943e277 preproc: don't pass an enum to %s
Need to use pp_directives[directive], not the plain directive, which
is an enum.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-14 15:17:11 -04:00
H. Peter Anvin
f9c9a6717c preproc: generic solution for error on NUL characters in string
Strings returned by nasm_unquote() can contain NUL characters, which
will not be legal if then used as a C string.  Create a general
function which looks for NUL characters in the string and issues an
error if they are found.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-14 15:14:05 -04:00
H. Peter Anvin
2f55bdaaca preproc: reject NUL characters in %deftok directives
We could either error out or convert them to whitespace; this
implements the error option.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-14 15:04:04 -04:00
Keith Kanios
b83fd0b947 preproc: add %[i]deftok support
pptok: add %deftok and %ideftok preprocessor directives
2009-07-14 01:04:12 -05:00
Keith Kanios
852f1eeed5 preproc: add %exitmacro support and clean up recursive macro handling 2009-07-12 00:19:55 -05:00
Keith Kanios
093513d0bc preproc: refine appropriate handling of PP_RMACRO/PP_RIMACRO/PP_MACRO/PP_IMACRO 2009-07-11 14:48:09 -05:00
Keith Kanios
0af5ee2732 pptok: add rmacro/rimacro
preproc: revamp for use with rmacro/rimacro instead of overloading macro/imacro with optional recursion parameter
2009-07-11 14:26:34 -05:00
Keith Kanios
8059902f12 preproc: fix potential bug regarding MMacro->prev and %rep 2009-07-11 06:18:43 -05:00
Keith Kanios
891775e5ba preproc: add recursive macro expansion support 2009-07-11 06:08:54 -05:00
H. Peter Anvin
931cab64d6 preproc: revert to older form of preprocessor user error messages
When the user generates an error via %warning, %error, or %fatal,
treat is as any other error message.  The attempt at making them stand
out really looked ugly when the preprocessor adds additional tracing
information.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-07 16:06:21 -07:00
H. Peter Anvin
8287daf2a4 preproc: always reprocess smacros after %+ - pasting
We always need to process %+ at least once, but we also always need to
reprocess smacros after pasting.  The solution to this is to make sure
we always reprocess %+ after the first expansion pass.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-07 16:00:58 -07:00
H. Peter Anvin
fc30f8c736 preproc: don't handle %+ until the final phase of smacro expansion
Revert to the earlier behavior of not expanding %+ until the final
phase of smacro expansion.  However, the previous code has:

    if (expanded && paste_tokens(&thead, true)) {

... which would inhibit paste_tokens() if expanded was false on the
first iteration.  However, if expand_mmac_params is not expanding %+,
then we cannot bypass this expansion.  Thus use:

    pasted = paste_tokens(&thead, true);
    if (expanded && pasted) {

... instead.

This seems to work with both Syslinux and x264 usage, and therefore
hopefully should be compatible with earlier versions of NASM.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06 18:48:23 -07:00
H. Peter Anvin
8ee2e244eb NASM: relicense under the 2-clause BSD license
*To the best of my knowledge*, we now have authorization from everyone
who has significantly contributed to NASM in the past.  As such,
change the license to the 2-clause BSD license.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06 11:09:11 -07:00
H. Peter Anvin
a8db5089b4 Correction: preproc.c is *not* in the clear just yet.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-03 13:39:25 -07:00
H. Peter Anvin
9e6747ccac Add copyright headers to the *.c/*.h files in the main directory
Add copyright headers to the *.c/*.h files in the main directory.  For
files where I'm sure enough that we have all the approvals, I have
given them the 2-BSD license, the others have been given the "LGPL for
now" license header.  Most of them can probably be changed after
auditing.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-28 17:13:04 -07:00
H. Peter Anvin
18f48793a9 preproc: use %if 0 instead of %ifdef BOGUS
When processing an unparsable TASM argument, convert it to %if 0 which
is guaranteed to not happen, rather than %ifdef BOGUS.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 15:56:27 -07:00
H. Peter Anvin
ba7a0d0566 preproc: handle %+ even during early token replacement
Preexisting code seems to rely on %+ being processed even during early
token replacement, e.g. Syslinux contains the following code:

%macro          superb 1
bx %+ %1        equ SuperInfo+($-superblock)*8+4
bs %+ %1        equ $
                zb 1
%endmacro

... which is expected to work when invoked as:

                superb Media

As a result, set handle_paste_tokens to true at all times; assuming
this turns out to be the way things are we can really just remove it
as an option.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-05-04 10:11:22 -07:00
H. Peter Anvin
d784a083a3 preproc: unify token-pasting code
Unify the token-pasting code between the macro expansion and the
preprocessor parameter case.  Parameterize whether or not to handle %+
tokens during expansion (%+ tokens have late binding semantics.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2009-04-20 14:01:18 -07:00
H. Peter Anvin
8e1f81110a preproc: make $ and $$ TOKEN_OTHER
Recognize $ and $$ as TOKEN_OTHER; they aren't really either
TOK_NUMBER nor TOK_ID, even though we have traditionally considered
them TOK_NUMBER.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2009-04-17 14:22:49 -07:00
Victor van den Elzen
fb5f2519ad BR 2760773: $$ tokens
The tokenizer didn't handle $$, but relied on token pasting of two $ tokens.
This broke after the improvements in 9bb46df4.
2009-04-17 16:17:59 +02:00
H. Peter Anvin
6125b62403 preproc: fix more token pasting cases
"+" can be a separate token that ends up having to get pulled into the
middle of a floating-point constant.  It's not even that strange.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-08 14:02:25 -07:00
H. Peter Anvin
9bb46df4b7 Handle weird cases of token pasting
Especially when token pasting involves floating-point numbers, we can
have some really strange effects from token pasting: for example,
pasting the two tokens "xyzzy" and "1e+10" ends up with *three*
tokens: "xyzzy1e" "+" "10".  The easiest way to deal with this is to
explicitly combine the string and then run tokenize() on it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-04-07 21:59:24 -07:00
H. Peter Anvin
f8ad53216f br704736: handle deep context-local macros
The documentation says that constructs with %$...$foo can be used
to access macros from deeper in the context stack.  From what
I can tell, that has never actually worked, since we'd enter names
like %$foo into the context-local macro name table.  Instead, only
insert the tail of the macro name into the context-local table;
expand get_ctx to also return a pointer to the macro name proper;
this is rather straightforward since we'd usually save away that
name at the point get_ctx is called anyway.
2009-02-21 17:55:08 -08:00
H. Peter Anvin
ec86b6ffe3 preproc: BR 2222615: fix segfault on bogus %ifmacro
BR 2222615: Fix segmentation fault on %ifmacro without an argument.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-11-04 14:24:34 -08:00
H. Peter Anvin
67c637236a preproc: merge expand_mmac_params() and expand_indirect()
These two really need to be done together, in order for constructs
such as %[%1] to work properly.  Furthermore, fix a token-pasting bug
in expand_mmac_params().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-26 23:49:00 -07:00
H. Peter Anvin
264b7b982c preproc: don't macro-expand the argument to %use
Use expand_id() for the argument to %use, instead of expand_smacro().
This really makes more sense for a "naked" argument.  This is a
semantic change, but is unlikely to break any real code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-24 16:38:17 -07:00
H. Peter Anvin
42b5639664 preproc: allow %pop to take an identifier, unify %push/%repl/%pop
Allow the %pop directive to take an identifier (an assert on the
context name); unify the parsing parts of %push, %repl,  and %pop.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-24 16:24:21 -07:00
H. Peter Anvin
49b33f398e preproc: fix terminal token pasting in indirect sequences
Fix the case where the terminal token pastes with the first token of
the unmodified sequence.  This is a really ugly version; we need to
merge the two instances plus the one in expand_mmac_params().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-19 22:22:05 -07:00
H. Peter Anvin
e126581f4d preproc: error on unterminated %[...]
Make unterminated %[...] constructs an error.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-19 22:14:30 -07:00
H. Peter Anvin
ec03301eb4 preproc: fix exit conditions for indirection loop
When locating the end of a %[...] construct, we need to end up with
the pointer pointing to the terminating character.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-19 22:13:34 -07:00
H. Peter Anvin
ca544db4b6 preproc: correctly handle quoted strings inside %[...] constructs
We need to skip quoted strings when determining the ending point of
%[...] constructs.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-19 19:30:11 -07:00
H. Peter Anvin
c0ab1cd15a preproc: fix list iteration in the case of expand_indirect()
Linked lists where an element may be deleted or substituted during
processing can be subtle to deal with.  Fix the iteration conditions
in this particular case.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-19 16:24:53 -07:00
H. Peter Anvin
992fe7591d preproc: Add new %[...] indirection construct
Add a new %[...] construct to support indirect macro expansion.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-19 15:45:05 -07:00
Victor van den Elzen
4c9d6220b4 Apply patch from BR 890790 2008-10-01 13:09:27 +02:00
H. Peter Anvin
2f16043879 Allow %warning output to be suppressed
Allow the user to suppress user-specified warnings.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-30 16:39:17 -07:00
H. Peter Anvin
61f130f4e9 Set __PASS__ to 3 for preprocess only
When running the preprocessor only, set __PASS__ to 3.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-25 15:45:06 -07:00
H. Peter Anvin
7383b407d9 Add __PASS__ builtin macro
Add a new builtin macro, __PASS__, which is either 1 (for a
preparatory pass), 2 (for a final pass, including preprocessor only),
or 0 (for dependency generation.)  This might be useful in special
contexts.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-24 10:20:40 -07:00
H. Peter Anvin
917a3496f0 Unbreak %warning
Since the error directives, including %warning, are now issued in the
final pass only, it is important that we do *not* pass ERR_PASS1 with
%warning.  Rather than playing even more ugly games in error(),
require ERR_PASS1 to be passed in with warnings elsewhere in the
preprocessor, just like the rest of the system.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-24 09:14:49 -07:00
H. Peter Anvin
8e3f75ea6e %error, %warning out on the final pass, add %fatal
Only process %error or %warning directives on the final pass.  Add a
new %fatal directive which terminates assembly immediately.
2008-09-24 00:21:58 -07:00
Victor van den Elzen
3b404c0f6b BR 1239818 - handle multiple %else clauses
Using multiple %else clauses or mixing %else and %elif
caused strange results.
Warn about it and produce sensible results.
2008-09-18 13:51:36 +02:00
H. Peter Anvin
91fb6f1626 BR 2048950: fix crash due to mmacro list overflow
When allocating the buffer for an mmacro list, we apparently failed to
guarantee space for the terminating NULL.  This almost certainly
caused the crash described in BR 2048950, and quite possibly BR
1284169.
2008-09-01 10:56:33 -07:00
Victor van den Elzen
22343c2c72 Add macro-defaults warning class and documentation. 2008-08-06 14:48:55 +02:00
H. Peter Anvin
932de6c252 BR 2034542: fix crash when touching __FILE__
Touching __FILE__ would cause a dereference of an uninitialized
pointer.  Fix.
2008-07-31 18:46:11 -07:00
H. Peter Anvin
ca348b6343 preproc: restore correct break; in do_directive()
Checkin a26433db68 incorrectly changed a
few break;s in do_directive() that were *inside loops* to returns.
This broke single-line macros as well as %exitrep; fix.
2008-07-23 10:52:43 -04:00
Victor van den Elzen
b916edecf4 BR 560960: warn about trailing garbage in %macro/%ifmacro 2008-07-23 15:14:22 +02:00
Victor van den Elzen
0e857f1fe5 Improve checking and documentation for %ifctx 2008-07-23 13:21:29 +02:00
H. Peter Anvin
a70547f3ae Avoid redundant "const" for macros_t
Don't use a redundant "const" for macros_t (which is const unsigned
char), since OpenWatcom doesn't like it, and I believe it is incorrect
per the C standard.
2008-07-19 21:44:26 -07:00
H. Peter Anvin
a26433db68 preproc: add %un[i]macro, add cleanups
Add %un[i]macro, and a few stylistic cleanups.

Note: unlike %undef, %un[i]macro takes an argument specification,
which must *exactly* match the macro being undefined.  Similarly,
%unimacro has to be used to undefine a macro defined with %imacro, and
vice versa.
2008-07-16 14:40:01 -07:00
H. Peter Anvin
90e6e811c9 preproc.c: fix %ifn, %elifn
The sense of %ifn and %elifn was reversed due to a bogus nonstandard
return sequence.
2008-07-16 14:38:24 -07:00
Victor van den Elzen
8f1120ff47 Fix %rep ... %endmacro crash
Also improved a comment and an error message.
2008-07-16 13:41:37 +02:00
H. Peter Anvin
97b6d5b676 preproc.c: make %warning actually issue a warning...
The calculation of "severity" was buggered up, with the result that
%warning actually issued an error.
2008-07-13 15:05:53 -07:00
Charles Crayne
d4200bed8e %EXITREP inside nested %REPs
Apply updated version of fix submitted with feature request 803785.
This fix causes %exitrep to terminate only the innermost %rep block,
and also allows the count for nested blocks to be calculated in the
containing block.
2008-07-12 16:42:33 -07:00
H. Peter Anvin
11dfa1a5a5 preproc: Allow anonymous contexts
Allow %push and %repl without a context name.  For a lot of uses, it
is only a potential source of namespace pollution.
2008-07-02 18:11:04 -07:00
H. Peter Anvin
accf43334d Permit commas in %strcat 2008-07-01 21:42:08 -07:00
H. Peter Anvin
f26e097304 preproc: %strcat directive to concatenate quoted strings
I noticed there was no sane way to concatenate the contents of quoted
strings, so add the %strcat directive.

These really need to become preprocessor functions at some stage.
2008-07-01 21:26:27 -07:00
H. Peter Anvin
538002dc01 preproc: MMacro.finishes is a pointer, not a boolean
MMacro.finishes is a pointer, not a boolean, so set it to "false", not
"NULL".
2008-06-28 18:30:27 -07:00
H. Peter Anvin
7e50d232ba Make the macros table "unsigned char"
It gets less ugly if we make the macros table "unsigned char".
2008-06-25 14:54:14 -07:00
H. Peter Anvin
cda816306d Drop the index tables from the canned macros
Instead of an array of strings, just have a character array; that
reduces the size of canned macros by up to 30%, and we only did
sequential access anyway.
2008-06-21 15:15:40 -07:00
H. Peter Anvin
f221b9ee08 Fix a few more <ctype.h> instances
A few isolated instances of isalpha() and isxdigit().
2008-06-21 11:03:51 -07:00
H. Peter Anvin
bda7a6e371 ctype.h: wrapper ctype functions with a cast to (unsigned char)
ctype functions take an *int*, which the user is expected to have
taken the input character from getc() and friends, or taken a
character and cast it to (unsigned char).

We don't care about EOF (-1), so use macros that cast to (unsigned
char) for us.
2008-06-21 10:23:17 -07:00
H. Peter Anvin
86877b294a preproc: free the include path and the final filename
Memory leaks: free the include path, and the final used filename.
2008-06-20 15:55:45 -07:00
H. Peter Anvin
cfb7176ca2 Move the output format macros into the macros.pl mechanism
Move the handling of "extra" macros (i.e. output format macros) into
the macros.pl mechanism.  This allows us to change the format of the
internal macro store in the future - e.g. to a single byte store
without redundant pointers.

Also, stop using indicies into a long array when there is no good
reason to not just use different arrays.
2008-06-20 15:20:16 -07:00
H. Peter Anvin
b2a5fda157 Somewhat more clever way to generate the %use guard macros
Automatically generate a %define as the first string in the include
block, and just pick the string out of it from that %define statement
to verify existence.  That way we eliminate any use of toupper() --
all case-insensitivity in NASM uses tolower()/nasm_tolower().
2008-06-19 21:42:42 -07:00
H. Peter Anvin
f4ae5ad11b Protect %use from multi-inclusion and provide a test macro
Automatically provide an include guard for %use packages; the macro
__USE_package__ is automatically defined, and inclusion is suppressed
if it is already defined.
2008-06-19 18:39:24 -07:00
H. Peter Anvin
926fc40b65 %use: call these directives "standard macro packages"
Adopt the term "standard macro packages", "modules" are too
ambiguous.
2008-06-19 16:26:12 -07:00
H. Peter Anvin
72edbb87ef macros.c: compress by tokenizing macro directives
Compress macros.c by representing macro directives with a single byte.
We can do this because we only use the ASCII character range inside
the standard macro files.

Note: we could save significant additional space by not having a
pointer array, and instead relying on the fact that we sweep
sequentially through the output array.
2008-06-19 16:00:04 -07:00
H. Peter Anvin
d2456590fc preproc: add support for builtin include modules (%use)
Add a builtin equivalent to the %include directive called %use.
%use includes a standard macro file compiled into the binary; these
come from the macros/ directory in the source code.

The idea here is to be able to provide optional macro packages with
the distribution, without adding complex host filesystem dependencies.
2008-06-19 15:04:18 -07:00
H. Peter Anvin
ac8f8fcb27 Use an explicit table for tolower() to avoid a function call
On some platforms, tolower() is implemented as a function call, in
order to handle locale support.  We never change locales, so can the
result of tolower() into a table, so we don't have to sit through the
function call every time.

~1.3% overall performance improvement on a macro-heavy benchmark under
Linux x86-64.
2008-06-11 15:49:41 -07:00
H. Peter Anvin
7b471fada8 Remove expand_macros_in_string()
Remove the now-unused expand_macros_in_string() function.
2008-06-10 18:29:11 -07:00
H. Peter Anvin
7df0417e58 Add %warning, saner unquoting of %error
- Add %warning directive
- Only unquote an %error or %warning string if it is the only thing on
  the directive line.
- Don't expand macros inside a quoted string, even for %error.
2008-06-10 18:27:38 -07:00
H. Peter Anvin
11627049ae Make strings a first-class token type; defer evaluation
Make strings a proper, first-class token type, instead of relying on
the "TOKEN_NUM with tv_charptr" hack.  Only convert a string to a
number if requested in an expression context; this also makes it
possible to actually issue a warning when it overflows.
2008-06-09 20:45:19 -07:00
H. Peter Anvin
c751e86145 Fix %? in multi-line macros with a label
The handling of %? in multi-line macros was broken when the macro name
was preceeded by a label; it would expand to the label instead of the
macro name.  This was particularly serious since this was used in
the macro implementation of INCBIN.
2008-06-09 10:18:45 -07:00
H. Peter Anvin
2b1c3b9527 Fix dependency list generation
The dependency list tail pointer wasn't actually updated correctly.
Fix that.  We may want to make this a structure of some sort to make
the code a bit cleaner, but this seems to be the cleanest hack for
now.
2008-06-06 10:38:46 -07:00
H. Peter Anvin
9e20016eda Add %defstr, %idefstr
Add %defstr and %idefstr, to define a macro as a quoted string.
2008-06-04 17:23:14 -07:00
H. Peter Anvin
f2936d729f Fix double free in %depend 2008-06-04 15:11:23 -07:00
H. Peter Anvin
88c9e1f88c Fix memory management issues with expanded %include
Ownership of the filename string was a bit fuzzy, with the result that
we were freeing it even though it was retained for use by __FILE__.
Clean up a number of other memory management issues with the new
quoting code, and change the stdscan implementation to one pass over
the string.
2008-06-04 11:26:59 -07:00
H. Peter Anvin
427cc912f8 qstring: fix unquoting in %pathsearch directive
%pathsearch unquoting should be done on the "t" token, not on the
"tline" token...
2008-06-01 21:43:03 -07:00
H. Peter Anvin
6ecc159a54 qstring: backquoted strings seem to work now...
Hopefully backquoted strings should work correctly now.
2008-06-01 21:34:49 -07:00
H. Peter Anvin
8cad14bbcf qstring: first cut at full quoted string support in the preprocessor
First attempt at properly handle quoted strings in the preprocessor.
This also adds range support in %substr.

No support in the assembler yet.
2008-06-01 17:23:51 -07:00
H. Peter Anvin
418ca70d4e Introduce %depend and %pathsearch, and make incbin a macro
Introduce new preprocessor directives %depend and %pathsearch, and
make incbin a standard macro using these filenames.  This lets us
remove the code that makes incbin search the path.
2008-05-30 10:42:30 -07:00
H. Peter Anvin
477f2e5fa9 preproc.c: %include: use expand_smacros() not expand_smacros_in_string()
Call expand_smacros() early instead of expand_smacros_in_string()
late.  expand_smacros_in_string() seems like a prodigiously bad idea
and a sheer brainfart in my opinion.
2008-05-30 10:09:45 -07:00
H. Peter Anvin
9e1f528c36 Add the -MP option to emit phony targets
Add the -MP option to emit phony targets.  Since this means each
header file has to be visited more than once, change the
implementation to use an internal list of all the dependencies, and
centralize the emission of the dependency files.
2008-05-29 21:38:00 -07:00
H. Peter Anvin
07b7b9e15e Implement -MD, -MF, -MT, -MQ
Implement the dependency options:

-MF: set the file to which dependencies are written.
-MD: generate dependencies in parallel with compilation.
-MT: set the name of the dependency target.
-MQ: same as -MT, but *attempt* to quote it for Makefile safety.
2008-05-29 19:09:11 -07:00
H. Peter Anvin
b037a67e68 preproc.c: get_ctx() can return NULL...
Handle the case where we would attempt to look up a possible local
context just to find that one doesn't exist.
2008-05-29 19:08:08 -07:00
H. Peter Anvin
166c247f36 hash user allocates struct hash_table
struct hash_table, a fixed-sized structure, is now allocated by the
caller.  This lets us integrate it into the Context structure, thus
avoiding an additional dynamically allocated object for no good
reason.

Add some minor code collapsing: make it more obvious that all that
differs is a pointer value, rather than relying on the compiler to do
tail merging.
2008-05-28 12:28:58 -07:00
H. Peter Anvin
5b76fa26c9 preproc.c: prevent the compiler from reducing enum pp_token_type
The compiler is free to store enum pp_token_type into any size integer
small enough to contain all the values up to 2^n-1 for the smallest n
which contains all the values.  Force it to size it to integer size,
since we use it to hold macro positional parameters.
2008-05-26 11:14:38 -07:00
H. Peter Anvin
ce2233bb9f Implement %? and %?? for mmacros
Same as before, but for mmacros this time
2008-05-25 21:57:00 -07:00
H. Peter Anvin
6c81f0a390 Implement %? and %?? for smacros
%?	- substitute the macro name as invoked
%??	- substitute the macro name as defined

In particular:

%idefine keyword $%?

... can be used to make a new keyword "disappear".
2008-05-25 21:46:17 -07:00
H. Peter Anvin
072771e4a5 Use hash tables even for context-sensitive macros
Normally, contexts aren't used with a large number of macros, but in
case someone does, do use hash tables for those as well.  This
simplifies the code somewhat, since *all* handling of macros is now
done via hash tables.

Future note: consider if it wouldn't be better to allow struct
hash_table to be allocated by the caller, instead of being allocated
by the hash table routine.
2008-05-22 13:17:51 -07:00
Philipp Thomas
76ec8e73db Fix buffer overflow in preproc.c (BR 1942146)
Fix buffer overflow in preproc.c due to an incorrect test.  In the
code:

        for (r = p, s = ourcopy; *r; r++) {
	    if (r >= p+MAX_KEYWORD)
	    	return tokval->t_type = TOKEN_ID; /* Not a keyword */
            *s++ = tolower(*r);
	    }
        *s = '\0';

... the test really needs to be >= since for the pass where there are
equal:

a) a nonzero byte means we have > MAX_KEYWORD characters, and
b) s = ourcopy+MAX_KEYWORD; but if the test doesn't trigger,
   we can write one more character *plus* the null byte, overflowing
   ourcopy.
2008-05-21 08:53:21 -07:00
H. Peter Anvin
a4835d466c Avoid #including .c files; instead compile as separate units
Don't #include .c files, even if they are auto-generated; instead
compile them as separate compilation units and let the linker do its
job.
2008-05-20 14:21:29 -07:00
H. Peter Anvin
dfb918047b Add DY, YWORD, and the SY instruction flag
Add the DY instruction, YWORD keyword, and an SY marker for
instruction sizes.  Add a few more AVX sample instructions.
2008-05-20 11:43:53 -07:00
H. Peter Anvin
d85d250fa2 First cut at AVX machinery.
First cut at AVX machinery support.  The only instruction implemented
is VPERMIL2PS, and it's probably buggy.  I'm checking this in with the
hope that other people can start helping out with (a) testing this,
and (b) adding instructions.

NDISASM support is not there yet.
2008-05-04 17:53:31 -07:00
H. Peter Anvin
134b94665d Add %ifempty and variants 2008-02-16 17:01:40 -08:00
H. Peter Anvin
cbf768d67d Implement %iftoken, test for a single token
Implement %iftoken, a test for a single token.  This is useful in
cases using %+ to splice a macro-provided token.
2008-02-16 16:41:25 -08:00
H. Peter Anvin
188ce76c46 Constipate the stdmac[] array. 2008-02-16 13:58:45 -08:00
H. Peter Anvin
927c92b478 BR 1582430: Allow numbers with leading + or - for %ifnum
Allow numbers with a leading + or - to return true for %ifnum.
2008-02-16 13:44:52 -08:00
H. Peter Anvin
b4daadc0d8 preproc.c: simplify detoken() slightly
Probably pointless optimization of detoken()...
2008-01-21 16:31:57 -08:00
Beroset
095e6a2973 regularized spelling of license to match name of LICENSE file 2007-12-29 09:44:23 -05:00
H. Peter Anvin
7061ad73fe BR 852464: Fix memory leak in %if/%elseif 2007-11-26 22:03:53 -08:00
H. Peter Anvin
2a15e69ebe Slightly faster implementation of the deadman counter
Count down to zero instead of up to a constant...
2007-11-19 13:14:59 -08:00
H. Peter Anvin
cb1cf59312 BR 812417: Deadman counter for macro expansion
Per BR 812417, certain macro expansions can hang NASM.  Allow a
deadman counter (currently set to 2^20) to fail out if it gets
ridiculous.
2007-11-19 12:26:50 -08:00
Charles Crayne
7eaf919a22 Add flat64 to %stacksize choices 2007-11-08 22:11:14 -08:00
H. Peter Anvin
8781cb0d00 BR 1828103: Fix %arg and %local
Correct the implementation of %arg and %local.

It's questionable how much they make sense for 64-bit mode; even in
32-bit mode one normally make references off the stack pointer instead
of the base pointer (frame pointer), but that requires keeping track
of the stack pointer offset.
2007-11-08 20:01:11 -08:00
H. Peter Anvin
c2df282092 Fix the handling of floating-point tokens in the preprocessor
Correct the handling of floating-point tokens in the preprocessor.
The preprocessor scanner and the main scanner really are painfully
divergent for no good reason.
2007-10-24 15:29:51 -07:00
H. Peter Anvin
7065309739 Formatting: kill off "stealth whitespace"
"Stealth whitespace" makes it harder to read diffs, and just generally
cause unwanted weirdness.  Do a source-wide pass to get rid of it.
2007-10-19 14:42:29 -07:00