tcc-xref
bellard 2001-12-17 21:57:01 +00:00
parent 2694c10547
commit b0b2d5d2e9
7 changed files with 49 additions and 62 deletions

View File

@ -5,13 +5,13 @@ prefix=/usr/local
CFLAGS=-O2 -g -Wall -Wno-parentheses -Wno-missing-braces -I. CFLAGS=-O2 -g -Wall -Wno-parentheses -Wno-missing-braces -I.
LIBS=-ldl LIBS=-ldl
#CFLAGS=-O2 -g -Wall -Wno-parentheses -I. -pg -static -DPROFILE CFLAGS_P=$(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
#LIBS= LIBS_P=
CFLAGS+=-m386 -malign-functions=0 CFLAGS+=-m386 -malign-functions=0
DISAS=objdump -D -b binary -m i386 DISAS=objdump -D -b binary -m i386
INSTALL=install INSTALL=install
VERSION=0.9.1 VERSION=0.9.2
all: tcc all: tcc
@ -21,7 +21,7 @@ test: test.ref test.out
@if diff -u test.ref test.out ; then echo "Auto Test OK"; fi @if diff -u test.ref test.out ; then echo "Auto Test OK"; fi
prog.ref: prog.c prog.ref: prog.c
gcc $(CFLAGS) -o $@ $< gcc3 $(CFLAGS) -o $@ $<
test.ref: prog.ref test.ref: prog.ref
./prog.ref > $@ ./prog.ref > $@
@ -33,12 +33,12 @@ run: tcc prog.c
./tcc -I. prog.c ./tcc -I. prog.c
# iterated test2 (compile tcc then compile prog.c !) # iterated test2 (compile tcc then compile prog.c !)
test2: tcc tcc.c prog.c test2: tcc tcc.c prog.c test.ref
./tcc -I. tcc.c -I. prog.c > test.out2 ./tcc -I. tcc.c -I. prog.c > test.out2
@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi @if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
# iterated test3 (compile tcc then compile tcc then compile prog.c !) # iterated test3 (compile tcc then compile tcc then compile prog.c !)
test3: tcc tcc.c prog.c test3: tcc tcc.c prog.c test.ref
./tcc -I. tcc.c -I. tcc.c -I. prog.c > test.out3 ./tcc -I. tcc.c -I. tcc.c -I. prog.c > test.out3
@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi @if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
@ -57,7 +57,7 @@ ex3: ex3.c
# Tiny C Compiler # Tiny C Compiler
tcc_g: tcc.c Makefile tcc_g: tcc.c i386-gen.c Makefile
gcc $(CFLAGS) -o $@ $< $(LIBS) gcc $(CFLAGS) -o $@ $< $(LIBS)
tcc: tcc_g tcc: tcc_g
@ -66,11 +66,15 @@ tcc: tcc_g
install: tcc install: tcc
$(INSTALL) -m755 tcc $(prefix)/bin $(INSTALL) -m755 tcc $(prefix)/bin
mkdir -p $(prefix)/lib/tcc mkdir -p $(prefix)/lib/tcc
$(INSTALL) -m644 stdarg.h stddef.h tcclib.h $(prefix)/lib/tcc $(INSTALL) -m644 stdarg.h stddef.h float.h tcclib.h $(prefix)/lib/tcc
clean: clean:
rm -f *~ *.o tcc tcc1 tcct tcc_g prog.ref *.bin *.i ex2 \ rm -f *~ *.o tcc tcc1 tcct tcc_g prog.ref *.bin *.i ex2 \
core gmon.out test.out test.ref a.out core gmon.out test.out test.ref a.out tcc_p
# profiling version
tcc_p: tcc.c Makefile
gcc $(CFLAGS_P) -o $@ $< $(LIBS_P)
# target for development # target for development
@ -78,6 +82,9 @@ clean:
./tcc -o $@ -I. $< ./tcc -o $@ -I. $<
$(DISAS) $@ $(DISAS) $@
instr: instr.o
objdump -d instr.o
instr.o: instr.S instr.o: instr.S
gcc -O2 -Wall -g -c -o $@ $< gcc -O2 -Wall -g -c -o $@ $<
@ -88,6 +95,9 @@ tar:
cp -r ../tcc /tmp/$(FILE) cp -r ../tcc /tmp/$(FILE)
( cd /tmp ; tar zcvf ~/$(FILE).tar.gz \ ( cd /tmp ; tar zcvf ~/$(FILE).tar.gz \
$(FILE)/Makefile $(FILE)/README $(FILE)/TODO $(FILE)/COPYING \ $(FILE)/Makefile $(FILE)/README $(FILE)/TODO $(FILE)/COPYING \
$(FILE)/tcc.c $(FILE)/stddef.h $(FILE)/stdarg.h $(FILE)/tcclib.h \ $(FILE)/Changelog $(FILE)/tcc-doc.html \
$(FILE)/tcc.c $(FILE)/i386-gen.c \
$(FILE)/stddef.h $(FILE)/stdarg.h $(FILE)/stdbool.h $(FILE)/float.h \
$(FILE)/tcclib.h \
$(FILE)/ex*.c $(FILE)/prog.c ) $(FILE)/ex*.c $(FILE)/prog.c )
rm -rf /tmp/$(FILE) rm -rf /tmp/$(FILE)

