move some global variables into TCCState

This commit is contained in:
grischka
2009-05-11 18:45:44 +02:00
parent 5c6509578e
commit f9181416f6
9 changed files with 91 additions and 86 deletions

View File

@ -20,6 +20,10 @@
#include "tcc.h"
/* display benchmark infos */
int total_lines;
int total_bytes;
/* parser */
static struct BufferedFile *file;
static int ch, tok;
@ -93,19 +97,6 @@ static SValue vstack[VSTACK_SIZE], *vtop;
/* some predefined types */
static CType char_pointer_type, func_old_type, int_type;
/* display some information during compilation */
static int verbose = 0;
/* compile with debug symbol (and use them if error during execution) */
static int do_debug = 0;
/* compile with built-in memory and bounds checker */
static int do_bounds_check = 0;
/* display benchmark infos */
static int total_lines;
static int total_bytes;
/* use GNU C extensions */
static int gnu_ext = 1;
@ -114,17 +105,13 @@ static int tcc_ext = 1;
/* max number of callers shown if error */
#ifdef CONFIG_TCC_BACKTRACE
static int num_callers = 6;
static const char **rt_bound_error_msg;
int num_callers = 6;
const char **rt_bound_error_msg;
#endif
/* XXX: get rid of this ASAP */
static struct TCCState *tcc_state;
/* give the path of the tcc libraries */
static const char *tcc_lib_path = CONFIG_TCCDIR;
#ifdef TCC_TARGET_I386
#include "i386-gen.c"
#endif
@ -564,7 +551,7 @@ static void put_extern_sym2(Sym *sym, Section *section,
if (!sym->c) {
name = get_tok_str(sym->v, NULL);
#ifdef CONFIG_TCC_BCHECK
if (do_bounds_check) {
if (tcc_state->do_bounds_check) {
char buf[32];
/* XXX: avoid doing that for statics ? */
@ -989,7 +976,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename)
fd = 0, filename = "stdin";
else
fd = open(filename, O_RDONLY | O_BINARY);
if ((verbose == 2 && fd >= 0) || verbose == 3)
if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
(s1->include_stack_ptr - s1->include_stack), "", filename);
if (fd < 0)
@ -1039,7 +1026,7 @@ static int tcc_compile(TCCState *s1)
/* file info: full path + filename */
section_sym = 0; /* avoid warning */
if (do_debug) {
if (s1->do_debug) {
section_sym = put_elf_sym(symtab_section, 0, 0,
ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
text_section->sh_num, NULL);
@ -1108,7 +1095,7 @@ static int tcc_compile(TCCState *s1)
expect("declaration");
/* end of translation unit info */
if (do_debug) {
if (s1->do_debug) {
put_stabs_r(NULL, N_SO, 0, 0,
text_section->data_offset, text_section, section_sym);
}
@ -1579,7 +1566,7 @@ int tcc_run(TCCState *s1, int argc, char **argv)
prog_main = tcc_get_symbol_err(s1, "main");
if (do_debug) {
if (s1->do_debug) {
#ifdef CONFIG_TCC_BACKTRACE
struct sigaction sigact;
/* install TCC signal handlers to print debug info on fatal
@ -1598,7 +1585,7 @@ int tcc_run(TCCState *s1, int argc, char **argv)
}
#ifdef CONFIG_TCC_BCHECK
if (do_bounds_check) {
if (s1->do_bounds_check) {
void (*bound_init)(void);
/* set error function */
@ -1659,6 +1646,7 @@ TCCState *tcc_new(void)
return NULL;
tcc_state = s;
s->output_type = TCC_OUTPUT_MEMORY;
s->tcc_lib_path = CONFIG_TCCDIR;
preprocess_new();
@ -1995,17 +1983,17 @@ int tcc_set_output_type(TCCState *s, int output_type)
tcc_add_sysinclude_path(s, CONFIG_SYSROOT "/usr/local/include");
tcc_add_sysinclude_path(s, CONFIG_SYSROOT "/usr/include");
#endif
snprintf(buf, sizeof(buf), "%s/include", tcc_lib_path);
snprintf(buf, sizeof(buf), "%s/include", s->tcc_lib_path);
tcc_add_sysinclude_path(s, buf);
#ifdef TCC_TARGET_PE
snprintf(buf, sizeof(buf), "%s/include/winapi", tcc_lib_path);
snprintf(buf, sizeof(buf), "%s/include/winapi", s->tcc_lib_path);
tcc_add_sysinclude_path(s, buf);
#endif
}
/* if bound checking, then add corresponding sections */
#ifdef CONFIG_TCC_BCHECK
if (do_bounds_check) {
if (s->do_bounds_check) {
/* define symbol */
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
/* create bounds sections */
@ -2021,7 +2009,7 @@ int tcc_set_output_type(TCCState *s, int output_type)
}
/* add debug sections */
if (do_debug) {
if (s->do_debug) {
/* stab symbols */
stab_section = new_section(s, ".stab", SHT_PROGBITS, 0);
stab_section->sh_entsize = sizeof(Stab_Sym);
@ -2043,7 +2031,7 @@ int tcc_set_output_type(TCCState *s, int output_type)
#endif
#ifdef TCC_TARGET_PE
snprintf(buf, sizeof(buf), "%s/lib", tcc_lib_path);
snprintf(buf, sizeof(buf), "%s/lib", s->tcc_lib_path);
tcc_add_library_path(s, buf);
#endif
@ -2127,6 +2115,19 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value)
/* set CONFIG_TCCDIR at runtime */
void tcc_set_lib_path(TCCState *s, const char *path)
{
tcc_lib_path = tcc_strdup(path);
s->tcc_lib_path = tcc_strdup(path);
}
LIBTCCAPI void print_stats(TCCState *s, int64_t total_time)
{
double tt;
tt = (double)total_time / 1000000.0;
if (tt < 0.001)
tt = 0.001;
if (total_bytes < 1)
total_bytes = 1;
printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
tok_ident - TOK_IDENT, total_lines, total_bytes,
tt, (int)(total_lines / tt),
total_bytes / tt / 1000000.0);
}