32 changes: 17 additions & 15 deletions src/backend/cgcod.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ targ_size_t retoffset; /* offset from start of func to ret code */
targ_size_t retsize; /* size of function return */

static regm_t lastretregs,last2retregs,last3retregs,last4retregs,last5retregs;


/*********************************
* Generate code for a function.
* Note at the end of this routine mfuncreg will contain the mask
Expand Down Expand Up @@ -383,11 +383,13 @@ void codgen()
#endif

// Compute starting offset for switch tables
#if ELFOBJ || MACHOBJ
targ_size_t swoffset = (config.flags & CFGromable) ? coffset : CDoffset;
#else
targ_size_t swoffset = (config.flags & CFGromable) ? coffset : Doffset;
#endif
targ_size_t swoffset;
if (config.flags & CFGromable)
swoffset = coffset;
else if (config.objfmt == OBJ_ELF || config.objfmt == OBJ_MACH)
swoffset = CDoffset;
else
swoffset = Doffset;
swoffset = align(0,swoffset);

// Emit the generated code
Expand Down Expand Up @@ -1217,7 +1219,7 @@ void stackoffsets(int flags)
free(autos);
}
}


/****************************
* Generate code for a block.
*/
Expand Down Expand Up @@ -1351,7 +1353,7 @@ STATIC void blcodgen(block *bl)
debugw && printf("code gen complete\n");
#endif
}


/*****************************************
* Add in exception handling code.
*/
Expand Down Expand Up @@ -1537,7 +1539,7 @@ STATIC void cgcod_eh()
}

#endif


/******************************
* Count the number of bits set in a register mask.
*/
Expand Down Expand Up @@ -1594,7 +1596,7 @@ unsigned findreg(regm_t regm
assert(0);
return 0;
}


/***************
* Free element (but not it's leaves! (assume they are already freed))
* Don't decrement Ecount! This is so we can detect if the common subexp
Expand Down Expand Up @@ -1909,7 +1911,7 @@ code *allocreg(regm_t *pretregs,unsigned *preg,tym_t tym
#warning cpu specific code
#endif
}


/*************************
* Mark registers as used.
*/
Expand Down Expand Up @@ -2038,7 +2040,7 @@ code *getregs_imm(regm_t r)
regcon.immed.mval = save;
return c;
}


/******************************************
* Flush all CSE's out of registers and into memory.
* Input:
Expand Down Expand Up @@ -2109,7 +2111,7 @@ bool cssave(elem *e,regm_t regm,unsigned opsflag)
}
return result;
}


/*************************************
* Determine if a computation should be done into a register.
*/
Expand Down Expand Up @@ -2181,7 +2183,7 @@ regm_t getscratch()
}
return scratch;
}


/******************************
* Evaluate an elem that is a common subexp that has been encountered
* before.
Expand Down Expand Up @@ -2442,7 +2444,7 @@ elem_print(e);
/* NOTREACHED */
return 0;
}


/***************************
* Generate code sequence for an elem.
* Input:
Expand Down
21 changes: 6 additions & 15 deletions src/backend/cgcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ STATIC void touchfunc(int);
STATIC void touchstar();
STATIC void touchaccess(elem *);
STATIC void touchall();


/*******************************
* Eliminate common subexpressions across extended basic blocks.
* String together as many blocks as we can.
Expand Down Expand Up @@ -153,7 +153,7 @@ void cgcs_term()
hcstab = NULL;
hcsmax = 0;
}


/*************************
* Eliminate common subexpressions for an element.
*/
Expand Down Expand Up @@ -215,10 +215,8 @@ STATIC void ecom(elem **pe)
case OPnegass:
if (EOP(e->E1)) /* if lvalue is an operator */
{
#ifdef DEBUG
if (e->E1->Eoper != OPind)
elem_print(e);
#endif
assert(e->E1->Eoper == OPind);
ecom(&(e->E1->E1));
}
Expand Down Expand Up @@ -324,9 +322,8 @@ STATIC void ecom(elem **pe)
touchfunc(0);
return;
default: /* other operators */
#ifdef DEBUG
if (!EBIN(e)) WROP(e->Eoper);
#endif
if (!EBIN(e))
WROP(e->Eoper);
assert(EBIN(e));
case OPadd:
case OPmin:
Expand All @@ -348,10 +345,8 @@ STATIC void ecom(elem **pe)
case OPstring:
case OPaddr:
case OPbit:
#ifdef DEBUG
WROP(e->Eoper);
elem_print(e);
#endif
assert(0); /* optelem() should have removed these */
/* NOTREACHED */

Expand Down Expand Up @@ -503,7 +498,7 @@ STATIC void addhcstab(elem *e,int hash)
hcstab[h].Hhash = hash;
hcsarray.top++;
}


/***************************
* "touch" the elem.
* If it is a pointer, "touch" all the suspects
Expand All @@ -530,10 +525,8 @@ STATIC void touchlvalue(elem *e)
hcstab[i].Helem = NULL;
}

#ifdef DEBUG
if (!(e->Eoper == OPvar || e->Eoper == OPrelconst))
elem_print(e);
#endif
assert(e->Eoper == OPvar || e->Eoper == OPrelconst);
switch (e->EV.sp.Vsym->Sclass)
{
Expand Down Expand Up @@ -561,14 +554,12 @@ STATIC void touchlvalue(elem *e)
touchstar();
break;
default:
#ifdef DEBUG
elem_print(e);
symbol_print(e->EV.sp.Vsym);
#endif
assert(0);
}
}


/**************************
* "touch" variables that could be changed by a function call or
* an indirect assignment.
Expand Down
20 changes: 6 additions & 14 deletions src/backend/cgcv.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ static unsigned debtyphash[DEBTYPHASHDIM];
*/
#define CVIDMAX (0xFF0-20) // the -20 is picked by trial and error

#if 0
#define DBG(a) a
#else
#define DBG(a)
#endif

#define LOCATsegrel 0xC000

/* Unfortunately, the fixup stuff is different for EASY OMF and Microsoft */
Expand Down Expand Up @@ -559,7 +553,7 @@ void cv_init()
#endif
cv_debtyp(d);
}


/////////////////////////// CodeView 4 ///////////////////////////////

/***********************************
Expand Down Expand Up @@ -739,9 +733,7 @@ STATIC int cv4_methodlist(symbol *sf,int *pcount)
case 0:
break;
default:
#ifdef DEBUG
symbol_print(s);
#endif
assert(0);
}
TOIDX(p,attribute);
Expand Down Expand Up @@ -987,7 +979,7 @@ idx_t cv4_struct(Classsym *s,int flags)
}
break;
default:
#if DEBUG && SCPP
#if SCPP
symbol_print(s);
#endif
assert(0);
Expand Down Expand Up @@ -2150,6 +2142,7 @@ unsigned cv4_typidx(type *t)
#endif
#if MARS
case TYref:
case TYnref:
attribute |= 0x20; // indicate reference pointer
tym = TYnptr; // convert to C data type
goto L1; // and try again
Expand Down Expand Up @@ -2214,7 +2207,7 @@ unsigned cv4_typidx(type *t)
assert(typidx);
return typidx;
}


/******************************************
* Write out symbol s.
*/
Expand Down Expand Up @@ -2602,6 +2595,7 @@ STATIC void cv4_func(Funcsym *s)
#endif
case TYnullptr:
case TYnptr:
case TYnref:
if (I32)
goto case_eax;
else
Expand Down Expand Up @@ -2732,7 +2726,7 @@ STATIC void cv4_func(Funcsym *s)

cv_outlist();
}


//////////////////////////////////////////////////////////

/******************************************
Expand Down Expand Up @@ -2911,5 +2905,3 @@ unsigned cv_typidx(type *t)
}

#endif // !SPP


40 changes: 21 additions & 19 deletions src/backend/cgelem.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int elemisnegone(elem *e)
nomatch:
return FALSE;
}


/**********************************
* Swap relational operators (like if we swapped the leaves).
*/
Expand All @@ -245,7 +245,7 @@ unsigned swaprel(unsigned op)
op = rel_swap(op);
return op;
}


/**************************
* Replace e1 by t=e1, replace e2 by t.
*/
Expand Down Expand Up @@ -316,7 +316,7 @@ int fcost(elem *e)
cost = 8;
return cost;
}


/*******************************
* The lvalue of an op= is a conversion operator. Since the code
* generator cannot handle this, we will have to fix it here. The
Expand Down Expand Up @@ -517,7 +517,7 @@ STATIC elem *fixconvop(elem *e)
//elem_print(e);
return e;
}


STATIC elem * elerr(elem *e, goal_t goal)
{
#ifdef DEBUG
Expand All @@ -531,7 +531,7 @@ STATIC elem * elerr(elem *e, goal_t goal)

STATIC elem * elzot(elem *e, goal_t goal)
{ return e; }


/****************************
*/

Expand Down Expand Up @@ -763,7 +763,7 @@ STATIC elem * elmemxxx(elem *e, goal_t goal)
return e;
}



/***********************
* + # (combine offsets with addresses)
* / \ => |
Expand Down Expand Up @@ -1039,7 +1039,7 @@ STATIC elem * elmul(elem *e, goal_t goal)
again = 1;
return e;
}


/************************
* Subtract
* - +
Expand Down Expand Up @@ -1844,7 +1844,7 @@ STATIC elem * elnot(elem *e, goal_t goal)
}
return e;
}


/*************************
* Complement
* ~ ~ e => e
Expand Down Expand Up @@ -2213,7 +2213,7 @@ STATIC elem * elcomma(elem *e, goal_t goal)
again = changes != 0;
return e;
}


/********************************
*/

Expand Down Expand Up @@ -2336,7 +2336,7 @@ STATIC elem * eldiv(elem *e, goal_t goal)

return e;
}


/**************************
* Convert (a op b) op c to a op (b op c).
*/
Expand Down Expand Up @@ -2777,7 +2777,7 @@ STATIC elem * elandand(elem *e, goal_t goal)
L1:
return e;
}


/**************************
* Reference to bit field
* bit
Expand Down Expand Up @@ -3035,7 +3035,7 @@ STATIC elem * elcall(elem *e, goal_t goal)
e = cgel_lvalue(e);
return e;
}


/***************************
* Walk tree, converting types to tym.
*/
Expand Down Expand Up @@ -3588,7 +3588,7 @@ STATIC elem * eleq(elem *e, goal_t goal)
return optelem(eres,GOALvalue);
#endif
}


/**********************************
*/

Expand All @@ -3597,7 +3597,7 @@ STATIC elem * elnegass(elem *e, goal_t goal)
e = cgel_lvalue(e);
return e;
}


