cbc/net/loveruby/cflat/asm/IndirectMemoryReference.java

58 lines
1.4 KiB
Java

package net.loveruby.cflat.asm;
public class IndirectMemoryReference extends MemoryReference {
protected Literal offset;
protected Register base;
protected boolean fixed;
public IndirectMemoryReference(Register base) {
this.offset = new IntegerLiteral(0);
this.base = base;
this.fixed = false;
}
public IndirectMemoryReference(long offset, Register base) {
this.offset = new IntegerLiteral(offset);
this.base = base;
this.fixed = true;
}
public IndirectMemoryReference(Symbol offset, Register base) {
this.offset = offset;
this.base = base;
this.fixed = true;
}
public Literal offset() {
return offset;
}
public void fixOffset(long realOffset) {
if (fixed) {
throw new Error("must not happen: fixed = true");
}
this.offset = new IntegerLiteral(realOffset);
this.fixed = true;
}
public Register base() {
return base;
}
public void collectStatistics(AsmStatistics stats) {
base.collectStatistics(stats);
}
public String toString() {
return toSource(SymbolTable.dummy());
}
public String toSource(SymbolTable table) {
if (! fixed) {
throw new Error("must not happen: writing unfixed variable");
}
return (offset.isZero() ? "" : offset.toSource(table))
+ "(" + base.toSource(table) + ")";
}
}