From 94bf4d2c227e2073458cabc768d1167e1f3ab2f8 Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 19 Dec 2009 22:08:52 +0100 Subject: tccpe: improve dllimport --- tccpe.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'tccpe.c') diff --git a/tccpe.c b/tccpe.c index 41de3f6..3a997bf 100644 --- a/tccpe.c +++ b/tccpe.c @@ -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 { @@ -1431,6 +1419,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) -- cgit v1.3.1