tccpp: convert TOK_GET macro into function
This commit is contained in:
parent
280e20b1d3
commit
4e5170d4a5
3 changed files with 71 additions and 75 deletions
6
tcc.h
6
tcc.h
|
@ -191,7 +191,7 @@ typedef union CValue {
|
||||||
unsigned long long ull;
|
unsigned long long ull;
|
||||||
struct CString *cstr;
|
struct CString *cstr;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
int tab[1];
|
int tab[2];
|
||||||
} CValue;
|
} CValue;
|
||||||
|
|
||||||
/* value on stack */
|
/* value on stack */
|
||||||
|
@ -334,7 +334,7 @@ typedef struct BufferedFile {
|
||||||
/* parsing state (used to save parser state to reparse part of the
|
/* parsing state (used to save parser state to reparse part of the
|
||||||
source several times) */
|
source several times) */
|
||||||
typedef struct ParseState {
|
typedef struct ParseState {
|
||||||
int *macro_ptr;
|
const int *macro_ptr;
|
||||||
int line_num;
|
int line_num;
|
||||||
int tok;
|
int tok;
|
||||||
CValue tokc;
|
CValue tokc;
|
||||||
|
@ -920,7 +920,7 @@ ST_FUNC int ieee_finite(double d);
|
||||||
ST_DATA struct BufferedFile *file;
|
ST_DATA struct BufferedFile *file;
|
||||||
ST_DATA int ch, tok;
|
ST_DATA int ch, tok;
|
||||||
ST_DATA CValue tokc;
|
ST_DATA CValue tokc;
|
||||||
ST_DATA int *macro_ptr;
|
ST_DATA const int *macro_ptr;
|
||||||
ST_DATA int parse_flags;
|
ST_DATA int parse_flags;
|
||||||
ST_DATA int tok_flags;
|
ST_DATA int tok_flags;
|
||||||
ST_DATA CString tokcstr; /* current parsed string, if any */
|
ST_DATA CString tokcstr; /* current parsed string, if any */
|
||||||
|
|
3
tccasm.c
3
tccasm.c
|
@ -738,7 +738,8 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
|
||||||
static void tcc_assemble_inline(TCCState *s1, char *str, int len)
|
static void tcc_assemble_inline(TCCState *s1, char *str, int len)
|
||||||
{
|
{
|
||||||
BufferedFile *bf, *saved_file;
|
BufferedFile *bf, *saved_file;
|
||||||
int saved_parse_flags, *saved_macro_ptr;
|
int saved_parse_flags;
|
||||||
|
const int *saved_macro_ptr;
|
||||||
|
|
||||||
bf = tcc_malloc(sizeof(BufferedFile));
|
bf = tcc_malloc(sizeof(BufferedFile));
|
||||||
memset(bf, 0, sizeof(BufferedFile));
|
memset(bf, 0, sizeof(BufferedFile));
|
||||||
|
|
129
tccpp.c
129
tccpp.c
|
@ -42,7 +42,7 @@ ST_DATA int parse_flags;
|
||||||
ST_DATA struct BufferedFile *file;
|
ST_DATA struct BufferedFile *file;
|
||||||
ST_DATA int ch, tok;
|
ST_DATA int ch, tok;
|
||||||
ST_DATA CValue tokc;
|
ST_DATA CValue tokc;
|
||||||
ST_DATA int *macro_ptr;
|
ST_DATA const int *macro_ptr;
|
||||||
ST_DATA CString tokcstr; /* current parsed string, if any */
|
ST_DATA CString tokcstr; /* current parsed string, if any */
|
||||||
|
|
||||||
/* display benchmark infos */
|
/* display benchmark infos */
|
||||||
|
@ -54,7 +54,7 @@ ST_DATA TokenSym **table_ident;
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int *macro_ptr_allocated;
|
static int *macro_ptr_allocated;
|
||||||
static int *unget_saved_macro_ptr;
|
static const int *unget_saved_macro_ptr;
|
||||||
static int unget_saved_buffer[TOK_MAX_SIZE + 1];
|
static int unget_saved_buffer[TOK_MAX_SIZE + 1];
|
||||||
static int unget_buffer_enabled;
|
static int unget_buffer_enabled;
|
||||||
static TokenSym *hash_ident[TOK_HASH_SIZE];
|
static TokenSym *hash_ident[TOK_HASH_SIZE];
|
||||||
|
@ -75,7 +75,7 @@ static const unsigned char tok_two_chars[] =
|
||||||
|
|
||||||
struct macro_level {
|
struct macro_level {
|
||||||
struct macro_level *prev;
|
struct macro_level *prev;
|
||||||
int *p;
|
const int *p;
|
||||||
};
|
};
|
||||||
|
|
||||||
ST_FUNC void next_nomacro(void);
|
ST_FUNC void next_nomacro(void);
|
||||||
|
@ -940,61 +940,54 @@ ST_FUNC void tok_str_add_tok(TokenString *s)
|
||||||
tok_str_add2(s, tok, &tokc);
|
tok_str_add2(s, tok, &tokc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get a token from an integer array and increment pointer
|
||||||
|
accordingly. we code it as a macro to avoid pointer aliasing. */
|
||||||
|
static inline void TOK_GET(int *t, const int **pp, CValue *cv)
|
||||||
|
{
|
||||||
|
const int *p = *pp;
|
||||||
|
int n, *tab;
|
||||||
|
|
||||||
|
tab = cv->tab;
|
||||||
|
switch(*t = *p++) {
|
||||||
|
case TOK_CINT:
|
||||||
|
case TOK_CUINT:
|
||||||
|
case TOK_CCHAR:
|
||||||
|
case TOK_LCHAR:
|
||||||
|
case TOK_CFLOAT:
|
||||||
|
case TOK_LINENUM:
|
||||||
|
tab[0] = *p++;
|
||||||
|
break;
|
||||||
|
case TOK_STR:
|
||||||
|
case TOK_LSTR:
|
||||||
|
case TOK_PPNUM:
|
||||||
|
cv->cstr = (CString *)p;
|
||||||
|
cv->cstr->data = (char *)p + sizeof(CString);
|
||||||
|
p += (sizeof(CString) + cv->cstr->size + 3) >> 2;
|
||||||
|
break;
|
||||||
|
case TOK_CDOUBLE:
|
||||||
|
case TOK_CLLONG:
|
||||||
|
case TOK_CULLONG:
|
||||||
|
n = 2;
|
||||||
|
goto copy;
|
||||||
|
case TOK_CLDOUBLE:
|
||||||
#if LDOUBLE_SIZE == 16
|
#if LDOUBLE_SIZE == 16
|
||||||
#define LDOUBLE_GET(p, cv) \
|
n = 4;
|
||||||
cv.tab[0] = p[0]; \
|
|
||||||
cv.tab[1] = p[1]; \
|
|
||||||
cv.tab[2] = p[2]; \
|
|
||||||
cv.tab[3] = p[3];
|
|
||||||
#elif LDOUBLE_SIZE == 12
|
#elif LDOUBLE_SIZE == 12
|
||||||
#define LDOUBLE_GET(p, cv) \
|
n = 3;
|
||||||
cv.tab[0] = p[0]; \
|
|
||||||
cv.tab[1] = p[1]; \
|
|
||||||
cv.tab[2] = p[2];
|
|
||||||
#elif LDOUBLE_SIZE == 8
|
#elif LDOUBLE_SIZE == 8
|
||||||
#define LDOUBLE_GET(p, cv) \
|
n = 2;
|
||||||
cv.tab[0] = p[0]; \
|
|
||||||
cv.tab[1] = p[1];
|
|
||||||
#else
|
#else
|
||||||
# error add long double size support
|
# error add long double size support
|
||||||
#endif
|
#endif
|
||||||
|
copy:
|
||||||
|
do
|
||||||
/* get a token from an integer array and increment pointer
|
*tab++ = *p++;
|
||||||
accordingly. we code it as a macro to avoid pointer aliasing. */
|
while (--n);
|
||||||
#define TOK_GET(t, p, cv) \
|
break;
|
||||||
{ \
|
default:
|
||||||
t = *p++; \
|
break;
|
||||||
switch(t) { \
|
}
|
||||||
case TOK_CINT: \
|
*pp = p;
|
||||||
case TOK_CUINT: \
|
|
||||||
case TOK_CCHAR: \
|
|
||||||
case TOK_LCHAR: \
|
|
||||||
case TOK_CFLOAT: \
|
|
||||||
case TOK_LINENUM: \
|
|
||||||
cv.tab[0] = *p++; \
|
|
||||||
break; \
|
|
||||||
case TOK_STR: \
|
|
||||||
case TOK_LSTR: \
|
|
||||||
case TOK_PPNUM: \
|
|
||||||
cv.cstr = (CString *)p; \
|
|
||||||
cv.cstr->data = (char *)p + sizeof(CString);\
|
|
||||||
p += (sizeof(CString) + cv.cstr->size + 3) >> 2;\
|
|
||||||
break; \
|
|
||||||
case TOK_CDOUBLE: \
|
|
||||||
case TOK_CLLONG: \
|
|
||||||
case TOK_CULLONG: \
|
|
||||||
cv.tab[0] = p[0]; \
|
|
||||||
cv.tab[1] = p[1]; \
|
|
||||||
p += 2; \
|
|
||||||
break; \
|
|
||||||
case TOK_CLDOUBLE: \
|
|
||||||
LDOUBLE_GET(p, cv); \
|
|
||||||
p += LDOUBLE_SIZE / 4; \
|
|
||||||
break; \
|
|
||||||
default: \
|
|
||||||
break; \
|
|
||||||
} \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int macro_is_equal(const int *a, const int *b)
|
static int macro_is_equal(const int *a, const int *b)
|
||||||
|
@ -1003,9 +996,9 @@ static int macro_is_equal(const int *a, const int *b)
|
||||||
CValue cv;
|
CValue cv;
|
||||||
int t;
|
int t;
|
||||||
while (*a && *b) {
|
while (*a && *b) {
|
||||||
TOK_GET(t, a, cv);
|
TOK_GET(&t, &a, &cv);
|
||||||
pstrcpy(buf, sizeof buf, get_tok_str(t, &cv));
|
pstrcpy(buf, sizeof buf, get_tok_str(t, &cv));
|
||||||
TOK_GET(t, b, cv);
|
TOK_GET(&t, &b, &cv);
|
||||||
if (strcmp(buf, get_tok_str(t, &cv)))
|
if (strcmp(buf, get_tok_str(t, &cv)))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1163,7 +1156,7 @@ static void tok_print(int *str)
|
||||||
|
|
||||||
printf("<");
|
printf("<");
|
||||||
while (1) {
|
while (1) {
|
||||||
TOK_GET(t, str, cval);
|
TOK_GET(&t, &str, &cval);
|
||||||
if (!t)
|
if (!t)
|
||||||
break;
|
break;
|
||||||
printf("%s", get_tok_str(t, &cval));
|
printf("%s", get_tok_str(t, &cval));
|
||||||
|
@ -2498,7 +2491,7 @@ static void next_nomacro_spc(void)
|
||||||
redo:
|
redo:
|
||||||
tok = *macro_ptr;
|
tok = *macro_ptr;
|
||||||
if (tok) {
|
if (tok) {
|
||||||
TOK_GET(tok, macro_ptr, tokc);
|
TOK_GET(&tok, ¯o_ptr, &tokc);
|
||||||
if (tok == TOK_LINENUM) {
|
if (tok == TOK_LINENUM) {
|
||||||
file->line_num = tokc.i;
|
file->line_num = tokc.i;
|
||||||
goto redo;
|
goto redo;
|
||||||
|
@ -2517,9 +2510,10 @@ ST_FUNC void next_nomacro(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* substitute args in macro_str and return allocated string */
|
/* substitute args in macro_str and return allocated string */
|
||||||
static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args)
|
||||||
{
|
{
|
||||||
int *st, last_tok, t, spc;
|
int last_tok, t, spc;
|
||||||
|
const int *st;
|
||||||
Sym *s;
|
Sym *s;
|
||||||
CValue cval;
|
CValue cval;
|
||||||
TokenString str;
|
TokenString str;
|
||||||
|
@ -2528,12 +2522,12 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
||||||
tok_str_new(&str);
|
tok_str_new(&str);
|
||||||
last_tok = 0;
|
last_tok = 0;
|
||||||
while(1) {
|
while(1) {
|
||||||
TOK_GET(t, macro_str, cval);
|
TOK_GET(&t, ¯o_str, &cval);
|
||||||
if (!t)
|
if (!t)
|
||||||
break;
|
break;
|
||||||
if (t == '#') {
|
if (t == '#') {
|
||||||
/* stringize */
|
/* stringize */
|
||||||
TOK_GET(t, macro_str, cval);
|
TOK_GET(&t, ¯o_str, &cval);
|
||||||
if (!t)
|
if (!t)
|
||||||
break;
|
break;
|
||||||
s = sym_find2(args, t);
|
s = sym_find2(args, t);
|
||||||
|
@ -2542,7 +2536,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
||||||
st = s->d;
|
st = s->d;
|
||||||
spc = 0;
|
spc = 0;
|
||||||
while (*st) {
|
while (*st) {
|
||||||
TOK_GET(t, st, cval);
|
TOK_GET(&t, &st, &cval);
|
||||||
if (!check_space(t, &spc))
|
if (!check_space(t, &spc))
|
||||||
cstr_cat(&cstr, get_tok_str(t, &cval));
|
cstr_cat(&cstr, get_tok_str(t, &cval));
|
||||||
}
|
}
|
||||||
|
@ -2584,7 +2578,7 @@ static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
|
||||||
int t1;
|
int t1;
|
||||||
add_var:
|
add_var:
|
||||||
for(;;) {
|
for(;;) {
|
||||||
TOK_GET(t1, st, cval);
|
TOK_GET(&t1, &st, &cval);
|
||||||
if (!t1)
|
if (!t1)
|
||||||
break;
|
break;
|
||||||
tok_str_add2(&str, t1, &cval);
|
tok_str_add2(&str, t1, &cval);
|
||||||
|
@ -2621,7 +2615,8 @@ static int macro_subst_tok(TokenString *tok_str,
|
||||||
Sym **nested_list, Sym *s, struct macro_level **can_read_stream)
|
Sym **nested_list, Sym *s, struct macro_level **can_read_stream)
|
||||||
{
|
{
|
||||||
Sym *args, *sa, *sa1;
|
Sym *args, *sa, *sa1;
|
||||||
int mstr_allocated, parlevel, *mstr, t, t1, *p, spc;
|
int mstr_allocated, parlevel, *mstr, t, t1, spc;
|
||||||
|
const int *p;
|
||||||
TokenString str;
|
TokenString str;
|
||||||
char *cstrval;
|
char *cstrval;
|
||||||
CValue cval;
|
CValue cval;
|
||||||
|
@ -2785,7 +2780,7 @@ static inline int *macro_twosharps(const int *macro_str)
|
||||||
|
|
||||||
/* we search the first '##' */
|
/* we search the first '##' */
|
||||||
for(ptr = macro_str;;) {
|
for(ptr = macro_str;;) {
|
||||||
TOK_GET(t, ptr, cval);
|
TOK_GET(&t, &ptr, &cval);
|
||||||
if (t == TOK_TWOSHARPS)
|
if (t == TOK_TWOSHARPS)
|
||||||
break;
|
break;
|
||||||
/* nothing more to do if end of string */
|
/* nothing more to do if end of string */
|
||||||
|
@ -2796,7 +2791,7 @@ static inline int *macro_twosharps(const int *macro_str)
|
||||||
/* we saw '##', so we need more processing to handle it */
|
/* we saw '##', so we need more processing to handle it */
|
||||||
tok_str_new(¯o_str1);
|
tok_str_new(¯o_str1);
|
||||||
for(ptr = macro_str;;) {
|
for(ptr = macro_str;;) {
|
||||||
TOK_GET(tok, ptr, tokc);
|
TOK_GET(&tok, &ptr, &tokc);
|
||||||
if (tok == 0)
|
if (tok == 0)
|
||||||
break;
|
break;
|
||||||
if (tok == TOK_TWOSHARPS)
|
if (tok == TOK_TWOSHARPS)
|
||||||
|
@ -2804,7 +2799,7 @@ static inline int *macro_twosharps(const int *macro_str)
|
||||||
while (*ptr == TOK_TWOSHARPS) {
|
while (*ptr == TOK_TWOSHARPS) {
|
||||||
t = *++ptr;
|
t = *++ptr;
|
||||||
if (t && t != TOK_TWOSHARPS) {
|
if (t && t != TOK_TWOSHARPS) {
|
||||||
TOK_GET(t, ptr, cval);
|
TOK_GET(&t, &ptr, &cval);
|
||||||
|
|
||||||
/* We concatenate the two tokens */
|
/* We concatenate the two tokens */
|
||||||
cstr_new(&cstr);
|
cstr_new(&cstr);
|
||||||
|
@ -2859,7 +2854,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list,
|
||||||
file stream due to a macro function call */
|
file stream due to a macro function call */
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
break;
|
break;
|
||||||
TOK_GET(t, ptr, cval);
|
TOK_GET(&t, &ptr, &cval);
|
||||||
if (t == 0)
|
if (t == 0)
|
||||||
break;
|
break;
|
||||||
s = define_find(t);
|
s = define_find(t);
|
||||||
|
|
Loading…
Reference in a new issue