/**************************
* Add assignment. Replace bit field assignment with
* equivalent tree.
Expand Down Expand Up @@ -3779,7 +3779,7 @@ STATIC elem * elopass(elem *e, goal_t goal)
}
return e;
}


/**************************
* Add assignment. Replace bit field post assignment with
* equivalent tree.
Expand Down Expand Up @@ -3815,7 +3815,7 @@ STATIC elem * elpost(elem *e, goal_t goal)
e = el_bin(OPand,ty,e,el_long(ty,m));
return optelem(e,GOALvalue);
}


/***************************
* Take care of compares.
* (e == 0) => (!e)
Expand Down Expand Up @@ -4232,7 +4232,7 @@ STATIC elem * elvptrfptr(elem *e, goal_t goal)
}

#endif


/************************
* Optimize conversions of longs to ints.
* Also used for (OPoffset) (TYfptr|TYvptr).
Expand Down Expand Up @@ -5364,7 +5364,9 @@ STATIC elem * optelem(elem *e, goal_t goal)
return optelem(e,GOALnone);
}

e1 = e->E1 = optelem(e->E1,(op == OPbool || op == OPnot) ? GOALflags : GOALvalue);
e1 = e->E1 = optelem(e->E1, (op == OPddtor) ? GOALnone : (op == OPbool || op == OPnot) ? GOALflags : GOALvalue);
if (!e1)
goto retnull;
if (e1->Eoper == OPconst)
{
#if TARGET_SEGMENTED
Expand Down Expand Up @@ -5392,7 +5394,7 @@ STATIC elem * optelem(elem *e, goal_t goal)
return (*elxxx[op])(e, goal);
#endif
}


/********************************
* Optimize and canonicalize an expression tree.
* Fiddle with double operators so that the rvalue is a pointer
Expand Down
8 changes: 4 additions & 4 deletions src/backend/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ code *setOpcode(code *c, code *cs, unsigned op)
* Concatenate two code lists together. Return pointer to result.
*/

#if TX86 && __INTSIZE == 4 && __SC__
#if TX86 && __INTSIZE == 4 && __DMC__
__declspec(naked) code * __pascal cat(code *c1,code *c2)
{
_asm
Expand Down Expand Up @@ -153,7 +153,7 @@ code * cat4(code *c1,code *c2,code *c3,code *c4)

code * cat6(code *c1,code *c2,code *c3,code *c4,code *c5,code *c6)
{ return cat(cat4(c1,c2,c3,c4),cat(c5,c6)); }


/*****************************
* Add code to end of linked list.
* Note that unused operands are garbage.
Expand Down Expand Up @@ -404,7 +404,7 @@ code *gennop(code *c)
return gen1(c,NOP);
}



/****************************************
* Clean stack after call to codelem().
*/
Expand All @@ -426,7 +426,7 @@ code *gencodelem(code *c,elem *e,regm_t *pretregs,bool constflag)
}
return c;
}


/**********************************
* Determine if one of the registers in regm has value in it.
* If so, return !=0 and set *preg to which register it is.
Expand Down
2 changes: 1 addition & 1 deletion src/backend/cgobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct Loc
void error(Loc loc, const char *format, ...);
#endif

#if OMFOBJ
#if TARGET_WINDOS

static char __file__[] = __FILE__; // for tassert.h
#include "tassert.h"
Expand Down
24 changes: 4 additions & 20 deletions src/backend/cod1.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,6 @@ code *loadea(elem *e,code *cs,unsigned op,unsigned reg,targ_size_t offset,
}
else if (reg == 6) // if DIV
{ cd = genregs(cd,0x33,DX,DX); // XOR DX,DX
if (I64 && sz == 8)
code_orrex(cd, REX_W);
}
}

Expand Down Expand Up @@ -854,9 +852,7 @@ code *getlvalue(code *pcs,elem *e,regm_t keepmsk)
e1isadd = e1->Eoper == OPadd;
break;
default:
#ifdef DEBUG
elem_print(e);
#endif
assert(0);
}
e1ty = tybasic(e1->Ety);
Expand Down Expand Up @@ -1485,8 +1481,8 @@ code *getlvalue(code *pcs,elem *e,regm_t keepmsk)
break;

default:
#ifdef DEBUG
WRFL((enum FL)fl);
#ifdef DEBUG
symbol_print(s);
#endif
assert(0);
Expand Down Expand Up @@ -3008,9 +3004,8 @@ STATIC code * funccall(elem *e,unsigned numpara,unsigned numalign,regm_t *pretre
{ /* Call function directly */
code *c1;

#ifdef DEBUG
if (!tyfunc(tym1)) WRTYxx(tym1);
#endif
if (!tyfunc(tym1))
WRTYxx(tym1);
assert(tyfunc(tym1));
s = e1->EV.sp.Vsym;
if (s->Sflags & SFLexit)
Expand Down Expand Up @@ -3111,10 +3106,7 @@ STATIC code * funccall(elem *e,unsigned numpara,unsigned numalign,regm_t *pretre
else
{ /* Call function via pointer */

#ifdef DEBUG
if (e1->Eoper != OPind
) { WRFL((enum FL)el_fl(e1)); WROP(e1->Eoper); }
#endif
if (e1->Eoper != OPind) { WRFL((enum FL)el_fl(e1)); WROP(e1->Eoper); }
c = save87(); // assume 8087 regs are all trashed
assert(e1->Eoper == OPind);
elem *e11 = e1->E1;
Expand Down Expand Up @@ -3307,9 +3299,7 @@ targ_size_t paramsize(elem *e,unsigned stackalign)
szb = type_size(e->ET);
else
{
#ifdef DEBUG
WRTYxx(tym);
#endif
assert(0);
}
psize += align(stackalign,szb); /* align on word stack boundary */
Expand Down Expand Up @@ -3360,9 +3350,7 @@ code *params(elem *e,unsigned stackalign)
szb = type_size(e->ET);
else
{
#ifdef DEBUG
WRTYxx(tym);
#endif
assert(0);
}
sz = align(stackalign,szb); /* align on word stack boundary */
Expand Down Expand Up @@ -3526,9 +3514,7 @@ code *params(elem *e,unsigned stackalign)
c1 = codelem(e1,&retregs,FALSE);
break;
default:
#ifdef DEBUG
elem_print(e1);
#endif
assert(0);
}
reg = findreglsw(retregs);
Expand Down Expand Up @@ -4140,9 +4126,7 @@ code *loaddata(elem *e,regm_t *pretregs)
return load87(e,0,pretregs,NULL,-1);
else
{
#ifdef DEBUG
elem_print(e);
#endif
assert(0);
}
return c;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/cod2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ code *cdcond(elem *e,regm_t *pretregs)
cgstate.stackclean--;
return c;
}


/*********************
* Comma operator
*/
Expand Down Expand Up @@ -3315,7 +3315,7 @@ code *cdmemcmp(elem *e,regm_t *pretregs)
*pretregs &= ~mPSW;
return cat4(c1,c2,c3,fixresult(e,mAX,pretregs));
}


/*********************************
* Generate code for strcpy(s1,s2) intrinsic.
*/
Expand Down
604 changes: 323 additions & 281 deletions src/backend/cod3.c

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/backend/cod4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,7 @@ code *longcmp(elem *e,bool jcond,unsigned fltarg,code *targ)
freenode(e);
return cat6(cl,cr,c,cmsw,clsw,ce);
}


/*****************************
* Do conversions.
* Depends on OPd_s32 and CLIBdbllng being in sequence.
Expand Down Expand Up @@ -3186,8 +3186,10 @@ code *cdlngsht(elem *e,regm_t *pretregs)

#ifdef DEBUG
if (!(!*pretregs || retregs))
{
WROP(e->Eoper),
printf(" *pretregs = %s, retregs = %s, e = %p\n",regm_str(*pretregs),regm_str(retregs),e);
}
#endif
assert(!*pretregs || retregs);
return cat(c,fixresult(e,retregs,pretregs)); /* lsw only */
Expand Down
3 changes: 0 additions & 3 deletions src/backend/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ struct seg_data



#if 1 //ELFOBJ || MACHOBJ

struct linnum_data
{
const char *filename;
Expand All @@ -618,7 +616,6 @@ struct linnum_data
unsigned (*linoff)[2]; // [0] = line number, [1] = offset
};

#endif

extern seg_data **SegData;
#define Offset(seg) SegData[seg]->SDoffset
Expand Down
6 changes: 3 additions & 3 deletions src/backend/cppman.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ char *cpp_operator(int *poper,type **pt)
}

#endif


/***********************************
* Generate and return a pointer to a string constructed from
* the type, appended to the prefix.
Expand Down Expand Up @@ -533,7 +533,7 @@ char *cpp_typetostring(type *t,char *prefix)
cpp_name[i] = 0; // terminate the string
return cpp_name;
}


/***********************************
* Create mangled name for template instantiation.
*/
Expand Down Expand Up @@ -696,7 +696,7 @@ char *template_mangle(symbol *s,param_t *arglist)
}

#endif


/*********************************
* Mangle a vtbl or vbtbl name.
* Returns:
Expand Down
16 changes: 15 additions & 1 deletion src/backend/cv8.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,8 @@ idx_t cv8_daarray(type *t, idx_t keyidx, idx_t validx)
/* Put out a struct:
* struct dAssocArray {
* void* ptr;
* typedef key-type __key_t;
* typedef val-type __val_t;
* }
*/

Expand All @@ -1028,12 +1030,24 @@ idx_t cv8_daarray(type *t, idx_t keyidx, idx_t validx)
0x00, 0x00, 0x00, 0x00, // void*
0x00, 0x00, // offset
'p','t','r',0, // "ptr"
0xf2, 0xf1, // align to 4-byte including length word before data
0xf2, 0xf1, // align to 4-byte including field id
// offset 18
0x10, 0x15, // LF_NESTTYPE_V3
0x00, 0x00, // padding
0x00, 0x00, 0x00, 0x00, // key type
'_','_','k','e','y','_','t',0, // "__key_t"
// offset 34
0x10, 0x15, // LF_NESTTYPE_V3
0x00, 0x00, // padding
0x00, 0x00, 0x00, 0x00, // value type
'_','_','v','a','l','_','t',0, // "__val_t"
};

debtyp_t *f = debtyp_alloc(sizeof(fl));
memcpy(f->data,fl,sizeof(fl));
TOLONG(f->data + 6, pvidx);
TOLONG(f->data + 22, keyidx);
TOLONG(f->data + 38, validx);
idx_t fieldlist = cv_debtyp(f);

const char *id = "dAssocArray";
Expand Down
6 changes: 3 additions & 3 deletions src/backend/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void WRBC(unsigned bc)
assert(bc < BCMAX);
dbg_printf("BC%s",bcs[bc]);
}


/************************
* Write arglst
*/
Expand All @@ -133,7 +133,7 @@ void WRarglst(list_t a)
n++;
}
}


/***************************
* Write out equation elem.
*/
Expand Down Expand Up @@ -251,7 +251,7 @@ void WRdefnod()
dbg_printf(");\n");
}
}


