Skip to content

Commit a0a1160

Browse files
WalterBrightdlang-bot
authored andcommitted
move BPoff to CGstate
1 parent 4b8318b commit a0a1160

File tree

6 files changed

+46
-45
lines changed

6 files changed

+46
-45
lines changed

compiler/src/dmd/backend/cgcod.d

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import dmd.backend.dwarfdbginf : dwarf_except_gentables;
5757

5858
__gshared
5959
{
60-
int BPoff; // offset from BP
6160
int EBPtoESP; // add to EBP offset to get ESP offset
6261

6362
REGSAVE regsave;
@@ -611,7 +610,7 @@ void prolog(ref CodeBuilder cdb)
611610
EBPtoESP = -REGSIZE;
612611
cgstate.hasframe = false;
613612
bool pushds = false;
614-
BPoff = 0;
613+
cgstate.BPoff = 0;
615614
bool pushalloc = false;
616615
tym_t tyf = funcsym_p.ty();
617616
tym_t tym = tybasic(tyf);
@@ -944,7 +943,7 @@ else
944943
assert(I32 || I64);
945944
prolog_frameadj2(cdbx, tyf, xlocalsize, &pushalloc);
946945
version (FRAMEPTR) { } else
947-
BPoff += REGSIZE;
946+
cgstate.BPoff += REGSIZE;
948947
}
949948
else
950949
assert((localsize | cgstate.Alloca.size) == 0 || (usednteh & NTEHjmonitor));
@@ -1006,7 +1005,7 @@ Lcont:
10061005
/* Alignment checks
10071006
*/
10081007
//assert(cgstate.Auto.alignment <= STACKALIGN);
1009-
//assert(((cgstate.Auto.size + cgstate.Para.size + BPoff) & (cgstate.Auto.alignment - 1)) == 0);
1008+
//assert(((cgstate.Auto.size + cgstate.Para.size + cgstate.BPoff) & (cgstate.Auto.alignment - 1)) == 0);
10101009
}
10111010

10121011
/************************************

compiler/src/dmd/backend/cod3.d

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,7 +3368,7 @@ void prolog_16bit_windows_farfunc(ref CodeBuilder cdb, tym_t* tyf, bool* pushds)
33683368
{
33693369
cdb.gen1(0x1E); // PUSH DS
33703370
*pushds = true;
3371-
BPoff = -REGSIZE;
3371+
cgstate.BPoff = -REGSIZE;
33723372
}
33733373
if (wflags & (WFds | WFss | WFdgroup))
33743374
cdb.gen2(0x8E,modregrm(3,3,AX)); // MOV DS,AX
@@ -3570,8 +3570,8 @@ void prolog_setupalloca(ref CodeBuilder cdb)
35703570
// Set up magic parameter for alloca()
35713571
// MOV -REGSIZE[BP],localsize - BPoff
35723572
cdb.genc(0xC7,modregrm(2,0,BPRM),
3573-
FLconst,cgstate.Alloca.offset + BPoff,
3574-
FLconst,localsize - BPoff);
3573+
FLconst,cgstate.Alloca.offset + cgstate.BPoff,
3574+
FLconst,localsize - cgstate.BPoff);
35753575
if (I64)
35763576
code_orrex(cdb.last(), REX_W);
35773577
}
@@ -3596,7 +3596,7 @@ void prolog_saveregs(ref CodeBuilder cdb, regm_t topush, int cfa_offset)
35963596
// Save to preallocated section in the stack frame
35973597
int xmmtopush = popcnt(topush & XMMREGS); // XMM regs take 16 bytes
35983598
int gptopush = popcnt(topush) - xmmtopush; // general purpose registers to save
3599-
targ_size_t xmmoffset = cgstate.pushoff + BPoff;
3599+
targ_size_t xmmoffset = cgstate.pushoff + cgstate.BPoff;
36003600
if (!cgstate.hasframe || cgstate.enforcealign)
36013601
xmmoffset += EBPtoESP;
36023602
targ_size_t gpoffset = xmmoffset + xmmtopush * 16;
@@ -3699,7 +3699,7 @@ private void epilog_restoreregs(ref CodeBuilder cdb, regm_t topop)
36993699
// Save to preallocated section in the stack frame
37003700
int xmmtopop = popcnt(topop & XMMREGS); // XMM regs take 16 bytes
37013701
int gptopop = popcnt(topop) - xmmtopop; // general purpose registers to save
3702-
targ_size_t xmmoffset = cgstate.pushoff + BPoff;
3702+
targ_size_t xmmoffset = cgstate.pushoff + cgstate.BPoff;
37033703
if (!cgstate.hasframe || cgstate.enforcealign)
37043704
xmmoffset += EBPtoESP;
37053705
targ_size_t gpoffset = xmmoffset + xmmtopop * 16;
@@ -3819,7 +3819,7 @@ void prolog_genvarargs(ref CodeBuilder cdb, Symbol* sv)
38193819

38203820
/* Save registers into the voff area on the stack
38213821
*/
3822-
targ_size_t voff = cgstate.Auto.size + BPoff + sv.Soffset; // EBP offset of start of sv
3822+
targ_size_t voff = cgstate.Auto.size + cgstate.BPoff + sv.Soffset; // EBP offset of start of sv
38233823
const int vregnum = 6;
38243824
const uint vsize = vregnum * 8 + 8 * 16;
38253825

