aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
Commit message (Collapse)AuthorAgeFilesLines
* #pragma comment(option,"-..."), bitfields test, etc...grischka2017-07-141-9/+13
| | | | | | | | | | | | | | | | | | tccpp.c: * #pragma comment(option,"-some-option") to set commandline option from C code. May work only for some options. libtcc.c: * option "-d1..9": sets a 'g_debug' global variable. (for development) tests2/Makefile: * new make targets: tests2.37 / tests2.37+ run single test from tests2, optionally update .expect * new variable GEN-ALWAYS to always generate certain .expects * bitfields test tccgen.c: * bitfields: fix a bug and improve slightly more * _Generic: ignore "type match twice"
* Fix statement exprs returning a local labelMichael Matz2017-07-101-3/+5
| | | | | | Like returned local variables also labels local to a statement expression can be returned, and so their symbols must not be immediately freed (though they need to be removed from the symbol table).
* unsorted adjustmentsgrischka2017-07-091-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - configure * use aarch64 instead of arm64 - Makefile * rename the custom include file to "config-extra.mak" * Also avoid "rm -r /*" if $(tccdir) is empty - pp/Makefile * fix .expect generation with gcc - tcc.h * cleanup #defines for _MSC_VER - tccgen.c: * fix const-propagation for &,| * fix anonymous named struct (ms-extension) and enable -fms-extension by default - i386-gen.c * clear VT_DEFSIGN - x86_64-gen.c/win64: * fix passing structs in registers * fix alloca (need to keep "func_scratch" below each alloca area on stack) (This allows to compile a working gnu-make on win64) - tccpp.c * alternative approach to 37999a4fbf3487b363fd0c2f9b7ab622401b202a This is to avoid some slowdown with ## token pasting. * get_tok_str() : return <eof> for TOK_EOF * -funsigned-char: apply to "string" literals as well - tccpe/tools.c: -impdef: support both 32 and 64 bit dlls anyway
* tccpp: allow "#define X defined Y ..."grischka2017-07-091-26/+24
| | | | | | | That means: we do not macro-expand the argument of 'defined' Also: store the last token position into the TokenString structure in order to get rid of the tok_last function.
* tccpp: Implement __COUNTER__Michael Matz2017-07-091-11/+28
| | | | | | | | | | | This requires one more change in how macro arguments are expanded: the standard requires that macro args are expanded before substituting into the replacement list. This implies expanding them only once even when they occur multiple times in the list. TCC expanded them repeatedly in that case. Without __COUNTER__ that's harmless. So, simply always expand arguments (when used without # and ##) once and store the resulting tokens.
* tccpp: CleanupMichael Matz2017-07-091-126/+111
| | | | | With last change the can_read_stream flag is unneeded, so tidy this a bit.
* tccpp: Fix corner caseMichael Matz2017-07-091-6/+8
| | | | | | | | | | | | | See added testcase 19.c from a bug report. The problem is reading outside the arguments buffers, even though we aren't allowed to. The single can_read_stream variable is not enough, sometimes we need to be able to pop into outer contexts but not into arbitrarily outside contexts. The trick is to terminate argument tokens with a EOF (and not just with 0 that makes us pop contexts), and deal with that in the few places we have to, This enables some cleanups of the can_read_stream variable use.
* configure: --config-musl/-uClibc switch & misc cleanupsgrischka2017-05-131-1/+0
| | | | | | | | | | | | | | | - configure: - add --config-uClibc,-musl switch and suggest to use it if uClibc/musl is detected - make warning options magic clang compatible - simplify (use $confvars instead of individual options) - Revert "Remove some unused-parameter lint" 7443db0d5f841b81a55e918bf8c228dd20f9ddb2 rather use -Wno-unused-parameter (or just not -Wextra) - #ifdef functions that are unused on some targets - tccgen.c: use PTR_SIZE==8 instead of (X86_64 || ARM64) - tccpe.c: fix some warnings - integrate dummy arm-asm better
* Remove some unused-parameter lintLarry Doolittle2017-05-081-0/+1
| | | | | | | | Mark TCCState parameter as unused in tcc_undefine_symbol(), tcc_add_symbol(), tcc_print_stats(), asm_get_local_label_name(), use_section1(), tccpp_delete(), tcc_tool_ar(), tcc_tool_impdef(), and tcc_tool_cross(). Also mark it unused in tcc_add_bcheck() unless CONFIG_TCC_BCHECK. Remove it entirely in ld_next().
* Spelling fixes in C comments onlyLarry Doolittle2017-05-071-2/+2
|
* Tidy unary() a bitMichael Matz2017-05-021-1/+4
| | | | | | factor code a bit for transforming tokens into SValues. This revealed a bug in TOK_GET (see testcase), which happened to be harmless before. So fix that as well.
* Simple-minded fix for bug #50847Larry Doolittle2017-04-251-1/+2
| | | | | | bug #50847: #line directive corrupts #include search path Keep a second copy of the filename, that isn't changed by the #line directive, and use that on the initial search path for #include files.
* final adjustments for releasegrischka2017-04-251-1/+31
| | | | | | | | | | | | | | | | | | | | | - configure/Makefiles: minor adjustments - build-tcc.bat: add -static to gcc options (avoids libgcc_s*.dll dependency with some mingw versions) - tccpe.c/tcctools.c: eliminate MAX_PATH (not available for cross compilers) - tccasm.c: use uint64_t/strtoull in unary() (unsigned long sometimes is only uint32_t, as always on windows) - tccgen.c: Revert (f077d16c) "tccgen: gen_cast: cast FLOAT to DOUBLE" Was a rather experimental, tentative commit, not really necessary and somewhat ugly too. - cleanup recent osx support: - Makefile/libtcc.c: cleanup copy&paste code - tccpp.c: restore deleted function
* tcc: fixup clang warningsAndrei Warkentin2017-04-251-31/+2
| | | | | | | | | | | The O(xxx) stuff in i386-asm.c had me scratching my head. Extracting the macro and trying it out in a separate program doesn't give me any warnings, so I'm confused about what could be going on there. Any cast will make things happy. I used a uint64_t to catch actual cases of overflow, which will still cause a -Wconstant-conversion warning. Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
* tccpp: Fix corner case of fnlike macro invocationMichael Matz2017-04-151-2/+4
| | | | | | | Arg substitution leaves placeholder marker in the stream for empty arguments. Those need to be skipped when searching for a fnlike macro invocation in the replacement list itself. See testcase.
* mems & leaksgrischka2017-02-131-6/+10
| | | | | | | | | | | | - define_start: set above preprocess_start because now preprocess_start is defining macros. - free "cmd_include_files" - free defines always (after error-longjmps) - close all files (after error-longjmps) - tccpe.c: free imports always - libtcc.c: call tcc_memstats only after all states have been deleted.
* fixes & cleanupsgrischka2017-02-131-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - tccgen.c/tcc.h: allow function declaration after use: int f() { return g(); } int g() { return 1; } may be a warning but not an error see also 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 - tccgen.c: redundant code related to inline functions removed (functions used anywhere have sym->c set automatically) - tccgen.c: make 32bit llop non-equal test portable (probably not on C67) - dynarray_add: change prototype to possibly avoid aliasing problems or at least warnings - lib/alloca*.S: ".section .note.GNU-stack,"",%progbits" removed (has no effect) - tccpe: set SizeOfCode field (for correct upx decompression) - libtcc.c: fixed alternative -run invocation tcc "-run -lxxx ..." file.c (meant to load the library after file). Also supported now: tcc files ... options ... -run @ arguments ...
* Fix pseudo leakMichael Matz2016-12-201-5/+6
| | | | | | Once-allocated buffers (here a string) that aren't explicitely freed at program end but rather freed at _exit about 1 nanosecond later are regarded a leak with MEM_DEBUG, so explicitely free it. Blaeh :-/
* libtcc.c: -m option cleanupgrischka2016-12-181-2/+2
| | | | | | | | | | | handle mms-bitfields as sub-options of -m. (-mfloat-abi is still special because it requires arguments) tcc.c: help(): - list -mms-bitfields under 'Target specific options' libtcc.c/MEM_DEBUG - add check for past buffer writes
* tests: add memory leak testgrischka2016-12-181-16/+19
| | | | | | | | | | | | | Also ... tcctest.c: - exclude stuff that gcc doesn't compile on windows. libtcc.c/tccpp.c: - use unsigned for memory sizes to avoid printf format warnings - use "file:line: message" to make IDE error parsers happy. tccgen.c: fix typo
* tccpp: Fix token pastingMichael Matz2016-12-151-7/+8
| | | | | | | | | See testcase. We must always paste tokens (at least if not currently substing a normal argument, which is a speed optimization only now) but at the same time must not regard a ## token coming from argument expansion as the token-paste operator, nor if we constructed a ## token due to pasting itself (that was already checked by pp/01.c).
* tccasm: Don't ignore # in preprocessor directivesMichael Matz2016-12-151-21/+24
| | | | | | | Our preprocessor throws away # line-comments in asm mode. It did so also inside preprocessor directives, thereby removing stringification. Parse defines in non-asm mode (but retain '.' as identifier character inside macro definitions).
* tccpp: Allow computed include like 42.hMichael Matz2016-12-151-26/+19
| | | | | | The include directive needs to be parsed as pp-tokens, not as token (i.e. no conversion to TOK_STR or TOK_NUM). Also fix parsing computed includes using quoted strings.
* tccpp: Implement __BASE_FILE__ macroMichael Matz2016-12-151-0/+6
| | | | | Like __FILE__ but always refers to the command line file name also from inside headers.
* Implement -include cmdline optionMichael Matz2016-12-151-0/+14
| | | | | | This option includes a file as if '#include "file"' is the first line of compiled files. It's processed after all -D/-U options and is processed per input file.
* tccpp: Fix macro_is_equalMichael Matz2016-12-151-4/+5
| | | | | | | When tokens in macro definitions need cstr_buf inside get_tok_str, the second might overwrite the first (happens when tokens are multi-character non-identifiers, see testcase) in macro_is_equal, failing to diagnose a difference. Use a real local buffer.
* tccpp: free defines also with PP_BENCHMichael Matz2016-12-151-1/+3
| | | | | When benchmarking preprocessing of multiple files we need to free the defines like when not benchmarking.
* tccgen: fix inline_functions double free fixgrischka2016-11-111-10/+15
|
* tccgen: inline_functions double free fixgrischka2016-11-111-2/+1
| | | | | | Fix double free of the inline function token_string which could happen when an error/longjmp occurred while compiling the inline function.
* tccpp_new/delete and other cleanupsgrischka2016-10-171-4/+7
|
* tccpp : "tcc -E -P" : suppress empty linesgrischka2016-10-091-7/+13
| | | | | | | | | Also: - regenerate all tests/pp/*.expect with gcc - test "insert one space" feature - test "0x1E-1" in asm mode case - PARSE_FLAG_SPACES: ignore \f\v\r better - tcc.h: move some things
* tccpp: no cache for include if #elif seengrischka2016-10-041-8/+9
| | | | | | | | #ifndef guards are cached, however after #elif on the same level, the file must be re-read. Also: preprocess asm as such even when there is no assembler (arm).
* tccpp: parse_line_comment: fix possible buffer overrungrischka2016-10-011-3/+3
|
* tccpp: allow "0x1e+1" in asmgrischka2016-10-011-9/+13
|
* tccpp: token ## pasting: preserve parts if pasting failsgrischka2016-10-011-10/+12
| | | | | | | | | for example #define LBL(name) _ ## name ## : LBL(main) will give two tokens '_main' and ':' and the warning
* Revert "-fnormalize-inc-dirs"grischka2016-10-011-1/+0
| | | | | | | Too much code. gcc 3.x doesn't have that either. This reverts commit 41785a0bf9d505a3647a10ddc330417f52fd4528. This reverts commit 21665f433890e2038626f0b3123b189a62a67dc9.
* tcc -E: add one space in cases: tiny solutiongrischka2016-10-011-52/+20
| | | | | | replaces f5f82abc99424c4ece836000934fcf57a867c635 Also: fix tcc flags in Makefile, fix tcc -E
* tccpp: cleanupgrischka2016-10-011-69/+101
| | | | | | | | | | | | | | | | - "utf8 in identifiers" from 936819a1b90f2618bb3f86730189cf2895948ba0 - CValue: remove member str.data_allocated - make tiny allocator private to tccpp - allocate macro_stack objects on heap because otherwise it could crash after error/setjmp in preprocess_delete():end_macro() - mov "TinyAlloc" defs to tccpp.c - define_push: take int* str again
* libtcc: cleanup @listfilegrischka2016-10-011-15/+0
| | | | | | | | | Also: - allow more than one item per line - respect "quoted items" and escaped quotes \" (also for LIBTCCAPI tcc_setoptions) - cleanup some copy & paste
* tccpp: #pragma once: make it workgrischka2016-10-011-35/+23
| | | | | | | | | | | after several "fixes" and "improvements" b3782c3cf5e66f74207303c381a305daabccdb12 5fb57bead41cd3a84f0aa3f98d00b5fe5de25a08 feature did not work at all - Use 'once' flag, not 'ifndef_macro' - Ignore filename letter case on _WIN32 - Increment global pp_once for each compilation
* tccpp: restore -D symbols for multiple sourcesgrischka2016-10-011-14/+16
| | | | | | | | | | | | | | | ... also for built-in defines The case: $ tcc -D FOO a.c b.c with // a.c #undef FOO // b.c #ifndef FOO # error -D FOO has been lost #endif
* Rein in unintended external functions.Jean-Claude Beaudoin2016-09-251-2/+2
|
* Remove vestiges of earlier type mergerDavid Mertens2016-08-161-4/+1
|
* win64: fix va_arggrischka2016-07-101-3/+0
| | | | | | | | | | | fixes 5c35ba66c5ade4713bbd9c005e66889f6d7db293 Implementation was consistent within tcc but incompatible with the ABI (for example library functions vprintf etc) Also: - tccpp.c/get_tok_str() : avoid "unknown format "%llu" warning - x86_64_gen.c/gen_vla_alloc() : fix vstack leak
* Redo "fix line number in macro redefined message"grischka2016-05-251-5/+2
| | | | | | Smaller change to fix more cases This reverts commit 0f36f60faa05da7e250a4b4eebd4b534e8a2b537.
* fix line number in macro redefined messageseyko2016-05-161-2/+5
|
* tcc -E -P10 : output all numbers as decimalsgrischka2016-05-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This may be used to preprocess Fabrice Bellards initial revision in this repository to demonstrate its capability to compile and run itself (on i386 32-bit linux or windows). Initial revision: 27f6e16bae9d0f73acec07f61aea696ab5adc680 Also needed: * an empty stdio.h * a wrapper named tc.c with void expr(void); void decl(int); void next(void); #include "tcc.c" * an hello.c such as int main() { printf("Hello World\n"); return 0; } All files with unix LF only lines. Then ... * preprocess the source $ tcc -E -P10 -I. tcc.c -o tc1.c * compile the compiler $ tcc -w -I. tc.c -o tc -ldl * run it to compile and run itself to compile and run itself to compile and run itself to compile and run hello.c $ ./tc tc1.c tc1.c tc1.c hello.c --> Hello World! ------------------------------------------------------ * On i386 windows this may be added to the tc.c wrapper #ifdef _WIN32 #include <windows.h> void *dlsym(int x, const char *func) { if (0 == strcmp(func, "dlsym")) return &dlsym; return GetProcAddress(LoadLibrary("msvcrt"), func); } #endif
* Insert spaces between certain tokens when tcc is invoked with -E.Edmund Grimley Evans2016-05-091-1/+53
| | | | | | Insert a space when it is required to prevent mistokenisation of the output, and also in a few cases where it is not strictly required, imitating GCC's behaviour.
* TOK_PPNUM in asm (Edmund Grimley Evans version)seyko2016-05-081-0/+1
|
* tccpp: cleanup options -dD -dM, remove -Cgrischka2016-05-051-202/+180
| | | | | | | The lexer is for reading files, not for writing. Also : - macro_is_equal(): avoid crash if redefining __FILE__