void WRFL(enum FL fl)
{ static char fls[FLMAX][7] =
{"unde ","const ","oper ","func ","data ",
Expand Down
90 changes: 90 additions & 0 deletions src/backend/dt.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,96 @@ dt_t **dtdtoff(dt_t **pdtend, dt_t *dt, unsigned offset)
return dtxoff(pdtend, s, offset);
}

/**************************************
* Repeat a list of dt_t's count times.
*/
dt_t **dtrepeat(dt_t **pdtend, dt_t *dt, size_t count)
{
unsigned size = dt_size(dt);

if (dtallzeros(dt))
return dtnzeros(pdtend, size * count);

while (*pdtend)
pdtend = &((*pdtend)->DTnext);

if (count == 0)
return pdtend;

if (dtpointers(dt))
{
dt_t *dtp = NULL;
dt_t **pdt = &dtp;
for (size_t i = 0; i < count; ++i)
{
for (dt_t *dtn = dt; dtn; dtn = dtn->DTnext)
{
dt_t *dtx = dt_calloc(dtn->dt);
*dtx = *dtn;
dtx->DTnext = NULL;
switch (dtx->dt)
{
case DT_abytes:
case DT_nbytes:
dtx->DTpbytes = (char *) MEM_PH_MALLOC(dtx->DTnbytes);
memcpy(dtx->DTpbytes, dtn->DTpbytes, dtx->DTnbytes);
break;
}

*pdt = dtx;
pdt = &dtx->DTnext;
}
}
*pdtend = dtp;
return pdt;
}

char *p = (char *)MEM_PH_MALLOC(size * count);
size_t offset = 0;

if (count)
{
for (dt_t *dtn = dt; dtn; dtn = dtn->DTnext)
{
switch (dtn->dt)
{
case DT_nbytes:
memcpy(p + offset, dtn->DTpbytes, dtn->DTnbytes);
offset += dtn->DTnbytes;
break;
case DT_ibytes:
memcpy(p + offset, dtn->DTdata, dtn->DTn);
offset += dtn->DTn;
break;
case DT_symsize:
case DT_azeros:
memset(p + offset, 0, dtn->DTazeros);
offset += dtn->DTazeros;
break;
default:
#ifdef DEBUG
dbg_printf("dt = %p, dt = %d\n",dt,dt->dt);
#endif
assert(0);
}
}
assert(offset == size);
}

for (size_t i = 1; i < count; ++i)
{
memcpy(p + offset, p, size);
offset += size;
}

dt_t *dtx = dt_calloc(DT_nbytes);
dtx->DTnbytes = size * count;
dtx->DTpbytes = p;
*pdtend = dtx;
pdtend = &dtx->DTnext;
return pdtend;
}

/**************************
* 'Optimize' a list of dt_t's.
* (Try to collapse it into one DT_azeros object.)
Expand Down
1 change: 1 addition & 0 deletions src/backend/dt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dt_t **dtxoff(dt_t **pdtend,Symbol *s,unsigned offset);
dt_t **dtdtoff(dt_t **pdtend, dt_t *dt, unsigned offset);
dt_t **dtcoff(dt_t **pdtend,unsigned offset);
dt_t ** dtcat(dt_t **pdtend,dt_t *dt);
dt_t ** dtrepeat(dt_t **pdtend, dt_t *dt, size_t count);
void dt_optimize(dt_t *dt);
void dtsymsize(Symbol *);
void init_common(Symbol *);
Expand Down
251 changes: 71 additions & 180 deletions src/backend/dwarf.c

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/backend/dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

/* ==================== Dwarf debug ======================= */

// #define USE_DWARF_D_EXTENSIONS
#define DWARF_VERSION 2
#define DWARF_VERSION 3

void dwarf_initfile(const char *filename);
void dwarf_termfile();
Expand Down
84 changes: 57 additions & 27 deletions src/backend/dwarf2.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum
DW_TAG_variable = 0x34,
DW_TAG_volatile_type = 0x35,

/* DWARF v3 */
DW_TAG_dwarf_procedure = 0x36,
DW_TAG_restrict_type = 0x37,
DW_TAG_interface_type = 0x38,
Expand All @@ -64,12 +65,10 @@ enum
DW_TAG_condition = 0x3F,
DW_TAG_shared_type = 0x40,

// D programming language extensions
#ifdef USE_DWARF_D_EXTENSIONS
DW_TAG_darray_type = 0x41,
DW_TAG_aarray_type = 0x42,
DW_TAG_delegate_type = 0x43,
#endif
/* DWARF v4 */
DW_TAG_type_unit = 0x41,
DW_TAG_rvalue_reference_type = 0x42,
DW_TAG_template_alias = 0x43,

DW_TAG_lo_user = 0x4080,
DW_TAG_hi_user = 0xFFFF,
Expand Down Expand Up @@ -143,6 +142,7 @@ enum
DW_AT_virtuality = 0x4C,
DW_AT_vtable_elem_location = 0x4D,

/* DWARF v3 */
DW_AT_allocated = 0x4E,
DW_AT_associated = 0x4F,
DW_AT_data_location = 0x50,
Expand Down Expand Up @@ -171,6 +171,14 @@ enum
DW_AT_pure = 0x67,
DW_AT_recursive = 0x68,

/* DWARF v4 */
DW_AT_signature = 0x69,
DW_AT_main_subprogram = 0x6a,
DW_AT_data_bit_offset = 0x6b,
DW_AT_const_expr = 0x6c,
DW_AT_enum_class = 0x6d,
DW_AT_linkage_name = 0x6e,

DW_AT_lo_user = 0x2000,
DW_AT_MIPS_linkage_name = 0x2007,
DW_AT_GNU_vector = 0x2107,
Expand All @@ -179,27 +187,33 @@ enum

enum
{
DW_FORM_addr = 0x01,
DW_FORM_block2 = 0x03,
DW_FORM_block4 = 0x04,
DW_FORM_data2 = 0x05,
DW_FORM_data4 = 0x06,
DW_FORM_data8 = 0x07,
DW_FORM_string = 0x08,
DW_FORM_block = 0x09,
DW_FORM_block1 = 0x0A,
DW_FORM_data1 = 0x0B,
DW_FORM_flag = 0x0C,
DW_FORM_sdata = 0x0D,
DW_FORM_strp = 0x0E,
DW_FORM_udata = 0x0F,
DW_FORM_ref_addr = 0x10,
DW_FORM_ref1 = 0x11,
DW_FORM_ref2 = 0x12,
DW_FORM_ref4 = 0x13,
DW_FORM_ref8 = 0x14,
DW_FORM_ref_udata = 0x15,
DW_FORM_indirect = 0x16,
DW_FORM_addr = 0x01,
DW_FORM_block2 = 0x03,
DW_FORM_block4 = 0x04,
DW_FORM_data2 = 0x05,
DW_FORM_data4 = 0x06,
DW_FORM_data8 = 0x07,
DW_FORM_string = 0x08,
DW_FORM_block = 0x09,
DW_FORM_block1 = 0x0A,
DW_FORM_data1 = 0x0B,
DW_FORM_flag = 0x0C,
DW_FORM_sdata = 0x0D,
DW_FORM_strp = 0x0E,
DW_FORM_udata = 0x0F,
DW_FORM_ref_addr = 0x10,
DW_FORM_ref1 = 0x11,
DW_FORM_ref2 = 0x12,
DW_FORM_ref4 = 0x13,
DW_FORM_ref8 = 0x14,
DW_FORM_ref_udata = 0x15,
DW_FORM_indirect = 0x16,

/* DWARF v4 */
DW_FORM_sec_offset = 0x17,
DW_FORM_exprloc = 0x18,
DW_FORM_flag_present = 0x19,
DW_FORM_ref_sig8 = 0x20,
};

enum
Expand Down Expand Up @@ -263,13 +277,20 @@ enum
DW_OP_deref_size = 0x94,
DW_OP_xderef_size = 0x95,
DW_OP_nop = 0x96,

/* DWARF v3 */
DW_OP_push_object_address = 0x97,
DW_OP_call2 = 0x98,
DW_OP_call4 = 0x99,
DW_OP_call_ref = 0x9a,
DW_OP_form_tls_address = 0x9b,
DW_OP_call_frame_cfa = 0x9c,
DW_OP_bit_piece = 0x9d,

/* DWARF v4 */
DW_OP_implicit_value = 0x9e,
DW_OP_stack_value = 0x9f,

DW_OP_lo_user = 0xe0,
DW_OP_hi_user = 0xff,

Expand All @@ -287,13 +308,19 @@ enum
DW_ATE_signed_char = 0x06,
DW_ATE_unsigned = 0x07,
DW_ATE_unsigned_char = 0x08,

/* DWARF v3 */
DW_ATE_imaginary_float = 0x09,
DW_ATE_packed_decimal = 0x0a,
DW_ATE_numeric_string = 0x0b,
DW_ATE_editted = 0x0c,
DW_ATE_signed_fixed = 0x0d,
DW_ATE_unsigned_fixed = 0x0e,
DW_ATE_decimal_float = 0x0f,

/* DWARF v4 */
DW_ATE_UTF = 0x10,

DW_ATE_lo_user = 0x80,
DW_ATE_hi_user = 0xff,
};
Expand Down Expand Up @@ -453,6 +480,8 @@ enum
DW_CFA_def_cfa = 0x0c,
DW_CFA_def_cfa_register = 0x0d,
DW_CFA_def_cfa_offset = 0x0e,

/* DWARF v3 */
DW_CFA_def_cfa_expression = 0x0f,
DW_CFA_expression = 0x10,
DW_CFA_offset_extended_sf = 0x11,
Expand All @@ -462,6 +491,7 @@ enum
DW_CFA_val_offset_sf = 0x15,
DW_CFA_val_expression = 0x16,

/* GNU extensions. */
DW_CFA_GNU_window_save = 0x2d,
DW_CFA_GNU_args_size = 0x2e,
DW_CFA_GNU_negative_offset_extended = 0x2f,
Expand Down
35 changes: 19 additions & 16 deletions src/backend/el.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ void el_free(elem *e)
switch (op)
{
case OPconst:
#if FLOATS_IN_CODE
if (!PARSER && FLT_CODESEG_CELEM(e))
flt_free_elem(e);
#endif
break;

case OPvar:
Expand Down Expand Up @@ -1769,7 +1765,7 @@ elem * el_ptr_offset(symbol *s,targ_size_t offset)
}

#endif


