r4892@macbookpro: aamine | 2009-05-24 00:41:44 +0900

* net/loveruby/cflat/ir: rename class: BranchIf -> CJump.
 * net/loveruby/cflat/ir/IRVisitor.java: follow it.
 * net/loveruby/cflat/compiler/IRGenerator.java: ditto.
 * net/loveruby/cflat/sysdep/x86/CodeGenerator.java: ditto.
 


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4234 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2009-05-23 16:18:03 +00:00
parent 1e3eae4634
commit 0f12ee78f1
5 changed files with 25 additions and 16 deletions

View File

@ -1,3 +1,13 @@
Sun May 24 00:42:28 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/ir: rename class: BranchIf -> CJump.
* net/loveruby/cflat/ir/IRVisitor.java: follow it.
* net/loveruby/cflat/compiler/IRGenerator.java: ditto.
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: ditto.
Sun May 24 00:01:07 2009 Minero Aoki <aamine@loveruby.net> Sun May 24 00:01:07 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/IRGenerator.java: refactoring: * net/loveruby/cflat/compiler/IRGenerator.java: refactoring:

View File

@ -166,7 +166,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
Label elseLabel = new Label(); Label elseLabel = new Label();
Label endLabel = new Label(); Label endLabel = new Label();
branch(node.location(), cjump(node.location(),
transformExpr(node.cond()), transformExpr(node.cond()),
thenLabel, thenLabel,
node.elseBody() == null ? endLabel : elseLabel); node.elseBody() == null ? endLabel : elseLabel);
@ -222,7 +222,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
Label endLabel = new Label(); Label endLabel = new Label();
label(begLabel); label(begLabel);
branch(node.location(), cjump(node.location(),
transformExpr(node.cond()), bodyLabel, endLabel); transformExpr(node.cond()), bodyLabel, endLabel);
label(bodyLabel); label(bodyLabel);
pushContinue(begLabel); pushContinue(begLabel);
@ -248,7 +248,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
popBreak(); popBreak();
popContinue(); popContinue();
label(contLabel); label(contLabel);
branch(node.location(), transformExpr(node.cond()), begLabel, endLabel); cjump(node.location(), transformExpr(node.cond()), begLabel, endLabel);
label(endLabel); label(endLabel);
return null; return null;
} }
@ -261,7 +261,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
transformStmt(node.init()); transformStmt(node.init());
label(begLabel); label(begLabel);
branch(node.location(), cjump(node.location(),
transformExpr(node.cond()), bodyLabel, endLabel); transformExpr(node.cond()), bodyLabel, endLabel);
label(bodyLabel); label(bodyLabel);
pushContinue(contLabel); pushContinue(contLabel);
@ -321,8 +321,8 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
return null; return null;
} }
private void branch(Location loc, Expr cond, Label thenLabel, Label elseLabel) { private void cjump(Location loc, Expr cond, Label thenLabel, Label elseLabel) {
stmts.add(new BranchIf(loc, cond, thenLabel, elseLabel)); stmts.add(new CJump(loc, cond, thenLabel, elseLabel));
} }
private void assign(Location loc, Expr lhs, Expr rhs) { private void assign(Location loc, Expr lhs, Expr rhs) {
@ -399,7 +399,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
DefinedVariable var = tmpVar(node.type()); DefinedVariable var = tmpVar(node.type());
Expr cond = transformExpr(node.cond()); Expr cond = transformExpr(node.cond());
branch(node.location(), cond, thenLabel, elseLabel); cjump(node.location(), cond, thenLabel, elseLabel);
label(thenLabel); label(thenLabel);
assign(node.thenExpr().location(), assign(node.thenExpr().location(),
ref(var), transformExpr(node.thenExpr())); ref(var), transformExpr(node.thenExpr()));
@ -419,7 +419,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
assign(node.left().location(), assign(node.left().location(),
ref(var), transformExpr(node.left())); ref(var), transformExpr(node.left()));
branch(node.location(), ref(var), rightLabel, endLabel); cjump(node.location(), ref(var), rightLabel, endLabel);
label(rightLabel); label(rightLabel);
assign(node.right().location(), assign(node.right().location(),
ref(var), transformExpr(node.right())); ref(var), transformExpr(node.right()));
@ -434,7 +434,7 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
assign(node.left().location(), assign(node.left().location(),
ref(var), transformExpr(node.left())); ref(var), transformExpr(node.left()));
branch(node.location(), ref(var), endLabel, rightLabel); cjump(node.location(), ref(var), endLabel, rightLabel);
label(rightLabel); label(rightLabel);
assign(node.right().location(), assign(node.right().location(),
ref(var), transformExpr(node.right())); ref(var), transformExpr(node.right()));

View File

@ -2,13 +2,12 @@ package net.loveruby.cflat.ir;
import net.loveruby.cflat.ast.Location; import net.loveruby.cflat.ast.Location;
import net.loveruby.cflat.asm.Label; import net.loveruby.cflat.asm.Label;
public class BranchIf extends Stmt { public class CJump extends Stmt {
protected Expr cond; protected Expr cond;
protected Label thenLabel; protected Label thenLabel;
protected Label elseLabel; protected Label elseLabel;
public BranchIf(Location loc, Expr cond, public CJump(Location loc, Expr cond, Label thenLabel, Label elseLabel) {
Label thenLabel, Label elseLabel) {
super(loc); super(loc);
this.cond = cond; this.cond = cond;
this.thenLabel = thenLabel; this.thenLabel = thenLabel;

View File

@ -3,10 +3,10 @@ package net.loveruby.cflat.ir;
public interface IRVisitor<S,E> { public interface IRVisitor<S,E> {
public S visit(ExprStmt s); public S visit(ExprStmt s);
public S visit(Assign s); public S visit(Assign s);
public S visit(BranchIf s); public S visit(CJump s);
public S visit(Jump s);
public S visit(Switch s); public S visit(Switch s);
public S visit(LabelStmt s); public S visit(LabelStmt s);
public S visit(Jump s);
public S visit(Return s); public S visit(Return s);
public E visit(Uni s); public E visit(Uni s);

View File

@ -697,8 +697,8 @@ public class CodeGenerator
} }
// #@@} // #@@}
// #@@range/compile_BranchIf{ // #@@range/compile_CJump{
public Void visit(BranchIf node) { public Void visit(CJump node) {
compile(node.cond()); compile(node.cond());
testCond(node.cond().type(), ax()); testCond(node.cond().type(), ax());
as.jnz(node.thenLabel()); as.jnz(node.thenLabel());