aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
Commit message (Collapse)AuthorAgeFilesLines
* "#pragma once" implementationseyko2015-04-211-1/+3
|
* * and #pragma pop_macro("macro_name")seyko2015-04-211-0/+34
| | | | | | | | | | * give warning if pragma is unknown for tcc * don't free asm_label in sym_free(), it's a job of the asm_free_labels(). The above pragmas are used in the mingw headers. Thise pragmas are implemented in gcc-4.5+ and current clang.
* -fdollar-in-identifiers addonseyko2015-04-201-7/+11
| | | | | | | * disable a -fdollar-in-identifiers option in assembler files * a test is added This is a patch addon from Daniel Holden.
* clarify error message when library not foundseyko2015-04-161-2/+1
| | | | | a prior error message: cannot find 'program_resolve_lib' after a patch: cannot find library 'libprogram_resolve_lib'
* implement #pragma comment(lib,...)Steven G. Messervey2015-04-151-0/+27
|
* Revert "implement #pragma comment(lib,...)"Steven G. Messervey2015-04-151-38/+0
| | | | | | This reverts commit 8615bb40fb39bf7435462ca54cbbc24aaecae502. Reverting as it breaks on MinGW targets
* implement #pragma comment(lib,...)Steven G. Messervey2015-04-151-0/+38
|
* -fdollar-in-identifiers switch which enables '$' in identifiersseyko2015-04-121-4/+8
| | | | | | | | | | library Cello: http://libcello.org/ which uses `$` and several variations of as macros. There is also RayLanguage which also uses it as a macro for a kind of ObjC style message passing: https://github.com/kojiba/RayLanguage This is a patch from Daniel Holden.
* fix a preprocessor for .Sseyko2015-04-101-3/+16
| | | | | | Lets assume that in *.S files a preprocessor directive follow '#' char w/o spaces between. Otherwise there is too many problems with the content of the comments.
* fix a preprocessor for .Sseyko2015-04-101-2/+6
| | | | | A test program (tcc -E test.S): # .. or else we have a high. This is a test.S
* fix a preprocessor for .Sseyko2015-04-101-17/+13
| | | | | | | | | | | | | | | | | | | | | | | | * tell a right line number in error message if a #line directive is wrong * don't print an error message if we preprocess a .S file and #line directive is wrong. This is the case of the # 4026 bytes comment in *.S file. * preprocess_skip: skip a line with if (parse_flags & PARSE_FLAG_ASM_COMMENTS) p = parse_line_comment(p); if line starts with # and a preprocessor command not found. A test program: #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) # This repeats until either a device doesn't exist, or until #endif * remove a second definition of the TOK_FLAG_* and PARSE_FLAG_* from the tccpp.c
* fix to allow build tcc by build-tcc.batseyko2015-03-191-1/+1
| | | | | move call to print_defines() from tcc.c to the libtcc.c define a print_defines() as a ST_FUNC
* tcc_free(table_ident) in preprocess_new() if table_ident != NULLseyko2015-03-031-1/+4
|
* Add a debug info when a #line directive is handled.seyko2015-03-031-0/+2
| | | | | The problem was: a debug info for the file which contain a #line directive (for example a preprocessed one) was wrong.
* pp-many-files: don't drop a preprocessor defines when tcc going to ↵seyko2015-03-031-4/+0
| | | | | | | | | | | | | | preprocess a next file in the same pass like tcc -E one.c two.c three.c -o combined.i This will allow to speed up a compilation process by using a commamd like tcc -E *.c | tcc -o program.exe -xc - It looks that multi-times initialization don't affect anything. Only call to the free_defines(define_start) in tcc_preprocess() is removed in assumption that free_defines(NULL) in tcc_cleanup() will free all defines.
* A gcc preprocessor option -dD addedseyko2015-03-031-22/+69
| | | | | | | | | With this option on a defines are included into the output (inside comments). This will allow to debug a problems like: In file included from math.c:8: In file included from /usr/include/math.h:43: /usr/include/bits/nan.h:52: warning: NAN redefined
* Added a gcc preprocessor options -P, -P1seyko2015-03-031-10/+34
| | | | | | | | | | | tcc -E -P do not output a #line directive, a gcc compatible option tcc -E -P1 don't follow a gcc preprocessor style and do output a standard #line directive. In such case we don't lose a location info when we going to compile a resulting file wtith a compiler not understanding a gnu style line info.
* Move a line_ref variable from tcc_preprocess() function into struct ↵seyko2015-03-031-5/+5
| | | | | | | BufferedFile. This id needed for a right ouput in other places, precisely to calculate a number of empty lines which are waiting to output.
* A preprocessor should Interpret an input line "# NUM FILENAME" as "#line NUM ↵seyko2015-03-031-1/+6
| | | | | | | | | | | FILENAME" A cpp from gcc do this. A test case: tcc -E tccasm.c -o tccasm.i tcc -E tccasm.i -o tccasm.ii After a patch the line numbers in tccasm.ii are the same as in tccasm.i
* The "open a whisky and cut your finger open" patchThomas Preud'homme2015-02-181-34/+41
| | | | Make integer constant parsing C99 compliant
* Fix macro expansion of empty args.Reimar Döffinger2015-01-181-1/+1
| | | | Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
* Fix parsing of binary floating point numberLee Duhem2014-12-151-1/+1
| | | | | | | * tccpp.c (parse_number): `shift' should be 1 while parsing binary floating point number. * tests/tests2/70_floating_point_literals.c: New test cases for floating point number parsing.
* bug:jiang2014-06-291-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ---------------------------------------------------------------------- #define hexCh(c (c >= 10 ? 'a' + c - 10 : '0' + c) hexCh(c); out: jiang@jiang:~/test$ ./tcc -E c4.c # 1 "c4.c" (c >= 10 ? 'a' + c - 10 : '0' + c); --------------------------------------------------------------- #define hexCh(c/3) (c >= 10 ? 'a' + c - 10 : '0' + c) hexCh(c); out: jiang@jiang:~/test$ ./tcc -E c4.c # 1 "c4.c" /3) (c >= 10 ? 'a' + c - 10 : '0' + c); jiang@jiang:~/test$ after patch: # 1 "c4.c" c4.c:1: error: may not appear in macro parameter list: "(" jiang@jiang:~/test$ jiang@jiang:~/test$ ./tcc -E c4.c # 1 "c4.c" c4.c:1: error: may not appear in macro parameter list: "/" jiang@jiang:~/test$
* 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
|