49
README
View File

@ -5,7 +5,7 @@ Features:
-------- --------
- SMALL! You can compile and execute C code everywhere, for example on - SMALL! You can compile and execute C code everywhere, for example on
rescue disks (29KB for x86 TCC executable). rescue disks.
- FAST! tcc generates optimized x86 code. No byte code - FAST! tcc generates optimized x86 code. No byte code
overhead. Compiles, assemble and link about 7 times faster than 'gcc overhead. Compiles, assemble and link about 7 times faster than 'gcc
@ -27,7 +27,7 @@ Documentation:
1) Installation 1) Installation
***TCC currently only work on Linux x86***. ***TCC currently only works on Linux x86***.
Type 'make install' to compile and install tcc in /usr/local/bin and Type 'make install' to compile and install tcc in /usr/local/bin and
/usr/local/lib/tcc. /usr/local/lib/tcc.
@ -60,8 +60,8 @@ default ones are: /usr/include, /usr/lib/tcc, /usr/local/lib/tcc.
libxxx.so. Standard library paths are checked, including those libxxx.so. Standard library paths are checked, including those
specificed with LD_LIBRARY_PATH. specificed with LD_LIBRARY_PATH.
Only one source code can be compiled. If you have multiple source '-i file' : compile C source 'file' before main C source. With this
files, add one which includes all your sources. command, multiple C files can be compiled and linked together.
4) Examples 4) Examples
@ -84,44 +84,9 @@ generator.
prog.c: auto test for TCC which tests many subtle possible bugs. Used prog.c: auto test for TCC which tests many subtle possible bugs. Used
when doing 'make test'. when doing 'make test'.
Exact differences with ANSI C: 5) Full Documentation
-----------------------------
- Preprocessor: the preprocessor tokens are the same as C. It means Please read tcc-doc.html to have all the features of TCC.
that in some rare cases, preprocessed numbers are not handled
exactly as in ANSI C. This approach has the advantage of being
simpler and FAST!
- Types: floating point numbers are not supported yet.
- Bit fields are not supported.
- Linking: extern variables must appear in a referenced dll and cannot
appear in current source.
Supported ANSI C extensions:
---------------------------
- 'inline' keyword is ignored (ISOC99).
- 'restrict' keyword is ignored (ISOC99).
- '__func__' is a string variable containing the current function name (ISOC99).
- Variadic macros: __VA_ARGS__ can be used for function-like macros (ISOC99):
#define dprintf(level, __VA_ARGS__) printf(__VA_ARGS__).
- Declarations can appear anywhere in a block (ISOC99).
- Array and struct/union elements can be initialized in any order by
using designators (.e.g. { [0].x = 1 }) (ISOC99).
- Compound initializers are supported (e.g. int *p = (int []){ 1, 2,
3}) (ISOC99).
- '#!' at the start of a line is ignored to allow scripting.
- Binary digits can be entered ('0b101' instead of '5').
Technical Description: Technical Description:
--------------------- ---------------------
@ -162,7 +127,7 @@ License:
TCC is distributed under the GNU General Public License (see COPYING TCC is distributed under the GNU General Public License (see COPYING
file). file).
I accept only patches where you give your copyright explictely to me I accept only patches where you give your copyright explicitely to me
to simplify licensing issues. to simplify licensing issues.
Fabrice Bellard - Nov 17, 2001. Fabrice Bellard - Nov 17, 2001.

