mirror of https://github.com/aamine/cbc
* net/loveruby/cflat/compiler/CodeGenerator.java (compileFunctionBody): remove bp from saveRegs first.
git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4107 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
0defdae27a
commit
e0105bda01
|
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Dec 14 20:43:47 2008 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* net/loveruby/cflat/compiler/CodeGenerator.java
|
||||||
|
(compileFunctionBody): remove bp from saveRegs first.
|
||||||
|
|
||||||
Mon Dec 8 00:55:33 2008 Minero Aoki <aamine@loveruby.net>
|
Mon Dec 8 00:55:33 2008 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* lib/alloca.s: alloca() implemeted.
|
* lib/alloca.s: alloca() implemeted.
|
||||||
|
|
|
||||||
|
|
@ -307,11 +307,12 @@ public class CodeGenerator
|
||||||
List<Assembly> bodyAsms = compileStmts(func);
|
List<Assembly> bodyAsms = compileStmts(func);
|
||||||
AsmStatistics stats = AsmStatistics.collect(bodyAsms);
|
AsmStatistics stats = AsmStatistics.collect(bodyAsms);
|
||||||
bodyAsms = reduceLabels(bodyAsms, stats);
|
bodyAsms = reduceLabels(bodyAsms, stats);
|
||||||
List<Register> saveRegs = usedCalleeSavedRegisters(stats);
|
List<Register> saveRegs = usedCalleeSavedRegistersWithoutBP(stats);
|
||||||
long lvarBytes = allocateLocalVariables(func.body().scope(),
|
long lvarBytes = allocateLocalVariables(func.body().scope(),
|
||||||
saveRegs.size());
|
saveRegs.size());
|
||||||
prologue(func, saveRegs, lvarBytes);
|
prologue(func, saveRegs, lvarBytes);
|
||||||
if (options.isPositionIndependent() && stats.doesRegisterUsed(GOTBaseReg())) {
|
if (options.isPositionIndependent()
|
||||||
|
&& stats.doesRegisterUsed(GOTBaseReg())) {
|
||||||
loadGOTBaseAddress(GOTBaseReg());
|
loadGOTBaseAddress(GOTBaseReg());
|
||||||
}
|
}
|
||||||
as.addAll(bodyAsms);
|
as.addAll(bodyAsms);
|
||||||
|
|
@ -354,10 +355,10 @@ public class CodeGenerator
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
|
|
||||||
protected List<Register> usedCalleeSavedRegisters(AsmStatistics stats) {
|
protected List<Register> usedCalleeSavedRegistersWithoutBP(AsmStatistics stats) {
|
||||||
List<Register> result = new ArrayList<Register>();
|
List<Register> result = new ArrayList<Register>();
|
||||||
for (Register reg : calleeSavedRegisters()) {
|
for (Register reg : calleeSavedRegisters()) {
|
||||||
if (stats.doesRegisterUsed(reg)) {
|
if (stats.doesRegisterUsed(reg) && !reg.equals(bp())) {
|
||||||
result.add(reg);
|
result.add(reg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -435,8 +436,14 @@ public class CodeGenerator
|
||||||
protected void epilogue(DefinedFunction func,
|
protected void epilogue(DefinedFunction func,
|
||||||
List<Register> savedRegs,
|
List<Register> savedRegs,
|
||||||
long lvarBytes) {
|
long lvarBytes) {
|
||||||
shrinkStack(lvarBytes);
|
//shrinkStack(lvarBytes);
|
||||||
restoreRegisters(savedRegs);
|
if (! savedRegs.isEmpty()) {
|
||||||
|
long offset = stackGrowsLower
|
||||||
|
? -1 * savedRegs.size() * stackWordSize
|
||||||
|
: (savedRegs.size() - 1) * stackWordSize;
|
||||||
|
lea(mem(offset, bp()), sp());
|
||||||
|
restoreRegisters(savedRegs);
|
||||||
|
}
|
||||||
mov(bp(), sp());
|
mov(bp(), sp());
|
||||||
pop(bp());
|
pop(bp());
|
||||||
ret();
|
ret();
|
||||||
|
|
@ -445,19 +452,14 @@ public class CodeGenerator
|
||||||
|
|
||||||
protected void saveRegisters(List<Register> saveRegs) {
|
protected void saveRegisters(List<Register> saveRegs) {
|
||||||
for (Register reg : saveRegs) {
|
for (Register reg : saveRegs) {
|
||||||
if (! reg.equals(bp())) { // bp is already saved.
|
push(reg);
|
||||||
push(reg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void restoreRegisters(List<Register> savedRegs) {
|
protected void restoreRegisters(List<Register> savedRegs) {
|
||||||
ListIterator<Register> regs = savedRegs.listIterator(savedRegs.size());
|
ListIterator<Register> regs = savedRegs.listIterator(savedRegs.size());
|
||||||
while (regs.hasPrevious()) {
|
while (regs.hasPrevious()) {
|
||||||
Register reg = regs.previous();
|
pop(regs.previous());
|
||||||
if (! reg.equals(bp())) { // bp is going to be restored.
|
|
||||||
pop(reg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -490,7 +492,7 @@ public class CodeGenerator
|
||||||
* Note that numSavedRegs includes bp.
|
* Note that numSavedRegs includes bp.
|
||||||
*/
|
*/
|
||||||
protected long allocateLocalVariables(LocalScope scope, long numSavedRegs) {
|
protected long allocateLocalVariables(LocalScope scope, long numSavedRegs) {
|
||||||
long initLen = (numSavedRegs - 1) * stackWordSize;
|
long initLen = numSavedRegs * stackWordSize;
|
||||||
long maxLen = allocateScope(scope, initLen);
|
long maxLen = allocateScope(scope, initLen);
|
||||||
return maxLen - initLen;
|
return maxLen - initLen;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue