* net: revert r4100; implementing alloca() is too difficult for current architecture.

git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4102 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-12-07 14:26:56 +00:00
parent 37476f6839
commit b598628af9
11 changed files with 33 additions and 146 deletions

View File

@ -1,3 +1,8 @@
Sun Dec 7 23:26:50 2008 Minero Aoki <aamine@loveruby.net>
* net: revert r4100; implementing alloca() is too difficult for
current architecture.
Sun Dec 7 23:25:25 2008 Minero Aoki <aamine@loveruby.net>
* lib/libcbc.cb -> lib/stdarg.cb

View File

@ -21,8 +21,4 @@ abstract public class AsmOperand implements OperandPattern {
public boolean match(AsmOperand operand) {
return equals(operand);
}
public void fixStackOffset(long diff) {
// does nothing by default
}
}

View File

@ -275,11 +275,6 @@ public class Assembler {
mov(naturalType, src, dest);
}
// for stack access
public void relocatableMov(AsmOperand src, AsmOperand dest) {
assemblies.add(new Instruction("mov", typeSuffix(naturalType), src, dest, true));
}
public void mov(Type type, AsmOperand src, AsmOperand dest) {
insn(type, "mov", src, dest);
}

View File

@ -22,8 +22,4 @@ abstract public class Assembly {
public void collectStatistics(AsmStatistics stats) {
// does nothing by default.
}
public void fixStackOffset(long diff) {
// does nothing by default.
}
}

View File

@ -8,8 +8,4 @@ abstract public class BaseSymbol implements Symbol {
public void collectStatistics(AsmStatistics stats) {
stats.symbolUsed(this);
}
public Literal plus(long n) {
throw new Error("must not happen: BaseSymbol.plus called");
}
}

View File

@ -43,10 +43,6 @@ public class IndirectMemoryReference extends MemoryReference {
base.collectStatistics(stats);
}
public void fixStackOffset(long diff) {
offset = offset.plus(diff);
}
public String toString() {
return toSource(SymbolTable.dummy());
}

View File

