diff options
| author | grischka <grischka> | 2009-12-19 22:08:52 +0100 |
|---|---|---|
| committer | grischka <grischka> | 2009-12-19 22:16:21 +0100 |
| commit | 94bf4d2c227e2073458cabc768d1167e1f3ab2f8 (patch) | |
| tree | c18160b09f29b7a3dddbdb10756edb1526d98f4e /tccpe.c | |
| parent | 1308e8ebcfba43b4b96b7ef32f1a177b1168665d (diff) | |
| download | tinycc-94bf4d2c227e2073458cabc768d1167e1f3ab2f8.tar.gz tinycc-94bf4d2c227e2073458cabc768d1167e1f3ab2f8.tar.bz2 | |
tccpe: improve dllimport
Diffstat (limited to 'tccpe.c')
| -rw-r--r-- | tccpe.c | 38 |
1 files changed, 26 insertions, 12 deletions
@@ -853,18 +853,6 @@ ST_FN void pe_build_imports(struct pe_info *pe) } /* ------------------------------------------------------------- */ -/* - For now only functions are exported. Export of data - would work, but import requires compiler support to - do an additional indirection. - - For instance: - __declspec(dllimport) extern int something; - - needs to be translated to: - - *(int*)something -*/ struct pe_sort_sym { @@ -1432,6 +1420,32 @@ ST_FN void pe_print_sections(TCCState *s1, const char *fname) #endif /* ------------------------------------------------------------- */ +/* helper function for load/store to insert one more indirection */ + +int pe_dllimport(int r, SValue *sv, void (*fn)(int r, SValue *sv)) +{ + int t; + if ((sv->r & (VT_VALMASK|VT_SYM|VT_CONST)) != (VT_SYM|VT_CONST)) + return 0; + t = sv->sym->type.t; + if (0 == (t & VT_IMPORT)) + return 0; + + sv->sym->type.t = t & ~VT_IMPORT; + //printf("import %x %04x %s\n", t, ind, get_tok_str(sv->sym->v, NULL)); + + *++vtop = *sv; + vtop->type.t &= ~(VT_ARRAY|VT_IMPORT); + mk_pointer(&vtop->type); + indir(); + fn(r, vtop); + --vtop; + + sv->sym->type.t = t; + return 1; +} + +/* ------------------------------------------------------------- */ ST_FN int read_mem(FILE *fp, unsigned offset, void *buffer, unsigned len) { |
