[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] [PATCH 06/11] tcc: Refactor "compute default outfile name
From: |
Kirill Smelkov |
Subject: |
[Tinycc-devel] [PATCH 06/11] tcc: Refactor "compute default outfile name" into libtcc function |
Date: |
Mon, 21 Jun 2010 18:31:25 +0400 |
From: Kirill Smelkov <address@hidden>
Since for upcoming -MD support default _compile_ output file be needed
even when preprocesssing (tcc -E), let's move this code out of one
particular condition block into a common function, so that we could use
it in deps generation code too.
v2:
- As suggested by grischka, moved into libtcc function instead of always
computing near start of main()
- There is a FIXME about how to return result - I don't want to bother
callers with allocating temp buffers, not I think it will be a good
idea to hook default_target to TCCState. Clearly, I'm to used to
things like std::string and python's str...
---
libtcc.c | 28 ++++++++++++++++++++++++++++
tcc.c | 29 ++++-------------------------
2 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/libtcc.c b/libtcc.c
index 9cc1b6f..1c963b5 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1557,3 +1557,31 @@ PUB_FUNC void set_num_callers(int n)
num_callers = n;
#endif
}
+
+
+LIBTCCAPI const char *tcc_default_target(TCCState *s)
+{
+ /* FIXME will break in multithreaded case */
+ static char outfile_default[1024];
+
+ char *ext;
+ const char *name =
+ strcmp(s->input_files[0], "-") == 0 ? "a"
+ : tcc_basename(s->input_files[0]);
+ pstrcpy(outfile_default, sizeof(outfile_default), name);
+ ext = tcc_fileextension(outfile_default);
+#ifdef TCC_TARGET_PE
+ if (s->output_type == TCC_OUTPUT_DLL)
+ strcpy(ext, ".dll");
+ else
+ if (s->output_type == TCC_OUTPUT_EXE)
+ strcpy(ext, ".exe");
+ else
+#endif
+ if (s->output_type == TCC_OUTPUT_OBJ && !s->reloc_output && *ext)
+ strcpy(ext, ".o");
+ else
+ pstrcpy(outfile_default, sizeof(outfile_default), "a.out");
+
+ return outfile_default;
+}
diff --git a/tcc.c b/tcc.c
index f973972..705f5e2 100644
--- a/tcc.c
+++ b/tcc.c
@@ -393,7 +393,6 @@ int main(int argc, char **argv)
int i;
TCCState *s;
int nb_objfiles, ret, optind;
- char objfilename[1024];
int64_t start_time = 0;
s = tcc_new();
@@ -446,28 +445,6 @@ int main(int argc, char **argv)
if (!s->outfile)
error("could not open '%s'", outfile);
}
- } else if (output_type != TCC_OUTPUT_MEMORY) {
- if (!outfile) {
- /* compute default outfile name */
- char *ext;
- const char *name =
- strcmp(files[0], "-") == 0 ? "a" : tcc_basename(files[0]);
- pstrcpy(objfilename, sizeof(objfilename), name);
- ext = tcc_fileextension(objfilename);
-#ifdef TCC_TARGET_PE
- if (output_type == TCC_OUTPUT_DLL)
- strcpy(ext, ".dll");
- else
- if (output_type == TCC_OUTPUT_EXE)
- strcpy(ext, ".exe");
- else
-#endif
- if (output_type == TCC_OUTPUT_OBJ && !reloc_output && *ext)
- strcpy(ext, ".o");
- else
- pstrcpy(objfilename, sizeof(objfilename), "a.out");
- outfile = objfilename;
- }
}
if (do_bench) {
@@ -507,8 +484,10 @@ int main(int argc, char **argv)
fclose(s->outfile);
} else if (s->output_type == TCC_OUTPUT_MEMORY)
ret = tcc_run(s, argc - optind, argv + optind);
- else
- ret = tcc_output_file(s, outfile) ? 1 : 0;
+ else {
+ ret = tcc_output_file(s, outfile ? outfile :
tcc_default_target(s));
+ ret = ret ? 1 : 0;
+ }
}
tcc_delete(s);
--
1.7.1.427.g9562c
- [Tinycc-devel] [PATCH 00/11] Teach tcc -MD/-MF (take 2), Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 02/11] .gitignore += *.o *.a, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 01/11] .cvsignore -> .gitignore, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 04/11] tcc: Fix typo in error (it's '%s', not '%s), Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 05/11] Add input files/libs and reloc_output switch to TCCState, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 06/11] tcc: Refactor "compute default outfile name" into libtcc function,
Kirill Smelkov <=
- [Tinycc-devel] [PATCH 08/11] tcc -E: Let output_default be <file>.o instead of a.out, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 10/11] tcc: Explicitly require -l<lib> for libraries, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 11/11] .gitignore += tags, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 09/11] Document what tcc_fileextension does, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 03/11] chmod a-x i386-gen.c, Kirill Smelkov, 2010/06/21
- [Tinycc-devel] [PATCH 07/11] tcc: Draft suppoprt for -MD/-MF options, Kirill Smelkov, 2010/06/21