@@ -4076,7 +4076,7 @@ void prolog_loadparams(ref CodeBuilder cdb, tym_t tyf, bool pushalloc)
40764076
continue;
40774077
}
40784078

4079-
targ_size_t offset = cgstate.Fast.size + BPoff;
4079+
targ_size_t offset = cgstate.Fast.size + cgstate.BPoff;
40804080
if (s.Sclass == SC.shadowreg)
40814081
offset = cgstate.Para.size;
40824082
offset += s.Soffset;
@@ -4109,7 +4109,7 @@ void prolog_loadparams(ref CodeBuilder cdb, tym_t tyf, bool pushalloc)
41094109
else
41104110
{
41114111
//printf("%s Fast.size = %d, BPoff = %d, Soffset = %d, sz = %d\n",
4112-
// s.Sident, (int)cgstate.Fast.size, (int)BPoff, (int)s.Soffset, (int)sz);
4112+
// s.Sident, (int)cgstate.Fast.size, (int)cgstate.BPoff, (int)s.Soffset, (int)sz);
41134113
if (I64 && sz > 4)
41144114
code_orrex(cdb.last(), REX_W);
41154115
}
@@ -5093,18 +5093,18 @@ void cod3_adjSymOffsets()
50935093
break;
50945094

50955095
case SC.fastpar:
5096-
//printf("\tfastpar %s %p Soffset %x Fast.size %x BPoff %x\n", s.Sident, s, cast(int)s.Soffset, cast(int)cgstate.Fast.size, cast(int)BPoff);
5097-
s.Soffset += cgstate.Fast.size + BPoff;
5096+
//printf("\tfastpar %s %p Soffset %x Fast.size %x BPoff %x\n", s.Sident, s, cast(int)s.Soffset, cast(int)cgstate.Fast.size, cast(int)cgstate.BPoff);
5097+
s.Soffset += cgstate.Fast.size + cgstate.BPoff;
50985098
break;
50995099

51005100
case SC.auto_:
51015101
case SC.register:
51025102
if (s.Sfl == FLfast)
5103-
s.Soffset += cgstate.Fast.size + BPoff;
5103+
s.Soffset += cgstate.Fast.size + cgstate.BPoff;
51045104
else
5105-
//printf("s = '%s', Soffset = x%x, Auto.size = x%x, BPoff = x%x EBPtoESP = x%x\n", s.Sident, cast(int)s.Soffset, cast(int)cgstate.Auto.size, cast(int)BPoff, cast(int)EBPtoESP);
5105+
//printf("s = '%s', Soffset = x%x, Auto.size = x%x, BPoff = x%x EBPtoESP = x%x\n", s.Sident, cast(int)s.Soffset, cast(int)cgstate.Auto.size, cast(int)cgstate.BPoff, cast(int)EBPtoESP);
51065106
// if (!(funcsym_p.Sfunc.Fflags3 & Fnested))
5107-
s.Soffset += cgstate.Auto.size + BPoff;
5107+
s.Soffset += cgstate.Auto.size + cgstate.BPoff;
51085108
break;
51095109