14
TODO
View File

@ -1,21 +1,21 @@
TODO list: TODO list:
Critical: Critical:
- finish float/double support. add function type convertion.
- add float/double support (should be as small as possible while being - section generation and GNUC __attributte__ handling.
usable for RISC code generator too). - D option with '=' handling
- 0 is pointer - fix type compare - 0 is pointer - fix type compare
- add message if external function or variable not found.
- To check: 'sizeof' may not work if too complex expression is given. - To check: 'sizeof' may not work if too complex expression is given.
- fix 'char' and 'short' casts (in function parameters and in assignment). - fix 'char' and 'short' casts (only in function parameters and in
- function pointers to forward reference (patch code generator). assignment).
Not critical: Not critical:
- interactive mode
- fix multiple compound literals inits in blocks (ISOC99 normative - fix multiple compound literals inits in blocks (ISOC99 normative
example - only relevant when using gotos! -> must add boolean example - only relevant when using gotos! -> must add boolean
variable to tell if compound literal was already initialized). variable to tell if compound literal was already initialized).
- fix L"\x1234" wide string case (need to store them as ints ?) */ - fix L"\x1234" wide string case (need to store them as utf8 ?)
- fix preprocessor symbol redefinition - fix preprocessor symbol redefinition
- better constant opt (&&, ||, ?:) - better constant opt (&&, ||, ?:)
- add ELF executable and shared library output option (would be needed - add ELF executable and shared library output option (would be needed

10
stdbool.h 100644
View File

@ -0,0 +1,10 @@
#ifndef _STDBOOL_H
#define _STDBOOL_H
/* ISOC99 boolean */
#define bool _Bool
#define true 1
#define false 0
#endif /* _STDBOOL_H */

View File

@ -1,9 +1,10 @@
#ifndef _STDDEF_H #ifndef _STDDEF_H
#define _STDDEF_H #define _STDDEF_H
/* TCC include file */
#define NULL ((void *)0) #define NULL ((void *)0)
typedef unsigned int size_t; typedef unsigned int size_t;
typedef int wchar_t; typedef int wchar_t;
typedef int ptrdiff_t;
#define offsetof(type, field) ((size_t) &((type *)0)->field)
#endif #endif

View File

@ -29,8 +29,8 @@ it was an executable.
<h2>Exact differences with ANSI C</h2> <h2>Exact differences with ANSI C</h2>
TCC implements almost all the ANSI C standard, except floating point TCC implements almost all the ANSI C standard, except floating points
and long long numbers. numbers.
<ul> <ul>
<li> The preprocessor tokens are the same as C. It means that in some <li> The preprocessor tokens are the same as C. It means that in some

View File

@ -4,6 +4,7 @@
* only for your convenience so that you do not need to put the whole * only for your convenience so that you do not need to put the whole
* glibc include files on your floppy disk * glibc include files on your floppy disk
*/ */
#include <stddef.h> #include <stddef.h>
#include <stdarg.h> #include <stdarg.h>