mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-19 05:30:07 +08:00
clean '\t'
This commit is contained in:
parent
c6345b5a8a
commit
07614b5e22
6
libtcc.c
6
libtcc.c
@ -879,10 +879,10 @@ static void tcc_cleanup(void)
|
|||||||
/* free tokens */
|
/* free tokens */
|
||||||
n = tok_ident - TOK_IDENT;
|
n = tok_ident - TOK_IDENT;
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
def = &table_ident[i]->sym_define;
|
def = &table_ident[i]->sym_define;
|
||||||
tcc_free(def->data);
|
tcc_free(def->data);
|
||||||
tcc_free(table_ident[i]);
|
tcc_free(table_ident[i]);
|
||||||
}
|
}
|
||||||
tcc_free(table_ident);
|
tcc_free(table_ident);
|
||||||
|
|
||||||
/* free sym_pools */
|
/* free sym_pools */
|
||||||
|
6
tccgen.c
6
tccgen.c
@ -5234,13 +5234,13 @@ static void init_putz(CType *t, Section *sec, unsigned long c, int size)
|
|||||||
} else {
|
} else {
|
||||||
vpush_global_sym(&func_old_type, TOK_memset);
|
vpush_global_sym(&func_old_type, TOK_memset);
|
||||||
vseti(VT_LOCAL, c);
|
vseti(VT_LOCAL, c);
|
||||||
# ifdef TCC_TARGET_ARM
|
#ifdef TCC_TARGET_ARM
|
||||||
vpushs(size);
|
vpushs(size);
|
||||||
vpushi(0);
|
vpushi(0);
|
||||||
# else
|
#else
|
||||||
vpushi(0);
|
vpushi(0);
|
||||||
vpushs(size);
|
vpushs(size);
|
||||||
# endif
|
#endif
|
||||||
gfunc_call(3);
|
gfunc_call(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
312
tccpp.c
312
tccpp.c
@ -1056,7 +1056,7 @@ static int macro_is_equal(const int *a, const int *b)
|
|||||||
ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
|
ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
|
||||||
{
|
{
|
||||||
Sym *s;
|
Sym *s;
|
||||||
CSym *def;
|
CSym *def;
|
||||||
s = define_find(v);
|
s = define_find(v);
|
||||||
if (s && !macro_is_equal(s->d, str))
|
if (s && !macro_is_equal(s->d, str))
|
||||||
tcc_warning("%s redefined", get_tok_str(v, NULL));
|
tcc_warning("%s redefined", get_tok_str(v, NULL));
|
||||||
@ -1064,19 +1064,19 @@ ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg)
|
|||||||
s->d = str;
|
s->d = str;
|
||||||
s->next = first_arg;
|
s->next = first_arg;
|
||||||
def = &table_ident[v - TOK_IDENT]->sym_define;
|
def = &table_ident[v - TOK_IDENT]->sym_define;
|
||||||
def->data[def->off] = s;
|
def->data[def->off] = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* undefined a define symbol. Its name is just set to zero */
|
/* undefined a define symbol. Its name is just set to zero */
|
||||||
ST_FUNC void define_undef(Sym *s)
|
ST_FUNC void define_undef(Sym *s)
|
||||||
{
|
{
|
||||||
int v;
|
int v;
|
||||||
CSym *def;
|
CSym *def;
|
||||||
v = s->v - TOK_IDENT;
|
v = s->v - TOK_IDENT;
|
||||||
if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){
|
if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){
|
||||||
def = &table_ident[v]->sym_define;
|
def = &table_ident[v]->sym_define;
|
||||||
def->data[def->off] = NULL;
|
def->data[def->off] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ST_INLN Sym *define_find(int v)
|
ST_INLN Sym *define_find(int v)
|
||||||
@ -1085,7 +1085,7 @@ ST_INLN Sym *define_find(int v)
|
|||||||
v -= TOK_IDENT;
|
v -= TOK_IDENT;
|
||||||
if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
|
if ((unsigned)v >= (unsigned)(tok_ident - TOK_IDENT))
|
||||||
return NULL;
|
return NULL;
|
||||||
def = &table_ident[v]->sym_define;
|
def = &table_ident[v]->sym_define;
|
||||||
return def->data[def->off];
|
return def->data[def->off];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1094,7 +1094,7 @@ ST_FUNC void free_defines(Sym *b)
|
|||||||
{
|
{
|
||||||
Sym *top, *tmp;
|
Sym *top, *tmp;
|
||||||
int v;
|
int v;
|
||||||
CSym *def;
|
CSym *def;
|
||||||
|
|
||||||
top = define_stack;
|
top = define_stack;
|
||||||
while (top != b) {
|
while (top != b) {
|
||||||
@ -1104,12 +1104,12 @@ ST_FUNC void free_defines(Sym *b)
|
|||||||
tok_str_free(top->d);
|
tok_str_free(top->d);
|
||||||
v = top->v - TOK_IDENT;
|
v = top->v - TOK_IDENT;
|
||||||
if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){
|
if ((unsigned)v < (unsigned)(tok_ident - TOK_IDENT)){
|
||||||
def = &table_ident[v]->sym_define;
|
def = &table_ident[v]->sym_define;
|
||||||
if(def->off)
|
if(def->off)
|
||||||
def->off = 0;
|
def->off = 0;
|
||||||
if(def->data[0])
|
if(def->data[0])
|
||||||
def->data[0] = NULL;
|
def->data[0] = NULL;
|
||||||
}
|
}
|
||||||
sym_free(top);
|
sym_free(top);
|
||||||
top = tmp;
|
top = tmp;
|
||||||
}
|
}
|
||||||
@ -1398,8 +1398,8 @@ read_name:
|
|||||||
} else
|
} else
|
||||||
inp();
|
inp();
|
||||||
}
|
}
|
||||||
if (ch != c)
|
if (ch != c)
|
||||||
goto include_syntax;
|
goto include_syntax;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
minp();
|
minp();
|
||||||
#if 0
|
#if 0
|
||||||
@ -1438,8 +1438,8 @@ read_name:
|
|||||||
c = '>';
|
c = '>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!buf[0])
|
if(!buf[0])
|
||||||
tcc_error(" empty filename in #include");
|
tcc_error(" empty filename in #include");
|
||||||
|
|
||||||
if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
|
if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
|
||||||
tcc_error("#include recursion too deep");
|
tcc_error("#include recursion too deep");
|
||||||
@ -1588,9 +1588,9 @@ skip:
|
|||||||
file->ifndef_macro = 0;
|
file->ifndef_macro = 0;
|
||||||
tok_flags |= TOK_FLAG_ENDIF;
|
tok_flags |= TOK_FLAG_ENDIF;
|
||||||
}
|
}
|
||||||
next_nomacro();
|
next_nomacro();
|
||||||
if (tok != TOK_LINEFEED)
|
if (tok != TOK_LINEFEED)
|
||||||
tcc_warning("Ignoring: %s", get_tok_str(tok, &tokc));
|
tcc_warning("Ignoring: %s", get_tok_str(tok, &tokc));
|
||||||
break;
|
break;
|
||||||
case TOK_LINE:
|
case TOK_LINE:
|
||||||
next();
|
next();
|
||||||
@ -1626,144 +1626,144 @@ skip:
|
|||||||
tcc_warning("#warning %s", buf);
|
tcc_warning("#warning %s", buf);
|
||||||
break;
|
break;
|
||||||
case TOK_PRAGMA:
|
case TOK_PRAGMA:
|
||||||
next();
|
next();
|
||||||
if (tok == TOK_pack && parse_flags & PARSE_FLAG_PACK) {
|
if (tok == TOK_pack && parse_flags & PARSE_FLAG_PACK) {
|
||||||
/*
|
/*
|
||||||
This may be:
|
This may be:
|
||||||
#pragma pack(1) // set
|
#pragma pack(1) // set
|
||||||
#pragma pack() // reset to default
|
#pragma pack() // reset to default
|
||||||
#pragma pack(push,1) // push & set
|
#pragma pack(push,1) // push & set
|
||||||
#pragma pack(pop) // restore previous
|
#pragma pack(pop) // restore previous
|
||||||
*/
|
*/
|
||||||
next();
|
next();
|
||||||
skip('(');
|
skip('(');
|
||||||
if (tok == TOK_ASM_pop) {
|
if (tok == TOK_ASM_pop) {
|
||||||
next();
|
next();
|
||||||
if (s1->pack_stack_ptr <= s1->pack_stack) {
|
if (s1->pack_stack_ptr <= s1->pack_stack) {
|
||||||
stk_error:
|
stk_error:
|
||||||
tcc_error("out of pack stack");
|
tcc_error("out of pack stack");
|
||||||
}
|
}
|
||||||
s1->pack_stack_ptr--;
|
s1->pack_stack_ptr--;
|
||||||
} else {
|
} else {
|
||||||
int val = 0;
|
int val = 0;
|
||||||
if (tok != ')') {
|
if (tok != ')') {
|
||||||
if (tok == TOK_ASM_push) {
|
if (tok == TOK_ASM_push) {
|
||||||
next();
|
next();
|
||||||
s1->pack_stack_ptr++;
|
s1->pack_stack_ptr++;
|
||||||
if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE)
|
if (s1->pack_stack_ptr >= s1->pack_stack + PACK_STACK_SIZE)
|
||||||
goto stk_error;
|
goto stk_error;
|
||||||
skip(',');
|
skip(',');
|
||||||
}
|
}
|
||||||
if (tok != TOK_CINT) {
|
if (tok != TOK_CINT) {
|
||||||
pack_error:
|
pack_error:
|
||||||
tcc_error("invalid pack pragma");
|
tcc_error("invalid pack pragma");
|
||||||
}
|
}
|
||||||
val = tokc.i;
|
val = tokc.i;
|
||||||
if (val < 1 || val > 16)
|
if (val < 1 || val > 16)
|
||||||
goto pack_error;
|
goto pack_error;
|
||||||
if (val < 1 || val > 16)
|
if (val < 1 || val > 16)
|
||||||
tcc_error("Value must be greater than 1 is less than or equal to 16");
|
tcc_error("Value must be greater than 1 is less than or equal to 16");
|
||||||
if ((val & (val - 1)) != 0)
|
if ((val & (val - 1)) != 0)
|
||||||
tcc_error("Value must be a power of 2 curtain");
|
tcc_error("Value must be a power of 2 curtain");
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
*s1->pack_stack_ptr = val;
|
*s1->pack_stack_ptr = val;
|
||||||
skip(')');
|
skip(')');
|
||||||
}
|
}
|
||||||
}else if (tok == TOK_PUSH_MACRO || tok == TOK_POP_MACRO) {
|
}else if (tok == TOK_PUSH_MACRO || tok == TOK_POP_MACRO) {
|
||||||
TokenSym *ts;
|
TokenSym *ts;
|
||||||
CSym *def;
|
CSym *def;
|
||||||
uint8_t *p1;
|
uint8_t *p1;
|
||||||
int len, t;
|
int len, t;
|
||||||
t = tok;
|
t = tok;
|
||||||
ch = file->buf_ptr[0];
|
ch = file->buf_ptr[0];
|
||||||
skip_spaces();
|
skip_spaces();
|
||||||
if (ch != '(')
|
if (ch != '(')
|
||||||
goto macro_xxx_syntax;
|
goto macro_xxx_syntax;
|
||||||
/* XXX: incorrect if comments : use next_nomacro with a special mode */
|
/* XXX: incorrect if comments : use next_nomacro with a special mode */
|
||||||
inp();
|
inp();
|
||||||
skip_spaces();
|
skip_spaces();
|
||||||
if (ch == '\"'){
|
if (ch == '\"'){
|
||||||
inp();
|
inp();
|
||||||
p = buf;
|
p = buf;
|
||||||
while (ch != '\"' && ch != '\n' && ch != CH_EOF) {
|
while (ch != '\"' && ch != '\n' && ch != CH_EOF) {
|
||||||
if ((p - buf) < sizeof(buf) - 1)
|
if ((p - buf) < sizeof(buf) - 1)
|
||||||
*p++ = ch;
|
*p++ = ch;
|
||||||
if (ch == CH_EOB) {
|
if (ch == CH_EOB) {
|
||||||
--p;
|
--p;
|
||||||
handle_stray();
|
handle_stray();
|
||||||
}else
|
}else
|
||||||
inp();
|
inp();
|
||||||
}
|
}
|
||||||
if(ch != '\"')
|
if(ch != '\"')
|
||||||
goto macro_xxx_syntax;
|
goto macro_xxx_syntax;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
minp();
|
minp();
|
||||||
next();
|
next();
|
||||||
}else{
|
}else{
|
||||||
/* computed #pragma macro_xxx for #define xxx */
|
/* computed #pragma macro_xxx for #define xxx */
|
||||||
next();
|
next();
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
while (tok != ')') {
|
while (tok != ')') {
|
||||||
if (tok != TOK_STR) {
|
if (tok != TOK_STR) {
|
||||||
macro_xxx_syntax:
|
macro_xxx_syntax:
|
||||||
tcc_error("'macro_xxx' expects (\"NAME\")");
|
tcc_error("'macro_xxx' expects (\"NAME\")");
|
||||||
}
|
}
|
||||||
pstrcat(buf, sizeof(buf), (char *)tokc.cstr->data);
|
pstrcat(buf, sizeof(buf), (char *)tokc.cstr->data);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
skip (')');
|
skip (')');
|
||||||
if(!buf[0])
|
if(!buf[0])
|
||||||
tcc_error(" empty string in #pragma");
|
tcc_error(" empty string in #pragma");
|
||||||
/* find TokenSym */
|
/* find TokenSym */
|
||||||
p = buf;
|
p = buf;
|
||||||
while (is_space(*p))
|
while (is_space(*p))
|
||||||
p++;
|
p++;
|
||||||
p1 = p;
|
p1 = p;
|
||||||
for(;;){
|
for(;;){
|
||||||
if (!isidnum_table[p[0] - CH_EOF])
|
if (!isidnum_table[p[0] - CH_EOF])
|
||||||
break;
|
break;
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
len = p - p1;
|
len = p - p1;
|
||||||
while (is_space(*p))
|
while (is_space(*p))
|
||||||
p++;
|
p++;
|
||||||
if(!p) //'\0'
|
if(!p) //'\0'
|
||||||
tcc_error("unrecognized string: %s", buf);
|
tcc_error("unrecognized string: %s", buf);
|
||||||
ts = tok_alloc(p1, len);
|
ts = tok_alloc(p1, len);
|
||||||
if(ts){
|
if(ts){
|
||||||
def = &ts->sym_define;
|
def = &ts->sym_define;
|
||||||
if(t == TOK_PUSH_MACRO){
|
if(t == TOK_PUSH_MACRO){
|
||||||
void *tmp = def->data[def->off];
|
void *tmp = def->data[def->off];
|
||||||
if(tmp){
|
if(tmp){
|
||||||
def->off++;
|
def->off++;
|
||||||
if(def->off >= def->size){
|
if(def->off >= def->size){
|
||||||
int size = def->size;
|
int size = def->size;
|
||||||
size *= 2;
|
size *= 2;
|
||||||
if (size >= MACRO_STACK_SIZE)
|
if (size >= MACRO_STACK_SIZE)
|
||||||
tcc_error("stack full");
|
tcc_error("stack full");
|
||||||
def->data = tcc_realloc(def->data, size*sizeof(Sym**));
|
def->data = tcc_realloc(def->data, size*sizeof(Sym**));
|
||||||
def->size = size;
|
def->size = size;
|
||||||
}
|
}
|
||||||
def->data[def->off] = tmp;
|
def->data[def->off] = tmp;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(def->off){
|
if(def->off){
|
||||||
--def->off;
|
--def->off;
|
||||||
}else{
|
}else{
|
||||||
tcc_warning("stack empty");
|
tcc_warning("stack empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
fputs("#pragma ", s1->ppfp);
|
fputs("#pragma ", s1->ppfp);
|
||||||
while (tok != TOK_LINEFEED){
|
while (tok != TOK_LINEFEED){
|
||||||
fputs(get_tok_str(tok, &tokc), s1->ppfp);
|
fputs(get_tok_str(tok, &tokc), s1->ppfp);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
goto the_end;
|
goto the_end;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (tok == TOK_LINEFEED || tok == '!' || tok == TOK_PPNUM) {
|
if (tok == TOK_LINEFEED || tok == '!' || tok == TOK_PPNUM) {
|
||||||
@ -3245,8 +3245,8 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
|
|||||||
line_ref = 0;
|
line_ref = 0;
|
||||||
file_ref = NULL;
|
file_ref = NULL;
|
||||||
iptr = s1->include_stack_ptr;
|
iptr = s1->include_stack_ptr;
|
||||||
tok = TOK_LINEFEED; /* print line */
|
tok = TOK_LINEFEED; /* print line */
|
||||||
goto print_line;
|
goto print_line;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
next();
|
next();
|
||||||
if (tok == TOK_EOF) {
|
if (tok == TOK_EOF) {
|
||||||
|
2
tcctok.h
2
tcctok.h
@ -139,7 +139,7 @@
|
|||||||
/* pragma */
|
/* pragma */
|
||||||
DEF(TOK_pack, "pack")
|
DEF(TOK_pack, "pack")
|
||||||
DEF(TOK_PUSH_MACRO, "push_macro")
|
DEF(TOK_PUSH_MACRO, "push_macro")
|
||||||
DEF(TOK_POP_MACRO, "pop_macro")
|
DEF(TOK_POP_MACRO, "pop_macro")
|
||||||
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
|
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
|
||||||
/* already defined for assembler */
|
/* already defined for assembler */
|
||||||
DEF(TOK_ASM_push, "push")
|
DEF(TOK_ASM_push, "push")
|
||||||
|
@ -380,21 +380,21 @@ comment
|
|||||||
comment. */
|
comment. */
|
||||||
TEST2 /* the comment */ ();
|
TEST2 /* the comment */ ();
|
||||||
/* macro_push and macro_pop test */
|
/* macro_push and macro_pop test */
|
||||||
#define MACRO_TEST "macro_test1\n"
|
#define MACRO_TEST "macro_test1\n"
|
||||||
#pragma push_macro("MACRO_TEST")
|
#pragma push_macro("MACRO_TEST")
|
||||||
#undef MACRO_TEST
|
#undef MACRO_TEST
|
||||||
#define MACRO_TEST "macro_test2\n"
|
#define MACRO_TEST "macro_test2\n"
|
||||||
printf(MACRO_TEST);
|
printf(MACRO_TEST);
|
||||||
#pragma pop_macro("MACRO_TEST")
|
#pragma pop_macro("MACRO_TEST")
|
||||||
printf(MACRO_TEST);
|
printf(MACRO_TEST);
|
||||||
/* gcc does not support
|
/* gcc does not support
|
||||||
#define MACRO_TEST_MACRO "MACRO_TEST"
|
#define MACRO_TEST_MACRO "MACRO_TEST"
|
||||||
#pragma push_macro(MACRO_TEST_MACRO)
|
#pragma push_macro(MACRO_TEST_MACRO)
|
||||||
#undef MACRO_TEST
|
#undef MACRO_TEST
|
||||||
#define MACRO_TEST "macro_test3\n"
|
#define MACRO_TEST "macro_test3\n"
|
||||||
printf(MACRO_TEST);
|
printf(MACRO_TEST);
|
||||||
#pragma pop_macro(MACRO_TEST_MACRO)
|
#pragma pop_macro(MACRO_TEST_MACRO)
|
||||||
printf(MACRO_TEST);
|
printf(MACRO_TEST);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user