summaryrefslogtreecommitdiff
path: root/preproc.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* preproc.c: Fix NULL dereference on package absenceCyrill Gorcunov2010-02-121-4/+4
| | | | | | | | | 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>
* expand_smacro: Don't search for ID in global contextCyrill Gorcunov2010-02-111-6/+6
| | | | | | | | | | | | | | | | | | | | 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>
* Use ALIGN helperCyrill Gorcunov2010-02-111-2/+2
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c: Use 16 byte offset in "flat64" stack modelPer Jessen2010-02-111-1/+1
| | | | | | | | | 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>
* preproc.c: expand_smacro -- break endless loop for interminable macro recursionCyrill Gorcunov2009-11-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* preproc.c: fix exitmacro to account for if/endif blocksKeith Kanios2009-10-251-3/+21
|
* preproc.c: use string helpersCyrill Gorcunov2009-10-131-10/+5
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* preproc.c - remove redundant assignmentCyrill Gorcunov2009-07-201-1/+0
| | | | | | | 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>
* Drop efunc and evalfunc as input to the preprocessorH. Peter Anvin2009-07-181-9/+4
| | | | | | | 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>
* preproc: style cleanupsH. Peter Anvin2009-07-151-204/+203
| | | | | | | 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>