mirror of https://github.com/aamine/cbc
* net/loveruby/cflat/asm/AsmEntity.java -> AsmOperand.java
* net/loveruby/cflat/*/*.java: AsmEntity -> AsmOperand. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4027 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
19ca32a89d
commit
de82f43658
|
|
@ -1,3 +1,9 @@
|
|||
Tue Sep 16 02:49:21 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/asm/AsmEntity.java -> AsmOperand.java
|
||||
|
||||
* net/loveruby/cflat/*/*.java: AsmEntity -> AsmOperand.
|
||||
|
||||
Tue Sep 16 02:37:46 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/asm/Address.java -> MemoryReference.java
|
||||
|
|
|
|||
1
ToDo
1
ToDo
|
|
@ -3,6 +3,7 @@
|
|||
== Current
|
||||
|
||||
* AsmEntity -> AsmOperand
|
||||
* Symbol -> LabelRef
|
||||
* reject struct/union/array on stmt context
|
||||
* -O (peephole optimization)
|
||||
* movl $0, %eax => xorl %eax, %eax
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package net.loveruby.cflat.asm;
|
||||
|
||||
public class AbsoluteAddress extends AsmEntity {
|
||||
public class AbsoluteAddress extends AsmOperand {
|
||||
protected Register register;
|
||||
|
||||
public AbsoluteAddress(Register reg) {
|
||||
this.register = reg;
|
||||
}
|
||||
|
||||
public AsmEntity register() {
|
||||
public AsmOperand register() {
|
||||
return this.register;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package net.loveruby.cflat.asm;
|
||||
|
||||
abstract public class AsmEntity {
|
||||
abstract public class AsmOperand {
|
||||
abstract public String toString();
|
||||
|
||||
public boolean isMemoryReference() {
|
||||
|
|
@ -47,23 +47,23 @@ public class Assembler {
|
|||
list.add(new Instruction(op));
|
||||
}
|
||||
|
||||
protected void insn(String op, AsmEntity a) {
|
||||
protected void insn(String op, AsmOperand a) {
|
||||
list.add(new Instruction(op, "", a));
|
||||
}
|
||||
|
||||
protected void insn(String op, String suffix, AsmEntity a) {
|
||||
protected void insn(String op, String suffix, AsmOperand a) {
|
||||
list.add(new Instruction(op, suffix, a));
|
||||
}
|
||||
|
||||
protected void insn(Type t, String op, AsmEntity a) {
|
||||
protected void insn(Type t, String op, AsmOperand a) {
|
||||
list.add(new Instruction(op, typeSuffix(t), a));
|
||||
}
|
||||
|
||||
protected void insn(String op, String suffix, AsmEntity a, AsmEntity b) {
|
||||
protected void insn(String op, String suffix, AsmOperand a, AsmOperand b) {
|
||||
list.add(new Instruction(op, suffix, a, b));
|
||||
}
|
||||
|
||||
protected void insn(Type t, String op, AsmEntity a, AsmEntity b) {
|
||||
protected void insn(Type t, String op, AsmOperand a, AsmOperand b) {
|
||||
list.add(new Instruction(op, typeSuffix(t), a, b));
|
||||
}
|
||||
|
||||
|
|
@ -251,47 +251,47 @@ public class Assembler {
|
|||
insn("ret");
|
||||
}
|
||||
|
||||
public void mov(AsmEntity src, AsmEntity dest) {
|
||||
public void mov(AsmOperand src, AsmOperand dest) {
|
||||
mov(naturalType, src, dest);
|
||||
}
|
||||
|
||||
public void mov(Type type, AsmEntity src, AsmEntity dest) {
|
||||
public void mov(Type type, AsmOperand src, AsmOperand dest) {
|
||||
insn(type, "mov", src, dest);
|
||||
}
|
||||
|
||||
public void movsx(Type t1, Type t2, AsmEntity src, AsmEntity dest) {
|
||||
public void movsx(Type t1, Type t2, AsmOperand src, AsmOperand dest) {
|
||||
insn("movs", typeSuffix(t1, t2), src, dest);
|
||||
}
|
||||
|
||||
public void movsbl(AsmEntity src, AsmEntity dest) {
|
||||
public void movsbl(AsmOperand src, AsmOperand dest) {
|
||||
insn("movs", "bl", src, dest);
|
||||
}
|
||||
|
||||
public void movswl(AsmEntity src, AsmEntity dest) {
|
||||
public void movswl(AsmOperand src, AsmOperand dest) {
|
||||
insn("movs", "wl", src, dest);
|
||||
}
|
||||
|
||||
public void movzx(Type t1, Type t2, AsmEntity src, AsmEntity dest) {
|
||||
public void movzx(Type t1, Type t2, AsmOperand src, AsmOperand dest) {
|
||||
insn("movz", typeSuffix(t1, t2), src, dest);
|
||||
}
|
||||
|
||||
public void movzb(Type t, AsmEntity src, AsmEntity dest) {
|
||||
public void movzb(Type t, AsmOperand src, AsmOperand dest) {
|
||||
insn("movz", "b" + typeSuffix(t), src, dest);
|
||||
}
|
||||
|
||||
public void movzbl(AsmEntity src, AsmEntity dest) {
|
||||
public void movzbl(AsmOperand src, AsmOperand dest) {
|
||||
insn("movz", "bl", src, dest);
|
||||
}
|
||||
|
||||
public void movzwl(AsmEntity src, AsmEntity dest) {
|
||||
public void movzwl(AsmOperand src, AsmOperand dest) {
|
||||
insn("movz", "wl", src, dest);
|
||||
}
|
||||
|
||||
public void lea(AsmEntity src, AsmEntity dest) {
|
||||
public void lea(AsmOperand src, AsmOperand dest) {
|
||||
lea(naturalType, src, dest);
|
||||
}
|
||||
|
||||
public void lea(Type type, AsmEntity src, AsmEntity dest) {
|
||||
public void lea(Type type, AsmOperand src, AsmOperand dest) {
|
||||
insn(type, "lea", src, dest);
|
||||
}
|
||||
|
||||
|
|
@ -299,35 +299,35 @@ public class Assembler {
|
|||
insn(type, "neg", reg);
|
||||
}
|
||||
|
||||
public void inc(Type type, AsmEntity reg) {
|
||||
public void inc(Type type, AsmOperand reg) {
|
||||
insn(type, "inc", reg);
|
||||
}
|
||||
|
||||
public void dec(Type type, AsmEntity reg) {
|
||||
public void dec(Type type, AsmOperand reg) {
|
||||
insn(type, "dec", reg);
|
||||
}
|
||||
|
||||
public void add(AsmEntity diff, AsmEntity base) {
|
||||
public void add(AsmOperand diff, AsmOperand base) {
|
||||
add(naturalType, diff, base);
|
||||
}
|
||||
|
||||
public void add(Type type, AsmEntity diff, AsmEntity base) {
|
||||
public void add(Type type, AsmOperand diff, AsmOperand base) {
|
||||
insn(type, "add", diff, base);
|
||||
}
|
||||
|
||||
public void sub(AsmEntity diff, AsmEntity base) {
|
||||
public void sub(AsmOperand diff, AsmOperand base) {
|
||||
sub(naturalType, diff, base);
|
||||
}
|
||||
|
||||
public void sub(Type type, AsmEntity diff, AsmEntity base) {
|
||||
public void sub(Type type, AsmOperand diff, AsmOperand base) {
|
||||
insn(type, "sub", diff, base);
|
||||
}
|
||||
|
||||
public void imul(AsmEntity m, Register base) {
|
||||
public void imul(AsmOperand m, Register base) {
|
||||
imul(naturalType, m, base);
|
||||
}
|
||||
|
||||
public void imul(Type type, AsmEntity m, Register base) {
|
||||
public void imul(Type type, AsmOperand m, Register base) {
|
||||
insn(type, "imul", m, base);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package net.loveruby.cflat.asm;
|
||||
|
||||
public class ImmediateValue extends AsmEntity {
|
||||
protected AsmEntity entity;
|
||||
public class ImmediateValue extends AsmOperand {
|
||||
protected AsmOperand entity;
|
||||
|
||||
public ImmediateValue(long n) {
|
||||
this(new IntegerLiteral(n));
|
||||
|
|
@ -11,11 +11,11 @@ public class ImmediateValue extends AsmEntity {
|
|||
this(new Symbol(label));
|
||||
}
|
||||
|
||||
public ImmediateValue(AsmEntity entity) {
|
||||
public ImmediateValue(AsmOperand entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public AsmEntity entity() {
|
||||
public AsmOperand entity() {
|
||||
return this.entity;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,22 +4,22 @@ import net.loveruby.cflat.type.Type;
|
|||
public class Instruction extends Assembly {
|
||||
protected String mnemonic;
|
||||
protected String suffix;
|
||||
protected AsmEntity[] operands;
|
||||
protected AsmOperand[] operands;
|
||||
|
||||
public Instruction(String mnemonic) {
|
||||
this(mnemonic, "", new AsmEntity[0]);
|
||||
this(mnemonic, "", new AsmOperand[0]);
|
||||
}
|
||||
|
||||
public Instruction(String mnemonic, String suffix, AsmEntity a1) {
|
||||
this(mnemonic, suffix, new AsmEntity[] { a1 });
|
||||
public Instruction(String mnemonic, String suffix, AsmOperand a1) {
|
||||
this(mnemonic, suffix, new AsmOperand[] { a1 });
|
||||
}
|
||||
|
||||
public Instruction(String mnemonic, String suffix,
|
||||
AsmEntity a1, AsmEntity a2) {
|
||||
this(mnemonic, suffix, new AsmEntity[] { a1, a2 });
|
||||
AsmOperand a1, AsmOperand a2) {
|
||||
this(mnemonic, suffix, new AsmOperand[] { a1, a2 });
|
||||
}
|
||||
|
||||
public Instruction(String mnemonic, String suffix, AsmEntity[] operands) {
|
||||
public Instruction(String mnemonic, String suffix, AsmOperand[] operands) {
|
||||
this.mnemonic = mnemonic;
|
||||
this.suffix = suffix;
|
||||
this.operands = operands;
|
||||
|
|
@ -37,11 +37,11 @@ public class Instruction extends Assembly {
|
|||
return this.operands.length;
|
||||
}
|
||||
|
||||
public AsmEntity operand1() {
|
||||
public AsmOperand operand1() {
|
||||
return this.operands[0];
|
||||
}
|
||||
|
||||
public AsmEntity operand2() {
|
||||
public AsmOperand operand2() {
|
||||
return this.operands[1];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package net.loveruby.cflat.asm;
|
||||
|
||||
abstract public class Literal extends AsmEntity {
|
||||
abstract public class Literal extends AsmOperand {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package net.loveruby.cflat.asm;
|
||||
|
||||
abstract public class MemoryReference extends AsmEntity {
|
||||
abstract public class MemoryReference extends AsmOperand {
|
||||
public boolean isMemoryReference() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package net.loveruby.cflat.asm;
|
||||
import net.loveruby.cflat.type.*;
|
||||
|
||||
public class Register extends AsmEntity {
|
||||
public class Register extends AsmOperand {
|
||||
protected int size;
|
||||
protected String name;
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class CastNode extends ExprNode {
|
|||
return expr.memref();
|
||||
}
|
||||
|
||||
public AsmEntity address() {
|
||||
public AsmOperand address() {
|
||||
return expr.address();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package net.loveruby.cflat.ast;
|
||||
import net.loveruby.cflat.asm.AsmEntity;
|
||||
import net.loveruby.cflat.asm.AsmOperand;
|
||||
import net.loveruby.cflat.asm.Label;
|
||||
|
||||
public class ConstantEntry
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class DefinedVariable extends Variable {
|
|||
return memref;
|
||||
}
|
||||
|
||||
public AsmEntity address() {
|
||||
public AsmOperand address() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ abstract public class Entity extends Node {
|
|||
}
|
||||
|
||||
abstract public MemoryReference memref();
|
||||
abstract public AsmEntity address();
|
||||
abstract public AsmOperand address();
|
||||
|
||||
public Location location() {
|
||||
return typeNode.location();
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ abstract public class ExprNode extends Node {
|
|||
throw new Error("ExprNode#isConstantAddress called");
|
||||
}
|
||||
|
||||
public AsmEntity address() {
|
||||
public AsmOperand address() {
|
||||
throw new Error("ExprNode#address called");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ abstract public class Function extends Entity {
|
|||
return null;
|
||||
}
|
||||
|
||||
public AsmEntity address() {
|
||||
public AsmOperand address() {
|
||||
return new ImmediateValue(new Label(name()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package net.loveruby.cflat.ast;
|
||||
import net.loveruby.cflat.type.*;
|
||||
import net.loveruby.cflat.asm.AsmEntity;
|
||||
import net.loveruby.cflat.asm.AsmOperand;
|
||||
import net.loveruby.cflat.exception.*;
|
||||
|
||||
public class MemberNode extends ExprNode {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class UndefinedVariable extends Variable {
|
|||
return new DirectMemoryReference(new Label(symbol()));
|
||||
}
|
||||
|
||||
public AsmEntity address() {
|
||||
public AsmOperand address() {
|
||||
return new ImmediateValue(new Label(symbol()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class VariableNode extends ExprNode {
|
|||
return true;
|
||||
}
|
||||
|
||||
public AsmEntity address() {
|
||||
public AsmOperand address() {
|
||||
return entity.address();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ public class CodeGenerator extends Visitor implements ASTLHSVisitor {
|
|||
|
||||
// spills: (none)
|
||||
protected void compileUnaryArithmetic(UnaryArithmeticOpNode node,
|
||||
AsmEntity dest) {
|
||||
AsmOperand dest) {
|
||||
if (node.operator().equals("++")) {
|
||||
add(imm(node.amount()), dest);
|
||||
}
|
||||
|
|
@ -963,26 +963,26 @@ public class CodeGenerator extends Visitor implements ASTLHSVisitor {
|
|||
public void call(String sym) { as.call(sym); }
|
||||
public void callAbsolute(Register reg) { as.callAbsolute(reg); }
|
||||
public void ret() { as.ret(); }
|
||||
public void mov(AsmEntity src, AsmEntity dest) { as.mov(src, dest); }
|
||||
public void mov(Type type, AsmEntity src, AsmEntity dest) { as.mov(type, src, dest); }
|
||||
public void movsx(Type from, Type to, AsmEntity src, AsmEntity dest) { as.movsx(from, to, src, dest); }
|
||||
public void movzx(Type from, Type to, AsmEntity src, AsmEntity dest) { as.movzx(from, to, src, dest); }
|
||||
public void movsbl(AsmEntity src, AsmEntity dest) { as.movsbl(src, dest); }
|
||||
public void movswl(AsmEntity src, AsmEntity dest) { as.movswl(src, dest); }
|
||||
public void movzb(Type type, AsmEntity src, AsmEntity dest) { as.movzb(type, src, dest); }
|
||||
public void movzbl(AsmEntity src, AsmEntity dest) { as.movzbl(src, dest); }
|
||||
public void movzwl(AsmEntity src, AsmEntity dest) { as.movzwl(src, dest); }
|
||||
public void lea(AsmEntity src, AsmEntity dest) { as.lea(src, dest); }
|
||||
public void lea(Type type, AsmEntity src, AsmEntity dest) { as.lea(type, src, dest); }
|
||||
public void mov(AsmOperand src, AsmOperand dest) { as.mov(src, dest); }
|
||||
public void mov(Type type, AsmOperand src, AsmOperand dest) { as.mov(type, src, dest); }
|
||||
public void movsx(Type from, Type to, AsmOperand src, AsmOperand dest) { as.movsx(from, to, src, dest); }
|
||||
public void movzx(Type from, Type to, AsmOperand src, AsmOperand dest) { as.movzx(from, to, src, dest); }
|
||||
public void movsbl(AsmOperand src, AsmOperand dest) { as.movsbl(src, dest); }
|
||||
public void movswl(AsmOperand src, AsmOperand dest) { as.movswl(src, dest); }
|
||||
public void movzb(Type type, AsmOperand src, AsmOperand dest) { as.movzb(type, src, dest); }
|
||||
public void movzbl(AsmOperand src, AsmOperand dest) { as.movzbl(src, dest); }
|
||||
public void movzwl(AsmOperand src, AsmOperand dest) { as.movzwl(src, dest); }
|
||||
public void lea(AsmOperand src, AsmOperand dest) { as.lea(src, dest); }
|
||||
public void lea(Type type, AsmOperand src, AsmOperand dest) { as.lea(type, src, dest); }
|
||||
public void neg(Type type, Register reg) { as.neg(type, reg); }
|
||||
public void inc(Type type, AsmEntity reg) { as.inc(type, reg); }
|
||||
public void dec(Type type, AsmEntity reg) { as.dec(type, reg); }
|
||||
public void add(AsmEntity diff, AsmEntity base) { as.add(diff, base); }
|
||||
public void add(Type type, AsmEntity diff, AsmEntity base) { as.add(type, diff, base); }
|
||||
public void sub(AsmEntity diff, AsmEntity base) { as.sub(diff, base); }
|
||||
public void sub(Type type, AsmEntity diff, AsmEntity base) { as.sub(type, diff, base); }
|
||||
public void imul(AsmEntity m, Register base) { as.imul(m, base); }
|
||||
public void imul(Type type, AsmEntity m, Register base) { as.imul(type, m, base); }
|
||||
public void inc(Type type, AsmOperand reg) { as.inc(type, reg); }
|
||||
public void dec(Type type, AsmOperand reg) { as.dec(type, reg); }
|
||||
public void add(AsmOperand diff, AsmOperand base) { as.add(diff, base); }
|
||||
public void add(Type type, AsmOperand diff, AsmOperand base) { as.add(type, diff, base); }
|
||||
public void sub(AsmOperand diff, AsmOperand base) { as.sub(diff, base); }
|
||||
public void sub(Type type, AsmOperand diff, AsmOperand base) { as.sub(type, diff, base); }
|
||||
public void imul(AsmOperand m, Register base) { as.imul(m, base); }
|
||||
public void imul(Type type, AsmOperand m, Register base) { as.imul(type, m, base); }
|
||||
public void cltd() { as.cltd(); }
|
||||
public void div(Type type, Register base) { as.div(type, base); }
|
||||
public void idiv(Type type, Register base) { as.idiv(type, base); }
|
||||
|
|
|
|||
Loading…
Reference in New Issue