51105110
case SC.bprel:
@@ -5333,7 +5333,7 @@ void assignaddrc(code *c)
53335333
goto do2;
53345334
}
53355335
else
5336-
{ c.IEV1.Vpointer += s.Soffset + soff + BPoff;
5336+
{ c.IEV1.Vpointer += s.Soffset + soff + cgstate.BPoff;
53375337
if (s.Sflags & SFLunambig)
53385338
c.Iflags |= CFunambig;
53395339
L2:
@@ -5361,22 +5361,22 @@ void assignaddrc(code *c)
53615361

53625362
case FLpara:
53635363
//printf("s = %s, Soffset = %d, Para.size = %d, BPoff = %d, EBPtoESP = %d, Vpointer = %d\n",
5364-
//s.Sident.ptr, cast(int)s.Soffset, cast(int)Para.size, cast(int)BPoff,
5364+
//s.Sident.ptr, cast(int)s.Soffset, cast(int)Para.size, cast(int)cgstate.BPoff,
53655365
//cast(int)EBPtoESP, cast(int)c.IEV1.Vpointer);
5366-
soff = cgstate.Para.size - BPoff; // cancel out add of BPoff
5366+
soff = cgstate.Para.size - cgstate.BPoff; // cancel out add of BPoff
53675367
goto L1;
53685368

53695369
case FLfltreg:
5370-
c.IEV1.Vpointer += cgstate.Foff + BPoff;
5370+
c.IEV1.Vpointer += cgstate.Foff + cgstate.BPoff;
53715371
c.Iflags |= CFunambig;
53725372
goto L2;
53735373

53745374
case FLallocatmp:
5375-
c.IEV1.Vpointer += cgstate.Alloca.offset + BPoff;
5375+
c.IEV1.Vpointer += cgstate.Alloca.offset + cgstate.BPoff;
53765376
goto L2;
53775377

53785378
case FLfuncarg:
5379-
c.IEV1.Vpointer += cgstate.funcarg.offset + BPoff;
5379+
c.IEV1.Vpointer += cgstate.funcarg.offset + cgstate.BPoff;
53805380
goto L2;
53815381

53825382
case FLbprel:
@@ -5390,19 +5390,19 @@ void assignaddrc(code *c)
53905390
c.Iop = NOP;
53915391
continue;
53925392
}
5393-
c.IEV1.Vpointer = CSE.offset(sn) + cgstate.CSoff + BPoff;
5393+
c.IEV1.Vpointer = CSE.offset(sn) + cgstate.CSoff + cgstate.BPoff;
53945394
c.Iflags |= CFunambig;
53955395
goto L2;
53965396

53975397
case FLregsave:
53985398
sn = c.IEV1.Vuns;
5399-
c.IEV1.Vpointer = sn + regsave.off + BPoff;
5399+
c.IEV1.Vpointer = sn + regsave.off + cgstate.BPoff;
54005400
c.Iflags |= CFunambig;
54015401
goto L2;
54025402

54035403
case FLndp:
54045404
assert(c.IEV1.Vuns < global87.save.length);
5405-
c.IEV1.Vpointer = c.IEV1.Vuns * tysize(TYldouble) + cgstate.NDPoff + BPoff;
5405+
c.IEV1.Vpointer = c.IEV1.Vuns * tysize(TYldouble) + cgstate.NDPoff + cgstate.BPoff;
54065406
c.Iflags |= CFunambig;
54075407
goto L2;
54085408

@@ -5478,11 +5478,11 @@ void assignaddrc(code *c)
54785478
/* NOTREACHED */
54795479

54805480
case FLfast:
5481-
c.IEV2.Vpointer += s.Soffset + cgstate.Fast.size + BPoff;
5481+
c.IEV2.Vpointer += s.Soffset + cgstate.Fast.size + cgstate.BPoff;
54825482
break;
54835483

54845484
case FLauto:
5485-
c.IEV2.Vpointer += s.Soffset + cgstate.Auto.size + BPoff;
5485+
c.IEV2.Vpointer += s.Soffset + cgstate.Auto.size + cgstate.BPoff;
54865486
L3:
54875487
if (!cgstate.hasframe || (cgstate.enforcealign && c.IFL2 != FLpara))
54885488
/* Convert to ESP relative address instead of EBP */
@@ -5494,15 +5494,15 @@ void assignaddrc(code *c)
54945494
goto L3;
54955495

54965496
case FLfltreg:
5497-
c.IEV2.Vpointer += cgstate.Foff + BPoff;
5497+
c.IEV2.Vpointer += cgstate.Foff + cgstate.BPoff;
54985498
goto L3;
54995499

55005500
case FLallocatmp:
5501-
c.IEV2.Vpointer += cgstate.Alloca.offset + BPoff;
5501+
c.IEV2.Vpointer += cgstate.Alloca.offset + cgstate.BPoff;
55025502
goto L3;
55035503

55045504
case FLfuncarg:
5505-
c.IEV2.Vpointer += cgstate.funcarg.offset + BPoff;
5505+
c.IEV2.Vpointer += cgstate.funcarg.offset + cgstate.BPoff;
55065506
goto L3;
55075507

55085508
case FLbprel:
@@ -5552,11 +5552,11 @@ targ_size_t cod3_bpoffset(Symbol *s)
55525552
break;
55535553

55545554
case FLfast:
5555-
offset += cgstate.Fast.size + BPoff;
5555+
offset += cgstate.Fast.size + cgstate.BPoff;
55565556
break;
55575557

55585558
case FLauto:
5559-
offset += cgstate.Auto.size + BPoff;
5559+
offset += cgstate.Auto.size + cgstate.BPoff;
55605560
break;
55615561

55625562
default:

compiler/src/dmd/backend/code.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ struct CGstate
160160
bool hasframe; // true if this function has a stack frame
161161
bool enforcealign; // enforced stack alignment
162162

163-
int stackclean; // if != 0, then clean the stack after function call
163+
int stackclean; // if != 0, then clean the stack after function call
164+
165+
int BPoff; // offset from BP
164166

165167
targ_size_t spoff;
166168
targ_size_t Foff; // BP offset of floating register

compiler/src/dmd/backend/cv8.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ void cv8_outsym(Symbol *s)
702702
s.Sfl = FLreg;
703703
goto case_register;
704704
}
705-
base = cast(uint)(cgstate.Para.size - BPoff); // cancel out add of BPoff
705+
base = cast(uint)(cgstate.Para.size - cgstate.BPoff); // cancel out add of BPoff
706706
goto L1;
707707

