History

Some in-between fixes (See Changelog for details).

grischka committed 18 years ago

Commit 2de1b2d1 parent 2bcb9642 files · +98 −66Browse files

Unified · Split

2 files
  1. tcc.c +68 −66
  2. win32/build-tcc.bat +30 −0
tcc.c+68−66
@@ -321,6 +321,7 @@ static int tok_flags; · 320 unmodified lines
321321 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
322322 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
323323 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
324+#define TOK_FLAG_EOF 0x0008 /* end of file */
324325
325326 static int *macro_ptr, *macro_ptr_allocated;
326327 static int *unget_saved_macro_ptr;
@@ -1032,6 +1033,32 @@ static int strstart(const char *str, const char *val, const char **ptr) · 705 unmodified lines
10321033 return 1;
10331034 }
10341035
1036+#ifdef WIN32
1037+char *normalize_slashes(char *path)
1038+{
1039+ char *p;
1040+ for (p = path; *p; ++p)
1041+ if (*p == '\\')
1042+ *p = '/';
1043+ return path;
1044+}
1045+
1046+char *w32_tcc_lib_path(void)
1047+{
1048+ /* on win32, we suppose the lib and includes are at the location
1049+ of 'tcc.exe' */
1050+ char path[1024], *p;
1051+ GetModuleFileNameA(NULL, path, sizeof path);
1052+ p = tcc_basename(normalize_slashes(strlwr(path)));
1053+ if (p - 5 > path && 0 == strncmp(p - 5, "/bin/", 5))
1054+ p -= 5;
1055+ else if (p > path)
1056+ p--;
1057+ *p = 0;
1058+ return strdup(path);
1059+}
1060+#endif
1061+
10351062 /* memory management */
10361063 #ifdef MEM_DEBUG
10371064 int mem_cur_size;
@@ -1844,7 +1871,6 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) · 806 unmodified lines
18441871 {
18451872 int fd;
18461873 BufferedFile *bf;
1847− int i, len;
18481874
18491875 fd = open(filename, O_RDONLY | O_BINARY);
18501876 if (fd < 0)
@@ -1859,10 +1885,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename) · 8 unmodified lines
18591885 bf->buf_end = bf->buffer;
18601886 bf->buffer[0] = CH_EOB; /* put eob symbol */
18611887 pstrcpy(bf->filename, sizeof(bf->filename), filename);
1862− len = strlen(bf->filename);
1863− for (i = 0; i < len; i++)
1864− if (bf->filename[i] == '\\')
1865− bf->filename[i] = '/';
1888+ normalize_slashes(bf->filename);
18661889 bf->line_num = 1;
18671890 bf->ifndef_macro = 0;
18681891 bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
@@ -3540,13 +3563,17 @@ static inline void next_nomacro1(void) · 1671 unmodified lines
35403563 parse_eof:
35413564 {
35423565 TCCState *s1 = tcc_state;
3543− if (parse_flags & PARSE_FLAG_LINEFEED) {
3566+ if ((parse_flags & PARSE_FLAG_LINEFEED)
3567+ && !(tok_flags & TOK_FLAG_EOF)) {
3568+ tok_flags |= TOK_FLAG_EOF;
35443569 tok = TOK_LINEFEED;
3570+ goto keep_tok_flags;
35453571 } else if (s1->include_stack_ptr == s1->include_stack ||
35463572 !(parse_flags & PARSE_FLAG_PREPROCESS)) {
35473573 /* no include left : end of file. */
35483574 tok = TOK_EOF;
35493575 } else {
3576+ tok_flags &= ~TOK_FLAG_EOF;
35503577 /* pop include file */
35513578
35523579 /* test if previous '#endif' was after a #ifdef at
@@ -3574,15 +3601,13 @@ static inline void next_nomacro1(void) · 21 unmodified lines
35743601 break;
35753602
35763603 case '\n':
3577− if (parse_flags & PARSE_FLAG_LINEFEED) {
3578− tok = TOK_LINEFEED;
3579− } else {
3580− file->line_num++;
3581− tok_flags |= TOK_FLAG_BOL;
3582− p++;
3604+ file->line_num++;
3605+ tok_flags |= TOK_FLAG_BOL;
3606+ p++;
3607+ if (0 == (parse_flags & PARSE_FLAG_LINEFEED))
35833608 goto redo_no_start;
3584− }
3585− break;
3609+ tok = TOK_LINEFEED;
3610+ goto keep_tok_flags;
35863611
35873612 case '#':
35883613 /* XXX: simplify */
@@ -3912,8 +3937,9 @@ static inline void next_nomacro1(void) · 323 unmodified lines
39123937 error("unrecognized character \\x%02x", c);
39133938 break;
39143939 }
3915− file->buf_ptr = p;
39163940 tok_flags = 0;
3941+keep_tok_flags:
3942+ file->buf_ptr = p;
39173943 #if defined(PARSE_DEBUG)
39183944 printf("token = %s\n", get_tok_str(tok, &tokc));
39193945 #endif
@@ -4140,7 +4166,8 @@ static int macro_subst_tok(TokenString *tok_str, · 220 unmodified lines
41404166 parlevel++;
41414167 else if (tok == ')')
41424168 parlevel--;
4143− tok_str_add2(&str, tok, &tokc);
4169+ if (tok != TOK_LINEFEED)
4170+ tok_str_add2(&str, tok, &tokc);
41444171 next_nomacro();
41454172 }
41464173 tok_str_add(&str, 0);
@@ -8188,9 +8215,6 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 4041 unmodified lines
81888215 int v1, v2;
81898216 if (!case_sym)
81908217 expect("switch");
8191− /* since a case is like a label, we must skip it with a jmp */
8192− b = gjmp(0);
8193− next_case:
81948218 next();
81958219 v1 = expr_const();
81968220 v2 = v1;
@@ -8200,26 +8224,24 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 3 unmodified lines
82008224 if (v2 < v1)
82018225 warning("empty case range");
82028226 }
8227+ /* since a case is like a label, we must skip it with a jmp */
8228+ b = gjmp(0);
82038229 gsym(*case_sym);
82048230 vseti(case_reg, 0);
82058231 vpushi(v1);
82068232 if (v1 == v2) {
82078233 gen_op(TOK_EQ);
8208− *case_sym = 0;
8234+ *case_sym = gtst(1, 0);
82098235 } else {
82108236 gen_op(TOK_GE);
82118237 *case_sym = gtst(1, 0);
82128238 vseti(case_reg, 0);
82138239 vpushi(v2);
82148240 gen_op(TOK_LE);
8241+ *case_sym = gtst(1, *case_sym);
82158242 }
8216− skip(':');
8217− if (tok == TOK_CASE) {
8218− b = gtst(0, b);
8219− goto next_case;
8220− }
8221− *case_sym = gtst(1, *case_sym);
82228243 gsym(b);
8244+ skip(':');
82238245 is_expr = 0;
82248246 goto block_after_label;
82258247 } else
@@ -9015,6 +9037,8 @@ static void func_decl_list(Sym *func_sym) · 789 unmodified lines
90159037 'cur_text_section' */
90169038 static void gen_function(Sym *sym)
90179039 {
9040+ int saved_nocode_wanted = nocode_wanted;
9041+ nocode_wanted = 0;
90189042 ind = cur_text_section->data_offset;
90199043 /* NOTE: we patch the symbol size later */
90209044 put_extern_sym(sym, cur_text_section, ind, 0);
@@ -9043,6 +9067,7 @@ static void gen_function(Sym *sym) · 22 unmodified lines
90439067 funcname = ""; /* for safety */
90449068 func_vt.t = VT_VOID; /* for safety */
90459069 ind = 0; /* for safety */
9070+ nocode_wanted = saved_nocode_wanted;
90469071 }
90479072
90489073 static void gen_inline_functions(void)
@@ -9350,6 +9375,7 @@ static int tcc_compile(TCCState *s1) · 301 unmodified lines
93509375 #endif
93519376
93529377 define_start = define_stack;
9378+ nocode_wanted = 1;
93539379
93549380 if (setjmp(s1->error_jmp_buf) == 0) {
93559381 s1->nb_errors = 0;
@@ -9400,26 +9426,19 @@ static int tcc_preprocess(TCCState *s1) · 44 unmodified lines
94009426 last_is_space = 1;
94019427 next();
94029428 for(;;) {
9403− if (tok == TOK_EOF)
9429+ if (tok == TOK_EOF) {
94049430 break;
9405− if (!last_is_space) {
9406− fputc(' ', s1->outfile);
9407− }
9408− fputs(get_tok_str(tok, &tokc), s1->outfile);
9409− if (tok == TOK_LINEFEED) {
9431+ } else if (tok == TOK_LINEFEED) {
94109432 last_is_space = 1;
9411− /* XXX: suppress that hack */
9412− parse_flags &= ~PARSE_FLAG_LINEFEED;
9413− next();
9414− parse_flags |= PARSE_FLAG_LINEFEED;
9415− } else {
9433+ } else {
9434+ if (!last_is_space)
9435+ fputc(' ', s1->outfile);
94169436 last_is_space = 0;
9417− next();
94189437 }
9438+ fputs(get_tok_str(tok, &tokc), s1->outfile);
9439+ next();
94199440 }
9420−
94219441 free_defines(define_start);
9422−
94239442 return 0;
94249443 }
94259444
@@ -10380,17 +10399,15 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value) · 954 unmodified lines
1038010399 /* extract the basename of a file */
1038110400 static char *tcc_basename(const char *name)
1038210401 {
10383− const char *p;
10384− p = strrchr(name, '/');
10402+ char *p = strchr(name, 0);
10403+ while (p > name
10404+ && p[-1] != '/'
1038510405 #ifdef WIN32
10386− if (!p)
10387− p = strrchr(name, '\\');
10388−#endif
10389− if (!p)
10390− p = name;
10391− else
10392− p++;
10393− return (char*)p;
10406+ && p[-1] != '\\'
10407+#endif
10408+ )
10409+ --p;
10410+ return p;
1039410411 }
1039510412
1039610413 #if !defined(LIBTCC)
@@ -10774,22 +10791,7 @@ int main(int argc, char **argv) · 377 unmodified lines
1077410791 int64_t start_time = 0;
1077510792
1077610793 #ifdef WIN32
10777− /* on win32, we suppose the lib and includes are at the location
10778− of 'tcc.exe' */
10779− {
10780− static char path[1024];
10781− char *p, *d;
10782−
10783− GetModuleFileNameA(NULL, path, sizeof path);
10784− p = d = strlwr(path);
10785− while (*d)
10786− {
10787− if (*d == '\\') *d = '/', p = d;
10788− ++d;
10789− }
10790− *p = '\0';
10791− tcc_lib_path = path;
10792− }
10794+ tcc_lib_path = w32_tcc_lib_path();
1079310795 #endif
1079410796
1079510797 s = tcc_new();
win32/build-tcc.bat+30−0
@@ -0,0 +1,30 @@
1+@rem ----------------------------------------------------
2+@rem batch file to build tcc using gcc and ar from mingw
3+@rem ----------------------------------------------------
4+:
5+@if exist ..\config.h goto configready
6+:
7+@echo>..\config.h #define TCC_VERSION "0.9.24pre"
8+@echo>>..\config.h #define TCC_TARGET_PE 1
9+@echo>>..\config.h #define CONFIG_TCCDIR NULL
10+:
11+:configready
12+:
13+gcc -Os -fno-strict-aliasing ../tcc.c -o tcc.exe -s
14+gcc -Os -fno-strict-aliasing ../tcc.c -D LIBTCC -c -o libtcc.o
15+gcc -Os -fno-strict-aliasing ../tiny_impdef.c -o tiny_impdef.exe -s
16+mkdir libtcc
17+ar rcs libtcc/libtcc.a libtcc.o
18+del libtcc.o
19+copy ..\libtcc.h libtcc
20+:
21+.\tcc -c lib/crt1.c
22+.\tcc -c lib/wincrt1.c
23+.\tcc -c lib/dllcrt1.c
24+.\tcc -c lib/dllmain.c
25+.\tcc -c lib/chkstk.S
26+.\tcc -c ../libtcc1.c
27+.\tcc -c ../alloca86.S
28+.\tcc -c ../alloca86-bt.S
29+ar rcs lib/libtcc1.a crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o libtcc1.o alloca86.o alloca86-bt.o
30+del *.o

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t