History

ability to specify a type of the input file with the -x switch

Usage example: tcc -xc ex5.cgi From a gcc docs: You can specify the input language explicitly with the -x option: -x language Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next -x option. Possible values for language are: c c-header c-cpp-output c++ c++-header c++-cpp-output objective-c objective-c-header objective-c-cpp-output objective-c++ objective-c++-header objective-c++-cpp-output assembler assembler-with-cpp ada f77 f77-cpp-input f95 f95-cpp-input java -x none Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if -x has not been used at all)

seyko committed 11 years ago

Commit 05364071 parent dcb36585 files · +67 −28Browse files

Unified · Split

5 files
  1. libtcc.c +55 −19
  2. libtcc.h +5 −1
  3. tcc.c +3 −4
  4. tcc.h +1 −1
  5. tccelf.c +3 −3
libtcc.c+55−19
@@ -1138,21 +1138,15 @@ LIBTCCAPI int tcc_add_sysinclude_path(TCCState *s, const char *pathname) · 1137 unmodified lines
1138 return 0;1138 return 0;
1139}1139}
1140 1140
1141ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)1141ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags, int filetype)
1142{1142{
1143 const char *ext;
1144 ElfW(Ehdr) ehdr;1143 ElfW(Ehdr) ehdr;
1145 int fd, ret, size;1144 int fd, ret, size;
1146 1145
1147 /* find source file type with extension */
1148 ext = tcc_fileextension(filename);
1149 if (ext[0])
1150 ext++;
1151
1152 parse_flags = 0;1146 parse_flags = 0;
1153#ifdef CONFIG_TCC_ASM1147#ifdef CONFIG_TCC_ASM
1154 /* if .S file, define __ASSEMBLER__ like gcc does */1148 /* if .S file, define __ASSEMBLER__ like gcc does */
1155 if (!strcmp(ext, "S") || !strcmp(ext, "s")) {1149 if ((filetype == TCC_FILETYPE_ASM) || (filetype == TCC_FILETYPE_ASM_PP)) {
1156 tcc_define_symbol(s1, "__ASSEMBLER__", NULL);1150 tcc_define_symbol(s1, "__ASSEMBLER__", NULL);
1157 parse_flags = PARSE_FLAG_ASM_FILE;1151 parse_flags = PARSE_FLAG_ASM_FILE;
1158 }1152 }
@@ -1175,20 +1169,20 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 16 unmodified lines
1175 goto the_end;1169 goto the_end;
1176 }1170 }
1177 1171
1178 if (!ext[0] || !PATHCMP(ext, "c") || !PATHCMP(ext, "i")) {1172 if (filetype == TCC_FILETYPE_C) {
1179 /* C file assumed */1173 /* C file assumed */
1180 ret = tcc_compile(s1);1174 ret = tcc_compile(s1);
1181 goto the_end;1175 goto the_end;
1182 }1176 }
1183 1177
1184#ifdef CONFIG_TCC_ASM1178#ifdef CONFIG_TCC_ASM
1185 if (!strcmp(ext, "S")) {1179 if (filetype == TCC_FILETYPE_ASM_PP) {
1186 /* non preprocessed assembler */1180 /* non preprocessed assembler */
1187 ret = tcc_assemble(s1, 1);1181 ret = tcc_assemble(s1, 1);
1188 goto the_end;1182 goto the_end;
1189 }1183 }
1190 1184
1191 if (!strcmp(ext, "s")) {1185 if (filetype == TCC_FILETYPE_ASM) {
1192 /* preprocessed assembler */1186 /* preprocessed assembler */
1193 ret = tcc_assemble(s1, 0);1187 ret = tcc_assemble(s1, 0);
1194 goto the_end;1188 goto the_end;
@@ -1264,12 +1258,12 @@ the_end: · 69 unmodified lines
1264 return ret;1258 return ret;
1265}1259}
1266 1260
1267LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)1261LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename, int filetype)
1268{1262{
1269 if (s->output_type == TCC_OUTPUT_PREPROCESS)1263 if (s->output_type == TCC_OUTPUT_PREPROCESS)
1270 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);1264 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS, filetype);
1271 else1265 else
1272 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR);1266 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR, filetype);
1273}1267}
1274 1268
1275LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)1269LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
@@ -1286,7 +1280,7 @@ static int tcc_add_library_internal(TCCState *s, const char *fmt, · 10 unmodified lines
1286 1280
1287 for(i = 0; i < nb_paths; i++) {1281 for(i = 0; i < nb_paths; i++) {
1288 snprintf(buf, sizeof(buf), fmt, paths[i], filename);1282 snprintf(buf, sizeof(buf), fmt, paths[i], filename);
1289 if (tcc_add_file_internal(s, buf, flags) == 0)1283 if (tcc_add_file_internal(s, buf, flags, TCC_FILETYPE_BINARY) == 0)
1290 return 0;1284 return 0;
1291 }1285 }
1292 return -1;1286 return -1;
@@ -1782,6 +1776,37 @@ static void parse_option_D(TCCState *s1, const char *optarg) · 489 unmodified lines
1782 tcc_free(sym);1776 tcc_free(sym);
1783}1777}
1784 1778
1779static void args_parser_add_file(TCCState *s, const char* filename, int filetype)
1780{
1781 int len = strlen(filename);
1782 char *p = tcc_malloc(len + 2);
1783 if (filetype) {
1784 *p = filetype;
1785 }
1786 else {
1787 /* use a file extension to detect a filetype */
1788 const char *ext = tcc_fileextension(filename);
1789 if (ext[0]) {
1790 ext++;
1791 if (!strcmp(ext, "S"))
1792 *p = TCC_FILETYPE_ASM_PP;
1793 else
1794 if (!strcmp(ext, "s"))
1795 *p = TCC_FILETYPE_ASM;
1796 else
1797 if (!PATHCMP(ext, "c") || !PATHCMP(ext, "i"))
1798 *p = TCC_FILETYPE_C;
1799 else
1800 *p = TCC_FILETYPE_BINARY;
1801 }
1802 else {
1803 *p = TCC_FILETYPE_C;
1804 }
1805 }
1806 strcpy(p+1, filename);
1807 dynarray_add((void ***)&s->files, &s->nb_files, p);
1808}
1809
1785PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)1810PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
1786{1811{
1787 const TCCOption *popt;1812 const TCCOption *popt;
@@ -1789,6 +1814,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 1 unmodified line
1789 int run = 0;1814 int run = 0;
1790 int pthread = 0;1815 int pthread = 0;
1791 int optind = 0;1816 int optind = 0;
1817 int filetype = 0;
1792 1818
1793 /* collect -Wl options for input such as "-Wl,-rpath -Wl,<path>" */1819 /* collect -Wl options for input such as "-Wl,-rpath -Wl,<path>" */
1794 CString linker_arg;1820 CString linker_arg;
@@ -1798,8 +1824,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 3 unmodified lines
1798 1824
1799 r = argv[optind++];1825 r = argv[optind++];
1800 if (r[0] != '-' || r[1] == '\0') {1826 if (r[0] != '-' || r[1] == '\0') {
1801 /* add a new file */1827 args_parser_add_file(s, r, filetype);
1802 dynarray_add((void ***)&s->files, &s->nb_files, tcc_strdup(r));
1803 if (run) {1828 if (run) {
1804 optind--;1829 optind--;
1805 /* argv[0] will be this file */1830 /* argv[0] will be this file */
@@ -1849,7 +1874,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 43 unmodified lines
1849 tcc_set_lib_path(s, optarg);1874 tcc_set_lib_path(s, optarg);
1850 break;1875 break;
1851 case TCC_OPTION_l:1876 case TCC_OPTION_l:
1852 dynarray_add((void ***)&s->files, &s->nb_files, tcc_strdup(r));1877 args_parser_add_file(s, r, TCC_FILETYPE_BINARY);
1853 s->nb_libraries++;1878 s->nb_libraries++;
1854 break;1879 break;
1855 case TCC_OPTION_pthread:1880 case TCC_OPTION_pthread:
@@ -1989,10 +2014,21 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 133 unmodified lines
1989 case TCC_OPTION_s:2014 case TCC_OPTION_s:
1990 s->do_strip = 1;2015 s->do_strip = 1;
1991 break;2016 break;
2017 case TCC_OPTION_x:
2018 if (*optarg == 'c')
2019 filetype = TCC_FILETYPE_C;
2020 else
2021 if (*optarg == 'a')
2022 filetype = TCC_FILETYPE_ASM_PP;
2023 else
2024 if (*optarg == 'n')
2025 filetype = 0;
2026 else
2027 tcc_warning("unsupported language '%s'", optarg);
2028 break;
1992 case TCC_OPTION_O:2029 case TCC_OPTION_O:
1993 case TCC_OPTION_pedantic:2030 case TCC_OPTION_pedantic:
1994 case TCC_OPTION_pipe:2031 case TCC_OPTION_pipe:
1995 case TCC_OPTION_x:
1996 /* ignored */2032 /* ignored */
1997 break;2033 break;
1998 default:2034 default:
libtcc.h+5−1
@@ -48,7 +48,11 @@ LIBTCCAPI void tcc_undefine_symbol(TCCState *s, const char *sym); · 47 unmodified lines
48/* compiling */48/* compiling */
49 49
50/* add a file (C file, dll, object, library, ld script). Return -1 if error. */50/* add a file (C file, dll, object, library, ld script). Return -1 if error. */
51LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename);51LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename, int filetype);
52#define TCC_FILETYPE_BINARY 1
53#define TCC_FILETYPE_C 2
54#define TCC_FILETYPE_ASM 3
55#define TCC_FILETYPE_ASM_PP 4
52 56
53/* compile a string containing a C source. Return -1 if error. */57/* compile a string containing a C source. Return -1 if error. */
54LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);58LIBTCCAPI int tcc_compile_string(TCCState *s, const char *buf);
tcc.c+3−4
@@ -312,9 +312,8 @@ int main(int argc, char **argv) · 311 unmodified lines
312 312
313 /* compile or add each files or library */313 /* compile or add each files or library */
314 for(i = ret = 0; i < s->nb_files && ret == 0; i++) {314 for(i = ret = 0; i < s->nb_files && ret == 0; i++) {
315 const char *filename;315 int filetype = *(unsigned char *)s->files[i];
316 316 const char *filename = s->files[i] + 1;
317 filename = s->files[i];
318 if (filename[0] == '-' && filename[1] == 'l') {317 if (filename[0] == '-' && filename[1] == 'l') {
319 if (tcc_add_library(s, filename + 2) < 0) {318 if (tcc_add_library(s, filename + 2) < 0) {
320 tcc_error_noabort("cannot find '%s'", filename);319 tcc_error_noabort("cannot find '%s'", filename);
@@ -323,7 +322,7 @@ int main(int argc, char **argv) · 2 unmodified lines
323 } else {322 } else {
324 if (1 == s->verbose)323 if (1 == s->verbose)
325 printf("-> %s\n", filename);324 printf("-> %s\n", filename);
326 if (tcc_add_file(s, filename) < 0)325 if (tcc_add_file(s, filename, filetype) < 0)
327 ret = 1;326 ret = 1;
328 if (!first_file)327 if (!first_file)
329 first_file = filename;328 first_file = filename;
tcc.h+1−1
@@ -1115,7 +1115,7 @@ ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen); · 1114 unmodified lines
1115ST_FUNC int tcc_open(TCCState *s1, const char *filename);1115ST_FUNC int tcc_open(TCCState *s1, const char *filename);
1116ST_FUNC void tcc_close(void);1116ST_FUNC void tcc_close(void);
1117 1117
1118ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);1118ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags, int filetype);
1119ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);1119ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
1120ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);1120ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1121 1121
tccelf.c+3−3
@@ -1562,7 +1562,7 @@ static int tcc_add_support(TCCState *s1, const char *filename) · 1561 unmodified lines
1562 #endif1562 #endif
1563 ,filename);1563 ,filename);
1564 1564
1565 return tcc_add_file(s1, buf);1565 return tcc_add_file(s1, buf, TCC_FILETYPE_BINARY);
1566}1566}
1567 1567
1568ST_FUNC void tcc_add_bcheck(TCCState *s1)1568ST_FUNC void tcc_add_bcheck(TCCState *s1)
@@ -1610,7 +1610,7 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) · 41 unmodified lines
1610 tcc_add_library(s1, "c");1610 tcc_add_library(s1, "c");
1611#ifdef CONFIG_USE_LIBGCC1611#ifdef CONFIG_USE_LIBGCC
1612 if (!s1->static_link) {1612 if (!s1->static_link) {
1613 tcc_add_file(s1, TCC_LIBGCC);1613 tcc_add_file(s1, TCC_LIBGCC, TCC_FILETYPE_BINARY);
1614 }1614 }
1615#endif1615#endif
1616 tcc_add_support(s1, "libtcc1.a");1616 tcc_add_support(s1, "libtcc1.a");
@@ -3366,7 +3366,7 @@ static int ld_add_file(TCCState *s1, const char filename[]) · 1749 unmodified lines
3366{3366{
3367 int ret;3367 int ret;
3368 3368
3369 ret = tcc_add_file_internal(s1, filename, 0);3369 ret = tcc_add_file_internal(s1, filename, 0, TCC_FILETYPE_BINARY);
3370 if (ret)3370 if (ret)
3371 ret = tcc_add_dll(s1, filename, 0);3371 ret = tcc_add_dll(s1, filename, 0);
3372 return ret;3372 return ret;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t