708708
case SC.auto_:
@@ -719,7 +719,7 @@ static if (1)
719719
buf.reserve(cast(uint)(2 + 2 + 4 + 4 + 2 + len + 1));
720720
buf.write16n(cast(uint)(2 + 4 + 4 + 2 + len + 1));
721721
buf.write16n(0x1111);
722-
buf.write32(cast(uint)(s.Soffset + base + BPoff));
722+
buf.write32(cast(uint)(s.Soffset + base + cgstate.BPoff));
723723
buf.write32(typidx);
724724
buf.write16n(I64 ? 334 : 22); // relative to RBP/EBP
725725
cv8_writename(buf, id, len);
@@ -731,15 +731,15 @@ else
731731
buf.reserve(2 + 2 + 4 + 4 + len + 1);
732732
buf.write16n( 2 + 4 + 4 + len + 1);
733733
buf.write16n(S_BPREL_V3);
734-
buf.write32(s.Soffset + base + BPoff);
734+
buf.write32(s.Soffset + base + cgstate.BPoff);
735735
buf.write32(typidx);
736736
cv8_writename(buf, id, len);
737737
buf.writeByte(0);
738738
}
739739
break;
740740

741741
case SC.bprel:
742-
base = -BPoff;
742+
base = -cgstate.BPoff;
743743
goto L1;
744744