@ -5,41 +5,32 @@ public class Instruction extends Assembly {
protected String mnemonic;
protected String suffix;
protected AsmOperand[] operands;
protected boolean needRelocation;
public Instruction(String mnemonic) {
this(mnemonic, "", new AsmOperand[0], false);
this(mnemonic, "", new AsmOperand[0]);
}
public Instruction(String mnemonic, String suffix, AsmOperand a1) {
this(mnemonic, suffix, new AsmOperand[] { a1 }, false);
this(mnemonic, suffix, new AsmOperand[] { a1 });
}
public Instruction(String mnemonic, String suffix,
AsmOperand a1, AsmOperand a2) {
this(mnemonic, suffix, new AsmOperand[] { a1, a2 }, false);
this(mnemonic, suffix, new AsmOperand[] { a1, a2 });
}
public Instruction(String mnemonic, String suffix,
AsmOperand a1, AsmOperand a2, boolean reloc) {
this(mnemonic, suffix, new AsmOperand[] { a1, a2 }, reloc);
}
public Instruction(String mnemonic, String suffix, AsmOperand[] operands, boolean reloc) {
public Instruction(String mnemonic, String suffix, AsmOperand[] operands) {
this.mnemonic = mnemonic;
this.suffix = suffix;
this.operands = operands;
this.needRelocation = reloc;
}
public Instruction build(String mnemonic, AsmOperand o1) {
return new Instruction(mnemonic, this.suffix,
new AsmOperand[] { o1 }, needRelocation);
return new Instruction(mnemonic, this.suffix, new AsmOperand[] { o1 });
}
public Instruction build(String mnemonic, AsmOperand o1, AsmOperand o2) {
return new Instruction(mnemonic, this.suffix,
new AsmOperand[] { o1, o2 }, needRelocation);
return new Instruction(mnemonic, this.suffix, new AsmOperand[] { o1, o2 });
}
public boolean isInstruction() {
@ -88,13 +79,6 @@ public class Instruction extends Assembly {
}
}
public void fixStackOffset(long diff) {
if (!needRelocation) return;
for (int i = 0; i < operands.length; i++) {
operands[i].fixStackOffset(diff);
}
}
public String toSource(SymbolTable table) {
StringBuffer buf = new StringBuffer();
buf.append("\t");

View File

@ -24,10 +24,6 @@ public class IntegerLiteral implements Literal {
return value == 0;
}
public IntegerLiteral plus(long diff) {
return new IntegerLiteral(value + diff);
}
public IntegerLiteral integerLiteral() {
return this;
}
@ -43,8 +39,4 @@ public class IntegerLiteral implements Literal {
public void collectStatistics(AsmStatistics stats) {
// does nothing
}
public String toString() {
return "$" + value;
}
}

View File

@ -5,5 +5,4 @@ public interface Literal {
public String toSource(SymbolTable table);
public void collectStatistics(AsmStatistics stats);
public boolean isZero();
public Literal plus(long diff);
}

View File

@ -17,10 +17,6 @@ public class SuffixedSymbol implements Symbol {
base.collectStatistics(stats);
}
public Literal plus(long n) {
throw new Error("must not happen: SuffixedSymbol.plus called");
}
public String name() {
return base.name();
}

View File

@ -304,15 +304,13 @@ public class CodeGenerator
// #@@}
protected void compileFunctionBody(DefinedFunction func) {
initStackParams();
List<Assembly> bodyAsms = compileStmts(func);
AsmStatistics stats = AsmStatistics.collect(bodyAsms);
bodyAsms = reduceLabels(bodyAsms, stats);
List<Register> saveRegs = usedCalleeSavedRegisters(stats);
long lvarBytes = allocateLocalVariables(func.body().scope(), savedRegsSize(saveRegs));
fixStackOffsets(bodyAsms, savedRegsSize(saveRegs) + lvarBytes);
prologue(func, saveRegs, savedRegsSize(saveRegs) + lvarBytes + maxStackLength());
long lvarBytes = allocateLocalVariables(func.body().scope(),
saveRegs.size());
prologue(func, saveRegs, lvarBytes);
if (options.isPositionIndependent() && stats.doesRegisterUsed(GOTBaseReg())) {
loadGOTBaseAddress(GOTBaseReg());
}
@ -320,16 +318,6 @@ public class CodeGenerator
epilogue(func, saveRegs, lvarBytes);
}
protected long savedRegsSize(List<Register> regs) {
long numReallySaved = 0;
for (Register reg : regs) {
if (! reg.baseName().equals("bp")) {
numReallySaved++;
}
}
return numReallySaved * stackWordSize;
}
protected List<Assembly> compileStmts(DefinedFunction func) {
pushAssembler();
currentFunction = func;
@ -430,11 +418,11 @@ public class CodeGenerator
// #@@range/prologue{
protected void prologue(DefinedFunction func,
List<Register> saveRegs,
long frameSize) {
truePush(bp());
long lvarBytes) {
push(bp());
mov(sp(), bp());
saveRegisters(saveRegs);
allocateStack(frameSize);
extendStack(lvarBytes);
if (options.isVerboseAsm()) {
for (DefinedVariable var : func.localVariables()) {
comment("mem " + var.memref() + ": " + var.name());
@ -447,10 +435,10 @@ public class CodeGenerator
protected void epilogue(DefinedFunction func,
List<Register> savedRegs,
long lvarBytes) {
//shrinkStack(lvarBytes);
shrinkStack(lvarBytes);
restoreRegisters(savedRegs);
mov(bp(), sp());
truePop(bp());
pop(bp());
ret();
}
// #@@}
@ -501,9 +489,10 @@ public class CodeGenerator
* Returns byte-length of the local variable area.
* Note that numSavedRegs includes bp.
*/
protected long allocateLocalVariables(LocalScope scope, long offset) {
long maxLen = allocateScope(scope, offset);
return maxLen - offset;
protected long allocateLocalVariables(LocalScope scope, long numSavedRegs) {
long initLen = (numSavedRegs - 1) * stackWordSize;
long maxLen = allocateScope(scope, initLen);
return maxLen - initLen;
}
protected long allocateScope(LocalScope scope, long parentStackLen) {
@ -532,60 +521,15 @@ public class CodeGenerator
memref.fixOffset(offset);
}
protected void allocateStack(long len) {
if (len > 0) {
if (stackGrowsLower) {
sub(imm(len), sp());
}
else {
add(imm(len), sp());
}
}
}
protected long stackPointer;
protected long stackPointerMax;
protected void initStackParams() {
stackPointer = 0;
stackPointerMax = stackPointer;
}
protected long maxStackLength() {
return stackPointerMax;
}
protected IndirectMemoryReference stackTop() {
if (stackGrowsLower) {
return mem(-stackPointer, bp());
}
else {
return mem(stackPointer - stackWordSize, bp());
}
}
protected void push(Register reg) {
extendStack(stackWordSize);
as.relocatableMov(reg, stackTop());
}
protected void pop(Register reg) {
as.relocatableMov(stackTop(), reg);
rewindStack(stackWordSize);
}
protected void extendStack(long len) {
stackPointer += len;
stackPointerMax = Math.max(stackPointerMax, stackPointer);
if (len > 0) {
add(imm(len * (stackGrowsLower ? -1 : 1)), sp());
}
}
protected void rewindStack(long len) {
stackPointer -= len;
}
protected void fixStackOffsets(List<Assembly> asms, long offset) {
for (Assembly asm : asms) {
asm.fixStackOffset(offset * (stackGrowsLower ? -1 : 1));
protected void shrinkStack(long len) {
if (len > 0) {
add(imm(len * (stackGrowsLower ? 1 : -1)), sp());
}
}
@ -597,12 +541,9 @@ public class CodeGenerator
public void visit(FuncallNode node) {
// compile function arguments from right to left.
ListIterator<ExprNode> args = node.finalArg();
long argIndex = node.numArgs() - 1;
while (args.hasPrevious()) {
compile(args.previous());
mov(reg("ax"), argMemory(argIndex));
argIndex--;
extendStack(stackWordSize);
push(reg("ax"));
}
// call
if (node.isStaticCall()) {
@ -616,16 +557,7 @@ public class CodeGenerator
}
// rewind stack
// >4 bytes arguments are not supported.
rewindStack(node.numArgs() * stackWordSize);
}
protected IndirectMemoryReference argMemory(long argIndex) {
if (stackGrowsLower) {
return mem(stackWordSize * argIndex, sp());
}
else {
return mem(-stackWordSize * (argIndex + 1), sp());
}
shrinkStack(node.numArgs() * stackWordSize);
}
public void visit(ReturnNode node) {
@ -1316,8 +1248,8 @@ public class CodeGenerator
public void setl(Register reg) { as.setl(reg); }
public void setle(Register reg) { as.setle(reg); }
public void test(Type type, Register a, Register b) { as.test(type, a, b); }
protected void truePush(Register reg) { as.push(reg); }
protected void truePop(Register reg) { as.pop(reg); }
public void push(Register reg) { as.push(reg); }
public void pop(Register reg) { as.pop(reg); }
public void call(Symbol sym) { as.call(sym); }
public void callAbsolute(Register reg) { as.callAbsolute(reg); }
public void ret() { as.ret(); }