even faster
This commit is contained in:
parent
711075fe3b
commit
5d7f7bb5ef
1 changed files with 29 additions and 19 deletions
48
tcc.c
48
tcc.c
|
|
@ -613,23 +613,32 @@ void sym_pop(SymStack *st, Sym *b)
|
||||||
st->top = b;
|
st->top = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* no need to put that inline */
|
||||||
|
int handle_eof(void)
|
||||||
|
{
|
||||||
|
if (include_stack_ptr == include_stack)
|
||||||
|
return -1;
|
||||||
|
/* pop include stack */
|
||||||
|
fclose(file);
|
||||||
|
free(filename);
|
||||||
|
include_stack_ptr--;
|
||||||
|
file = include_stack_ptr->file;
|
||||||
|
filename = include_stack_ptr->filename;
|
||||||
|
line_num = include_stack_ptr->line_num;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* read next char from current input file */
|
/* read next char from current input file */
|
||||||
void inp(void)
|
static inline void inp(void)
|
||||||
{
|
{
|
||||||
redo:
|
redo:
|
||||||
/* faster than fgetc */
|
/* faster than fgetc */
|
||||||
ch1 = getc_unlocked(file);
|
ch1 = getc_unlocked(file);
|
||||||
if (ch1 == -1) {
|
if (ch1 == -1) {
|
||||||
if (include_stack_ptr == include_stack)
|
if (handle_eof() < 0)
|
||||||
return;
|
return;
|
||||||
/* pop include stack */
|
else
|
||||||
fclose(file);
|
goto redo;
|
||||||
free(filename);
|
|
||||||
include_stack_ptr--;
|
|
||||||
file = include_stack_ptr->file;
|
|
||||||
filename = include_stack_ptr->filename;
|
|
||||||
line_num = include_stack_ptr->line_num;
|
|
||||||
goto redo;
|
|
||||||
}
|
}
|
||||||
if (ch1 == '\n')
|
if (ch1 == '\n')
|
||||||
line_num++;
|
line_num++;
|
||||||
|
|
@ -637,9 +646,9 @@ void inp(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* input with '\\n' handling */
|
/* input with '\\n' handling */
|
||||||
void minp()
|
static inline void minp(void)
|
||||||
{
|
{
|
||||||
redo:
|
redo:
|
||||||
ch = ch1;
|
ch = ch1;
|
||||||
inp();
|
inp();
|
||||||
if (ch == '\\' && ch1 == '\n') {
|
if (ch == '\\' && ch1 == '\n') {
|
||||||
|
|
@ -649,8 +658,9 @@ void minp()
|
||||||
//printf("ch=%c 0x%x\n", ch, ch);
|
//printf("ch=%c 0x%x\n", ch, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* same as minp, but also skip comments */
|
/* same as minp, but also skip comments */
|
||||||
void cinp()
|
void cinp(void)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
|
@ -669,11 +679,11 @@ void cinp()
|
||||||
while (ch1 != -1) {
|
while (ch1 != -1) {
|
||||||
c = ch1;
|
c = ch1;
|
||||||
inp();
|
inp();
|
||||||
if (c == '*' && ch1 == '/') {
|
if (c == '*' && ch1 == '/') {
|
||||||
inp();
|
inp();
|
||||||
ch = ' '; /* return space */
|
ch = ' '; /* return space */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ch = '/';
|
ch = '/';
|
||||||
|
|
@ -683,7 +693,7 @@ void cinp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void skip_spaces()
|
void skip_spaces(void)
|
||||||
{
|
{
|
||||||
while (ch == ' ' || ch == '\t')
|
while (ch == ' ' || ch == '\t')
|
||||||
cinp();
|
cinp();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue