Skip to content

Commit

Permalink
merge back end changes with D2
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Mar 1, 2014
1 parent e39e070 commit dc6169b
Show file tree
Hide file tree
Showing 26 changed files with 196 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/backend/cc.h
Expand Up @@ -201,6 +201,7 @@ extern Config config;
typedef struct Srcpos
{
unsigned Slinnum; // 0 means no info available
unsigned Scharnum;
#if SPP || SCPP
struct Sfile **Sfilptr; // file
#define srcpos_sfile(p) (**(p).Sfilptr)
Expand Down
9 changes: 5 additions & 4 deletions src/backend/cdef.h
Expand Up @@ -23,7 +23,7 @@
Host operating system:
_WIN32 Microsoft NT, Windows 95, Windows 98, Win32s, Windows 2000
_WIN64 Windows for AMD64
linux Linux
__linux__ Linux
__APPLE__ Mac OSX
__FreeBSD__ FreeBSD
__OpenBSD__ OpenBSD
Expand Down Expand Up @@ -166,7 +166,7 @@ One and only one of these macros must be set by the makefile:

// Set to 1 using the makefile
#ifndef TARGET_LINUX
#if 0 //linux
#if 0 //__linux__
#define TARGET_LINUX 1
#else
#define TARGET_LINUX 0 // target is a linux executable
Expand Down Expand Up @@ -271,7 +271,7 @@ typedef long double longdouble;

// Precompiled header variations
#define MEMORYHX (_WINDLL && _WIN32) // HX and SYM files are cached in memory
#define MMFIO (_WIN32 || linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun) // if memory mapped files
#define MMFIO (_WIN32 || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun) // if memory mapped files
#define LINEARALLOC _WIN32 // if we can reserve address ranges

// H_STYLE takes on one of these precompiled header methods
Expand Down Expand Up @@ -575,6 +575,7 @@ typedef targ_uns targ_size_t; /* size_t for the target machine */
#define DATA 2 /* initialized data */
#define CDATA 3 /* constant data */
#define UDATA 4 /* uninitialized data */
#define CDATAREL 5 /* constant data with relocs */
#define UNKNOWN -1 /* unknown segment */
#define DGROUPIDX 1 /* group index of DGROUP */

Expand Down Expand Up @@ -612,7 +613,7 @@ typedef int bool;
Written by Walter Bright\n\
*****BETA TEST VERSION*****"
#else
#if linux
#if __linux__
#define COPYRIGHT "Copyright (C) Digital Mars 2000-2013. All Rights Reserved.\n\
Written by Walter Bright, Linux version by Pat Nelson"
#else
Expand Down
14 changes: 13 additions & 1 deletion src/backend/cgcv.c
Expand Up @@ -17,7 +17,7 @@
#include <time.h>
#include <stdlib.h>

#if _WIN32 || linux
#if _WIN32 || __linux__
#include <malloc.h>
#endif

Expand Down Expand Up @@ -2155,6 +2155,18 @@ unsigned cv4_typidx(type *t)
t = tspvoid;
goto L1;

// vector types
case TYfloat4: size = 16; next = dttab4[TYfloat]; goto Larray;
case TYdouble2: size = 16; next = dttab4[TYdouble]; goto Larray;
case TYschar16: size = 16; next = dttab4[TYschar]; goto Larray;
case TYuchar16: size = 16; next = dttab4[TYuchar]; goto Larray;
case TYshort8: size = 16; next = dttab4[TYshort]; goto Larray;
case TYushort8: size = 16; next = dttab4[TYushort]; goto Larray;
case TYlong4: size = 16; next = dttab4[TYlong]; goto Larray;
case TYulong4: size = 16; next = dttab4[TYulong]; goto Larray;
case TYllong2: size = 16; next = dttab4[TYllong]; goto Larray;
case TYullong2: size = 16; next = dttab4[TYullong]; goto Larray;

default:
#ifdef DEBUG
WRTYxx(tym);
Expand Down
23 changes: 9 additions & 14 deletions src/backend/cgelem.c
Expand Up @@ -27,7 +27,7 @@
static char __file__[] = __FILE__; /* for tassert.h */
#include "tassert.h"

extern void error(const char *filename, unsigned linnum, const char *format, ...);
extern void error(const char *filename, unsigned linnum, unsigned charnum, const char *format, ...);

STATIC elem * optelem(elem *,goal_t);
STATIC elem * elarray(elem *e);
Expand Down Expand Up @@ -2192,7 +2192,7 @@ STATIC elem * elremquo(elem *e, goal_t goal)
{
#if 0 && MARS
if (cnst(e->E2) && !boolres(e->E2))
error(e->Esrcpos.Sfilename, e->Esrcpos.Slinnum, "divide by zero\n");
error(e->Esrcpos.Sfilename, e->Esrcpos.Slinnum, e->Esrcpos.Scharnum, "divide by zero\n");
#endif
return e;
}
Expand Down Expand Up @@ -2229,7 +2229,7 @@ STATIC elem * eldiv(elem *e, goal_t goal)
{
#if 0 && MARS
if (!boolres(e2))
error(e->Esrcpos.Sfilename, e->Esrcpos.Slinnum, "divide by zero\n");
error(e->Esrcpos.Sfilename, e->Esrcpos.Slinnum, e->Esrcpos.Scharnum, "divide by zero\n");
#endif
if (uns)
{ int i;
Expand Down Expand Up @@ -5318,8 +5318,7 @@ elem *doptelem(elem *e, goal_t goal)

void postoptelem(elem *e)
{
int linnum = 0;
const char *filename = NULL;
Srcpos pos = {0};

elem_debug(e);
while (1)
Expand All @@ -5329,18 +5328,16 @@ void postoptelem(elem *e)
/* This is necessary as the optimizer tends to lose this information
*/
#if MARS
if (e->Esrcpos.Slinnum > linnum)
{ linnum = e->Esrcpos.Slinnum;
filename = e->Esrcpos.Sfilename;
}
if (e->Esrcpos.Slinnum > pos.Slinnum)
pos = e->Esrcpos;
#endif
if (e->Eoper == OPind)
{
#if MARS
if (e->E1->Eoper == OPconst &&
el_tolong(e->E1) >= 0 && el_tolong(e->E1) < 4096)
{
error(filename, linnum, "null dereference in function %s", funcsym_p->Sident);
error(pos.Sfilename, pos.Slinnum, pos.Scharnum, "null dereference in function %s", funcsym_p->Sident);
e->E1->EV.Vlong = 4096; // suppress redundant messages
}
#endif
Expand All @@ -5352,10 +5349,8 @@ void postoptelem(elem *e)
#if MARS
/* This is necessary as the optimizer tends to lose this information
*/
if (e->Esrcpos.Slinnum > linnum)
{ linnum = e->Esrcpos.Slinnum;
filename = e->Esrcpos.Sfilename;
}
if (e->Esrcpos.Slinnum > pos.Slinnum)
pos = e->Esrcpos;
#endif
if (e->Eoper == OPparam)
{
Expand Down
10 changes: 6 additions & 4 deletions src/backend/cgobj.c
Expand Up @@ -34,10 +34,12 @@ struct Loc
{
char *filename;
unsigned linnum;
unsigned charnum;

Loc(int x)
Loc(int y, int x)
{
linnum = x;
linnum = y;
charnum = x;
filename = NULL;
}
};
Expand Down Expand Up @@ -364,15 +366,15 @@ void objrecord(unsigned rectyp,const char *record,unsigned reclen)
* # of bytes stored
*/

extern void error(const char *filename, unsigned linnum, const char *format, ...);
extern void error(const char *filename, unsigned linnum, unsigned charnum, const char *format, ...);
extern void fatal();

void too_many_symbols()
{
#if SCPP
err_fatal(EM_too_many_symbols, 0x7FFF);
#else // MARS
error(NULL, 0, "more than %d symbols in object file", 0x7FFF);
error(NULL, 0, 0, "more than %d symbols in object file", 0x7FFF);
fatal();
#endif
}
Expand Down
20 changes: 18 additions & 2 deletions src/backend/cod3.c
Expand Up @@ -3846,7 +3846,23 @@ void epilog(block *b)
else
{ // Stack is always aligned on register size boundary
Para.offset = (Para.offset + (REGSIZE - 1)) & ~(REGSIZE - 1);
c = genc2(c,op,0,Para.offset); // RET Para.offset
if (Para.offset >= 0x10000)
{
/*
POP REG
ADD ESP, Para.offset
JMP REG
*/
c = gen1(c, 0x58+regx);
c = genc2(c, 0x81, modregrm(3,0,SP), Para.offset);
if (I64)
code_orrex(c, REX_W);
c = genc2(c, 0xFF, modregrm(3,4,regx), 0);
if (I64)
code_orrex(c, REX_W);
}
else
c = genc2(c,op,0,Para.offset); // RET Para.offset
}
}

Expand Down Expand Up @@ -6033,7 +6049,7 @@ unsigned codout(code *c)
unsigned reg = rm & modregrm(0,7,0);
if (ins & T ||
((op == 0xF6 || op == 0xF7) && (reg == modregrm(0,0,0) || reg == modregrm(0,1,0))))
{ if (ins & E)
{ if (ins & E || op == 0xF6)
val = -5;
else if (c->Iflags & CFopsize)
val = -6;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/debug.c
Expand Up @@ -91,7 +91,7 @@ void WRTYxx(tym_t t)
dbg_printf("mTYconst|");
if (t & mTYvolatile)
dbg_printf("mTYvolatile|");
#if !MARS && (linux || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun)
#if !MARS && (__linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun)
if (t & mTYtransu)
dbg_printf("mTYtransu|");
#endif
Expand Down
19 changes: 19 additions & 0 deletions src/backend/dt.c
Expand Up @@ -390,6 +390,25 @@ bool dtallzeros(const dt_t *dt)
return dt->dt == DT_azeros && !dt->DTnext;
}

/************************************
* Return true if dt contains pointers (requires relocations).
*/

bool dtpointers(const dt_t *dtstart)
{
for (const dt_t *dt = dtstart; dt; dt = dt->DTnext)
{
switch (dt->dt)
{
case DT_abytes:
case DT_xoff:
case DT_coff:
return true;
}
}
return false;
}

/***********************************
* Turn DT_azeros into DTcommon
*/
Expand Down
1 change: 1 addition & 0 deletions src/backend/dt.h
Expand Up @@ -27,6 +27,7 @@ void init_common(Symbol *);
unsigned dt_size(const dt_t *dtstart);
dt_t **dtend(dt_t** pdt);
bool dtallzeros(const dt_t *dt);
bool dtpointers(const dt_t *dt);
void dt2common(dt_t **pdt);

#endif /* DT_H */
Expand Down

0 comments on commit dc6169b

Please sign in to comment.