/*************************
* Returns:
* !=0 elem evaluates right-to-left
Expand Down Expand Up @@ -2029,7 +2025,7 @@ elem *el_convstring(elem *e)
if (tybasic(e->Ety) == TYcptr ||
(tyfv(e->Ety) && config.flags3 & CFG3strcod))
{
assert(OMFOBJ); // option not done yet for others
assert(config.objfmt == OBJ_OMF); // option not done yet for others
s = symbol_generate(SCstatic, type_fake(mTYcs | e->Ety));
s->Sfl = FLcsdata;
s->Soffset = Coffset;
Expand Down Expand Up @@ -2519,6 +2515,7 @@ int el_match(elem *n1,elem *n2)

case TYnullptr:
case TYnptr:
case TYnref:
#if TARGET_SEGMENTED
case TYsptr:
case TYcptr:
Expand Down Expand Up @@ -2587,7 +2584,19 @@ int el_match(elem *n1,elem *n2)
if (memcmp(&n1->EV,&n2->EV,sizeof(n1->EV.Vcdouble)))
goto nomatch;
break;

case TYfloat4:
case TYdouble2:
case TYschar16:
case TYuchar16:
case TYshort8:
case TYushort8:
case TYlong4:
case TYulong4:
case TYllong2:
case TYullong2:
if (n1->EV.Vcent.msw != n2->EV.Vcent.msw || n1->EV.Vcent.lsw != n2->EV.Vcent.lsw)
goto nomatch;
break;
case TYcldouble:
#if LNGDBLSIZE > 10
/* sizeof is 12, but actual size of each part is 10 */
Expand All @@ -2606,9 +2615,7 @@ int el_match(elem *n1,elem *n2)
goto nomatch;
#endif
default:
#ifdef DEBUG
elem_print(n1);
#endif
assert(0);
}
break;
Expand Down Expand Up @@ -2660,9 +2667,7 @@ int el_match(elem *n1,elem *n2)
break;
#endif
default:
#ifdef DEBUG
WROP(op);
#endif
assert(0);
}
ismatch:
Expand Down Expand Up @@ -2757,10 +2762,8 @@ targ_llong el_tolong(elem *e)
e->EV.Vllong = type_size(e->EV.sp.Vsym->Stype);
}
#endif
#ifdef DEBUG
if (e->Eoper != OPconst)
elem_print(e);
#endif
assert(e->Eoper == OPconst);
ty = tybasic(typemask(e));
L1:
Expand Down Expand Up @@ -2801,6 +2804,7 @@ targ_llong el_tolong(elem *e)
#endif
case TYnptr:
case TYnullptr:
case TYnref:
if (NPTRSIZE == SHORTSIZE)
goto Ushort;
if (NPTRSIZE == LONGSIZE)
Expand Down Expand Up @@ -2869,9 +2873,7 @@ targ_llong el_tolong(elem *e)
// Can happen as result of syntax errors
assert(errcnt);
#else
#ifdef DEBUG
elem_print(e);
#endif
assert(0);
#endif
}
Expand Down Expand Up @@ -3024,7 +3026,7 @@ void el_check(elem *e)
}

#endif


/*******************************
* Write out expression elem.
*/
Expand Down Expand Up @@ -3142,6 +3144,7 @@ void elem_print_const(elem *e)
#endif
case TYnullptr:
case TYnptr:
case TYnref:
if (NPTRSIZE == LONGSIZE)
goto L1;
if (NPTRSIZE == SHORTSIZE)
Expand Down
8 changes: 6 additions & 2 deletions src/backend/el.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/* Routines to handle elems. */

#if __SC__
#if __DMC__
#pragma once
#endif

Expand Down Expand Up @@ -116,7 +116,7 @@ struct elem
#define Erd EV.sp.spu.Erd // reaching definition

#define el_int(a,b) el_long(a,b)


typedef elem *elem_p; /* try to reduce the symbol table size */

void el_init(void);
Expand Down Expand Up @@ -203,7 +203,11 @@ void el_opArray(elem ***parray, elem *e, unsigned op);
void el_opFree(elem *e, unsigned op);
elem *el_opCombine(elem **args, size_t length, unsigned op, unsigned ty);

#ifdef DEBUG
void elem_print(elem *);
#else
#define elem_print(e)
#endif
void elem_print_const(elem *);
void el_hydrate(elem **);
void el_dehydrate(elem **);
Expand Down
9 changes: 9 additions & 0 deletions src/backend/elfobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,15 @@ int ElfObj::getsegment(const char *name, const char *suffix, int type, int flags
return seg;
}

/**********************************
* Reset code seg to existing seg.
* Used after a COMDAT for a function is done.
*/

void Obj::setcodeseg(int seg)
{
}

/********************************
* Define a new code segment.
* Input:
Expand Down
7 changes: 5 additions & 2 deletions src/backend/evalu8.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ int boolres(elem *e)
case TYnptr:
b = el_tolong(e) != 0;
break;
case TYnref: // reference can't be converted to bool
assert(0);
break;
case TYfloat:
case TYifloat:
case TYdouble:
Expand Down Expand Up @@ -329,7 +332,7 @@ int iffalse(elem *e)
}
}
}


/******************************
* Constant fold expression tree.
* Calculate &symbol and &*e1 if we can.
Expand Down Expand Up @@ -1643,7 +1646,7 @@ elem * evalu8(elem *e, goal_t goal)
break;
case TYfloat:
case TYifloat:
#if __SC__
#if __DMC__
e->EV.Vfloat = fabsf(e1->EV.Vfloat);
#else
e->EV.Vfloat = fabs(e1->EV.Vfloat);
Expand Down
12 changes: 4 additions & 8 deletions src/backend/gdag.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void builddags()
}
}
}


/**********************************
*/

Expand Down Expand Up @@ -352,7 +352,7 @@ STATIC void aewalk(elem **pn,vec_t ae)
vec_setbit(n->Eexp,ae); /* mark this elem as available */
}
}


/**************************
* Remove a CSE.
* Input:
Expand Down Expand Up @@ -416,10 +416,6 @@ STATIC elem * delcse(elem **pe)
#endif
(*pe)->Nflags |= NFLdelcse; // not generating node
e->Ecount = 0;
#if FLOATS_IN_CODE
if (FLT_CODESEG_CELEM(e))
flt_record_const(e);
#endif
*pe = e;
return *pe;
}
Expand Down Expand Up @@ -558,7 +554,7 @@ L1: e = *pe;
pe = &(e->E1);
goto L1;
}


/*****************************************
* Do optimizations based on if we know an expression is
* 0 or !=0, even though we don't know anything else.
Expand Down Expand Up @@ -635,7 +631,7 @@ void boolopt()
vec_free(aevec);
vec_free(aevecval);
}


/****************************
* Walk tree, replacing bool expressions that we know
* ae = vector of available boolean expressions
Expand Down
30 changes: 15 additions & 15 deletions src/backend/gflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ STATIC void accumlv(vec_t GEN , vec_t KILL , elem *n);
STATIC void accumvbe(vec_t GEN , vec_t KILL , elem *n);
STATIC void accumrd(vec_t GEN , vec_t KILL , elem *n);
STATIC void flowaecp(void);


/***************** REACHING DEFINITIONS *********************/

/************************************
Expand Down Expand Up @@ -128,7 +128,7 @@ void flowrd()
}
#endif
}


/***************************
* Compute Bgen and Bkill for RDs.
*/
Expand Down Expand Up @@ -181,7 +181,7 @@ STATIC void rdgenkill()
b->Boutrd = vec_calloc(deftop);
}
}


/**********************
* Compute # of definition elems (deftop).
*/
Expand Down Expand Up @@ -234,7 +234,7 @@ STATIC void asgdefelems(block *b,elem *n)
deftop++;
}
}


/*************************************
* Allocate and compute rd GEN and KILL.
*/
Expand Down Expand Up @@ -307,7 +307,7 @@ STATIC void accumrd(vec_t GEN,vec_t KILL,elem *n)
if (OTdef(op)) /* if definition elem */
updaterd(n,GEN,KILL);
}


/******************** AVAILABLE EXPRESSIONS ***********************/

/************************************
Expand Down Expand Up @@ -455,7 +455,7 @@ STATIC void flowaecp()
} while (anychng);
vec_free(tmp);
}


/******************************
* A variable to avoid parameter overhead to asgexpelems().
*/
Expand Down Expand Up @@ -613,7 +613,7 @@ STATIC void aecpgenkill()
b->Bout = vec_calloc(exptop);
}
}


/*****************************
* Accumulate number of expressions in exptop.
* Set NFLaecp as a flag indicating an AE elem.
Expand Down Expand Up @@ -681,7 +681,7 @@ STATIC void numcpelems(elem *n)
}
n->Nflags &= ~NFLaecp;
}


/********************************
* Assign ae (or cp) elems to expnod[] (in order of evaluation).
*/
Expand Down Expand Up @@ -710,7 +710,7 @@ STATIC void asgexpelems(elem *n)
else
n->Eexp = 0;
}


/********************************
* Compute defkill, starkill and vptrkill vectors.
* starkill: set of expressions killed when a variable is
Expand Down Expand Up @@ -868,7 +868,7 @@ void genkillae()
}
}
}


/************************************
* Allocate and compute KILL and GEN vectors for a elem.
*/
Expand Down Expand Up @@ -1120,7 +1120,7 @@ STATIC void accumaecpx(elem *n)
}
}
}


/************************* LIVE VARIABLES **********************/

/*********************************
Expand Down Expand Up @@ -1211,7 +1211,7 @@ void flowlv()
}
#endif
}


/***********************************
* Compute Bgen and Bkill for LVs.
* Allocate Binlv and Boutlv vectors.
Expand Down Expand Up @@ -1249,7 +1249,7 @@ STATIC void lvgenkill()
vec_free(ambigsym); /* dump any existing one */
ambigsym = NULL;
}


/*****************************
* Allocate and compute KILL and GEN for live variables.
*/
Expand Down Expand Up @@ -1425,7 +1425,7 @@ STATIC void accumlv(vec_t GEN,vec_t KILL,elem *n)
break;
}
}


/********************* VERY BUSY EXPRESSIONS ********************/

/**********************************************
Expand Down Expand Up @@ -1512,7 +1512,7 @@ void flowvbe()
} while (anychng); /* while any changes occurred to any Bin */
vec_free(tmp);
}


/*************************************
* Accumulate GEN and KILL sets for VBEs for this elem.
*/
Expand Down
44 changes: 38 additions & 6 deletions src/backend/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ extern char debugu;
extern char debugw; /* watch progress */
extern char debugx; /* suppress predefined CPP stuff */
extern char debugy; /* watch output to il buffer */
#else
#define debuga 0
//#define debugb 0
//#define debugc 0
#define debugd 0
#define debuge 0
//#define debugf 0
#define debugg 0
#define debugo 0
//#define debugr 0
#define debugs 0
#define debugt 0
#define debugu 0
//#define debugw 0
//#define debugy 0
#endif /* DEBUG */

#define CR '\r' // Used because the MPW version of the compiler warps
Expand Down Expand Up @@ -161,7 +176,7 @@ char *unsstr(unsigned);
int isignore(int);
int isillegal(int);

#if !defined(__SC__) && !defined(_MSC_VER)
#if !defined(__DMC__) && !defined(_MSC_VER)
int ishex(int);
#endif

Expand All @@ -172,7 +187,7 @@ void cgcs_term();
/* errmsgs.c */
extern char *dlcmsgs(int);
extern void errmsgs_term();


/* from evalu8.c */
int boolres(elem *);
int iftrue(elem *);
Expand Down Expand Up @@ -325,7 +340,11 @@ void symbol_keep(Symbol *s);
#else
#define symbol_keep(s) ((void)(s))
#endif
#ifdef DEBUG
void symbol_print(Symbol *s);
#else
#define symbol_print(s)
#endif
void symbol_term(void);
char *symbol_ident(symbol *s);
Symbol *symbol_calloc(const char *id);
Expand Down Expand Up @@ -439,11 +458,24 @@ void WRarglst(list_t a);
void WRblock(block *b);
void WRblocklist(list_t bl);
void WReqn(elem *e);
void WRfunc(void);
void WRdefnod(void);
void WRfunc();
void WRdefnod();
void WRFL(enum FL);
char *sym_ident(SYMIDX si);

