Skip to content

Commit

Permalink
merge with D2 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Sep 1, 2014
1 parent c570315 commit d50d2cb
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 37 deletions.
17 changes: 13 additions & 4 deletions src/backend/aa.c
Expand Up @@ -42,6 +42,15 @@ size_t aligntsize(size_t tsize)
return (tsize + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1);
}

static int hashCmp(hash_t lhs, hash_t rhs)
{
if (lhs == rhs)
return 0;
else if (lhs < rhs)
return -1;
return 1;
}

/**********************************
* Constructor.
*/
Expand Down Expand Up @@ -122,7 +131,7 @@ void* AArray::get(void *pkey)
while ((e = *pe) != NULL)
{ int c;

c = key_hash - e->hash;
c = hashCmp(key_hash, e->hash);
if (c == 0)
{
c = keyti->compare(pkey, e + 1);
Expand Down Expand Up @@ -180,7 +189,7 @@ void* AArray::in(void *pkey)
while (e != NULL)
{ int c;

c = key_hash - e->hash;
c = hashCmp(key_hash, e->hash);
if (c == 0)
{
c = keyti->compare(pkey, e + 1);
Expand Down Expand Up @@ -218,7 +227,7 @@ void AArray::del(void *pkey)
while ((e = *pe) != NULL) // NULL means not found
{ int c;

c = key_hash - e->hash;
c = hashCmp(key_hash, e->hash);
if (c == 0)
{
c = keyti->compare(pkey, e + 1);
Expand Down Expand Up @@ -412,7 +421,7 @@ void AArray::rehash_x(aaA* olde, aaA** newbuckets, size_t newbuckets_length)
//printf("\te = %p, e->left = %p, e->right = %p\n", e, e->left, e->right);
assert(e->left != e);
assert(e->right != e);
c = key_hash - e->hash;
c = hashCmp(key_hash, e->hash);
if (c == 0)
c = keyti->compare(olde + 1, e + 1);
if (c < 0)
Expand Down
12 changes: 11 additions & 1 deletion src/backend/backconfig.c
Expand Up @@ -38,6 +38,7 @@ extern void ph_init();
void out_config_init(
int model, // 32: 32 bit code
// 64: 64 bit code
// Windows: set bit 0 to generate MS-COFF instead of OMF
bool exe, // true: exe file
// false: dll or shared library (generate PIC code)
bool trace, // add profiling code
Expand All @@ -64,6 +65,8 @@ void out_config_init(
config.memmodel = 0;
config.flags |= CFGuchar; // make sure TYchar is unsigned
tytab[TYchar] |= TYFLuns;
bool mscoff = model & 1;
model &= 32 | 64;
#if TARGET_WINDOS
if (model == 64)
{ config.exe = EX_WIN64;
Expand All @@ -73,10 +76,12 @@ void out_config_init(
config.flags |= CFGnoebp;
config.flags |= CFGalwaysframe;
config.flags |= CFGromable; // put switch tables in code segment
config.objfmt = OBJ_MSCOFF;
}
else
{ config.exe = EX_NT;
config.flags2 |= CFG2seh; // Win32 eh
config.objfmt = mscoff ? OBJ_MSCOFF : OBJ_OMF;
}

if (exe)
Expand All @@ -98,6 +103,7 @@ void out_config_init(
config.flags |= CFGalwaysframe;
if (!exe)
config.flags3 |= CFG3pic;
config.objfmt = OBJ_ELF;
#endif
#if TARGET_OSX
config.fpxmmregs = TRUE;
Expand All @@ -112,6 +118,7 @@ void out_config_init(
if (!exe)
config.flags3 |= CFG3pic;
config.flags |= CFGromable; // put switch tables in code segment
config.objfmt = OBJ_MACH;
#endif
#if TARGET_FREEBSD
if (model == 64)
Expand All @@ -128,6 +135,7 @@ void out_config_init(
config.flags |= CFGalwaysframe;
if (!exe)
config.flags3 |= CFG3pic;
config.objfmt = OBJ_ELF;
#endif
#if TARGET_OPENBSD
if (model == 64)
Expand All @@ -144,6 +152,7 @@ void out_config_init(
config.flags |= CFGalwaysframe;
if (!exe)
config.flags3 |= CFG3pic;
config.objfmt = OBJ_ELF;
#endif
#if TARGET_SOLARIS
if (model == 64)
Expand All @@ -160,6 +169,7 @@ void out_config_init(
config.flags |= CFGalwaysframe;
if (!exe)
config.flags3 |= CFG3pic;
config.objfmt = OBJ_ELF;
#endif
config.flags2 |= CFG2nodeflib; // no default library
config.flags3 |= CFG3eseqds;
Expand Down Expand Up @@ -189,7 +199,7 @@ void out_config_init(
config.fulltypes = (symdebug == 1) ? CVDWARF_D : CVDWARF_C;
#endif
#if SYMDEB_CODEVIEW
if (model == 64)
if (config.objfmt == OBJ_MSCOFF)
{
configv.addlinenumbers = 1;
config.fulltypes = CV8;
Expand Down
5 changes: 5 additions & 0 deletions src/backend/cdef.h
Expand Up @@ -703,6 +703,11 @@ struct Config
2: fast inline 8087 code
*/
short memmodel; // 0:S,X,N,F, 1:M, 2:C, 3:L, 4:V
unsigned objfmt; // target object format
#define OBJ_OMF 1
#define OBJ_MSCOFF 2
#define OBJ_ELF 3
#define OBJ_MACH 4
unsigned exe; // target operating system
#define EX_DOSX 1 // DOSX 386 program
#define EX_ZPM 2 // ZPM 286 program
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cgen.c
Expand Up @@ -525,7 +525,7 @@ size_t addtofixlist(symbol *s,targ_size_t soffset,int seg,targ_size_t val,int fl
static char zeros[8];

//printf("addtofixlist(%p '%s')\n",s,s->Sident);
assert(flags);
assert(I32 || flags);
fixlist *ln = (fixlist *) mem_calloc(sizeof(fixlist));
//ln->Lsymbol = s;
ln->Loffset = soffset;
Expand Down
7 changes: 7 additions & 0 deletions src/backend/cod1.c
Expand Up @@ -2213,6 +2213,13 @@ code *callclib(elem *e,unsigned clib,regm_t *pretregs,regm_t keepmask)
info[CLIBullngdbl].retregs32 = mAX;
info[CLIBdblullng].retregs32 = mAX;
}
else if (config.objfmt == OBJ_MSCOFF)
{
strcpy(lib[CLIBldiv].Sident, "_ms_alldiv");
strcpy(lib[CLIBlmod].Sident, "_ms_allrem"); info[CLIBlmod].retregs32 = mAX|mDX;
strcpy(lib[CLIBuldiv].Sident, "_ms_aulldiv");
strcpy(lib[CLIBulmod].Sident, "_ms_aullrem"); info[CLIBulmod].retregs32 = mAX|mDX;
}
}
clib_inited++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cod3.c
Expand Up @@ -4152,7 +4152,7 @@ void cod3_thunk(symbol *sthunk,symbol *sfunc,unsigned p,tym_t thisty,
objmod->pubdef(cseg,sthunk,sthunk->Soffset);
#endif
#if TARGET_WINDOS
if (config.exe == EX_WIN64)
if (config.objfmt == OBJ_MSCOFF)
objmod->pubdef(cseg,sthunk,sthunk->Soffset);
#endif
searchfixlist(sthunk); /* resolve forward refs */
Expand Down
13 changes: 8 additions & 5 deletions src/backend/cv8.c
Expand Up @@ -277,7 +277,7 @@ void cv8_initmodule(const char *filename, const char *modulename)
void cv8_termmodule()
{
//printf("cv8_termmodule()\n");
assert(config.exe == EX_WIN64);
assert(config.objfmt == OBJ_MSCOFF);
}

/******************************************
Expand Down Expand Up @@ -614,14 +614,14 @@ void cv8_outsym(Symbol *s)
buf->writeWordn(0x1111);
buf->write32(s->Soffset + base + BPoff);
buf->write32(typidx);
buf->writeWordn(334); // relative to RBP
buf->writeWordn(I64 ? 334 : 22); // relative to RBP/EBP
cv8_writename(buf, id, len);
buf->writeByte(0);
#else
// This is supposed to work, implicit BP relative addressing, but it does not
buf->reserve(2 + 2 + 4 + 4 + len + 1);
buf->writeWordn( 2 + 4 + 4 + len + 1);
buf->writeWordn(0x1006);
buf->writeWordn(S_BPREL_V3);
buf->write32(s->Soffset + base + BPoff);
buf->write32(typidx);
cv8_writename(buf, id, len);
Expand Down Expand Up @@ -864,7 +864,9 @@ idx_t cv8_darray(type *t, idx_t etypidx)

debtyp_t *f = debtyp_alloc(sizeof(fl));
memcpy(f->data,fl,sizeof(fl));
TOLONG(f->data + 6, I64 ? 0x23 : 0x22); // size_t
TOLONG(f->data + 26, ptridx);
TOWORD(f->data + 30, NPTRSIZE);
idx_t fieldlist = cv_debtyp(f);

const char *id;
Expand Down Expand Up @@ -899,7 +901,7 @@ idx_t cv8_darray(type *t, idx_t etypidx)
TOLONG(d->data + 6, fieldlist);
TOLONG(d->data + 10, 0); // dList
TOLONG(d->data + 14, 0); // vtshape
TOWORD(d->data + 18, 16); // size
TOWORD(d->data + 18, 2 * NPTRSIZE); // size
cv_namestring(d->data + 20, id, idlen);
d->data[20 + idlen] = 0;

Expand Down Expand Up @@ -966,6 +968,7 @@ idx_t cv8_ddelegate(type *t, idx_t functypidx)
memcpy(f->data,fl,sizeof(fl));
TOLONG(f->data + 6, pvidx);
TOLONG(f->data + 22, ptridx);
TOWORD(f->data + 26, NPTRSIZE);
idx_t fieldlist = cv_debtyp(f);

const char *id = "dDelegate";
Expand All @@ -980,7 +983,7 @@ idx_t cv8_ddelegate(type *t, idx_t functypidx)
TOLONG(d->data + 6, fieldlist);
TOLONG(d->data + 10, 0); // dList
TOLONG(d->data + 14, 0); // vtshape
TOWORD(d->data + 18, 16); // size
TOWORD(d->data + 18, 2 * NPTRSIZE); // size
memcpy(d->data + 20, id, idlen);
d->data[20 + idlen] = 0;
#endif
Expand Down
12 changes: 10 additions & 2 deletions src/backend/el.c
Expand Up @@ -588,10 +588,18 @@ elem *exp2_copytotemp(elem *e)
{
//printf("exp2_copytotemp()\n");
elem_debug(e);
Symbol *stmp = symbol_genauto(e);
tym_t ty = tybasic(e->Ety);
type *t;
#if MARS
if ((ty == TYstruct || ty == TYarray) && e->ET)
t = e->ET;
else
#endif
t = type_fake(ty);
Symbol *stmp = symbol_genauto(t);
elem *eeq = el_bin(OPeq,e->Ety,el_var(stmp),e);
elem *er = el_bin(OPcomma,e->Ety,eeq,el_var(stmp));
if (tybasic(e->Ety) == TYstruct || tybasic(e->Ety) == TYarray)
if (ty == TYstruct || ty == TYarray)
{
eeq->Eoper = OPstreq;
eeq->ET = e->ET;
Expand Down

0 comments on commit d50d2cb

Please sign in to comment.