Skip to content

Commit

Permalink
Merge pull request #2285 from WalterBright/jmptab-for-linux
Browse files Browse the repository at this point in the history
add switch jump tables for Win64, Linux, FreeBSD and OSX
  • Loading branch information
Don Clugston committed Jul 3, 2013
2 parents 64e05bb + 5609df9 commit ded8858
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 30 deletions.
18 changes: 18 additions & 0 deletions src/backend/backconfig.c
Expand Up @@ -72,6 +72,7 @@ void out_config_init(
// Not sure we really need these two lines, try removing them later
config.flags |= CFGnoebp;
config.flags |= CFGalwaysframe;
config.flags |= CFGromable; // put switch tables in code segment
}
else
{ config.exe = EX_NT;
Expand All @@ -88,7 +89,11 @@ void out_config_init(
config.fpxmmregs = TRUE;
}
else
{
config.exe = EX_LINUX;
if (!exe)
config.flags |= CFGromable; // put switch tables in code segment
}
config.flags |= CFGnoebp;
config.flags |= CFGalwaysframe;
if (!exe)
Expand All @@ -106,14 +111,19 @@ void out_config_init(
config.flags |= CFGalwaysframe;
if (!exe)
config.flags3 |= CFG3pic;
config.flags |= CFGromable; // put switch tables in code segment
#endif
#if TARGET_FREEBSD
if (model == 64)
{ config.exe = EX_FREEBSD64;
config.fpxmmregs = TRUE;
}
else
{
config.exe = EX_FREEBSD;
if (!exe)
config.flags |= CFGromable; // put switch tables in code segment
}
config.flags |= CFGnoebp;
config.flags |= CFGalwaysframe;
if (!exe)
Expand All @@ -125,7 +135,11 @@ void out_config_init(
config.fpxmmregs = TRUE;
}
else
{
config.exe = EX_OPENBSD;
if (!exe)
config.flags |= CFGromable; // put switch tables in code segment
}
config.flags |= CFGnoebp;
config.flags |= CFGalwaysframe;
if (!exe)
Expand All @@ -137,7 +151,11 @@ void out_config_init(
config.fpxmmregs = TRUE;
}
else
{
config.exe = EX_SOLARIS;
if (!exe)
config.flags |= CFGromable; // put switch tables in code segment
}
config.flags |= CFGnoebp;
config.flags |= CFGalwaysframe;
if (!exe)
Expand Down
8 changes: 6 additions & 2 deletions src/backend/cc.h
Expand Up @@ -541,15 +541,19 @@ typedef struct block
// CODGEN
struct
{
targ_size_t Btablesize; // BCswitch, BCjmptab
targ_size_t Btableoffset; // BCswitch, BCjmptab
// For BCswitch, BCjmptab
targ_size_t Btablesize; // size of generated table
targ_size_t Btableoffset; // offset to start of table
targ_size_t Btablebase; // offset to instruction pointer base

targ_size_t Boffset; // code offset of start of this block
targ_size_t Bsize; // code size of this block
con_t Bregcon; // register state at block exit
targ_size_t Btryoff; // BCtry: offset of try block data

#define Btablesize _BLU._UD.Btablesize
#define Btableoffset _BLU._UD.Btableoffset
#define Btablebase _BLU._UD.Btablebase
#define Boffset _BLU._UD.Boffset
#define Bsize _BLU._UD.Bsize
// #define Bcode _BLU._UD.Bcode
Expand Down
4 changes: 3 additions & 1 deletion src/backend/cgcod.c
Expand Up @@ -404,7 +404,9 @@ void codgen()
for (block* b = startblock; b; b = b->Bnext)
{
if (b->BC == BCjmptab || b->BC == BCswitch)
{ b->Btableoffset = swoffset; /* offset of sw tab */
{
swoffset = align(0,swoffset);
b->Btableoffset = swoffset; /* offset of sw tab */
swoffset += b->Btablesize;
}
jmpaddr(b->Bcode); /* assign jump addresses */
Expand Down

0 comments on commit ded8858

Please sign in to comment.