aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
Commit message (Collapse)AuthorAgeFilesLines
* fix push_macro, asked Tom to help me testfix push_macrojiang2014-05-161-2/+2
|
* clean '\t'jiang2014-05-141-156/+156
|
* restore 2dd8587c2f32d17a2cd0443a60a614a3fa9bbe29jiang2014-05-131-99/+203
|
* Revert "update static void parse_number()"grischka2014-05-061-138/+244
| | | | | | | | | | | | | | | | | | | because: - Constructing fp numbers isn't quite trivial - 3 additional calls to strchr per number is noticeable slow Also: exclude abitest.c:ret_longdouble_test2 on _WIN32 for mixed gcc/tcc scenario test case: - make -k test (on win32): -2.120000 0.500000 23000000000.000000 +2.120000 0.500000 22999999999.999996 ... ret_longdouble_test2... failure This reverts 857f7dbfa65179e6690dbee7ab915fb4458cee11 and deaee6c2496ecb25858290405fef8ef79aece979
* Return to: e20c1eb99e1003c1e59522c136dbb15c52d7cc7cjiang2014-05-041-203/+99
| | | | | | | | | | | | | | | | | | | | | | | 1: The new patch for the other machines still have the problem. 2: libcrt Rename (what if gcc had libcrt as well) 3: parse_number exact problem 4: VT_VLS is to allow tcc Compile the following int b = 9; struct st { int a; int b [b] }; struct st st1; st1.b [8] = 9; printf ("% d \ n", st1.b [8]); tcc a problem. Due to problems in front, and now can not be improved 5: they commit much, bug difficult to lock, you can not let other people help develop. 6: ('\ t') too Thanks to Michael and Ray Their criticism I have benefited!
* Fixes include the double quotes bugjiang2014-05-021-99/+203
| | | | | Added push_macro, pop_macro support Fix pack bug, when output with-E will pack the bug
* fix tccpp.cjiang2014-04-281-24/+0
|
* update static void parse_number(const char *p) for tccpp.cjiang2014-04-281-220/+138
|
* Improve efficiency of macro concatenationThomas Preud'homme2014-04-141-26/+2
| | | | | | As per grischka comment, always output a space after macro concatenation instead of trying to detect if it's necessary as the current approach has a huge cost.
* Fix preprocessor concat with empty argThomas Preud'homme2014-04-121-5/+37
|
* Prevent ## to appear at start or end of macroThomas Preud'homme2014-04-081-3/+11
|
* tccgen: x86_64: fix garbage in the SValue upper bitsgrischka2014-04-041-12/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This was going wrong (case TOK_LAND in unary: computed labels) - vset(&s->type, VT_CONST | VT_SYM, 0); - vtop->sym = s; This does the right thing and is shorter: + vpushsym(&s->type, s); Test case was: int main(int argc, char **argv) { int x; static void *label_return = &&lbl_return; printf("label_return = %p\n", label_return); goto *label_return; //<<<<< here segfault on linux X86_64 without the memset on vset printf("unreachable\n"); lbl_return: return 0; } Also:: - Rename "void* CValue.ptr" to more usable "addr_t ptr_offset" and start to use it in obvious cases. - use __attribute__ ((noreturn)) only with gnu compiler - Revert CValue memsets ("After several days searching ...") commit 4bc83ac3933efa565ae3326b55fcd711b63c073d Doesn't mean that the vsetX/vpush thingy isn't brittle and there still might be bugs as to differences in how the CValue union was set and is then interpreted later on. However the big memset hammer was just too slow (-3% overall).
* Fixed typo from commit 0ac8aaab1bef770929e5592d02bc06d3a529952eVincent Lefevre2014-03-311-1/+1
|
* tccpp: reorder some tokensgrischka2014-03-291-6/+38
| | | | | | ... and make future reordering possibly easier related to 9a6ee577f6165dccfde424732bfc6f16f1e2811b
* Make get_tok_str support NULL as second param.Thomas Preud'homme2014-03-291-0/+6
| | | | | | | As was pointed out on tinycc-devel, many uses of get_tok_str gives as second parameter the value NULL. However, that pointer was unconditionally dereferenced in get_tok_ptr. This commit explicitely add support for thas case.
* After several days searching why my code refactoring to remove globals was ↵mingodad2014-03-261-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | crashing, I found the problem it was because CValue stack variables have rubish as it inital values and assigning to a member that is smaller than the big union item and trying to recover it later as a different member gives bak garbage. ST_FUNC void vset(TCCState* tcc_state, CType *type, int r, int v) { CValue cval; memset(&cval, 0, sizeof(CValue)); cval.i = v; //,<<<<<<<<<<< here is the main bug that mix with garbage vsetc(tcc_state, type, r, &cval); } /* store a value or an expression directly in global data or in local array */ static void init_putv(TCCState* tcc_state, CType *type, Section *sec, unsigned long c, int v, int expr_type) { ... case VT_PTR: if (tcc_state->tccgen_vtop->r & VT_SYM) { greloc(tcc_state, sec, tcc_state->tccgen_vtop->sym, c, R_DATA_PTR); } //<<< on the next line is where we try to get the assigned value to cvalue.i as cvalue.ull *(addr_t *)ptr |= (tcc_state->tccgen_vtop->c.ull & bit_mask) << bit_pos; break; Also this patch makes vla tests pass on linux 32 bits
* Fix warning of clangThomas Preud'homme2014-03-091-2/+2
|
* Fix various errors uncovered by static analysisThomas Preud'homme2014-03-081-1/+1
| | | | Reported-by: Carlos Montiers <cmontiers@gmail.com>
* misc. fixesgrischka2014-01-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | - tccgen: error out for cast to void, as in void foo(void) { return 1; } This avoids an assertion failure in x86_64-gen.c, also. also fix tests2/03_struct.c accordingly - Error: "memory full" - be more specific - Makefiles: remove circular dependencies, lookup tcctest.c from VPATH - tcc.h: cleanup lib, include, crt and libgcc search paths" avoid duplication or trailing slashes with no CONFIG_MULTIARCHDIR (as from 9382d6f1a0e2d0104a82ed805207d9e742c6b068) - tcc.h: remove ";{B}" from PE search path in ce5e12c2f950052d8109b6b7a56d900547705c08 James Lyon wrote: "... I'm not sure this is the right way to fix this problem." And the answer is: No, please. (copying libtcc1.a for tests instead) - win32/build_tcc.bat: do not move away a versioned file
* remove doubled prototypeUrs Janssen2013-02-181-1/+0
| | | | | fix documentation about __TINYC__ define __STDC_HOSTED__ like __STDC__
* - document -dumpversionUrs Janssen2013-02-151-1/+1
| | | | - fixed a broken prototype
* configure: cleanupgrischka2013-02-141-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - add quotes: eval opt=\"$opt\" - use $source_path/conftest.c for OOT build - add fn_makelink() for OOT build - do not check lddir etc. on Windows/MSYS - formatting config-print.c - rename to conftest.c (for consistency) - change option e to b - change output from that from "yes" to "no" - remove inttypes.h dependency - simpify version output Makefile: - improve GCC warning flag checks tcc.h: - add back default CONFIG_LDDIR - add default CONFIG_TCCDIR also (just for fun) tccpp.c: - fix Christian's last warning tccpp.c: In function ‘macro_subst’: tccpp.c:2803:12: warning: ‘*((void *)&cval+4)’ is used uninitialized in this function [-Wuninitialized] That the change fixes the warning doesn't make sense but anyway. libtcc.c: - tcc_error/warning: print correct source filename/line for token :paste: (also inline :asm:) lddir and multiarch logic still needs fixing.
* libtcc: new LIBTCCAPI tcc_set_options(TCCState*, const char*str)grischka2013-02-121-9/+9
| | | | | | | | | | | | | | | | | | | This replaces -> use instead: ----------------------------------- - tcc_set_linker -> tcc_set_options(s, "-Wl,..."); - tcc_set_warning -> tcc_set_options(s, "-W..."); - tcc_enable_debug -> tcc_set_options(s, "-g"); parse_args is moved to libtcc.c (now tcc_parse_args). Also some cleanups: - reorder TCCState members - add some comments here and there - do not use argv's directly, make string copies - use const char* in tcc_set_linker - tccpe: use fd instead of fp tested with -D MEM_DEBUG: 0 bytes left
* Revert "Added what I call virtual io to tinycc this way we can make a ↵Thomas Preud'homme2013-01-141-11/+5
| | | | | | | | monolitic executable or library that contains all needed to compile programs, truly tinycc portable." This reverts commit 59e18aee0e509a3ca75dbe6f909e18c1d17893d1. tcc is being stabilized now in order to do a new release soon. Therefore, such a change is not appropriate now.
* Added what I call virtual io to tinycc this way we can make a monolitic ↵mingodad2013-01-111-5/+11
| | | | | | executable or library that contains all needed to compile programs, truly tinycc portable. Tested under linux exec the "mk-it" shell script and you'll end up with a portable tinycc executable that doesn't depend on anything else.
* Fix "Optimize cstr_reset() to only reset string to empty"grischka2013-01-061-1/+1
| | | | | | This fixes commit 8eb92e605200b1fe8d570ad309e28245c3f1af0a Remove memory leak.
* tccpp: alternative fix for #include_next infinite loop buggrischka2013-01-061-41/+32
| | | | | | | | | | | | | | | This replaces commit 3d409b08893873b917ccb8c34398bc41a4e84d7c - revert old fix in libtcc.c - #include_next: look up the file in the include stack to see if it is already included. Also: - streamline include code - remove 'type' from struct CachedInclude (obsolete because we check full filename anyway) - remove inc_type & inc_filename from struct Bufferedfile (obsolete) - fix bug with TOK_FLAG_ENDIF not being reset - unrelated: get rid of an 'variable potentially uninitialized' warning
* Optimize cstr_reset() to only reset string to empty, not call free() and ↵Kirill Smelkov2012-12-211-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | later malloc() A CString could be reset to empty just setting its .size to 0. If memory was already allocated, that would be remembered in .data_allocated and .size_allocated and on consequent string manipulations that memory will be used without immediate need to call malloc(). For $ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c after the patch malloc/free are called less often: (tcc is run in loop; perf record -a sleep 10 && perf report) before: # Overhead Command Shared Object Symbol # ........ ........... .................. .......................................... # 13.89% tcc tcc [.] next_nomacro1 4.73% tcc libc-2.13.so [.] _int_malloc 4.39% tcc tcc [.] next 2.94% tcc tcc [.] tok_str_add2 2.78% tcc tcc [.] macro_subst_tok 2.75% tcc libc-2.13.so [.] free 2.74% tcc tcc [.] macro_subst 2.63% tcc libc-2.13.so [.] _int_free 2.28% tcc tcc [.] vswap 2.24% tcc tcc [.] next_nomacro_spc 2.06% tcc libc-2.13.so [.] realloc 2.00% tcc libc-2.13.so [.] malloc 1.99% tcc tcc [.] unary 1.85% tcc libc-2.13.so [.] __i686.get_pc_thunk.bx 1.76% kworker/0:1 [kernel.kallsyms] [k] delay_tsc 1.70% tcc tcc [.] next_nomacro 1.62% tcc tcc [.] preprocess 1.41% tcc libc-2.13.so [.] __memcmp_ssse3 1.38% tcc [kernel.kallsyms] [k] memset 1.10% tcc tcc [.] g 1.06% tcc tcc [.] parse_btype 1.05% tcc tcc [.] sym_push2 1.04% tcc libc-2.13.so [.] _int_realloc 1.00% tcc libc-2.13.so [.] malloc_consolidate after: # Overhead Command Shared Object Symbol # ........ ........... .................. .............................................. # 15.26% tcc tcc [.] next_nomacro1 5.07% tcc libc-2.13.so [.] _int_malloc 4.62% tcc tcc [.] next 3.22% tcc tcc [.] tok_str_add2 3.03% tcc tcc [.] macro_subst_tok 3.02% tcc tcc [.] macro_subst 2.59% tcc tcc [.] next_nomacro_spc 2.44% tcc tcc [.] vswap 2.39% tcc libc-2.13.so [.] _int_free 2.28% tcc libc-2.13.so [.] free 2.22% tcc tcc [.] unary 2.07% tcc libc-2.13.so [.] realloc 1.97% tcc libc-2.13.so [.] malloc 1.70% tcc tcc [.] preprocess 1.69% tcc libc-2.13.so [.] __i686.get_pc_thunk.bx 1.68% tcc tcc [.] next_nomacro 1.59% tcc [kernel.kallsyms] [k] memset 1.55% tcc libc-2.13.so [.] __memcmp_ssse3 1.22% tcc tcc [.] parse_comment 1.11% tcc tcc [.] g 1.11% tcc tcc [.] sym_push2 1.10% tcc tcc [.] parse_btype 1.10% tcc libc-2.13.so [.] _int_realloc 1.06% tcc tcc [.] vsetc 0.98% tcc libc-2.13.so [.] malloc_consolidate and this gains small speedup for tcc: # best of 5 runs before: 8268 idents, 47191 lines, 1526670 bytes, 0.153 s, 307997 lines/s, 10.0 MB/s after: 8268 idents, 47203 lines, 1526763 bytes, 0.148 s, 319217 lines/s, 10.3 MB/s
* Make tcc work after self-compiling with bounds-check enabledKirill Smelkov2012-12-091-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For vstack Fabrice used the trick to initialize vtop to &vstack[-1], so that on first push, vtop becomes &vstack[0] and a value is also stored there - everything works. Except that when tcc is compiled with bounds-checking enabled, vstack - 1 returns INVALID_POINTER and oops... Let's workaround it with artificial 1 vstack slot which will not be used, but only serve as an indicator that pointing to &vstack[-1] is ok. Now, tcc, after being self-compiled with -b works: $ ./tcc -B. -o tccb -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" tcc.c -ldl $ cd tests $ ../tcc -B.. -run tcctest.c >1 $ ../tccb -B.. -run tcctest.c >2 $ diff -u 1 2 and note, tcc's compilation speed is not affected: $ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c before: 8270 idents, 47221 lines, 1527730 bytes, 0.152 s, 309800 lines/s, 10.0 MB/s after: 8271 idents, 47221 lines, 1527733 bytes, 0.152 s, 310107 lines/s, 10.0 MB/s But note, that `tcc -b -run tcc` is still broken - for example it crashes on $ cat x.c double get100 () { return 100.0; } $ ./tcc -B. -b -DTCC_TARGET_I386 -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -run \ -DONE_SOURCE ./tcc.c -B. -c x.c Runtime error: dereferencing invalid pointer ./tccpp.c:1953: at 0xa7beebdf parse_number() (included from ./libtcc.c, ./tcc.c) ./tccpp.c:3003: by 0xa7bf0708 next() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:4465: by 0xa7bfe348 block() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:4440: by 0xa7bfe212 block() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:5529: by 0xa7c01929 gen_function() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:5767: by 0xa7c02602 decl0() (included from ./libtcc.c, ./tcc.c) that's because lib/bcheck.c runtime needs more fixes -- see next patches.
* Fix parsing function macro invocationsMichael Matz2012-04-181-3/+18
| | | | | | If a function macro name is separated from the parentheses in an macro invocation the substitution doesn't take place. Fix this by handling comments.
* Fix detection of labels with a typedef nameMichael Matz2012-04-181-2/+10
| | | | | | | | | | | | | | This needs to be accepted: typedef int foo; void f (void) { foo: return; } namespaces for labels and types are different. The problem is that the block parser always tries to find a decl first and that routine doesn't peek enough to detect this case. Needs some adjustments to unget_tok() so that we can call it even when we already called it once, but next() didn't come around restoring the buffer yet. (It lazily does so not when the buffer becomes empty, but rather when the next call detects that the buffer is empty, i.e. it requires two next() calls until the unget buffer gets switched back).
* tcc_realloc: auto "memory full" errorgrischka2012-04-181-6/+0
|
* tcc.c: fix previous commit "Use CString to concat linker options"grischka2012-04-181-6/+6
| | | | | | | | | - remove redunant else branch - zero-terminate linker_arg - declare cstr_xxx as PUB_FUNC (which are functions used in tcc.c but not in the libtcc API. Useful for a tcc(.exe) that uses the libtcc.(so/dll)) - while at it, export PUB_FUNCs from dll
* Consider long int constant as 64 bits on x86-64Thomas Preud'homme2012-03-141-0/+4
| | | | | Quick and dirty hack to consider long int constant (as in 1UL or 1L) as 64 bits integer on x86-64 non Windows systems.
* rename error/warning -> tcc_(error/warning)grischka2011-08-111-48/+48
|
* libtcc: minor adjustmentsgrischka2011-08-111-0/+5
| | | | | | | | | | | | | | | | | - use {B} to substitute tcc_lih_path (instead of \b) - expand CONFIG_TCC_CRTPREFIX in CONFIG_TCC_LIBPATHS which fixes duplicate CONFIG_SYSROOT. - put default CONFIG_SYSROOT ("") into tcc.h - remove hack from commit db6fcce78f4d8ea25036dd6643e9fa83d8e52e5a because $(tccdir)/include is already in sysincludes - configure: error out for unrecognized options. - win32/build-tcc.bat: put libtcc into base dir where it will find lib/include automatically, and build libtcc_test example.
* fix self-referential token pastingJoe Soroka2011-07-081-2/+14
|
* fix end-of-scope for self-referential macrosJoe Soroka2011-07-081-0/+2
|
* Remove unused variablesThomas Preud'homme2011-05-161-2/+1
| | | | | Remove unused local variables and declare them conditionally when they are used only on some architectures.
* tccpp: fix problem in preprocess_skip with empty #grischka2011-03-061-0/+2
| | | | | | | | for example: #ifdef stuff # /* some comment */ #endif
* Replace comment by a blankChangming Xu2011-03-011-7/+11
| | | | | | | | - fix my prev commit: put declaration above statements to stay c89 compatible - replace commit by a blank #define con(a, b) a/**/b this should yield a b, not ab
* tcc -E: append a ' ' after substChangming Xu2011-02-271-0/+10
| | | | | | | | | | We need a ' ' after subst of m in the following case #define m(name,r) name ## r #define m0(a,b,c) int m(a,b) c #define m1(a,b,c) int m(a,b)c m0(a, b, c); m1(a, b, c);
* tccpp: treat gas comments in .S files as raw text, not tokensJoe Soroka2011-02-231-0/+5
|
* fix crash with get_tok_str() in skip()grischka2011-02-041-1/+1
| | | | | crash was triggered by numbers etc. as unexpected token, i.e. everything that requires additional information with the token.
* tccpp: fix bug in handling of recursive macrosJoe Soroka2011-02-011-2/+15
|
* tccpp: fix token pasting ##grischka2010-11-251-5/+3
| | | | | This patch takes advantage of new function tcc_open_bf from previous commit.
* libtcc: new function tcc_open_bf to create BufferedFilegrischka2010-11-251-18/+13
| | | | | | | | Use it in: - tcc_open - tcc_compile_string - tcc_define_symbol - tcc_assemble_inline
* tcc: Draft suppoprt for -MD/-MF optionsKirill Smelkov2010-06-211-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In build systems, this is used to automatically collect target dependencies, e.g. ---- 8< (hello.c) ---- #include "hello.h" #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } $ tcc -MD -c hello.c # -> hello.o, hello.d $ cat hello.d hello.o : \ hello.c \ hello.h \ /usr/include/stdio.h \ /usr/include/features.h \ /usr/include/bits/predefs.h \ /usr/include/sys/cdefs.h \ /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs.h \ /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs-32.h \ /home/kirr/local/tcc/lib/tcc/include/stddef.h \ /usr/include/bits/types.h \ /usr/include/bits/wordsize.h \ /usr/include/bits/typesizes.h \ /usr/include/libio.h \ /usr/include/_G_config.h \ /usr/include/wchar.h \ /home/kirr/local/tcc/lib/tcc/include/stdarg.h \ /usr/include/bits/stdio_lim.h \ /usr/include/bits/sys_errlist.h \ NOTE: gcc supports -MD only for .c -> .o, but in tcc, we generate dependencies for whatever action is being taken. E.g. for .c -> exe, the result will be: $ tcc -MD -o hello hello.c # -> hello, hello.d hello: \ /usr/lib/crt1.o \ /usr/lib/crti.o \ hello.c \ hello.h \ /usr/include/stdio.h \ /usr/include/features.h \ /usr/include/bits/predefs.h \ /usr/include/sys/cdefs.h \ /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs.h \ /usr/include/bits/wordsize.h \ /usr/include/gnu/stubs-32.h \ /home/kirr/local/tcc/lib/tcc/include/stddef.h \ /usr/include/bits/types.h \ /usr/include/bits/wordsize.h \ /usr/include/bits/typesizes.h \ /usr/include/libio.h \ /usr/include/_G_config.h \ /usr/include/wchar.h \ /home/kirr/local/tcc/lib/tcc/include/stdarg.h \ /usr/include/bits/stdio_lim.h \ /usr/include/bits/sys_errlist.h \ /usr/lib/libc.so \ /lib/libc.so.6 \ /usr/lib/ld-linux.so.2 \ /lib/ld-linux.so.2 \ /usr/lib/libc_nonshared.a \ /lib/libc.so.6 \ /usr/lib/libc_nonshared.a \ /home/kirr/local/tcc/lib/tcc/libtcc1.a \ /usr/lib/crtn.o \ So tcc dependency generator is a bit more clever than one used in gcc :) Also, I've updated TODO and Changelog (in not-yet-released section). v2: (Taking inputs from grischka and me myself) - put code to generate deps file into a function. - used tcc_fileextension() instead of open-coding - generate deps only when compilation/preprocessing was successful v3: - use pstrcpy instead of snprintf(buf, sizeof(buf), "%s", ...)
* Revert "tccpp: Allow local labels to start with a dot"Daniel Glöckner2010-05-061-6/+0
| | | | | | This reverts commit f740485a5ab2ecef741bf1161b9feeea9c18cac0. It breaks access to structure elements starting with L
* Clean changes introduced by 47abdbdThomas Preud'homme2010-04-201-21/+0
| | | | | | | | | | | | * Replace the save/load_buffer_state by a dynarray approach: - Filename and libname are added to a dynarray when first encountered - Load repeatedly the files in the dynarray until no new undefined symbol are encountered * Replace snprintf by sprintf in libname_to_filename * Use tcc_fileextension in filename_to_libname * Introduce a tcc_strcpy_part fonction to copy only a subset of a string * Move new_undef_syms declaration from tcc.h to tccelf.c