summaryrefslogtreecommitdiff
path: root/nasmlib.c
AgeCommit message (Collapse)AuthorFilesLines
2010-06-03nasmlib: Rename elements() macro to ARRAY_SIZECyrill Gorcunov1-1/+1
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-04-11nasmlib.c: Make nasm_opt_val robustCyrill Gorcunov1-15/+34
nasm_opt_val should be able handle various text stream passed, including tainted ones. Make it so. Also it fixes the case when Elf section has multiple attributes such as "progbits align=16" and friends (introduced by commit bb0745f). The former just ignore any other options/values except first one. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-11nasmlib.c: Introduce nasm_get_word helperCyrill Gorcunov1-0/+21
For easier space separated words extraction from a text stream. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10nasmlib: Do not hang on if log file creation has been failedCyrill Gorcunov1-2/+7
In case if we can't open "malloc.log" for writing we should not hang out but rather switch to stderr and continue processing. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10nasmlib: Introduce nasm_trim_spaces and nasm_opt_val helpersCyrill Gorcunov1-0/+35
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-01-24nasmlib.c: Use UINT64_C for 64bit constantsCyrill Gorcunov1-2/+2
In a sake of portability we should better use UINT64_C instead of open-coded ULL postfix. [ BR2938449 ] Reported-by: Alexander Ilyin <dragity@mail.ru> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31nasmlib: Introduce idata_bytes helperCyrill Gorcunov1-0/+38
This allow us to eliminate code duplication Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13nasm: rename nasm_zap_spaces() to nasm_zap_spaces_fwd()H. Peter Anvin1-1/+1
By analogy with nasm_zap_spaces_rev() have nasm_zap_spaces_fwd(). The forward version isn't a super-common operation, and it might be possible to think the reverse one is the "normal" version... therefore we might as well be explicit. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-10-13nasmlib: introduce string helpersCyrill Gorcunov1-0/+36
To make code more compact we introduce the following string helpers: 1) nasm_scip_spaces - skip leading spaces 2) nasm_skip_word - skip leading non-spaces 3) nasm_zap_spaces - zap leading spaces with zero 4) nasm_zap_spaces_rev - zap spaces in reverse order Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-18Remove function pointers in output, simplify error handlingH. Peter Anvin1-21/+32
Remove a bunch of function pointers in the output stage; they are never changed and don't add any value. Also make "ofile" a global variable and let the backend use it directly. All we ever did with these variables were stashing it in locals and using them as-is anyway for no benefit. Also change the global error function, nasm_error() into a true function which invokes a function pointer internally. That lets us use direct calls to it. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-06NASM: relicense under the 2-clause BSD licenseH. Peter Anvin1-12/+0
*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-05Change noreturn macro to no_return to avoid header file problemsH. Peter Anvin1-1/+1
Change the "noreturn" macro to "no_return", to avoid problems with system header files which use __attribute__((noreturn)) rather than __attribute__((__noreturn__)) as is appropriate for system headers. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-01nasmlib: add nasm_assert(); use const char * for filenamesH. Peter Anvin1-7/+14
Add new nasm_assert() function, and add "const" to the declarations which take filenames, as well as to the nasm_strdup/strndup functions. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-28Add copyright headers to the *.c/*.h files in the main directoryH. Peter Anvin1-5/+46
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-27Move backend-specific code to output/; break out null debug stuffH. Peter Anvin1-54/+0
Move backend-specific code into the output/ directory, and make the null debugging backend a separate file (it certainly isn't needed for ndisasm...) Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-02-21BR 2592476: Treat WAIT as a prefix even though it's really an instructionH. Peter Anvin1-2/+2
WAIT is technically an instruction, but from an assembler standpoint it behaves as if it had been a prefix. In particular, it has to be ordered *before* any real hardware prefixes.
2009-02-21nasmlib: make nasm_strcat() take const argumentsH. Peter Anvin1-1/+1
None of the strings passed to nasm_strcat() are modified, to make them const.
2009-02-21Unify all-zero buffers; add fwritezero()H. Peter Anvin1-0/+23
We have a number of all-zero buffers in the code. Put a single all-zero buffer in nasmlib.c. Additionally, add fwritezero() which can be used to write an arbitrary number of all-zero bytes; this prevents the situation where the all-zero buffer is simply too small.
2008-06-28nasmlib: fix nasm_str[n]icmp()H. Peter Anvin1-4/+4
Fix nasm_str[n]icmp() on platforms which don't have this function natively. XXX: Given the new nasm_tolower() implementation, we should consider if this might actually be a faster function than the platform-native one.
2008-06-21ctype.h: wrapper ctype functions with a cast to (unsigned char)H. Peter Anvin1-2/+2
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-11Use an explicit table for tolower() to avoid a function callH. Peter Anvin1-2/+17
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-10nasmlib.c: fwriteint*() only need WORDS_LITTLEENDIANH. Peter Anvin1-2/+2
fwriteint*() don't require unaligned references, so they can be optimized for WORDS_LITTLEENDIAN rather than X86_MEMORY...
2008-06-09Move all the RAA code out of nasmlibH. Peter Anvin1-93/+0
The RAA code doesn't have to be in nasmlib; it is only used by nasm itself, and is better handled in a separate module.
2008-06-09Move all the SAA code out of nasmlibH. Peter Anvin1-305/+0
Move all the SAA code out of nasmlib; it's not used by anything than nasm itself. Cleaning out the kitchen sink known as nasmlib is a good thing, too.
2008-06-01qstring: backquoted strings seem to work now...H. Peter Anvin1-18/+45
Hopefully backquoted strings should work correctly now.
2008-06-01qstring: first cut at full quoted string support in the preprocessorH. Peter Anvin1-225/+0
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-01qstring: add nasm_unquote() supporting `...`H. Peter Anvin1-0/+205
Add a nasm_unquote() function supporting the intended `...` syntax.
2008-05-30Introduce %depend and %pathsearch, and make incbin a macroH. Peter Anvin1-0/+2
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-04First cut at AVX machinery.H. Peter Anvin1-3/+3
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-02-24Dwarf3 support for ELF32Charles Crayne1-0/+55
1. Port dwarf3 support from ELF64 to ELF32 2. Move common SAA extentions to nasmlib
2008-01-21RAA subsystem: use shift instead of divideH. Peter Anvin1-16/+12
Make the RAA size always a power of two, so we can use shifts instead of multiple, expensive divides.
2008-01-21nasmlib.c: log nasm_free() before calling free()H. Peter Anvin1-1/+1
If we're logging nasm_free(), then log it before we actually call free(); that way we can find out what the last thing was if free() crashes.
2008-01-08BR 1864243: better warnings for out-of-range constantsH. Peter Anvin1-1/+1
In particular, we'd miss issuing warnings for out-of-range dword values, and the message for constants too large (we can't deal with > 64 bits) said 32 bits, not 64.
2007-12-29regularized spelling of license to match name of LICENSE fileBeroset1-1/+1
2007-11-19BR 877583: Fix RAA memory leakH. Peter Anvin1-3/+2
raa_free() didn't actually do the proper job; it would only free leaf nodes, not internal nodes.
2007-11-17Check in Keith's FixesCharles Crayne1-8/+5
1. Don't warn on 32-bit overflow 2. Change EM64T to Intel 64 in Defining CPU Dependencies section of documentation.
2007-11-13Clean up the fwrite*() function definitions somewhatH. Peter Anvin1-16/+12
Slight cleanup of the fwrite*() functions. This actually helps gcc generate better code on i386, for no apparent reason.
2007-11-13x86-host-specific performance improvementH. Peter Anvin1-0/+30
If we're on an x86 host, we can do unaligned littleendian memory references directly. Just do'em.
2007-11-13Address data is int64_t; simplify writing an address objectH. Peter Anvin1-14/+16
Address data is always int64_t even if the size itself is smaller; this was broken on bigendian hosts (still need testing!) Create simple "write sized object" macros.
2007-11-08nasmlib.c: prefix_name(): use the elements() macroH. Peter Anvin1-1/+1
Use the elements() macro to count the elements in a static array.
2007-11-08constipate the "str" argument to bsi() and bsii()H. Peter Anvin1-2/+2
The string argument to bsi() and bsii() should be const.
2007-11-07Upgrade RAA functions to hold 64-bit data.Charles Crayne1-2/+2
2007-11-05Upgrade label functions to 64-bitCharles Crayne1-1/+1
2007-10-26readnum(): handle prefix-suffix collision like "0h"H. Peter Anvin1-15/+11
Suffixed versions of zero will look like both a prefix and a suffix. Reject the prefixed version as being too short to decode.
2007-10-23Slightly simplify the radix-detection codeH. Peter Anvin1-2/+4
(pradix && pradix > sradix) etc. is unnecessary since pradix and sradix cannot be negative, so zero is always the smallest value. Put in a comment explaining why making the default radix == 10 doesn't need any additional error checking.
2007-10-22Unbreak particularly tricky hex constantsH. Peter Anvin1-7/+20
Unbreak hex constants which contain 'b' or 'd' in potentially tricky places.
2007-10-22More consistent handling of radix lettersH. Peter Anvin1-15/+31
Allow any radix letter from the set [bydtoqhx] to be used either "Intel-style" (0...x) or "C-style" (0x...). In Intel style, the leading 0 remains optional as long as the first digit is in the range 0-9. As a consequence, allow the prefix "0h" for hexadecimal floating point.
2007-10-19Formatting: kill off "stealth whitespace"H. Peter Anvin1-6/+6
"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-19Allow underscores in numbers; better detection of FPH. Peter Anvin1-11/+14
- Allow underscores as group separators in numbers, for example: 0x1234_5678 is now a legal number. The underscore is just ignored, it adds no meaning. - Recognize dotless floating-point numbers, such as "1e30". This entails distinguishing hexadecimal numbers in the scanner, since e.g. 0x1e30 is a perfectly legitimate hex constant.
2007-10-15Recognize 'd', 't' and 'y' as radix suffixesH. Peter Anvin1-1/+3
'd', 't' and 'y' now recognized as radix suffixes.