mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-01 04:20:09 +08:00
implement #pragma comment(lib,...)
This commit is contained in:
parent
a13f183e4c
commit
8615bb40fb
44
libtcc.c
44
libtcc.c
@ -515,7 +515,7 @@ ST_FUNC void put_extern_sym2(Sym *sym, Section *section,
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (! (sym->type.t & VT_STATIC))
|
if (! (sym->type.t & VT_STATIC))
|
||||||
other = (sym->type.t & VT_VIS_MASK) >> VT_VIS_SHIFT;
|
other = (sym->type.t & VT_VIS_MASK) >> VT_VIS_SHIFT;
|
||||||
#endif
|
#endif
|
||||||
if (tcc_state->leading_underscore && can_add_underscore) {
|
if (tcc_state->leading_underscore && can_add_underscore) {
|
||||||
buf1[0] = '_';
|
buf1[0] = '_';
|
||||||
@ -829,13 +829,31 @@ static int tcc_compile(TCCState *s1)
|
|||||||
|
|
||||||
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
|
LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
int len, ret;
|
int len, ret;
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
|
|
||||||
tcc_open_bf(s, "<string>", len);
|
tcc_open_bf(s, "<string>", len);
|
||||||
memcpy(file->buffer, str, len);
|
memcpy(file->buffer, str, len);
|
||||||
|
|
||||||
|
len = s->nb_files;
|
||||||
ret = tcc_compile(s);
|
ret = tcc_compile(s);
|
||||||
tcc_close();
|
tcc_close();
|
||||||
|
|
||||||
|
/* habdle #pragma comment(lib,) */
|
||||||
|
for(i = len; i < s->nb_files; i++) {
|
||||||
|
/* int filetype = *(unsigned char *)s->files[i]; */
|
||||||
|
const char *filename = s->files[i] + 1;
|
||||||
|
if (filename[0] == '-' && filename[1] == 'l') {
|
||||||
|
if (tcc_add_library(s, filename + 2) < 0) {
|
||||||
|
tcc_warning("cannot find '%s'", filename+2);
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tcc_free(s->files[i]);
|
||||||
|
}
|
||||||
|
s->nb_files = len;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1339,7 +1357,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
|||||||
{
|
{
|
||||||
s->output_type = output_type;
|
s->output_type = output_type;
|
||||||
if (output_type == TCC_OUTPUT_PREPROCESS)
|
if (output_type == TCC_OUTPUT_PREPROCESS)
|
||||||
print_defines();
|
print_defines();
|
||||||
|
|
||||||
if (!s->nostdinc) {
|
if (!s->nostdinc) {
|
||||||
/* default include paths */
|
/* default include paths */
|
||||||
@ -1899,16 +1917,16 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
|
|||||||
s->do_debug = 1;
|
s->do_debug = 1;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_c:
|
case TCC_OPTION_c:
|
||||||
if (s->output_type)
|
if (s->output_type)
|
||||||
tcc_warning("-c: some compiler action already specified (%d)", s->output_type);
|
tcc_warning("-c: some compiler action already specified (%d)", s->output_type);
|
||||||
s->output_type = TCC_OUTPUT_OBJ;
|
s->output_type = TCC_OUTPUT_OBJ;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_d:
|
case TCC_OPTION_d:
|
||||||
if (*optarg != 'D') {
|
if (*optarg != 'D') {
|
||||||
if (s->warn_unsupported)
|
if (s->warn_unsupported)
|
||||||
goto unsupported_option;
|
goto unsupported_option;
|
||||||
tcc_error("invalid option -- '%s'", r);
|
tcc_error("invalid option -- '%s'", r);
|
||||||
}
|
}
|
||||||
s->dflag = 1;
|
s->dflag = 1;
|
||||||
break;
|
break;
|
||||||
#ifdef TCC_TARGET_ARM
|
#ifdef TCC_TARGET_ARM
|
||||||
@ -1927,11 +1945,11 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
|
|||||||
s->static_link = 1;
|
s->static_link = 1;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_std:
|
case TCC_OPTION_std:
|
||||||
/* silently ignore, a current purpose:
|
/* silently ignore, a current purpose:
|
||||||
allow to use a tcc as a reference compiler for "make test" */
|
allow to use a tcc as a reference compiler for "make test" */
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_shared:
|
case TCC_OPTION_shared:
|
||||||
if (s->output_type)
|
if (s->output_type)
|
||||||
tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);
|
tcc_warning("-shared: some compiler action already specified (%d)", s->output_type);
|
||||||
s->output_type = TCC_OUTPUT_DLL;
|
s->output_type = TCC_OUTPUT_DLL;
|
||||||
break;
|
break;
|
||||||
@ -1946,7 +1964,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case TCC_OPTION_r:
|
case TCC_OPTION_r:
|
||||||
/* generate a .o merging several output files */
|
/* generate a .o merging several output files */
|
||||||
if (s->output_type)
|
if (s->output_type)
|
||||||
tcc_warning("-r: some compiler action already specified (%d)", s->output_type);
|
tcc_warning("-r: some compiler action already specified (%d)", s->output_type);
|
||||||
s->option_r = 1;
|
s->option_r = 1;
|
||||||
s->output_type = TCC_OUTPUT_OBJ;
|
s->output_type = TCC_OUTPUT_OBJ;
|
||||||
@ -1964,7 +1982,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
|
|||||||
s->print_search_dirs = 1;
|
s->print_search_dirs = 1;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_run:
|
case TCC_OPTION_run:
|
||||||
if (s->output_type)
|
if (s->output_type)
|
||||||
tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
|
tcc_warning("-run: some compiler action already specified (%d)", s->output_type);
|
||||||
s->output_type = TCC_OUTPUT_MEMORY;
|
s->output_type = TCC_OUTPUT_MEMORY;
|
||||||
tcc_set_options(s, optarg);
|
tcc_set_options(s, optarg);
|
||||||
@ -1995,7 +2013,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv)
|
|||||||
cstr_ccat(&linker_arg, '\0');
|
cstr_ccat(&linker_arg, '\0');
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_E:
|
case TCC_OPTION_E:
|
||||||
if (s->output_type)
|
if (s->output_type)
|
||||||
tcc_warning("-E: some compiler action already specified (%d)", s->output_type);
|
tcc_warning("-E: some compiler action already specified (%d)", s->output_type);
|
||||||
s->output_type = TCC_OUTPUT_PREPROCESS;
|
s->output_type = TCC_OUTPUT_PREPROCESS;
|
||||||
break;
|
break;
|
||||||
|
4
tcc.c
4
tcc.c
@ -265,7 +265,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s->output_type == 0)
|
if (s->output_type == 0)
|
||||||
s->output_type = TCC_OUTPUT_EXE;
|
s->output_type = TCC_OUTPUT_EXE;
|
||||||
|
|
||||||
if (s->option_m)
|
if (s->option_m)
|
||||||
exec_other_tcc(s, argv, s->option_m);
|
exec_other_tcc(s, argv, s->option_m);
|
||||||
@ -317,7 +317,7 @@ int main(int argc, char **argv)
|
|||||||
const char *filename = s->files[i] + 1;
|
const char *filename = s->files[i] + 1;
|
||||||
if (filename[0] == '-' && filename[1] == 'l') {
|
if (filename[0] == '-' && filename[1] == 'l') {
|
||||||
if (tcc_add_library(s, filename + 2) < 0) {
|
if (tcc_add_library(s, filename + 2) < 0) {
|
||||||
tcc_error_noabort("cannot find '%s'", filename);
|
tcc_error_noabort("cannot find '%s'", filename+2);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
38
tccpp.c
38
tccpp.c
@ -1420,7 +1420,45 @@ static void pragma_parse(TCCState *s1)
|
|||||||
*s1->pack_stack_ptr = val;
|
*s1->pack_stack_ptr = val;
|
||||||
skip(')');
|
skip(')');
|
||||||
}
|
}
|
||||||
|
} else if (tok == TOK_comment) {
|
||||||
|
if (s1->ms_extensions) {
|
||||||
|
next();
|
||||||
|
skip('(');
|
||||||
|
if (tok == TOK_lib) {
|
||||||
|
next();
|
||||||
|
skip(',');
|
||||||
|
if (tok != TOK_STR)
|
||||||
|
tcc_error("invalid library specification");
|
||||||
|
else {
|
||||||
|
/**/
|
||||||
|
int len = strlen((char *)tokc.cstr->data);
|
||||||
|
char *file = tcc_malloc(len+4); /* filetype, "-l" and 0 at the end */
|
||||||
|
file[0] = TCC_FILETYPE_BINARY;
|
||||||
|
file[1] = '-';
|
||||||
|
file[2] = 'l';
|
||||||
|
strcpy(&file[3], (char *)tokc.cstr->data);
|
||||||
|
dynarray_add((void ***)&s1->files, &s1->nb_files, file);
|
||||||
|
/**/
|
||||||
|
/* we can't use
|
||||||
|
tcc_add_library(s1,(char *)tokc.cstr->data);
|
||||||
|
while compiling some file
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
if (strrchr((char *)tokc.cstr->data,'.') == NULL)
|
||||||
|
tcc_add_library(s1,(char *)tokc.cstr->data);
|
||||||
|
else
|
||||||
|
tcc_add_file(s1,(char *)tokc.cstr->data,TCC_FILETYPE_BINARY);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
tok = TOK_LINEFEED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tcc_warning("#pragma comment(lib) is ignored");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
tcc_warning("unknown #pragma %s", get_tok_str(tok, &tokc));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is_bof is true if first non space token at beginning of file */
|
/* is_bof is true if first non space token at beginning of file */
|
||||||
|
3
tcctok.h
3
tcctok.h
@ -153,6 +153,9 @@
|
|||||||
DEF(TOK_ASM_push, "push")
|
DEF(TOK_ASM_push, "push")
|
||||||
DEF(TOK_ASM_pop, "pop")
|
DEF(TOK_ASM_pop, "pop")
|
||||||
#endif
|
#endif
|
||||||
|
/* pragma comment & comment(lib,...) */
|
||||||
|
DEF(TOK_comment, "comment")
|
||||||
|
DEF(TOK_lib, "lib")
|
||||||
|
|
||||||
/* builtin functions or variables */
|
/* builtin functions or variables */
|
||||||
#ifndef TCC_ARM_EABI
|
#ifndef TCC_ARM_EABI
|
||||||
|
Loading…
Reference in New Issue
Block a user