#else
#define WRclass(sc)
#define WRTYxx(ty)
#define WROP(oper)
#define WRBC(bc)
#define WRarglst(a)
#define WRblock(b)
#define WRblocklist(bl)
#define WReqn(e)
#define WRfunc()
#define WRdefnod()
#define WRFL(fl)
#define sym_ident(si)
#endif

/* cgelem.c */
Expand Down Expand Up @@ -495,12 +527,12 @@ void rtlsym_init();
void rtlsym_reset();
void rtlsym_term();

#if SYMDEB_DWARF
// Dwarf
void dwarf_CFA_set_loc(size_t location);
void dwarf_CFA_set_reg_offset(int reg, int offset);
void dwarf_CFA_offset(int reg, int offset);
void dwarf_CFA_args_size(size_t sz);
#endif


#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
elem * exp_isconst();
Expand Down
1 change: 1 addition & 0 deletions src/backend/glocal.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ STATIC void local_exp(elem *e,int goal)
if (em->Eoper == op &&
em->E1->EV.sp.Vsym == s &&
tysize(em->Ety) == tysize(e1->Ety) &&
!tyfloating(em->Ety) &&
em->E1->EV.sp.Voffset == e1->EV.sp.Voffset &&
!el_sideeffect(em->E2)
)
Expand Down
40 changes: 19 additions & 21 deletions src/backend/gloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ STATIC void freeloop(loop **pl)
}
*pl = NULL;
}


/**********************************
* Initialize block information.
* Returns:
Expand Down Expand Up @@ -263,7 +263,7 @@ int blockinit()
}
return hasasm;
}


/****************************************
* Compute dominators (Bdom) for each block.
* See Aho & Ullman Fig. 13.5.
Expand Down Expand Up @@ -330,7 +330,7 @@ bool dom(block *A,block *B)
assert(A && B && dfo && dfo[A->Bdfoidx] == A);
return vec_testbit(A->Bdfoidx,B->Bdom) != 0;
}


/**********************
* Find all the loops.
*/
Expand Down Expand Up @@ -487,7 +487,7 @@ STATIC void insert(block *b, vec_t lv)
insert(list_block(bl),lv); /* insert all its predecessors */
}
}


/**************************************
* Perform loop rotations.
* Loop starts as:
Expand Down Expand Up @@ -670,7 +670,7 @@ STATIC int looprotate(loop *l)
Lret:
return FALSE;
}


static int gref; // parameter for markinvar()
static block *gblock; // parameter for markinvar()
static vec_t lv; // parameter for markinvar()
Expand Down Expand Up @@ -902,7 +902,7 @@ void loopopt()
} /* for */
freeloop(&startloop);
}


/*****************************
* If elem is loop invariant, mark it.
* Input:
Expand Down Expand Up @@ -1228,9 +1228,7 @@ STATIC void markinvar(elem *n,vec_t rd)
break;

default:
#ifdef DEBUG
WROP(n->Eoper);
#endif
//printf("n->Eoper = %d, OPconst = %d\n", n->Eoper, OPconst);
assert(0);
}
Expand All @@ -1242,7 +1240,7 @@ STATIC void markinvar(elem *n,vec_t rd)
}
#endif
}


/********************
* Update rd vector.
* Input:
Expand Down Expand Up @@ -1349,7 +1347,7 @@ void updaterd(elem *n,vec_t GEN,vec_t KILL)

vec_setbit(ni,GEN); // set bit in GEN for this def
}


/***************************
* Mark all elems as not being loop invariant.
*/
Expand Down Expand Up @@ -1423,7 +1421,7 @@ STATIC bool refs(symbol *v,elem *n,elem *nstop)
return TRUE;
return f;
}


/*************************
* Move LIs to preheader.
* Conditions to be satisfied for code motion are:
Expand Down Expand Up @@ -1829,7 +1827,7 @@ STATIC void appendelem(elem *n,elem **pn)
else
*pn = n; /* else create a elem */
}


/************** LOOP INDUCTION VARIABLES **********************/

/***************************
Expand Down Expand Up @@ -1976,7 +1974,7 @@ STATIC famlist * newfamlist(tym_t ty)
fl->c2 = el_const(ty,&c); /* c2 = 0 */
return fl;
}


/***************************
* Remove induction variables from loop l.
* Loop invariant removal should have been done just previously.
Expand Down Expand Up @@ -2010,7 +2008,7 @@ STATIC void loopiv(loop *l)
/* Do copy propagation and dead assignment elimination */
/* upon return to optfunc() */
}


/*************************************
* Find basic IVs of loop l.
* A basic IV x of loop l is a variable x which has
Expand Down Expand Up @@ -2142,7 +2140,7 @@ STATIC void findbasivs(loop *l)
vec_free(poss);
vec_free(notposs);
}


/*************************************
* Find op= elems of loop l.
* Analogous to findbasivs().
Expand Down Expand Up @@ -2271,7 +2269,7 @@ STATIC void findopeqs(loop *l)
vec_free(poss);
vec_free(notposs);
}


/*****************************
* Find families for each basic IV.
* An IV family is a list of elems of the form
Expand Down Expand Up @@ -2477,7 +2475,7 @@ STATIC void ivfamelems(Iv *biv,elem **pn)
} /* for */
} /* if */
}


/*********************************
* Eliminate frivolous family ivs, that is,
* if we can't eliminate the BIV, then eliminate family ivs that
Expand Down Expand Up @@ -2610,7 +2608,7 @@ STATIC void intronvars(loop *l)
} /* for */
} /* for */
}


/*******************************
* Determine if induction variable can be rewritten as a simple
* function of a previously generated temporary.
Expand Down Expand Up @@ -2760,7 +2758,7 @@ STATIC bool funcprev(Iv *biv,famlist *fl)
}
return FALSE; /* need to create a new variable */
}


/***********************
* Eliminate basic IVs.
*/
Expand Down Expand Up @@ -3276,7 +3274,7 @@ STATIC famlist * flcmp(famlist *f1,famlist *f2)
//printf("picking f2\n");
return f2;
}


/************************************
* Input:
* x basic IV symbol
Expand Down Expand Up @@ -3387,7 +3385,7 @@ STATIC int countrefs2(elem *e)
return ((e->Eoper == OPvar || e->Eoper == OPrelconst) &&
e->EV.sp.Vsym == X);
}


/****************************
* Eliminate some special cases.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/backend/go.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* For any other uses, please contact Digital Mars.
*/

#if __SC__
#if __DMC__
#pragma once
#endif

Expand Down Expand Up @@ -37,7 +37,7 @@ typedef unsigned mftype; /* a type big enough for all the flags */
#define MFtree 0x1000 // optelem (tree optimization)
#define MFlocal 0x2000 // localize expressions
#define MFall (~0) // do everything


/**********************************
* Definition elem vector, used for reaching definitions.
*/
Expand Down
20 changes: 10 additions & 10 deletions src/backend/gother.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ STATIC void rd_compute()
}
}
}


/***************************
* Support routine for constprop().
* Visit each elem in order
Expand Down Expand Up @@ -347,7 +347,7 @@ STATIC void conpropwalk(elem *n,vec_t IN)
}
}
}


/******************************
* Give error if there are no reaching defs for variable v.
*/
Expand Down Expand Up @@ -439,7 +439,7 @@ STATIC void chkrd(elem *n,list_t rdlist)
//elem_print(n);
#endif
}


/**********************************
* Look through the vector of reaching defs (IN) to see
* if all defs of n are of the same constant. If so, replace
Expand Down Expand Up @@ -557,7 +557,7 @@ STATIC elem * chkprop(elem *n,list_t rdlist)
noprop:
return NULL;
}


/***********************************
* Find all the reaching defs of OPvar e.
* Put into a linked list, or just set the RD bits in a vector.
Expand Down Expand Up @@ -861,7 +861,7 @@ STATIC int loopcheck(block *start,block *inc,block *rel)
}
return FALSE;
}


/****************************
* Do copy propagation.
* Copy propagation elems are of the form OPvar=OPvar, and they are
Expand Down Expand Up @@ -1127,7 +1127,7 @@ STATIC void cpwalk(elem *n,vec_t IN)
;
}
}


/********************************
* Remove dead assignments. Those are assignments to a variable v
* for which there are no subsequent uses of v.
Expand Down Expand Up @@ -1286,7 +1286,7 @@ STATIC unsigned numasg(elem *e)
return OTunary(e->Eoper) ? numasg(e->E1) :
OTbinary(e->Eoper) ? numasg(e->E1) + numasg(e->E2) : 0;
}


/******************************
* Tree walk routine for rmdeadass().
* DEAD = assignments which are dead
Expand Down Expand Up @@ -1499,7 +1499,7 @@ STATIC void accumda(elem *n,vec_t DEAD, vec_t POSS)
break;
}
}


/***************************
* Mark all dead variables. Only worry about register candidates.
* Compute live ranges for register candidates.
Expand Down Expand Up @@ -1591,7 +1591,7 @@ STATIC void dvwalk(elem *n,unsigned i)
break;
}
}


/*********************************
* Optimize very busy expressions (VBEs).
*/
Expand Down Expand Up @@ -1761,7 +1761,7 @@ void verybusyexp()
} /* for */
vec_free(blockseen);
}


/****************************
* Return TRUE if elem j is killed somewhere
* between b and bp.
Expand Down
9 changes: 9 additions & 0 deletions src/backend/machobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,15 @@ int MachObj::getsegment(const char *sectname, const char *segname,
return seg;
}

/**********************************
* Reset code seg to existing seg.
* Used after a COMDAT for a function is done.
*/

void Obj::setcodeseg(int seg)
{
}

/********************************
* Define a new code segment.
* Input:
Expand Down
108 changes: 76 additions & 32 deletions src/backend/mscoffobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "aa.h"
#include "tinfo.h"

#if OMFOBJ
#if TARGET_WINDOS

#if MARS
#include "mars.h"
Expand Down Expand Up @@ -567,12 +567,30 @@ static void syment_set_name(syment *sym, const char *name)
}
}

void build_syment_table()
void write_sym(struct syment* sym, bool bigobj)
{
assert(sizeof(*sym) == 20);
if (bigobj)
{
syment_buf->write(sym, sizeof(*sym));
}
else
{
// the only difference between syment and syment_old
// is that field n_scnum is long instead of short
unsigned scoff = (char*)&sym->n_scnum - (char*)sym;
syment_buf->write(sym, scoff + 2);
syment_buf->write((char*)sym + scoff + 4, sizeof(*sym) - scoff - 4);
}
}

void build_syment_table(bool bigobj)
{
/* The @comp.id symbol appears to be the version of VC that generated the .obj file.
* Anything we put in there would have no relevance, so we'll not put out this symbol.
*/

unsigned symsize = bigobj ? sizeof(syment) : sizeof(syment_old);
/* Now goes one symbol per section.
*/
for (segidx_t seg = 1; seg <= seg_count; seg++)
Expand All @@ -588,8 +606,7 @@ void build_syment_table()
sym.n_sclass = IMAGE_SYM_CLASS_STATIC;
sym.n_numaux = 1;

assert(sizeof(sym) == 20);
syment_buf->write(&sym, sizeof(sym));
write_sym(&sym, bigobj);