745745
case SC.fastpar:

compiler/src/dmd/backend/dcgcv.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ private void cv4_outsym(Symbol *s)
16371637
s.Sfl = FLreg;
16381638
goto case_register;
16391639
}
1640-
base = cgstate.Para.size - BPoff; // cancel out add of BPoff
1640+
base = cgstate.Para.size - cgstate.BPoff; // cancel out add of BPoff
16411641
goto L1;
16421642

16431643
case SC.auto_:
@@ -1650,11 +1650,11 @@ private void cv4_outsym(Symbol *s)
16501650
goto Lret;
16511651
TOWORD(debsym + 2,I32 ? S_BPREL32 : S_BPREL16);
16521652
if (config.fulltypes == CV4)
1653-
{ TOOFFSET(debsym + 4,s.Soffset + base + BPoff);
1653+
{ TOOFFSET(debsym + 4,s.Soffset + base + cgstate.BPoff);
16541654
TOIDX(debsym + 4 + _tysize[TYint],typidx);
16551655
}
16561656
else
1657-
{ TOOFFSET(debsym + 4 + cgcv.sz_idx,s.Soffset + base + BPoff);
1657+
{ TOOFFSET(debsym + 4 + cgcv.sz_idx,s.Soffset + base + cgstate.BPoff);
16581658
TOIDX(debsym + 4,typidx);
16591659
}
16601660
length = 2 + 2 + _tysize[TYint] + cgcv.sz_idx;
@@ -1663,7 +1663,7 @@ private void cv4_outsym(Symbol *s)
16631663
break;
16641664

16651665
case SC.bprel:
1666-
base = -BPoff;
1666+
base = -cgstate.BPoff;
16671667
goto L1;
16681668

16691669
case SC.fastpar:

compiler/src/dmd/backend/dwarfdbginf.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ static if (1)
19871987
// sa.Sident.ptr, sa.Sscope.Sident.ptr, closptr_off, memb_off);
19881988

19891989
debug_info.buf.writeByte(DW_OP_fbreg);
1990-
debug_info.buf.writesLEB128(cast(uint)(cgstate.Auto.size + BPoff - cgstate.Para.size + closptr_off)); // closure pointer offset from frame base
1990+
debug_info.buf.writesLEB128(cast(uint)(cgstate.Auto.size + cgstate.BPoff - cgstate.Para.size + closptr_off)); // closure pointer offset from frame base
19911991
debug_info.buf.writeByte(DW_OP_deref);
19921992
debug_info.buf.writeByte(DW_OP_plus_uconst);
19931993
debug_info.buf.writeuLEB128(cast(uint)memb_off); // closure variable offset
@@ -1999,11 +1999,11 @@ static if (1)
19991999
sa.Sclass == SC.parameter)
20002000
debug_info.buf.writesLEB128(cast(int)sa.Soffset);
20012001
else if (sa.Sclass == SC.fastpar)
2002-
debug_info.buf.writesLEB128(cast(int)(cgstate.Fast.size + BPoff - cgstate.Para.size + sa.Soffset));
2002+
debug_info.buf.writesLEB128(cast(int)(cgstate.Fast.size + cgstate.BPoff - cgstate.Para.size + sa.Soffset));
20032003
else if (sa.Sclass == SC.bprel)
20042004
debug_info.buf.writesLEB128(cast(int)(-cgstate.Para.size + sa.Soffset));
20052005
else
2006-
debug_info.buf.writesLEB128(cast(int)(cgstate.Auto.size + BPoff - cgstate.Para.size + sa.Soffset));
2006+
debug_info.buf.writesLEB128(cast(int)(cgstate.Auto.size + cgstate.BPoff - cgstate.Para.size + sa.Soffset));
20072007
}
20082008
debug_info.buf.buf[soffset] = cast(ubyte)(debug_info.buf.length() - soffset - 1);
20092009
break;

0 commit comments

Comments
 (0)