Commit Graph

1868 Commits

Author SHA1 Message Date
Michael Matz
7cfd21440b x86-asm: Add .fill test 2016-05-14 04:41:06 +02:00
Michael Matz
4f27e217a8 x86-asm: Fix signed constants and opcode order
Two things: negative constants were rejected (e.g. "add $-15,%eax").
Second the insn order was such that the arithmetic IM8S forms
weren't used (always the IM32 ones).  Switching them prefers those
but requires a fix for size calculation in case the opcodes were
OPC_ARITH and OPC_WLX (whose size starts with 1, not zero).
2016-05-14 04:33:41 +02:00
Michael Matz
080ec9fadd x86-asm: Consolidate insn descriptions
Use OPC_BWLX and OPC_WLX in i386-asm.h and x86_64-asm.h to
reduce number of differences between both.
2016-05-14 04:05:34 +02:00
grischka
5e4d0718ff tcc -E -P10 : output all numbers as decimals
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: 27f6e16bae

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
2016-05-12 10:25:50 +02:00
Michael Matz
a66ba1f2a1 Error out on operations on structs
The check for structs was too late and on amd64 and aarch64 could
lead to accepting and then asserting with code like:
  struct S {...} s;
  char *c = (char*)0x10 - s;
2016-05-12 01:12:04 +02:00
Michael Matz
6bd8c936e3 x86-64-asm: Add mov[sz]xq opcodes
This adds the zero/sign-extending opcodes with 64bit destinations.
2016-05-12 00:57:02 +02:00
Michael Matz
b9f01dffc6 x86-64-asm: Clean up 64bit immediate support
Fix it to actually be able to parse 64bit immediates (enlarge
operand value type).  Then, generally there's no need for accepting
IM64 anywhere, except in the 0xba+r mov opcodes, so OP_IM is
unnecessary, as is OPT_IMNO64.  Improve the generated code a bit
by preferring the 0xc7 opcode for im32->reg64, instead of the
im64->reg64 form (which we therefore hardcode).
2016-05-11 23:47:02 +02:00
Michael Matz
f3cee9ceff x86-asm: Get rid of is_short_jump
Can be implemented differently.
2016-05-11 23:45:14 +02:00
Michael Matz
55bd08c5ae x86-asm: Remove old ASM_16 code
This code was inactive since a long time (and was deactivated because
it was wrong to start with) and just clutters the sources.  Remove
it.
2016-05-11 19:13:38 +02:00
Michael Matz
f0fa5603cf x86-64: Run asmtest as well
This fixes and activates the asm test that's part of tcctest.c
also on x86-64, requiring a small fix for the 'm' constraint.
2016-05-11 19:00:02 +02:00
Michael Matz
4d68828259 tests: Compile asmtest.S without -m32
Don't hardcode that option, if you want it do make CC="gcc -m32".
The test assembles with -m64 as well now.
2016-05-11 18:58:14 +02:00
Michael Matz
613962e353 x86-64 asm: Remove useless jmp opcode
Also remove the hacky mod/rm byte emission during
disp/imm writing.
2016-05-11 18:56:19 +02:00
Michael Matz
bd93dc6923 x86: Improve cmov handling
cmov can accept multi sizes, but is also a OPC_TEST opcode,
deal with this.
2016-05-11 18:54:24 +02:00
Michael Matz
9645b62a65 x86_64: Use addend on relocs
Traditional behaviour on x86-64 is to encode the relocation
addend in r_addend, not in the relocated field (after all,
that's the reason to use RELA relocs to begin with).  Our
linker can deal with both, other linkers as well.  But using
e.g. the GNU assembler one can detect differences (equivalent
code in the end, but still a difference).

Now there's only a trivial difference in tests/asmtest.S
(having to do with ordering of prefixes).
2016-05-09 23:17:47 +02:00
Michael Matz
5e47b08dc8 [x86] Fix some asm problems
A bag of assembler fixes, to be either compatible with GAS
(e.g. order of 'test' operands), accept more instructions,
count correct foo{bwlq} variants on x86_64, fix modrm/sib bytes
on x86_64 to not use %rip relative addressing mode, to not use
invalid insns in tests/asmtest.S for x86_64.

Result is that now output of GAS and of tcc on tests/asmtest.S
is mostly the same.
2016-05-09 23:17:47 +02:00
Edmund Grimley Evans
f5f82abc99 Insert spaces between certain tokens when tcc is invoked with -E.
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.
2016-05-09 19:27:31 +01:00
seyko
75243f744c TOK_PPNUM in asm (Edmund Grimley Evans version) 2016-05-08 05:14:03 +03:00
grischka
a94e8d439a tccgen: scopes levels for local symbols (update 2)
allow
    typedef int xxx;
    typedef int xxx;
in the same scope as long as it is the same type
2016-05-06 08:32:54 +02:00
grischka
d48662d496 tccgen: scopes levels for local symbols (update 1)
Catch top level redeclarations too.

Also fix mistakes in tcctest.c and the tcc sources (win32)
showing up now.
2016-05-05 20:04:00 +02:00
grischka
fe845cf53d tccpp: cleanup options -dD -dM, remove -C
The lexer is for reading files, not for writing.

Also :
- macro_is_equal(): avoid crash if redefining __FILE__
2016-05-05 14:12:53 +02:00
grischka
caebbc3ee1 tccgen: scope levels for local symbols
... for fast redeclaration checks

Also, check function parameters too:
    void foo(int a) { int a; ... }

Also, try to fix struct/union/enum's on different scopes:
    { struct xxx { int x; };
         { struct xxx { int y; }; ... }}
and some (probably not all) combination with incomplete
declarations "struct xxx;"

Replaces 2bfedb1867
and 07d896c8e5

Fixes cf95ac399c
2016-05-05 10:39:09 +02:00
Edmund Grimley Evans
0fbc77cac6 tests/tests2/Makefile: Make 85-asm-outside-function Intel-only. 2016-05-04 21:23:25 +01:00
Edmund Grimley Evans
a348513569 Revert 78e4ee5. 2016-05-04 20:27:39 +01:00
Edmund Grimley Evans
6015840583 Revert 3283c26 and a1c1390 in tccpp.c. 2016-05-04 20:14:39 +01:00
seyko
07d896c8e5 sym_push2 optimized for the local_stack case.
A constant expression removed from the loop.
    If subroutine have 50000+ local variables, then currently
    compilation of such code takes obly 15 sec. Was 2 min.
    gcc-4.1.2 compiles such code in 7 sec. pcc -- 3.44 min.

    A test generator:
    #include <stdio.h>
    int main() {
        puts("#include <stdio.h>"); puts("int main()"); puts("{");
        for (int i = 0; i < 50000; ++i) printf("int X%d = 1;\n", i);
        for (int i = 0; i < 50000; ++i) puts("scanf(\"%d\", &X0);");
        puts("}");
        return 0;
    }
2016-05-04 17:23:25 +03:00
seyko
2bfedb1867 -fno-type-redefinition-check
don't catch redefinition for local vars. With this option on
    tcc accepts the following code:
    int main()
    {
        int a = 0;
        long a = 0;
    }
    But if you shure there is no problem with your local variables,
    then a compilation speed can be improved if you have a lots of
    the local variables (50000+)
2016-05-04 17:17:51 +03:00
seyko
78e4ee55b7 PP_NUM in ASM mode
oxe+1 is parsed as 0xe +1 if (parse_flags & PARSE_FLAG_ASM_FILE)
        Helps to compile a code:
        __asm__("mov $0xe" "+1", "%eax\n")
2016-05-04 16:54:40 +03:00
Michael Matz
78ee3759b8 x86-asm: Fix lcall/ljmp, xchg and inc/dec
Various x86 asm fixes: 64bit lcall/ljmp like 32bit a commit before,
xchgw accepted wrong operands on 32 and 64bit, and 64bit used
0x40/0x48+reg for incw/decw, but those are REX prefixes, not
instructions.
2016-05-03 01:16:43 +02:00
Michael Matz
d1515a0536 i386-asm: correct lcall/ljmp encoding
The 0xff/3 form of lcall needs a mod/rm byte, so reflect this.
2016-05-02 04:50:12 +02:00
seyko
6afe668ec7 __asm__() outside function
gcc/pcc allow __asm__() outside a function body:
    extern void vide(void);
    __asm__("vide: ret");

    There is many such code in the Linux kernels.
2016-05-01 22:38:38 +03:00
seyko
09a78412f0 lcall hex code correction 2016-05-01 22:14:00 +03:00
seyko
3283c26827 clearing "output space after TOK_PPNUM ..." 2016-05-01 16:36:19 +03:00
seyko
a1c139063b output space after TOK_PPNUM which followed by '+' or '-'
* correct -E output for the case ++ + ++ concatenation
        do this only for expanded from macro string
        and only when tcc_state->output_type == TCC_OUTPUT_PREPROCESS
2016-05-01 05:43:57 +03:00
grischka
256078933c tccpp: macro subst fix
#define Y(x) Z(x)
#define X Y
return X(X(1));

was : return Z(Y(1));
now : return Z(Z(1));
2016-04-29 19:00:33 +02:00
Edmund Grimley Evans
68ce8639bb TODO: Add two issues. 2016-04-24 22:44:57 +01:00
seyko
b4125ba0c1 fix for the "Reduce allocations overhead"
Now no trap when compiling tccboot
2016-04-22 20:32:15 +03:00
seyko
1f49441a27 .rept asm directive
and '.' alone is a token now in *.S (not an identifier)
    representing a current position in the code (PC).
2016-04-22 18:29:56 +03:00
seyko
edcb15c31f section alignment
Alignment of unknown sections changed from 32 to PTR_SIZE
    This is gcc/pcc default value. This helps to use
    tcc as linux kernel compiler.
2016-04-22 18:25:40 +03:00
seyko
8db7a0f7af Source and destination overlap in memcpy, cstr_cat (tccpp.c:322)
This code is from "Improve hash performance"
2016-04-22 18:21:09 +03:00
Michael Matz
d25f67ec12 Run testcases in sorted order
Without sorting they run in whatever order readdir returns,
I like it better when the order is reliable (and alphanumeric).
2016-04-22 15:57:23 +02:00
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