History

implement #pragma comment(lib,...)

Steven G. Messervey committed 11 years ago

Commit 8615bb41 parent a13f1834 files · +74 −15Browse files

Unified · Split

4 files
  1. libtcc.c +31 −13
  2. tcc.c +2 −2
  3. tccpp.c +38 −0
  4. tcctok.h +3 −0
libtcc.c+31−13
@@ -515,7 +515,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section, · 514 unmodified lines
515 }515 }
516#else516#else
517 if (! (sym->type.t & VT_STATIC))517 if (! (sym->type.t & VT_STATIC))
518 other = (sym->type.t & VT_VIS_MASK) >> VT_VIS_SHIFT;518 other = (sym->type.t & VT_VIS_MASK) >> VT_VIS_SHIFT;
519#endif519#endif
520 if (tcc_state->leading_underscore && can_add_underscore) {520 if (tcc_state->leading_underscore && can_add_underscore) {
521 buf1[0] = '_';521 buf1[0] = '_';
@@ -829,13 +829,31 @@ static int tcc_compile(TCCState *s1) · 307 unmodified lines
829 829
830LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)830LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
831{831{
832 int i;
832 int len, ret;833 int len, ret;
833 len = strlen(str);834 len = strlen(str);
834 835
835 tcc_open_bf(s, "<string>", len);836 tcc_open_bf(s, "<string>", len);
836 memcpy(file->buffer, str, len);837 memcpy(file->buffer, str, len);
838
839 len = s->nb_files;
837 ret = tcc_compile(s);840 ret = tcc_compile(s);
838 tcc_close();841 tcc_close();
842
843 /* habdle #pragma comment(lib,) */
844 for(i = len; i < s->nb_files; i++) {
845 /* int filetype = *(unsigned char *)s->files[i]; */
846 const char *filename = s->files[i] + 1;
847 if (filename[0] == '-' && filename[1] == 'l') {
848 if (tcc_add_library(s, filename + 2) < 0) {
849 tcc_warning("cannot find '%s'", filename+2);
850 ret++;
851 }
852 }
853 tcc_free(s->files[i]);
854 }
855 s->nb_files = len;
856
839 return ret;857 return ret;
840}858}
841 859
@@ -1339,7 +1357,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 497 unmodified lines
1339{1357{
1340 s->output_type = output_type;1358 s->output_type = output_type;
1341 if (output_type == TCC_OUTPUT_PREPROCESS)1359 if (output_type == TCC_OUTPUT_PREPROCESS)
1342 print_defines();1360 print_defines();
1343 1361
1344 if (!s->nostdinc) {1362 if (!s->nostdinc) {
1345 /* default include paths */1363 /* default include paths */
@@ -1899,16 +1917,16 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 553 unmodified lines
1899 s->do_debug = 1;1917 s->do_debug = 1;
1900 break;1918 break;
1901 case TCC_OPTION_c:1919 case TCC_OPTION_c:
1902 if (s->output_type)1920 if (s->output_type)
1903 tcc_warning("-c: some compiler action already specified (%d)", s->output_type);1921 tcc_warning("-c: some compiler action already specified (%d)", s->output_type);
1904 s->output_type = TCC_OUTPUT_OBJ;1922 s->output_type = TCC_OUTPUT_OBJ;
1905 break;1923 break;
1906 case TCC_OPTION_d:1924 case TCC_OPTION_d:
1907 if (*optarg != 'D') {1925 if (*optarg != 'D') {
1908 if (s->warn_unsupported)1926 if (s->warn_unsupported)
1909 goto unsupported_option;1927 goto unsupported_option;
1910 tcc_error("invalid option -- '%s'", r);1928 tcc_error("invalid option -- '%s'", r);
1911 }1929 }
1912 s->dflag = 1;1930 s->dflag = 1;
1913 break;1931 break;
1914#ifdef TCC_TARGET_ARM1932#ifdef TCC_TARGET_ARM
@@ -1927,11 +1945,11 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 12 unmodified lines
1927 s->static_link = 1;1945 s->static_link = 1;
1928 break;1946 break;
1929 case TCC_OPTION_std:1947 case TCC_OPTION_std:
1930 /* silently ignore, a current purpose:1948 /* silently ignore, a current purpose:
1931 allow to use a tcc as a reference compiler for "make test" */1949 allow to use a tcc as a reference compiler for "make test" */
1932 break;1950 break;
1933 case TCC_OPTION_shared:1951 case TCC_OPTION_shared:
1934 if (s->output_type)1952 if (s->output_type)
1935 tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);1953 tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);
1936 s->output_type = TCC_OUTPUT_DLL;1954 s->output_type = TCC_OUTPUT_DLL;
1937 break;1955 break;
@@ -1946,7 +1964,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 8 unmodified lines
1946 break;1964 break;
1947 case TCC_OPTION_r:1965 case TCC_OPTION_r:
1948 /* generate a .o merging several output files */1966 /* generate a .o merging several output files */
1949 if (s->output_type)1967 if (s->output_type)
1950 tcc_warning("-r: some compiler action already specified (%d)", s->output_type);1968 tcc_warning("-r: some compiler action already specified (%d)", s->output_type);
1951 s->option_r = 1;1969 s->option_r = 1;
1952 s->output_type = TCC_OUTPUT_OBJ;1970 s->output_type = TCC_OUTPUT_OBJ;
@@ -1964,7 +1982,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 11 unmodified lines
1964 s->print_search_dirs = 1;1982 s->print_search_dirs = 1;
1965 break;1983 break;
1966 case TCC_OPTION_run:1984 case TCC_OPTION_run:
1967 if (s->output_type)1985 if (s->output_type)
1968 tcc_warning("-run: some compiler action already specified (%d)", s->output_type);1986 tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
1969 s->output_type = TCC_OUTPUT_MEMORY;1987 s->output_type = TCC_OUTPUT_MEMORY;
1970 tcc_set_options(s, optarg);1988 tcc_set_options(s, optarg);
@@ -1995,7 +2013,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 24 unmodified lines
1995 cstr_ccat(&linker_arg, '\0');2013 cstr_ccat(&linker_arg, '\0');
1996 break;2014 break;
1997 case TCC_OPTION_E:2015 case TCC_OPTION_E:
1998 if (s->output_type)2016 if (s->output_type)
1999 tcc_warning("-E: some compiler action already specified (%d)", s->output_type);2017 tcc_warning("-E: some compiler action already specified (%d)", s->output_type);
2000 s->output_type = TCC_OUTPUT_PREPROCESS;2018 s->output_type = TCC_OUTPUT_PREPROCESS;
2001 break;2019 break;
tcc.c+2−2
@@ -265,7 +265,7 @@ int main(int argc, char **argv) · 264 unmodified lines
265 }265 }
266 266
267 if (s->output_type == 0)267 if (s->output_type == 0)
268 s->output_type = TCC_OUTPUT_EXE;268 s->output_type = TCC_OUTPUT_EXE;
269 269
270 if (s->option_m)270 if (s->option_m)
271 exec_other_tcc(s, argv, s->option_m);271 exec_other_tcc(s, argv, s->option_m);
@@ -317,7 +317,7 @@ int main(int argc, char **argv) · 45 unmodified lines
317 const char *filename = s->files[i] + 1;317 const char *filename = s->files[i] + 1;
318 if (filename[0] == '-' && filename[1] == 'l') {318 if (filename[0] == '-' && filename[1] == 'l') {
319 if (tcc_add_library(s, filename + 2) < 0) {319 if (tcc_add_library(s, filename + 2) < 0) {
320 tcc_error_noabort("cannot find '%s'", filename);320 tcc_error_noabort("cannot find '%s'", filename+2);
321 ret = 1;321 ret = 1;
322 }322 }
323 } else {323 } else {
tccpp.c+38−0
@@ -1420,7 +1420,45 @@ static void pragma_parse(TCCState *s1) · 1419 unmodified lines
1420 *s1->pack_stack_ptr = val;1420 *s1->pack_stack_ptr = val;
1421 skip(')');1421 skip(')');
1422 }1422 }
1423 } else if (tok == TOK_comment) {
1424 if (s1->ms_extensions) {
1425 next();
1426 skip('(');
1427 if (tok == TOK_lib) {
1428 next();
1429 skip(',');
1430 if (tok != TOK_STR)
1431 tcc_error("invalid library specification");
1432 else {
1433 /**/
1434 int len = strlen((char *)tokc.cstr->data);
1435 char *file = tcc_malloc(len+4); /* filetype, "-l" and 0 at the end */
1436 file[0] = TCC_FILETYPE_BINARY;
1437 file[1] = '-';
1438 file[2] = 'l';
1439 strcpy(&file[3], (char *)tokc.cstr->data);
1440 dynarray_add((void ***)&s1->files, &s1->nb_files, file);
1441 /**/
1442 /* we can't use
1443 tcc_add_library(s1,(char *)tokc.cstr->data);
1444 while compiling some file
1445 */
1446 /*
1447 if (strrchr((char *)tokc.cstr->data,'.') == NULL)
1448 tcc_add_library(s1,(char *)tokc.cstr->data);
1449 else
1450 tcc_add_file(s1,(char *)tokc.cstr->data,TCC_FILETYPE_BINARY);
1451 */
1452 }
1453 next();
1454 tok = TOK_LINEFEED;
1455 }
1456 }
1457 else
1458 tcc_warning("#pragma comment(lib) is ignored");
1423 }1459 }
1460 else
1461 tcc_warning("unknown #pragma %s", get_tok_str(tok, &tokc));
1424}1462}
1425 1463
1426/* is_bof is true if first non space token at beginning of file */1464/* is_bof is true if first non space token at beginning of file */
tcctok.h+3−0
@@ -153,6 +153,9 @@ · 152 unmodified lines
153 DEF(TOK_ASM_push, "push")153 DEF(TOK_ASM_push, "push")
154 DEF(TOK_ASM_pop, "pop")154 DEF(TOK_ASM_pop, "pop")
155#endif155#endif
156 /* pragma comment & comment(lib,...) */
157 DEF(TOK_comment, "comment")
158 DEF(TOK_lib, "lib")
156 159
157/* builtin functions or variables */160/* builtin functions or variables */
158#ifndef TCC_ARM_EABI161#ifndef TCC_ARM_EABI