Commit Graph

2078 Commits

Author SHA1 Message Date
Vlad Vissoultchev
cdc16d428f Reduce allocations overhead
- uses new `TinyAlloc`-ators for small `TokenSym`, `CString` and
  `TokenString` instances
- conditional `TAL_DEBUG` for mem leaks and double frees detection
- on `TAL_DEBUG` collects allocation origin (file + line)
- conditional `TAL_INFO` for allocators stats (in release mode too)
- chain a new allocator twice current capacity on buffer exhaustion
2016-04-17 17:26:10 +03:00
Vlad Vissoultchev
224236f57c Improve hash performance
- better `TOK_HASH_FUNC`
- increases `hash_ident` initial size to 16k (from 8k)
- `cstr_cat` uses single `realloc` + `memcpy`
- `cstr_cat` can append terminating zero
- `tok_str_realloc` initial size to 16 (from 8)
- `parse_define` uses static `tokstr_buf`
- `next` uses static `tokstr_buf`
- fixes two latent bugs (wrong deallocations in libtcc.c:482 and
  tccpp.c:2987)
2016-04-17 17:25:55 +03:00
Vlad Vissoultchev
acc8f602e5 Revert "Fix tests Makefiles on Windows"
This reverts commit fa2472c172.
2016-04-17 17:24:17 +03:00
Vlad Vissoultchev
f021a7cd94 Add travis tests integration 2016-04-17 17:24:07 +03:00
seyko
587aacedf3 simplify -C printing
parse_print_line_comment() and parse_print_comment() are
    combined and made more simply:
        * don't worry about speed with -E option
        * don't handle straya in comments
            Do we need to handle strays in regular
            parse_line_comment() and
            parse_comment() ?
2016-04-17 10:07:55 +03:00
seyko
e010b1396b __builtin_expect no-op
Taken from David Mertens tcc branch on github
    https://github.com/run4flat/tinycc.git
2016-04-16 12:41:53 +03:00
seyko
5ee097fce9 allow to compile tcc by pcc
* pcc have only __linux__ macro (and no __linux)
    * pcc don't have __clear_cache proc
2016-04-15 17:41:49 +03:00
seyko
c6dc756d4e preprocessor oprtion -C (keep comments)
This is done by impression of the pcc -C option.
    Usual execution path and speed are not changed.