union auxent aux;
memset(&aux, 0, sizeof(aux));
Expand All @@ -616,7 +633,7 @@ void build_syment_table()

memset(&aux.x_section.Zeros, 0, 2);

syment_buf->write(&aux, sizeof(aux));
syment_buf->write(&aux, symsize);

assert(sizeof(aux) == 20);
}
Expand All @@ -628,7 +645,7 @@ void build_syment_table()
size_t dim = symbuf->size() / sizeof(symbol *);
for (size_t i = 0; i < dim; i++)
{ symbol *s = ((symbol **)symbuf->buf)[i];
s->Sxtrnnum = syment_buf->size() / sizeof(syment);
s->Sxtrnnum = syment_buf->size() / symsize;
n++;

struct syment sym;
Expand Down Expand Up @@ -665,7 +682,7 @@ void build_syment_table()
}
sym.n_numaux = 0;

syment_buf->write(&sym, sizeof(sym));
write_sym(&sym, bigobj);
}
}

Expand Down Expand Up @@ -707,8 +724,12 @@ void MsCoffObj::term(const char *objfilename)
if (errcnt)
return;
#endif

build_syment_table();
// To allow tooling support for most output files
// switch to new object file format (similar to C++ with /bigobj)
// only when exceeding the limit for 16-bit section count according to
// https://msdn.microsoft.com/en-us/library/8578y171%28v=vs.71%29.aspx
bool bigobj = scnhdr_cnt > 65279;
build_syment_table(bigobj);

/* Write out the object file in the following order:
* Header
Expand All @@ -723,30 +744,45 @@ void MsCoffObj::term(const char *objfilename)
// Write out the bytes for the header

struct filehdr header;
struct filehdr_old header_old;

header.f_sig1 = IMAGE_FILE_MACHINE_UNKNOWN;
header.f_sig2 = 0xFFFF;
header.f_minver = 2;
header.f_magic = I64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386;
header.f_nscns = scnhdr_cnt;
time_t f_timedat = 0;
time(&f_timedat);
header.f_timdat = (unsigned long)f_timedat;
header.f_symptr = 0; // offset to symbol table
header.f_nsyms = 0;
unsigned char uuid[16] = { '\xc7', '\xa1', '\xba', '\xd1', '\xee', '\xba', '\xa9', '\x4b',
'\xaf', '\x20', '\xfa', '\xf6', '\x6a', '\xa4', '\xdc', '\xb8' };
memcpy(header.f_uuid, uuid, 16);
memset(header.f_unused, 0, sizeof(header.f_unused));


foffset = sizeof(header); // start after header
unsigned symtable_offset;

foffset += ScnhdrBuf->size(); // section headers

header.f_symptr = foffset;
header.f_nsyms = syment_buf->size() / sizeof(struct syment);
foffset += header.f_nsyms * sizeof(struct syment); // symbol table
if (bigobj)
{
header.f_sig1 = IMAGE_FILE_MACHINE_UNKNOWN;
header.f_sig2 = 0xFFFF;
header.f_minver = 2;
header.f_magic = I64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386;
header.f_nscns = scnhdr_cnt;
header.f_timdat = (unsigned long)f_timedat;
unsigned char uuid[16] = { '\xc7', '\xa1', '\xba', '\xd1', '\xee', '\xba', '\xa9', '\x4b',
'\xaf', '\x20', '\xfa', '\xf6', '\x6a', '\xa4', '\xdc', '\xb8' };
memcpy(header.f_uuid, uuid, 16);
memset(header.f_unused, 0, sizeof(header.f_unused));
foffset = sizeof(header); // start after header
foffset += ScnhdrBuf->size(); // section headers
header.f_symptr = foffset; // offset to symbol table
symtable_offset = foffset;
header.f_nsyms = syment_buf->size() / sizeof(struct syment);
foffset += header.f_nsyms * sizeof(struct syment); // symbol table
}
else
{
header_old.f_magic = I64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386;
header_old.f_nscns = scnhdr_cnt;
header_old.f_timdat = (unsigned long)f_timedat;
header_old.f_opthdr = 0;
header_old.f_flags = 0;
foffset = sizeof(header_old); // start after header
foffset += ScnhdrBuf->size(); // section headers
header_old.f_symptr = foffset; // offset to symbol table
symtable_offset = foffset;
header_old.f_nsyms = syment_buf->size() / sizeof(struct syment_old);
foffset += header_old.f_nsyms * sizeof(struct syment_old); // symbol table
}

unsigned string_table_offset = foffset;
foffset += string_table->size(); // string table
Expand Down Expand Up @@ -796,15 +832,23 @@ void MsCoffObj::term(const char *objfilename)
assert(fobjbuf->size() == 0);

// Write the header
fobjbuf->write(&header, sizeof(header));
foffset = sizeof(header);
if (bigobj)
{
fobjbuf->write(&header, sizeof(header));
foffset = sizeof(header);
}
else
{
fobjbuf->write(&header_old, sizeof(header_old));
foffset = sizeof(header_old);
}

// Write the section headers
fobjbuf->write(ScnhdrBuf);
foffset += ScnhdrBuf->size();

// Write the symbol table
assert(foffset == header.f_symptr);
assert(foffset == symtable_offset);
fobjbuf->write(syment_buf);
foffset += syment_buf->size();

Expand Down
10 changes: 5 additions & 5 deletions src/backend/newman.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ char *cpp_operator2(token_t *to, int *pcastoverload)
}

#endif


/***********************************
* Generate and return a pointer to a string constructed from
* the type, appended to the prefix.
Expand Down Expand Up @@ -522,7 +522,7 @@ char *cpp_mangle(symbol *s)
return mangle.buf;
}
}


///////////////////////////////////////////////////////

/*********************************
Expand Down Expand Up @@ -584,7 +584,7 @@ STATIC int cpp_protection(symbol *s)
}
return i;
}


/***********************************
* Create mangled name for template instantiation.
*/
Expand Down Expand Up @@ -749,7 +749,7 @@ char *template_mangle(symbol *s,param_t *arglist)
}

#endif


//////////////////////////////////////////////////////
// Functions corresponding to the name mangling grammar in the
// "Microsoft Object Mapping Specification"
Expand Down Expand Up @@ -1662,7 +1662,7 @@ STATIC void cpp_decorated_name(symbol *s)
CHAR('@');
cpp_type_encoding(s);
}


/*********************************
* Mangle a vtbl or vbtbl name.
* Returns:
Expand Down
1 change: 1 addition & 0 deletions src/backend/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct Obj

#if TARGET_WINDOS
VIRTUAL int seg_debugT(); // where the symbolic debug type data goes
static void gotref(symbol *s) { }
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/backend/oper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/


#if __SC__
#if __DMC__
#pragma once
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/backend/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void *globalrealloc(void *oldp,size_t newsize)
dbg_printf("globalrealloc(oldp = %p, size = x%x) = %p\n",oldp,newsize,p);
return p;
}


/*****************************************
* Functions to manage allocating a single virtual address space.
*/
Expand Down
161 changes: 69 additions & 92 deletions src/backend/out.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,10 @@ void outdata(symbol *s)
{ seg_data *pseg = objmod->tlsseg_bss();
s->Sseg = pseg->SDseg;
objmod->data_start(s, datasize, pseg->SDseg);
#if ELFOBJ || MACHOBJ
objmod->lidata(pseg->SDseg, pseg->SDoffset, datasize);
#endif
#if OMFOBJ
if (config.objfmt == OBJ_MSCOFF)
objmod->lidata(pseg->SDseg, pseg->SDoffset, datasize);
else
if (config.objfmt == OBJ_OMF)
pseg->SDoffset += datasize;
#endif
else
objmod->lidata(pseg->SDseg, pseg->SDoffset, datasize);
s->Sfl = FLtlsdata;
break;
}
Expand All @@ -208,12 +203,7 @@ void outdata(symbol *s)
break;
}
assert(s->Sseg && s->Sseg != UNKNOWN);
#if ELFOBJ || MACHOBJ
if (s->Sclass == SCglobal || s->Sclass == SCstatic) // if a pubdef to be done
#endif
#if OMFOBJ
if (s->Sclass == SCglobal || (s->Sclass == SCstatic && config.objfmt == OBJ_MSCOFF)) // if a pubdef to be done
#endif
if (s->Sclass == SCglobal || (s->Sclass == SCstatic && config.objfmt != OBJ_OMF)) // if a pubdef to be done
objmod->pubdefsize(s->Sseg,s,s->Soffset,datasize); // do the definition
searchfixlist(s);
if (config.fulltypes &&
Expand Down Expand Up @@ -320,26 +310,16 @@ void outdata(symbol *s)
assert(0);
}
}
#if ELFOBJ || MACHOBJ
if (s->Sseg == UNKNOWN)
if (s->Sseg == UNKNOWN && (config.objfmt == OBJ_ELF || config.objfmt == OBJ_MACH))
s->Sseg = seg;
else if (config.objfmt == OBJ_OMF)
s->Sseg = seg;
else
seg = s->Sseg;
#endif
#if OMFOBJ
s->Sseg = seg;
#endif
if (s->Sclass == SCglobal
#if ELFOBJ || MACHOBJ
|| s->Sclass == SCstatic
#endif
#if OMFOBJ
|| (s->Sclass == SCstatic && config.objfmt == OBJ_MSCOFF)
#endif
)
{

if (s->Sclass == SCglobal || (s->Sclass == SCstatic && config.objfmt != OBJ_OMF))
objmod->pubdefsize(seg,s,s->Soffset,datasize); /* do the definition */
}

assert(s->Sseg != UNKNOWN);
if (config.fulltypes &&
!(s->Sclass == SCstatic && funcsym_p)) // not local static
Expand Down Expand Up @@ -462,31 +442,29 @@ void outcommon(symbol *s,targ_size_t n)
#endif
if (s->ty() & mTYthread) // if store in thread local segment
{
#if ELFOBJ
s->Sclass = SCcomdef;
objmod->common_block(s, 0, n, 1);
#else
/* COMDEFs not supported in tls segment
* so put them out as COMDATs with initialized 0s
*/
s->Sclass = SCcomdat;
dtnzeros(&s->Sdt,n);
outdata(s);
#if SCPP && OMFOBJ
out_extdef(s);
#endif
if (config.objfmt == OBJ_ELF)
{
s->Sclass = SCcomdef;
objmod->common_block(s, 0, n, 1);
}
else
{
/* COMDEFs not supported in tls segment
* so put them out as COMDATs with initialized 0s
*/
s->Sclass = SCcomdat;
dtnzeros(&s->Sdt,n);
outdata(s);
#if SCPP
if (config.objfmt == OBJ_OMF)
out_extdef(s);
#endif
}
}
else
{
s->Sclass = SCcomdef;
#if ELFOBJ || MACHOBJ
objmod->common_block(s, 0, n, 1);
#endif
#if OMFOBJ
if (config.objfmt == OBJ_MSCOFF)
objmod->common_block(s, 0, n, 1);
else
if (config.objfmt == OBJ_OMF)
{
#if TARGET_SEGMENTED
s->Sxtrnnum = objmod->common_block(s,(s->ty() & mTYfar) == 0,n,1);
Expand All @@ -504,7 +482,8 @@ void outcommon(symbol *s,targ_size_t n)
ph_comdef(s); // notify PH that a COMDEF went out
#endif
}
#endif
else
objmod->common_block(s, 0, n, 1);
}
if (config.fulltypes)
cv_outsym(s);
Expand All @@ -518,19 +497,21 @@ void outcommon(symbol *s,targ_size_t n)
void out_readonly(symbol *s)
{
// The default is DATA
#if ELFOBJ || MACHOBJ
/* Cannot have pointers in CDATA when compiling PIC code, because
* they require dynamic relocations of the read-only segment.
* Instead use the .data.rel.ro section. See Bugzilla 11171.
*/
if (config.flags3 & CFG3pic && dtpointers(s->Sdt))
s->Sseg = CDATAREL;
if (config.objfmt == OBJ_ELF || config.objfmt == OBJ_MACH)
{
/* Cannot have pointers in CDATA when compiling PIC code, because
* they require dynamic relocations of the read-only segment.
* Instead use the .data.rel.ro section. See Bugzilla 11171.
*/
if (config.flags3 & CFG3pic && dtpointers(s->Sdt))
s->Sseg = CDATAREL;
else
s->Sseg = CDATA;
}
else
s->Sseg = CDATA;
#endif
#if OMFOBJ
// Haven't really worked out where immutable read-only data can go.
#endif
{
// Haven't really worked out where immutable read-only data can go.
}
}

