Commit Graph

103 Commits

Author SHA1 Message Date
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
Charles Crayne
192d5b5e9c Suppress a few signedness warnings 2007-10-18 19:02:42 -07:00
Keith Kanios
a5fc6467ab Fix 32-bit types in preproc.c and eval.c
Fix 32-bit types in preproc.c and eval.c that should have been 64-bit
types.  This allows %assign to work correctly with 64-bit integers.
2007-10-13 07:09:22 -07:00
H. Peter Anvin
4db5a16128 preproc.c: move smacro define/undef to separate functions
Instead of tons of replicated code, move smacro define/undef into
separate static functions.
2007-10-11 13:42:09 -07:00
H. Peter Anvin
95e7f957f2 preproc.c: PP_DEFINE and PP_XDEFINE are case-sensitive
The statement for case-sensitivity had PP_DEFINE and PP_IXDEFINE,
rather than PP_XDEFINE.
2007-10-11 13:38:38 -07:00
H. Peter Anvin
4bc9f1de73 preproc.c: normalize the handling of case sensitivity
Fix a bug relating to case sensitivity, and make remaining code more
similar.
2007-10-11 12:52:03 -07:00
H. Peter Anvin
f8ba53eb2a preproc.c: allow 64-bit repeat counts
Allow the count of %rep to exceed 2^31.
2007-10-11 10:11:57 -07:00
H. Peter Anvin
16ed438e71 preproc.c: For an SMacro, in_progress really is a boolean (no %rep) 2007-10-11 10:06:19 -07:00
H. Peter Anvin
70055964fc Additional uses of bool and enum
Proper use of bool and enum makes code easier to debug.  Do more of
it.  In particular, we really should stomp out any residual uses of
magic constants that aren't enums or, in some cases, even #defines.
2007-10-11 00:05:57 -07:00
H. Peter Anvin
54901e1785 preproc.c: MMacro.in_progress is not a boolean
Per the comment:

 * In a MMacro describing a `%rep' block, the `in_progress' field
 * isn't merely boolean, but gives the number of repeats left to
 * run.

This fixes the "global" directive not getting recognized, since it
repeats over all its arguments.
2007-10-11 00:05:57 -07:00
H. Peter Anvin
6867acc18e Use the compiler-provided booleans if available, otherwise emulate
Both C and C++ have "bool", "true" and "false" in lower case; C
requires <stdbool.h> for this, in C++ it is an inherent type built
into the compiler.  Use those instead of the old macros; emulate with
a simple typedef enum if unavailable.
2007-10-10 14:58:45 -07:00
H. Peter Anvin
476d2864b0 preproc.c: constipation
Add "const" in suitable places
2007-10-02 22:04:15 -07:00