2016-04-15 17:15:11 +03:00
seyko
16cbca281f fix preprocessing *.S with ` ' chars in #comments
with a test program. Problem detected when trying to
    compile linux-2.4.37.9 with tcc.
2016-04-14 21:46:46 +03:00
seyko
5fb57bead4 fix for thev "#pragna once" guard
gcc 3.4.6 don't understand "#if PATHCMP==stricmp"
    where "#define PATHCMP stricmp"
2016-04-14 21:39:34 +03:00
Vlad Vissoultchev
34feee0ed6 Move utility functions trimfront/back to tccpp.c
These are used in `libtcc.c` now and cannot remain in `tccpe.c`
2016-04-13 14:33:21 +03:00
Vlad Vissoultchev
cb5f6b063b Simplify @listfiles parsing
This moves listfiles parsing inline in `tcc_parse_args1`
2016-04-13 11:35:24 +03:00
Vlad Vissoultchev
b3782c3cf5 Better pragma once guard
This takes care of case-insensitive filenames (like on win32)
2016-04-13 11:18:40 +03:00
Vlad Vissoultchev
98ffeaa0c5 win32: Better VS2015 solution and project files
These include all header and source files from source directory
2016-04-13 11:10:13 +03:00
Vlad Vissoultchev
810a677d32 tccpp.c: Guard against ppfp being NULL
Missed these in e946eb2a41
2016-04-13 10:58:42 +03:00
seyko
6a49afb3ed correct version of "Identifiers can start and/or contain"
A problem was in TOK_ASMDIR_text:
    -    sprintf(sname, ".%s", get_tok_str(tok1, NULL));
    +    sprintf(sname, "%s", get_tok_str(tok1, NULL));
    When tok1 is '.text', then sname is '..text'
2016-04-13 10:23:46 +03:00
seyko
989b5ee8ae Allow tcc arguments to be read from @listfiles
From: Vlad Vissoultchev
    Date: Tue, 12 Apr 2016 20:43:15 +0300
    Subject: Allow tcc arguments to be read from @listfiles

    This allows all @ prefixed arguments to be treated as listfiles
    containing list of source files or tcc options where each one is on a
    separate line. Can be used to benchmark compilation speed with
    non-trivial amount of source files.

    The impl of `tcc_parse_args` had to be moved to a new function that is
    able to be called recursively w/ the original one remaining as a driver
    of the new one. Listfiles parsing happens in a new
    `args_parser_add_listfile` function that uses `tcc_open`/`tcc_close/inp`
    for buffered file input.
2016-04-13 07:05:38 +03:00
seyko
a1a5c81e6c win32: Add missing header files for nginx compilation
From: Vlad Vissoultchev
    Date: Tue, 12 Apr 2016 21:02:43 +0300
    Subject: win32: Add missing header files for nginx compilation

    The new ones are hoisted from mingw-w64 as most other headers under
    `win32/include/winapi`
2016-04-13 06:51:59 +03:00
seyko
52d194a1e6 VS2015 solution and project files
From: Vlad Vissoultchev
    Date: Mon, 11 Apr 2016 01:32:28 +0300
    Subject: Add VS2015 solution and project files to `win32/vs2015`
             directory

    This allows release/debug builds for both x86 and x64 targets. Some
    warnings had to be suppressed.

    Output libtcc.dll and tcc.exe are copied to parent `win32` directory
    w/ a post-build action.
2016-04-13 06:29:24 +03:00
seyko
b5b3e89f9e Fix pragma once guard
From: Vlad Vissoultchev
    Date: Mon, 11 Apr 2016 01:26:32 +0300
    Subject: Fix pragma once guard when compiling multiple source files

    When compiling multiple source files directly to executable cached
    include files guard was incorrectly checked for TOK_once in ifndef_macro
    member.

    If two source files included the same header guarded by pragma once, then
    the second one erroneously skipped it as `cached_includes` is not cleared
    on second `tcc_compile`
2016-04-13 06:17:02 +03:00
seyko
b0296139a8 fix for the -dM patch
assign fopen("/dev/null","w") to the s->ppfp insteed of NULL
2016-04-13 05:17:13 +03:00
seyko
f869dfb47f document -dM in "tcc -h" output 2016-04-13 04:27:27 +03:00
seyko
131d776d66 revert of the 'Identifiers can start and/or contain'
When tccboot kernels compiles with
    'Identifiers can start and/or', this kernel don't start.
    It is hard to find what is wrong.

    PS: there was no test for identifiers in *.S with '.'
2016-04-13 03:52:07 +03:00
Vlad Vissoultchev
174d06a3ff Skip math library if not found when -lm option is used
This only silences "cannot find library" error and allows Makefiles targeting gcc to not complain about missing libraries

If there is custom libm then standard handling applies.
2016-04-08 12:18:31 +03:00
Vlad Vissoultchev
e946eb2a41 Implement -dM preprocessor option as in gcc
There was already support for -dD option but in contrast -dM dumps only `#define` directives w/o actual preprocessor output.

The original -dD output differs from gcc output by additional comment in front of `#define`s so this quirk is left for -dM as well.
2016-04-06 18:57:11 +03:00
Vlad Vissoultchev
0691b7630b tccgen.c: Allow type attributes to prefix enum/struct/union name
From gcc docs: "You may also specify attributes between the enum, struct or union tag and the name of the type rather than after the closing brace."

Adds `82_attribs_position.c` in `tests/tests2`
2016-04-06 14:32:52 +03:00
seyko
effc7d9ed4 cleaning "Identifiers can start and/or contain"
more logical algorithm of the isidnum_table[] changing
2016-04-05 15:06:47 +03:00
seyko
983c40f58b compilation speed of the tccboot correction
we use gnu extension "case 0x80 ... 0xFF" for tcc & gcc
    and perform test
        if(c & 0x80)
    for other compilers
2016-04-05 13:38:53 +03:00
seyko
936819a1b9 utf8 in identifiers
made like in pcc
    (pcc.ludd.ltu.se/ftp/pub/pcc-docs/pcc-utf8-ver3.pdf)
    We treat all chars with high bit set as alphabetic.
    This allow code like

    #include <stdio.h>
    int Lefèvre=2;
    int main() {
        printf("Lefèvre=%d\n",Lefèvre);
        return 0;
    }
2016-04-05 13:05:09 +03:00
seyko
c9473a7529 nocode_wanted with while/for inside ({})
a test included.
2016-04-05 11:47:20 +03:00
seyko
5a704457e2 optimization of the previous patch
compilation speed of the tccboot restored
    (patch remove testing of the parse_flags in loop)
