History

Add input files/libs and reloc_output switch to TCCState

files[0], and reloc_outpu will be needed for (upcoming in the next patch) "compute default outfile name" refactored into libtcc function. Also, since for symmetry and from libification point of view, it makes some sense to also put all information about what was given as input to compilation into TCCState, let's not only put files[0], but all files and all libraries given explicitely by user. One point: I've used bitfield for reloc_output & trimmed down output_type to 8 bits so that TCCState stays the same in size, and also access to output_type is (hopefully) is not slower. By the way -- as of today, sizeof(TCCState) on i686-pc-linux-gnu is 2884 bytes...

Kirill Smelkov committed 16 years ago

Commit a919a371 parent 66b54af4 files · +24 −1Browse files

Unified · Split

4 files
  1. libtcc.c +8 −0
  2. libtcc.h +7 −0
  3. tcc.c +1 −0
  4. tcc.h +8 −1
libtcc.c+8−0
@@ -1038,6 +1038,10 @@ LIBTCCAPI void tcc_delete(TCCState *s1) · 1037 unmodified lines
1038 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);1038 dynarray_reset(&s1->sysinclude_paths, &s1->nb_sysinclude_paths);
1039 1039
1040 tcc_free(s1->tcc_lib_path);1040 tcc_free(s1->tcc_lib_path);
1041
1042 dynarray_reset(&s1->input_files, &s1->nb_input_files);
1043 dynarray_reset(&s1->input_libs, &s1->nb_input_libs);
1044
1041#ifdef HAVE_SELINUX1045#ifdef HAVE_SELINUX
1042 munmap (s1->write_mem, s1->mem_size);1046 munmap (s1->write_mem, s1->mem_size);
1043 munmap (s1->runtime_mem, s1->mem_size); 1047 munmap (s1->runtime_mem, s1->mem_size);
@@ -1184,6 +1188,8 @@ the_end: · 140 unmodified lines
1184 1188
1185LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)1189LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
1186{1190{
1191 dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename));
1192
1187 if (s->output_type == TCC_OUTPUT_PREPROCESS)1193 if (s->output_type == TCC_OUTPUT_PREPROCESS)
1188 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);1194 return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
1189 else1195 else
@@ -1220,6 +1226,8 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 30 unmodified lines
1220{1226{
1221 char buf[1024];1227 char buf[1024];
1222 int i;1228 int i;
1229
1230 dynarray_add((void ***)&s->input_libs, &s->nb_input_libs, tcc_strdup(libraryname));
1223 1231
1224 /* first we look for the dynamic library if not static linking */1232 /* first we look for the dynamic library if not static linking */
1225 if (!s->static_link) {1233 if (!s->static_link) {
libtcc.h+7−0
@@ -103,6 +103,13 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name); · 102 unmodified lines
103/* set CONFIG_TCCDIR at runtime */103/* set CONFIG_TCCDIR at runtime */
104LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);104LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path);
105 105
106
107/*****************************/
108/* Miscellaneous */
109
110/* Get default target filename for this compilation */
111LIBTCCAPI const char *tcc_default_target(TCCState *s);
112
106#ifdef __cplusplus113#ifdef __cplusplus
107}114}
108#endif115#endif
tcc.c+1−0
@@ -475,6 +475,7 @@ int main(int argc, char **argv) · 474 unmodified lines
475 }475 }
476 476
477 tcc_set_output_type(s, output_type);477 tcc_set_output_type(s, output_type);
478 s->reloc_output = reloc_output;
478 479
479 /* compile or add each files or library */480 /* compile or add each files or library */
480 for(i = 0; i < nb_files && ret == 0; i++) {481 for(i = 0; i < nb_files && ret == 0; i++) {
tcc.h+8−1
@@ -397,7 +397,8 @@ typedef struct ASMOperand { · 396 unmodified lines
397#endif397#endif
398 398
399struct TCCState {399struct TCCState {
400 int output_type;400 unsigned output_type : 8;
401 unsigned reloc_output : 1;
401 402
402 BufferedFile **include_stack_ptr;403 BufferedFile **include_stack_ptr;
403 int *ifdef_stack_ptr;404 int *ifdef_stack_ptr;
@@ -518,6 +519,12 @@ struct TCCState { · 114 unmodified lines
518 /* output file for preprocessing */519 /* output file for preprocessing */
519 FILE *outfile;520 FILE *outfile;
520 521
522 /* input files and libraries for this compilation */
523 char **input_files;
524 int nb_input_files;
525 char **input_libs;
526 int nb_input_libs;
527
521 /* for tcc_relocate */528 /* for tcc_relocate */
522 int runtime_added;529 int runtime_added;
523 void *runtime_mem;530 void *runtime_mem;

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