/******************************
Expand Down Expand Up @@ -713,12 +694,10 @@ STATIC void outelem(elem *e)
}
else if (s->Sdt) /* if initializer for symbol */
outdata(s); // write out data for symbol
#if ELFOBJ || MACHOBJ
if (config.flags3 & CFG3pic)
{
objmod->gotref(s);
}
#endif
#endif
break;
case OPstring:
Expand Down Expand Up @@ -910,9 +889,7 @@ STATIC void writefunc2(symbol *sfunc)
unsigned nsymbols;
SYMIDX si;
int anyasm;
#if OMFOBJ
int csegsave;
#endif
int csegsave; // for OMF
func_t *f = sfunc->Sfunc;
tym_t tyf;

Expand Down Expand Up @@ -1202,9 +1179,7 @@ STATIC void writefunc2(symbol *sfunc)
{
if (symbol_iscomdat(sfunc))
{
#if OMFOBJ
csegsave = cseg;
#endif
objmod->comdat(sfunc);
}
else
Expand Down Expand Up @@ -1237,13 +1212,11 @@ STATIC void writefunc2(symbol *sfunc)
goto Ldone;
if (sfunc->Sclass == SCglobal)
{
#if OMFOBJ
if (!(config.flags4 & CFG4allcomdat))
if ((config.objfmt == OBJ_OMF || config.objfmt == OBJ_MSCOFF) && !(config.flags4 & CFG4allcomdat))
{
assert(sfunc->Sseg == cseg);
objmod->pubdef(sfunc->Sseg,sfunc,sfunc->Soffset); // make a public definition
}
#endif

#if SCPP && _WIN32
char *id;
Expand Down Expand Up @@ -1345,10 +1318,9 @@ STATIC void writefunc2(symbol *sfunc)
cod3_adjSymOffsets();
#endif

#if OMFOBJ
if (symbol_iscomdat(sfunc)) // if generated a COMDAT
if ((config.objfmt == OBJ_OMF || config.objfmt == OBJ_MSCOFF) &&
symbol_iscomdat(sfunc)) // if generated a COMDAT
objmod->setcodeseg(csegsave); // reset to real code seg
#endif

/* Check if function is a constructor or destructor, by */
/* seeing if the function name starts with _STI or _STD */
Expand Down Expand Up @@ -1423,6 +1395,9 @@ void out_reset()

symbol *out_readonly_sym(tym_t ty, void *p, int len)
{
#if HTOD
return;
#endif
#if 0
printf("out_readonly_sym(ty = x%x)\n", ty);
for (int i = 0; i < len; i++)
Expand All @@ -1438,20 +1413,25 @@ symbol *out_readonly_sym(tym_t ty, void *p, int len)

symbol *s;

#if ELFOBJ || (OMFOBJ && MARS) /* includes COFF */
/* MACHOBJ can't go here, because the const data segment goes into
* the _TEXT segment, and one cannot have a fixup from _TEXT to _TEXT.
*/
s = objmod->sym_cdata(ty, (char *)p, len);
#else
unsigned sz = tysize(ty);
if (config.objfmt == OBJ_ELF ||
(MARS && (config.objfmt == OBJ_OMF || config.objfmt == OBJ_MSCOFF)))
{
/* MACHOBJ can't go here, because the const data segment goes into
* the _TEXT segment, and one cannot have a fixup from _TEXT to _TEXT.
*/
s = objmod->sym_cdata(ty, (char *)p, len);
}
else
{
unsigned sz = tysize(ty);

alignOffset(DATA, sz);
s = symboldata(Doffset,ty | mTYconst);
s->Sseg = DATA;
objmod->write_bytes(SegData[DATA], len, p);
//printf("s->Sseg = %d:x%x\n", s->Sseg, s->Soffset);
}

alignOffset(DATA, sz);
s = symboldata(Doffset,ty | mTYconst);
s->Sseg = DATA;
objmod->write_bytes(SegData[DATA], len, p);
//printf("s->Sseg = %d:x%x\n", s->Sseg, s->Soffset);
#endif
if (len <= ROMAX)
{ Readonly *r;

Expand Down Expand Up @@ -1483,9 +1463,6 @@ void Srcpos::print(const char *func)
printf("Sfilptr = %p (filename = %s)", sf, sf ? sf->SFname : "null");
#endif
printf(", Slinnum = %u", Slinnum);
#if SOURCE_OFFSETS
printf(", Sfiloff = %d", Sfiloff);
#endif
printf(")\n");
}

Expand Down
7 changes: 1 addition & 6 deletions src/backend/rtlsym.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,8 @@ void rtlsym_init()
tv->Tcount++;
#endif

#if MACHOBJ
type *tw = type_fake(TYnpfunc);
tw->Tmangle = mTYman_sys;
tw->Tcount++;
#else
// Only used by dmd1 for RTLSYM_THROWC
type *tw = NULL;
#endif

#undef SYMBOL_Z
#define SYMBOL_Z(e, fl, saved, n, flags, ty) \
Expand Down
28 changes: 27 additions & 1 deletion src/backend/rtlsym.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#define RTLSYMS \
\
SYMBOL_MARS(THROW, FLfunc,(mES | mBP),"_d_throw@4", SFLexit, tw) \
SYMBOL_MARS(THROW, FLfunc,(mES | mBP),"_d_throw@4", SFLexit, tw) /* D1 only */ \
SYMBOL_MARS(THROWC, FLfunc,(mES | mBP),"_d_throwc", SFLexit, t) \
SYMBOL_MARS(MONITOR_HANDLER, FLfunc,FREGSAVED,"_d_monitor_handler", 0, 0) \
SYMBOL_MARS(MONITOR_PROLOG, FLfunc,FREGSAVED,"_d_monitor_prolog",0,t) \
Expand Down Expand Up @@ -163,6 +163,32 @@ SYMBOL_Z(TRACE_EPI_N, FLfunc,ALLREGS|mBP|mES,"_trace_epi_n",0,tstrace) \
SYMBOL_Z(TRACE_EPI_F, FLfunc,ALLREGS|mBP|mES,"_trace_epi_f",0,tstrace) \
SYMBOL_MARS(TRACE_CPRO, FLfunc,FREGSAVED,"_c_trace_pro",0,t) \
SYMBOL_MARS(TRACE_CEPI, FLfunc,FREGSAVED,"_c_trace_epi",0,t) \
\
SYMBOL_MARS(TRACENEWCLASS, FLfunc,FREGSAVED,"_d_newclassTrace", 0, t) \
SYMBOL_MARS(TRACENEWARRAYT, FLfunc,FREGSAVED,"_d_newarrayTTrace", 0, t) \
SYMBOL_MARS(TRACENEWARRAYIT, FLfunc,FREGSAVED,"_d_newarrayiTTrace", 0, t) \
SYMBOL_MARS(TRACENEWARRAYMTX, FLfunc,FREGSAVED,"_d_newarraymTXTrace", 0, t) \
SYMBOL_MARS(TRACENEWARRAYMITX, FLfunc,FREGSAVED,"_d_newarraymiTXTrace", 0, t) \
SYMBOL_MARS(TRACENEWITEMT, FLfunc,FREGSAVED,"_d_newitemTTrace", 0, t) \
SYMBOL_MARS(TRACENEWITEMIT, FLfunc,FREGSAVED,"_d_newitemiTTrace", 0, t) \
SYMBOL_MARS(TRACECALLFINALIZER, FLfunc,FREGSAVED,"_d_callfinalizerTrace", 0, t) \
SYMBOL_MARS(TRACECALLINTERFACEFINALIZER, FLfunc,FREGSAVED,"_d_callinterfacefinalizerTrace", 0, t) \
SYMBOL_MARS(TRACEDELCLASS, FLfunc,FREGSAVED,"_d_delclassTrace", 0, t) \
SYMBOL_MARS(TRACEDELINTERFACE, FLfunc,FREGSAVED,"_d_delinterfaceTrace", 0, t) \
SYMBOL_MARS(TRACEDELSTRUCT, FLfunc,FREGSAVED,"_d_delstructTrace", 0, t) \
SYMBOL_MARS(TRACEDELARRAYT, FLfunc,FREGSAVED,"_d_delarray_tTrace", 0, t) \
SYMBOL_MARS(TRACEDELMEMORY, FLfunc,FREGSAVED,"_d_delmemoryTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYLITERALTX, FLfunc,FREGSAVED,"_d_arrayliteralTXTrace", 0, t) \
SYMBOL_MARS(TRACEASSOCARRAYLITERALTX, FLfunc,FREGSAVED,"_d_assocarrayliteralTXTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYCATT, FLfunc,FREGSAVED,"_d_arraycatTTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYCATNTX, FLfunc,FREGSAVED,"_d_arraycatnTXTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYAPPENDT, FLfunc,FREGSAVED,"_d_arrayappendTTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYAPPENDCTX, FLfunc,FREGSAVED,"_d_arrayappendcTXTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYAPPENDCD, FLfunc,FREGSAVED,"_d_arrayappendcdTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYAPPENDWD, FLfunc,FREGSAVED,"_d_arrayappendwdTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYSETLENGTHT, FLfunc,FREGSAVED,"_d_arraysetlengthTTrace", 0, t) \
SYMBOL_MARS(TRACEARRAYSETLENGTHIT,FLfunc,FREGSAVED,"_d_arraysetlengthiTTrace", 0, t) \
SYMBOL_MARS(TRACEALLOCMEMORY, FLfunc,FREGSAVED,"_d_allocmemoryTrace", 0, t) \



29 changes: 20 additions & 9 deletions src/backend/strtold.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static longdouble postab[] =
* Terminates on first unrecognized character.
*/

longdouble strtold(const char *p,char **endp)
longdouble strtold_dm(const char *p,char **endp)
{
longdouble ldval;
int exp;
Expand All @@ -145,10 +145,11 @@ longdouble strtold(const char *p,char **endp)
int pow;
int ndigits;
const char *pinit = p;
#if __DMC__
static char infinity[] = "infinity";
static char nans[] = "nans";
#endif
unsigned int old_cw;
unsigned int old_status;

#if _WIN32 && __DMC__
fenv_t flagp;
Expand Down Expand Up @@ -342,8 +343,18 @@ longdouble strtold(const char *p,char **endp)
}

// Stuff mantissa directly into long double
*(long long *)&ldval = msdec;
((unsigned short *)&ldval)[4] = e2;
union U
{
longdouble ld;
struct S
{
long long mantissa;
unsigned short exp;
} s;
} u;
u.s.mantissa = msdec;
u.s.exp = e2;
ldval = u.ld;
#endif

#if 0
Expand Down Expand Up @@ -564,7 +575,7 @@ longdouble strtold(const char *p,char **endp)

#else

longdouble strtold(const char *p,char **endp)
longdouble strtold_dm(const char *p,char **endp)
{
return strtod(p, endp);
}
Expand All @@ -579,7 +590,7 @@ longdouble strtold(const char *p,char **endp)
#include <float.h>
#include <errno.h>

extern "C" longdouble strtold(const char *p,char **endp);
longdouble strtold_dm(const char *p,char **endp);

struct longdouble
{
Expand All @@ -593,16 +604,16 @@ void main()
int i;

errno = 0;
// ld = strtold("0x1.FFFFFFFFFFFFFFFEp16383", NULL);
ld = strtold("0x1.FFFFFFFFFFFFFFFEp-16382", NULL);
// ld = strtold_dm("0x1.FFFFFFFFFFFFFFFEp16383", NULL);
ld = strtold_dm("0x1.FFFFFFFFFFFFFFFEp-16382", NULL);
x = *(struct longdouble *)&ld;
for (i = 4; i >= 0; i--)
{
printf("%04x ", x.value[i]);
}
printf("\t%d\n", errno);

ld = strtold("1.0e5", NULL);
ld = strtold_dm("1.0e5", NULL);
x = *(struct longdouble *)&ld;
for (i = 4; i >= 0; i--)
{
Expand Down
33 changes: 14 additions & 19 deletions src/backend/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void symbol_addtotree(symbol **parent,symbol *s)
}

#endif


/*************************************
* Search for symbol in multiple symbol tables,
* starting with most recently nested one.
Expand Down Expand Up @@ -692,7 +692,7 @@ L6: mov EAX,EBX
}

#endif


/***********************************
* Create a new symbol table.
*/
Expand Down Expand Up @@ -749,7 +749,7 @@ void deletesymtab()
}

#endif


/*********************************
* Delete symbol from symbol table, taking care to delete
* all children of a symbol.
Expand Down Expand Up @@ -1145,7 +1145,7 @@ symbol *symbol_search(const char *id)
}

#endif


/*******************************************
* Hydrate a symbol tree.
*/
Expand All @@ -1166,7 +1166,7 @@ void symbol_tree_hydrate(symbol **ps)

}
#endif


/*******************************************
* Dehydrate a symbol tree.
*/
Expand All @@ -1189,7 +1189,7 @@ void symbol_tree_dehydrate(symbol **ps)
}
}
#endif


