mirror of
https://github.com/TinyCC/tinycc.git
synced 2025-11-16 04:24:45 +00:00
Revert "Move almost all global variables to TCCState, actually all tests pass on Ubuntu 18.04 x86_64"
This reverts commit af686a796b.
This commit is contained in:
54
tcctools.c
54
tcctools.c
@@ -66,7 +66,7 @@ static int ar_usage(int ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
|
||||
ST_FUNC int tcc_tool_ar(TCCState *s1, int argc, char **argv)
|
||||
{
|
||||
static const ArHdr arhdr_init = {
|
||||
"/ ",
|
||||
@@ -135,7 +135,7 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
|
||||
}
|
||||
|
||||
funcmax = 250;
|
||||
afpos = tcc_realloc(S, NULL, funcmax * sizeof *afpos); // 250 func
|
||||
afpos = tcc_realloc(NULL, funcmax * sizeof *afpos); // 250 func
|
||||
memcpy(&arhdro.ar_mode, "100666", 6);
|
||||
|
||||
// i_obj = first input object file
|
||||
@@ -155,7 +155,7 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
|
||||
fseek(fi, 0, SEEK_END);
|
||||
fsize = ftell(fi);
|
||||
fseek(fi, 0, SEEK_SET);
|
||||
buf = tcc_malloc(S, fsize + 1);
|
||||
buf = tcc_malloc(fsize + 1);
|
||||
fread(buf, fsize, 1, fi);
|
||||
fclose(fi);
|
||||
|
||||
@@ -203,12 +203,12 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
|
||||
)) {
|
||||
//printf("symtab: %2Xh %4Xh %2Xh %s\n", sym->st_info, sym->st_size, sym->st_shndx, strtab + sym->st_name);
|
||||
istrlen = strlen(strtab + sym->st_name)+1;
|
||||
anames = tcc_realloc(S, anames, strpos+istrlen);
|
||||
anames = tcc_realloc(anames, strpos+istrlen);
|
||||
strcpy(anames + strpos, strtab + sym->st_name);
|
||||
strpos += istrlen;
|
||||
if (++funccnt >= funcmax) {
|
||||
funcmax += 250;
|
||||
afpos = tcc_realloc(S, afpos, funcmax * sizeof *afpos); // 250 func more
|
||||
afpos = tcc_realloc(afpos, funcmax * sizeof *afpos); // 250 func more
|
||||
}
|
||||
afpos[funccnt] = fpos;
|
||||
}
|
||||
@@ -229,7 +229,7 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
|
||||
memcpy(&arhdro.ar_size, stmp, 10);
|
||||
fwrite(&arhdro, sizeof(arhdro), 1, fo);
|
||||
fwrite(buf, fsize, 1, fo);
|
||||
tcc_free(S, buf);
|
||||
tcc_free(buf);
|
||||
i_obj++;
|
||||
fpos += (fsize + sizeof(arhdro));
|
||||
}
|
||||
@@ -253,16 +253,16 @@ ST_FUNC int tcc_tool_ar(TCCState *S, int argc, char **argv)
|
||||
fseek(fo, 0, SEEK_END);
|
||||
fsize = ftell(fo);
|
||||
fseek(fo, 0, SEEK_SET);
|
||||
buf = tcc_malloc(S, fsize + 1);
|
||||
buf = tcc_malloc(fsize + 1);
|
||||
fread(buf, fsize, 1, fo);
|
||||
fwrite(buf, fsize, 1, fh);
|
||||
tcc_free(S, buf);
|
||||
tcc_free(buf);
|
||||
ret = 0;
|
||||
the_end:
|
||||
if (anames)
|
||||
tcc_free(S, anames);
|
||||
tcc_free(anames);
|
||||
if (afpos)
|
||||
tcc_free(S, afpos);
|
||||
tcc_free(afpos);
|
||||
if (fh)
|
||||
fclose(fh);
|
||||
if (fo)
|
||||
@@ -294,7 +294,7 @@ the_end:
|
||||
|
||||
#ifdef TCC_TARGET_PE
|
||||
|
||||
ST_FUNC int tcc_tool_impdef(TCCState *S, int argc, char **argv)
|
||||
ST_FUNC int tcc_tool_impdef(TCCState *s1, int argc, char **argv)
|
||||
{
|
||||
int ret, v, i;
|
||||
char infile[260];
|
||||
@@ -353,7 +353,7 @@ usage:
|
||||
if (SearchPath(NULL, file, ".dll", sizeof path, path, NULL))
|
||||
file = path;
|
||||
#endif
|
||||
ret = tcc_get_dllexports(S, file, &p);
|
||||
ret = tcc_get_dllexports(file, &p);
|
||||
if (ret || !p) {
|
||||
fprintf(stderr, "tcc: impdef: %s '%s'\n",
|
||||
ret == -1 ? "can't find file" :
|
||||
@@ -386,7 +386,7 @@ usage:
|
||||
|
||||
the_end:
|
||||
if (p)
|
||||
tcc_free(S, p);
|
||||
tcc_free(p);
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (op)
|
||||
@@ -421,9 +421,9 @@ the_end:
|
||||
|
||||
#if !defined TCC_TARGET_I386 && !defined TCC_TARGET_X86_64
|
||||
|
||||
ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int option)
|
||||
ST_FUNC void tcc_tool_cross(TCCState *s1, char **argv, int option)
|
||||
{
|
||||
tcc_error(S, "-m%d not implemented.", option);
|
||||
tcc_error("-m%d not implemented.", option);
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -439,7 +439,7 @@ static char *str_replace(const char *str, const char *p, const char *r)
|
||||
sl = strlen(str);
|
||||
pl = strlen(p);
|
||||
rl = strlen(r);
|
||||
for (d0 = NULL;; d0 = tcc_malloc(S, sl + 1)) {
|
||||
for (d0 = NULL;; d0 = tcc_malloc(sl + 1)) {
|
||||
for (d = d0, s = str; s0 = s, s = strstr(s, p), s; s += pl) {
|
||||
if (d) {
|
||||
memcpy(d, s0, sl = s - s0), d += sl;
|
||||
@@ -470,7 +470,7 @@ static int execvp_win32(const char *prog, char **argv)
|
||||
#define execvp execvp_win32
|
||||
#endif /* _WIN32 */
|
||||
|
||||
ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int target)
|
||||
ST_FUNC void tcc_tool_cross(TCCState *s1, char **argv, int target)
|
||||
{
|
||||
char program[4096];
|
||||
char *a0 = argv[0];
|
||||
@@ -489,7 +489,7 @@ ST_FUNC void tcc_tool_cross(TCCState *S, char **argv, int target)
|
||||
|
||||
if (strcmp(a0, program))
|
||||
execvp(argv[0] = program, argv);
|
||||
tcc_error(S, "could not run '%s'", program);
|
||||
tcc_error("could not run '%s'", program);
|
||||
}
|
||||
|
||||
#endif /* TCC_TARGET_I386 && TCC_TARGET_X86_64 */
|
||||
@@ -506,8 +506,8 @@ const int _dowildcard = 1;
|
||||
/* -------------------------------------------------------------- */
|
||||
/* generate xxx.d file */
|
||||
|
||||
static char *escape_target_dep(TCCState *S, const char *s) {
|
||||
char *res = tcc_malloc(S, strlen(s) * 2 + 1);
|
||||
static char *escape_target_dep(const char *s) {
|
||||
char *res = tcc_malloc(strlen(s) * 2 + 1);
|
||||
int j;
|
||||
for (j = 0; *s; s++, j++) {
|
||||
if (is_space(*s)) {
|
||||
@@ -519,7 +519,7 @@ static char *escape_target_dep(TCCState *S, const char *s) {
|
||||
return res;
|
||||
}
|
||||
|
||||
ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename)
|
||||
ST_FUNC void gen_makedeps(TCCState *s1, const char *target, const char *filename)
|
||||
{
|
||||
FILE *depout;
|
||||
char buf[1024], *escaped_target;
|
||||
@@ -532,7 +532,7 @@ ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename)
|
||||
filename = buf;
|
||||
}
|
||||
|
||||
if (S->verbose)
|
||||
if (s1->verbose)
|
||||
printf("<- %s\n", filename);
|
||||
|
||||
if(!strcmp(filename, "-"))
|
||||
@@ -541,15 +541,15 @@ ST_FUNC void gen_makedeps(TCCState *S, const char *target, const char *filename)
|
||||
/* XXX return err codes instead of error() ? */
|
||||
depout = fopen(filename, "w");
|
||||
if (!depout)
|
||||
tcc_error(S, "could not open '%s'", filename);
|
||||
tcc_error("could not open '%s'", filename);
|
||||
fprintf(depout, "%s:", target);
|
||||
for (i = 0; i<S->nb_target_deps; ++i) {
|
||||
for (i = 0; i<s1->nb_target_deps; ++i) {
|
||||
for (k = 0; k < i; ++k)
|
||||
if (0 == strcmp(S->target_deps[i], S->target_deps[k]))
|
||||
if (0 == strcmp(s1->target_deps[i], s1->target_deps[k]))
|
||||
goto next;
|
||||
escaped_target = escape_target_dep(S, S->target_deps[i]);
|
||||
escaped_target = escape_target_dep(s1->target_deps[i]);
|
||||
fprintf(depout, " \\\n %s", escaped_target);
|
||||
tcc_free(S, escaped_target);
|
||||
tcc_free(escaped_target);
|
||||
next:;
|
||||
}
|
||||
fprintf(depout, "\n");
|
||||
|
||||
Reference in New Issue
Block a user