Commit Graph

137 Commits

Author SHA1 Message Date
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