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
515515 }
516516 #else
517517 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;
519519 #endif
520520 if (tcc_state->leading_underscore && can_add_underscore) {
521521 buf1[0] = '_';
@@ -829,13 +829,31 @@ static int tcc_compile(TCCState *s1) · 307 unmodified lines
829829
830830 LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
831831 {
832+ int i;
832833 int len, ret;
833834 len = strlen(str);
834835
835836 tcc_open_bf(s, "<string>", len);
836837 memcpy(file->buffer, str, len);
838+
839+ len = s->nb_files;
837840 ret = tcc_compile(s);
838841 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+
839857 return ret;
840858 }
841859
@@ -1339,7 +1357,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 497 unmodified lines
13391357 {
13401358 s->output_type = output_type;
13411359 if (output_type == TCC_OUTPUT_PREPROCESS)
1342− print_defines();
1360+ print_defines();
13431361
13441362 if (!s->nostdinc) {
13451363 /* default include paths */
@@ -1899,16 +1917,16 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 553 unmodified lines
18991917 s->do_debug = 1;
19001918 break;
19011919 case TCC_OPTION_c:
1902− if (s->output_type)
1920+ if (s->output_type)
19031921 tcc_warning("-c: some compiler action already specified (%d)", s->output_type);
19041922 s->output_type = TCC_OUTPUT_OBJ;
19051923 break;
19061924 case TCC_OPTION_d:
1907− if (*optarg != 'D') {
1908− if (s->warn_unsupported)
1909− goto unsupported_option;
1925+ if (*optarg != 'D') {
1926+ if (s->warn_unsupported)
1927+ goto unsupported_option;
19101928 tcc_error("invalid option -- '%s'", r);
1911− }
1929+ }
19121930 s->dflag = 1;
19131931 break;
19141932 #ifdef TCC_TARGET_ARM
@@ -1927,11 +1945,11 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 12 unmodified lines
19271945 s->static_link = 1;
19281946 break;
19291947 case TCC_OPTION_std:
1930− /* silently ignore, a current purpose:
1931− allow to use a tcc as a reference compiler for "make test" */
1948+ /* silently ignore, a current purpose:
1949+ allow to use a tcc as a reference compiler for "make test" */
19321950 break;
19331951 case TCC_OPTION_shared:
1934− if (s->output_type)
1952+ if (s->output_type)
19351953 tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);
19361954 s->output_type = TCC_OUTPUT_DLL;
19371955 break;
@@ -1946,7 +1964,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 8 unmodified lines
19461964 break;
19471965 case TCC_OPTION_r:
19481966 /* generate a .o merging several output files */
1949− if (s->output_type)
1967+ if (s->output_type)
19501968 tcc_warning("-r: some compiler action already specified (%d)", s->output_type);
19511969 s->option_r = 1;
19521970 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
19641982 s->print_search_dirs = 1;
19651983 break;
19661984 case TCC_OPTION_run:
1967− if (s->output_type)
1985+ if (s->output_type)
19681986 tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
19691987 s->output_type = TCC_OUTPUT_MEMORY;
19701988 tcc_set_options(s, optarg);
@@ -1995,7 +2013,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 24 unmodified lines
19952013 cstr_ccat(&linker_arg, '\0');
19962014 break;
19972015 case TCC_OPTION_E:
1998− if (s->output_type)
2016+ if (s->output_type)
19992017 tcc_warning("-E: some compiler action already specified (%d)", s->output_type);
20002018 s->output_type = TCC_OUTPUT_PREPROCESS;
20012019 break;
tcc.c+2−2
@@ -265,7 +265,7 @@ int main(int argc, char **argv) · 264 unmodified lines
265265 }
266266
267267 if (s->output_type == 0)
268− s->output_type = TCC_OUTPUT_EXE;
268+ s->output_type = TCC_OUTPUT_EXE;
269269
270270 if (s->option_m)
271271 exec_other_tcc(s, argv, s->option_m);
@@ -317,7 +317,7 @@ int main(int argc, char **argv) · 45 unmodified lines
317317 const char *filename = s->files[i] + 1;
318318 if (filename[0] == '-' && filename[1] == 'l') {
319319 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);
321321 ret = 1;
322322 }
323323 } else {
tccpp.c+38−0
@@ -1420,7 +1420,45 @@ static void pragma_parse(TCCState *s1) · 1419 unmodified lines
14201420 *s1->pack_stack_ptr = val;
14211421 skip(')');
14221422 }
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");
14231459 }
1460+ else
1461+ tcc_warning("unknown #pragma %s", get_tok_str(tok, &tokc));
14241462 }
14251463
14261464 /* is_bof is true if first non space token at beginning of file */
tcctok.h+3−0
@@ -153,6 +153,9 @@ · 152 unmodified lines
153153 DEF(TOK_ASM_push, "push")
154154 DEF(TOK_ASM_pop, "pop")
155155 #endif
156+ /* pragma comment & comment(lib,...) */
157+ DEF(TOK_comment, "comment")
158+ DEF(TOK_lib, "lib")
156159
157160 /* builtin functions or variables */
158161 #ifndef TCC_ARM_EABI