summaryrefslogtreecommitdiff
path: root/preproc.c
Commit message (Collapse)AuthorAgeFilesLines
* preproc.c: Restore concat rules on context local variablesCyrill Gorcunov2010-10-271-89/+95
| | | | | | | | | This is a backport of commits 8dcbbd7af0d6d07b455de0b6460dca6db6113553 575d4289c9b1fb47774cb79764a24899a69a8d52 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc: Issue warning on unterminated %{ constructCyrill Gorcunov2010-10-271-1/+5
| | | | | | | | | | | | | | | As being pointed by "matching braces" topic on [ http://forum.nasm.us/index.php?topic=905.0 ] we don't issue warning on missed match for "{" brace opened. Strictly speaking we should issue error instead and force user to fix asm source code but since it's here for a long time already -- lets be "admissive". Reported-by: Klod CC: Frank Kotler <fbkotler@zytor.com> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3074517: Print %macro name inside %rep blocksCyrill Gorcunov2010-10-271-3/+13
| | | | | | | | If we're to print inside %rep block we should find out which %macro it belongs. Reported-by: Rob Neff Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3066383: Restore backward compatibility with token pastingCyrill Gorcunov2010-09-181-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It seems to be a bit long story for the reason if this bug. But lets be verbose and describe all byte-to-byte. And it is all about preprocessor code, in particular paste_tokens and expand_mmac_params. Initially the problem (not the same but similar) was noticed and fixed in commit ec88c1be. The problem reveals itself with code snippets like | %macro m 1 | %push | %define %$arg %1 | %%top_%$arg: | resb ($ - %%top_%$arg) | %pop | %endmacro So with commits ec88c1be, 51fd86e0, 1f6741fc, 985d880c we did expand local single macro before processing tokens pasting unconditionally. But then it being found that such approach breaks %assign directive. The snippets like below didn't work | %macro m 1 | %push | %assign %$arg %1 | %assign %$arg %1+%$arg | %pop | %endmacro So all these commits were reverted and we just stop pasting tokens in paste_tokens() after TOK_PREPROC_ID (commit 20a94ad7). Unfortunately this breaks %assign with compound preproc id | %macro m3 1 | %push | %assign %$_uses 0 | %rep 4 | %assign %$_ur%$_uses %$_uses | mov ecx, %$_ur%$_uses | %assign %$_uses %$_uses+1 | %endrep | %pop | %endmacro To fix this bug we have to combine two approaches at once, we should continue pasting after TOK_PREPROC_ID and expand sequential TOK_PREPROC_IDs except first one. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3064459: Missing %endif doesn't always cause errorCyrill Gorcunov2010-09-151-3/+5
| | | | | | | | error() routine is conditional dependent so we should use nasm_error instead to yield message unconditionally. Reported-by: Christian Masloch Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc: reverse the order of the tokens in %deftokH. Peter Anvin2010-09-151-1/+24
| | | | | | | Smacros are apparently stored with the token stream reversed, so make sure %deftok matches that sense of relatity. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc.c: Make %substr robustCyrill Gorcunov2010-09-071-4/+5
| | | | | | | | Make %substr robust to handle -1,-1 parameters and restore old behavior when number of characters in substring is greater then length of string itself. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Handle %substr invalid parameters preventing NULL dereferenceCyrill Gorcunov2010-09-071-9/+14
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Fix NULL dereferences on %substr missing operandsCyrill Gorcunov2010-09-071-2/+3
| | | | | | %substr with dangling id issues SIGSEV. Fix it. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3060469: Fix SIGSEV on missed %deftok second parameterCyrill Gorcunov2010-09-061-1/+1
| | | | | | | | In case if a second parameter of %deftok is missed we hit NULL dereference. Fix it. Reported-by: Christian Masloch Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: revamped context-local fall-through warning messageKeith Kanios2010-08-141-5/+6
|
* preproc.c: Context-through single macros expansion is deprecatedCyrill Gorcunov2010-08-111-10/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | For now we inform users about their sources need to be updated and also since _all_ context case are legit for single macros only we split lookup into two phases: 1) Lookup in active context, which is perfectly valid 2) Lookup in external contexts, which will be deprecated soon. If (2) happens we yield warning. A typical testcase is --- %macro one 0 %push %$a: %assign %$b 12 %push mov eax, %$a mov eax, %$b ; hit -- context through %pop %pop %endmacro one --- Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: modified deprecation warning for context-local label fallthroughKeith Kanios2010-08-101-8/+9
|
* preproc.c: Fix error message typoCyrill Gorcunov2010-08-091-1/+1
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3041451: Implement upper bound for %rep counterCyrill Gorcunov2010-08-091-1/+9
| | | | | | | | | | Since %rep counter is a 64 bit signed integer we have to use some "maximum possible value" limit (upper bound) otherwise there may be a situation when %rep counter is 0 or even negative while user has been passing big positive integer value. Reported-by: nasm64developer Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: added deprecation warning for context-local label fallthroughKeith Kanios2010-08-091-1/+7
|
* preproc.: Fix NULL dereference on broken %strlen argumentCyrill Gorcunov2010-07-231-1/+1
| | | | | | | | | Under particular circumstances %strlen may cause SIGSEG. A typical example is %strlen with nonexistent macro argument. [ Testcase test/strlen.asm ] Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc: allow non-identifier character in environment variablesH. Peter Anvin2010-07-201-28/+68
| | | | | | | | Allow non-identifier characters in the name of environment variables, by surrounding them with string quotes (subject to ordinary string-quoting rules.) Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* preproc: add %ifenvH. Peter Anvin2010-07-131-0/+21
| | | | | | | 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>
* BR3028880: Revert to nonfatal, better error message, cleanupH. Peter Anvin2010-07-131-4/+6
| | | | | | | | | | | | | | | 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>
* BR3028880: Make nonexistent environment variable being fatal errorCyrill Gorcunov2010-07-131-5/+3
| | | | | | | | 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>
* BR3028880: Fix NULL dereference on nonexistent environment variableCyrill Gorcunov2010-07-131-4/+7
| | | | | | | | | 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>
* tokenize: Fix wrong string index in indirect stringsCyrill Gorcunov2010-07-131-1/+1
| | | | | | | | 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>
* preproc: Extract reading line from predefined macros from read_lineCyrill Gorcunov2010-07-131-60/+83
| | | | | | It makes read_line less complex Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3026808: Assign to local preprocessor variable does not work in 2.09Cyrill Gorcunov2010-07-131-1/+0
| | | | | | | | | | | | | | | The commits 20a94ad7fe41c82f77fb670abb68f0de40d2b3e5 29c96651de1c43e59b7db58a4f06ff21dc854125 13dbfad76b4d3dbf27ef41761873584c6bd9fd7f 6f5f7ef417c37c154d10c2b3813808ad3fa65fd7 ddd08c3cccb4b68ecdb24d7a92eab6b2b82e8c68 seems to do the tricks we need. Eventually get rid of commented "case". Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: Fix NULL deref on token pastingCyrill Gorcunov2010-07-101-1/+3
| | | | | | | | | | | 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>
* preproc: don't paste TOK_PREPROC_IDH. Peter Anvin2010-07-081-1/+1
| | | | | | | 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>
* Revert "BR3005117: Expland local single macro before pasting tokens"H. Peter Anvin2010-07-081-26/+0
| | | | | | | | This reverts commit ec88c1beac003bd6660037da3cef3aebeee7af20. Revert due to BR 3026808. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Revert "expand_mmac_params: Don't forget to handle TOK_OTHER"H. Peter Anvin2010-07-081-2/+1
| | | | | | | | This reverts commit 51fd86e0fed8f5162f8c1e45e4ceaf237d6e5539. Revert due to BR 3026808. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Revert "expand_mmac_params: Expand local single macros unconditionally"H. Peter Anvin2010-07-081-1/+6
| | | | | | | | This reverts commit 1f6741fc78413236816c42d26b34134ab18ba4f1. Revert due to BR 3026808. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Revert "expand_mmac_params: Expand local single macros unconditionally"H. Peter Anvin2010-07-081-1/+8
| | | | | | | | This reverts commit 985d880c15a5b26e59cdcec4af2eba0748ecfe1f. Revert due to BR 3026808. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc.c: Get rid of signed/unsigned comparison warningCyrill Gorcunov2010-06-201-2/+2
| | | | | | | | | 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>
* expand_mmac_params: Expand local single macros unconditionallyCyrill Gorcunov2010-06-081-8/+1
| | | | | | | | 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>
* expand_mmac_params: Expand local single macros unconditionallyCyrill Gorcunov2010-06-081-6/+1
| | | | | | | | 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>
* expand_mmac_params_range: Simplify conditionCyrill Gorcunov2010-06-051-4/+2
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: Fix argument indices checking in parameters rangeCyrill Gorcunov2010-06-051-2/+4
| | | | | | Otherwise %{-1:-1} fails. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: Introduce macros parameters range expansionCyrill Gorcunov2010-06-051-77/+164
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* expand_mmac_params: Format conditionCyrill Gorcunov2010-06-041-3/+3
| | | | | | It's much easier to read aligned Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasmlib: Rename elements() macro to ARRAY_SIZECyrill Gorcunov2010-06-031-3/+3
| | | | | | | | | | 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>
* preproc.c: Use list_ helpersCyrill Gorcunov2010-06-021-33/+23
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* expand_mmac_params: Don't forget to handle TOK_OTHERCyrill Gorcunov2010-06-021-1/+2
| | | | | | | | TOK_OTHER is legitime to follow TOK_PREPROC_ID so don't forget to handle it as well. [ An addition to commit ec88c1beac00 ] Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3005117: Expland local single macro before pasting tokensCyrill Gorcunov2010-06-021-0/+26
| | | | | | | | | | | | | | 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>
* expand_mmacro: Use list helpersCyrill Gorcunov2010-04-101-2/+2
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* detoken: Use list_for_each helpersCyrill Gorcunov2010-04-101-7/+8
| | | | | | And a few style nits. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* expand_smacro: stylish nitsCyrill Gorcunov2010-04-101-16/+10
| | | | | | | | | | | | - 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>
* preproc.c: Fix regression introduced in bebf0d215Victor van den Elzen2010-03-101-1/+1
|
* preproc.c: Turn off rmacro,exitmacro supportCyrill Gorcunov2010-02-281-0/+11
| | | | | | | | | | | | | | 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>
* preproc.c: Eliminate parasite comment on PP_STACKSIZECyrill Gorcunov2010-02-171-3/+0
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: Fix tab\space messCyrill Gorcunov2010-02-171-1076/+1088
| | | | | | | | | | | 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>
* preproc.c: Fix SIGSEV on missed %endmCyrill Gorcunov2010-02-141-0/+1
| | | | | | | | | 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.