2016-04-05 11:19:09 +03:00
seyko
d3e85e80fd Identifiers can start and/or contain '.' in *.S
modified version of the old one which don't allow '.'
    in #define Identifiers. This allow correctly preprocess
    the following code in *.S

        #define SRC(y...)               \
        9999: y;                        \
        .section __ex_table, "a";       \
        .long 9999b, 6001f      ;       \
        // .previous

        SRC(1: movw (%esi), %bx)
        6001:

    A test included.
2016-04-05 10:43:50 +03:00
seyko
21665f4338 describe -fnormalize-inc-dirs in tcc-doc.texi 2016-04-04 19:22:52 +03:00
seyko
5278d217ff R_386_COPY
This reloction must copy initialized data from the library
    to the program .bss segment. Currently made like for ARM
    (to remove noise of defaukt case). Is this true?
2016-04-03 18:13:53 +03:00
seyko
41785a0bf9 -fnormalize-inc-dirs
remove non-existent or duplicate directories from include paths
    if -fnormalize-inc-dirs is specified. This will help
    to compile current coreutils package
2016-04-03 11:42:15 +03:00
seyko
2bf43b5483 reverse of the "Identifiers can start and/or contain '.'"
- Identifiers can start and/or contain '.' in PARSE_FLAG_ASM_FILE
    - Move all GAS directives under TOK_ASMDIR prefix

    This patches breaks compilation of the tccboot (linux 2.4.26
    kernel). A test.S which fails with this patches:

    #define SRC(y...) \
    9999: y; \
    .section __ex_table, "a"; \
    .long 9999b, 6001f<---->; \
    .previous

    SRC(1:<>movw (%esi), %bx<------>)
    // 029-test.S:7: error: macro 'SRC' used with too many args
2016-04-03 11:01:05 +03:00
Michael Matz
80343ab7d8 Fix assignment to/from volatile types
Code like this was broken:

   char volatile vi = i;

See testcase, happens in ideosyncratic legacy code sprinkling
volatile all over.
2016-03-26 17:57:22 +01:00
Michael Matz
8fc5a6a2a4 Fix tokenization of TOK_DOTS
We really need to use PEEKC during tokenization so as to
skip line continuations automatically.
2016-03-24 15:58:32 +01:00
Michael Matz
f85db99ff0 Fix type parsing
the check on incomplete struct/union/enum types was too early,
disallowing mixed specifiers and qualifiers.  Simply rely on
the size (->c) field for that.  See testcases.
2016-03-24 15:44:01 +01:00
Vlad Vissoultchev
aa1ed616eb Move all GAS directives under TOK_ASMDIR prefix to include leading '.'
Use only these tokens in `asm_parse_directive` and don't recycle others' tokens (like TOK_SECTION1)
2016-03-15 10:00:50 +02:00
Vlad Vissoultchev
05ec6654a7 Identifiers can start and/or contain '.' in PARSE_FLAG_ASM_FILE
Including labels, directives and section names
2016-03-14 18:37:39 +02:00
Vlad Vissoultchev
17395ea507 tccpp.c: Fix failing PPTest 03 by reverting rogue modification in macro_arg_subst 2016-03-14 18:26:41 +02:00
Vlad Vissoultchev
fa2472c172 Fix tests Makefiles on Windows
Compiled tcc.exe location is under $(top_srcdir)/win32
2016-03-14 18:11:49 +02:00
Vlad Vissoultchev
5175b1ad87 Use proper ifdef for x64 check in winnt.h 2016-03-14 18:07:38 +02:00
Vlad Vissoultchev
712eca44d5 Revert spawnvp param cast and use no-incompatible-pointer-types in build-tcc.bat 2016-03-14 18:06:42 +02:00
Vlad Vissoultchev
9d778c7bb6 Keep lvalue category on structs when evaluating ternary operator 2016-03-13 04:32:18 +02:00
Vlad Vissoultchev
32755dbea9 Migrate static STRING_MAX_SIZE buffers to CString instances for large macros expansion 2016-03-13 04:26:45 +02:00
Vlad Vissoultchev
d715ebdae0 Add x64 SEH decls. Add exports to kernel32.def 2016-03-13 04:23:15 +02:00
Vlad Vissoultchev
95aac21130 Move WIN32_LEAN_AND_MEAN to windows.h (silence redeclarations) 2016-03-13 04:21:23 +02:00
Vlad Vissoultchev
2dc7161453 Win32 build script handles x64 and debug params 2016-03-13 04:19:32 +02:00