/*******************************************
* Hydrate a symbol.
*/
Expand All @@ -1210,9 +1210,6 @@ symbol *symbol_hydrate(symbol **ps)
symbol_debug(s);
if (!isdehydrated(s->Stype)) // if this symbol is already dehydrated
return s; // no need to do it again
#if SOURCE_4SYMS
s->Ssrcpos.Sfilnum += File_Hydrate_Num; /* file number relative header build */
#endif
if (pstate.SThflag != FLAG_INPLACE && s->Sfl != FLreg)
s->Sxtrnnum = 0; // not written to .OBJ file yet
type_hydrate(&s->Stype);
Expand Down Expand Up @@ -1392,7 +1389,7 @@ symbol *symbol_hydrate(symbol **ps)
return s;
}
#endif


/*******************************************
* Dehydrate a symbol.
*/
Expand Down Expand Up @@ -1617,7 +1614,7 @@ void symbol_dehydrate(symbol **ps)
}
}
#endif


/***************************
* Dehydrate threaded list of symbols.
*/
Expand Down Expand Up @@ -1773,7 +1770,7 @@ void symbol_symdefs_hydrate(symbol **ps,symbol **parent,int flag)
}

#endif


#if 0

/*************************************
Expand Down Expand Up @@ -1859,7 +1856,7 @@ void symboltable_hydrate(symbol *s,symbol **parent)
}

#endif



/************************************
* Hydrate/dehydrate an mptr_t.
Expand Down Expand Up @@ -2000,7 +1997,7 @@ int baseclass_nitems(baseclass_t *b)

#endif



/*****************************
* Go through symbol table preparing it to be written to a precompiled
* header. That means removing references to things in the .OBJ file.
Expand Down Expand Up @@ -2072,7 +2069,7 @@ void symboltable_clean(symbol *s)
}

#endif


#if SCPP

/*
Expand Down Expand Up @@ -2192,7 +2189,7 @@ void symboltable_balance(symbol **ps)
}

#endif


/*****************************************
* Symbol table search routine for members of structs, given that
* we don't know which struct it is in.
Expand Down Expand Up @@ -2256,7 +2253,7 @@ symbol *symbol_membersearch(const char *id)
}
return pb.sm;
}


/*******************************************
* Generate debug info for global struct tag symbols.
*/
Expand Down Expand Up @@ -2325,9 +2322,7 @@ void slist_reset()
{
Symbol *s = slist[i];

#if MACHOBJ
s->Soffset = 0;
#endif
s->Sxtrnnum = 0;
s->Stypidx = 0;
s->Sflags &= ~(STRoutdef | SFLweak);
Expand Down
7 changes: 3 additions & 4 deletions src/backend/ty.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/


#if __SC__
#if __DMC__
#pragma once
#endif

Expand Down Expand Up @@ -218,7 +218,7 @@ extern unsigned tytab[];

#define tyaggregate(ty) (tytab[(ty) & 0xFF] & TYFLaggregate)

#define tyscalar(ty) (tytab[(ty) & 0xFF] & (TYFLintegral | TYFLreal | TYFLimaginary | TYFLcomplex | TYFLptr | TYFLmptr | TYFLnullptr))
#define tyscalar(ty) (tytab[(ty) & 0xFF] & (TYFLintegral | TYFLreal | TYFLimaginary | TYFLcomplex | TYFLptr | TYFLmptr | TYFLnullptr | TYFLref))

#define tyfloating(ty) (tytab[(ty) & 0xFF] & (TYFLreal | TYFLimaginary | TYFLcomplex))

Expand All @@ -229,7 +229,7 @@ extern unsigned tytab[];
#define tyreal(ty) (tytab[(ty) & 0xFF] & TYFLreal)

// Fits into 64 bit register
#define ty64reg(ty) (tytab[(ty) & 0xFF] & (TYFLintegral | TYFLptr) && tysize(ty) <= NPTRSIZE)
#define ty64reg(ty) (tytab[(ty) & 0xFF] & (TYFLintegral | TYFLptr | TYFLref) && tysize(ty) <= NPTRSIZE)

// Can go in XMM floating point register
#if TX86
Expand Down Expand Up @@ -366,4 +366,3 @@ extern unsigned short dttab4[];
#endif

#endif /* TY_H */

6 changes: 0 additions & 6 deletions src/backend/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,9 +1477,6 @@ symbol *param_search(const char *name, param_t **pp)
s->Sclass = SCparameter;
s->Stype = p->Ptype;
s->Stype->Tcount++;
#if SOURCE_4PARAMS
s->Ssrcpos = p->Psrcpos;
#endif
p->Psym = s;
}
}
Expand All @@ -1500,9 +1497,6 @@ void param_hydrate(param_t **pp)
{ while (*pp)
{ assert(isdehydrated(*pp));
p = (param_t *) ph_hydrate(pp);
#if SOURCE_4PARAMS
p->Psrcpos.Sfilnum += File_Hydrate_Num; /* file number relative header build */
#endif
param_debug(p);

type_hydrate(&p->Ptype);
Expand Down
5 changes: 1 addition & 4 deletions src/backend/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* For any other uses, please contact Digital Mars.
*/

#if __SC__
#if __DMC__
#pragma once
#endif

Expand Down Expand Up @@ -71,9 +71,6 @@ struct TYPE
#if 0
unsigned short Tstabidx; // Index into stab types
#endif
#if SOURCE_4TYPES
Srcpos Tsrcpos; /* position of type definition */
#endif
#if HTOD
Symbol *Ttypedef; // if this type came from a typedef, this is
// the typedef symbol
Expand Down
4 changes: 2 additions & 2 deletions src/backend/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "optab.c"
#include "tytab.c"

#if __SC__ && _MSDOS
#if __DMC__ && _MSDOS
unsigned __cdecl _stack = 100000; // set default stack size
#endif

Expand Down Expand Up @@ -149,7 +149,7 @@ int xc = ' '; // character last read
*/

int colnumber = 0; /* current column number */


/* Other variables: */

int level = 0; /* declaration level */
Expand Down
2 changes: 1 addition & 1 deletion src/func.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ void FuncDeclaration::semantic(Scope *sc)
if (f->varargs)
{
Lmainerr:
error("parameters must be main() or main(char[][] args)");
error("parameters must be main() or main(string[] args)");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ struct Param
OutBuffer *moduleDeps; // contents to be written to deps file

// Hidden debug switches
char debuga;
// char debuga;
char debugb;
char debugc;
char debugf;
Expand Down
2 changes: 1 addition & 1 deletion src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2979,7 +2979,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
{
if (tf->linkage != LINKc)
{
error(loc, "cannot have out, ref or lazy parameter of type %s", t->toChars());
error(loc, "cannot have out or ref parameter of type %s", t->toChars());
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion src/win32.mak
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ OBJ8= go.obj gdag.obj gother.obj gflow.obj gloop.obj var.obj el.obj \
cgcod.obj cod1.obj cod2.obj cod3.obj cod4.obj cod5.obj outbuf.obj \
bcomplex.obj iasm.obj ptrntab.obj aa.obj ti_achar.obj md5.obj \
ti_pvoid.obj mscoffobj.obj pdata.obj cv8.obj backconfig.obj \
divcoeff.obj \
divcoeff.obj dwarf.obj \
ph2.obj util2.obj \
html.obj

Expand Down Expand Up @@ -460,6 +460,9 @@ divcoeff.obj : $C\divcoeff.c
dt.obj : $C\dt.h $C\dt.c
$(CC) -c $(MFLAGS) $C\dt

dwarf.obj : $C\dwarf.h $C\dwarf.c
$(CC) -c $(MFLAGS) $C\dwarf

ee.obj : $C\ee.c
$(CC) -c $(MFLAGS) $C\ee

Expand Down