From b9ad38ef165a1daeb0f0743a16def5e50e916a27 Mon Sep 17 00:00:00 2001 From: Minero Aoki Date: Sun, 24 May 2009 12:56:38 +0000 Subject: [PATCH] r4942@macbookpro: aamine | 2009-05-24 21:56:17 +0900 * net/loveruby/cflat/compiler/IRGenerator.java: do not use Expr#isConstantAddress, it confuses semantics. * net/loveruby/cflat/sysdep/x86/CodeGenerator.java: ditto. * net/loveruby/cflat/ir/Expr.java: introduce new methods #isVar and #isAddr, instead of #isConstantAddress. * net/loveruby/cflat/ir/Addr.java: override #isAddr. * net/loveruby/cflat/ir/Var.java: override #isVar. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4247 1b9489fe-b721-0410-924e-b54b9192deb8 --- ChangeLog | 14 ++++++++++++++ net/loveruby/cflat/compiler/IRGenerator.java | 4 ++-- net/loveruby/cflat/ir/Addr.java | 2 +- net/loveruby/cflat/ir/Expr.java | 15 ++++++--------- net/loveruby/cflat/ir/Var.java | 2 ++ net/loveruby/cflat/sysdep/x86/CodeGenerator.java | 4 ++-- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd7d4ca..8d47230 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Sun May 24 21:57:04 2009 Minero Aoki + + * net/loveruby/cflat/compiler/IRGenerator.java: do not use + Expr#isConstantAddress, it confuses semantics. + + * net/loveruby/cflat/sysdep/x86/CodeGenerator.java: ditto. + + * net/loveruby/cflat/ir/Expr.java: introduce new methods #isVar + and #isAddr, instead of #isConstantAddress. + + * net/loveruby/cflat/ir/Addr.java: override #isAddr. + + * net/loveruby/cflat/ir/Var.java: override #isVar. + Sun May 24 21:54:57 2009 Minero Aoki * net/loveruby/cflat/ast: remove useless methods: diff --git a/net/loveruby/cflat/compiler/IRGenerator.java b/net/loveruby/cflat/compiler/IRGenerator.java index 6508d37..fb035dd 100644 --- a/net/loveruby/cflat/compiler/IRGenerator.java +++ b/net/loveruby/cflat/compiler/IRGenerator.java @@ -532,7 +532,7 @@ class IRGenerator implements ASTVisitor { transformOpAssign(loc, op, t, expr, imm(t, 1)); return null; } - else if (expr.isConstantAddress()) { + else if (expr.isVar()) { // cont(expr++) -> v = expr; expr = v + 1; cont(v) DefinedVariable v = tmpVar(t); assign(loc, ref(v), expr); @@ -556,7 +556,7 @@ class IRGenerator implements ASTVisitor { // #@@range/transformOpAssign{ private Expr transformOpAssign(Location loc, Op op, Type lhsType, Expr lhs, Expr rhs) { - if (lhs.isConstantAddress()) { + if (lhs.isVar()) { // cont(lhs += rhs) -> lhs = lhs + rhs; cont(lhs) assign(loc, lhs, bin(op, lhsType, lhs, rhs)); return isStatement() ? null : lhs; diff --git a/net/loveruby/cflat/ir/Addr.java b/net/loveruby/cflat/ir/Addr.java index 043ce90..33f32ab 100644 --- a/net/loveruby/cflat/ir/Addr.java +++ b/net/loveruby/cflat/ir/Addr.java @@ -12,7 +12,7 @@ public class Addr extends Expr { this.entity = entity; } - public boolean isConstantAddress() { return true; } + public boolean isAddr() { return true; } public Entity entity() { return entity; } diff --git a/net/loveruby/cflat/ir/Expr.java b/net/loveruby/cflat/ir/Expr.java index 89bb304..6f590e7 100644 --- a/net/loveruby/cflat/ir/Expr.java +++ b/net/loveruby/cflat/ir/Expr.java @@ -3,26 +3,23 @@ import net.loveruby.cflat.asm.*; import net.loveruby.cflat.entity.Entity; abstract public class Expr implements Dumpable { - protected Type type; + final Type type; - protected Expr(Type type) { + Expr(Type type) { this.type = type; } public Type type() { return type; } - public boolean isConstant() { - return false; - } + public boolean isVar() { return false; } + public boolean isAddr() { return false; } + + public boolean isConstant() { return false; } public ImmediateValue asmValue() { throw new Error("Expr#asmValue called"); } - public boolean isConstantAddress() { - return false; - } - public AsmOperand address() { throw new Error("Expr#address called"); } diff --git a/net/loveruby/cflat/ir/Var.java b/net/loveruby/cflat/ir/Var.java index 39d26ed..81cb532 100644 --- a/net/loveruby/cflat/ir/Var.java +++ b/net/loveruby/cflat/ir/Var.java @@ -12,6 +12,8 @@ public class Var extends Expr { this.entity = entity; } + public boolean isVar() { return true; } + public Type type() { if (super.type() == null) { throw new Error("Var is too big to load by 1 insn"); diff --git a/net/loveruby/cflat/sysdep/x86/CodeGenerator.java b/net/loveruby/cflat/sysdep/x86/CodeGenerator.java index 634ed85..2cfc75d 100644 --- a/net/loveruby/cflat/sysdep/x86/CodeGenerator.java +++ b/net/loveruby/cflat/sysdep/x86/CodeGenerator.java @@ -760,7 +760,7 @@ public class CodeGenerator compile(node.left()); right = node.right().asmValue(); } - else if (node.right().isConstantAddress()) { + else if (node.right().isVar()) { compile(node.left()); loadVariable(((Var)node.right()), cx()); right = cx(node.type()); @@ -934,7 +934,7 @@ public class CodeGenerator // #@@range/compile_Assign{ public Void visit(Assign node) { - if (node.lhs().isConstantAddress() && node.lhs().memref() != null) { + if (node.lhs().isAddr() && node.lhs().memref() != null) { compile(node.rhs()); save(node.lhs().type(), ax(), node.lhs().memref()); }