* net/loveruby/cflat/compiler/IRGenerator.java (BlockNode): static variables are special case.

* net/loveruby/cflat/compiler/IRGenerator.java (SwitchNode): Switch must precedes Case bodies to prevent programs from infinite loop.
* net/loveruby/cflat/compiler/CodeGenerator.java (Bin): fix MOD problem.
* net/loveruby/cflat/compiler/CodeGenerator.java (Bin): fix LSHIFT problem.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4155 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2009-04-26 13:41:19 +00:00
parent 0b3098612a
commit 04f5d8e6cc
4 changed files with 37 additions and 19 deletions

View File

@ -1,3 +1,18 @@
Sun Apr 26 22:41:08 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/IRGenerator.java (BlockNode): static
variables are special case.
* net/loveruby/cflat/compiler/IRGenerator.java (SwitchNode):
Switch must precedes Case bodies to prevent programs from infinite
loop.
* net/loveruby/cflat/compiler/CodeGenerator.java (Bin): fix MOD
problem.
* net/loveruby/cflat/compiler/CodeGenerator.java (Bin): fix LSHIFT
problem.
Sun Apr 26 22:08:35 2009 Minero Aoki <aamine@loveruby.net>
* now IR nodes are separated from AST. Sources are compilable but

View File

@ -3,7 +3,7 @@ import net.loveruby.cflat.asm.Label;
import java.util.*;
public class CaseNode extends StmtNode {
protected Label beginLabel;
protected Label label;
protected List<ExprNode> values;
protected BlockNode body;
@ -11,17 +11,13 @@ public class CaseNode extends StmtNode {
super(loc);
this.values = values;
this.body = body;
this.beginLabel = new Label();
this.label = new Label();
}
public List<ExprNode> values() {
return values;
}
public void setValues(List<ExprNode> values) {
this.values = values;
}
public boolean isDefault() {
return values.isEmpty();
}
@ -30,8 +26,8 @@ public class CaseNode extends StmtNode {
return body;
}
public Label beginLabel() {
return beginLabel;
public Label label() {
return label;
}
protected void _dump(Dumper d) {

View File

@ -905,7 +905,7 @@ public class CodeGenerator implements IRVisitor<Void,Void>, ELFConstants {
mov(imm(0), reg("dx"));
div(t, reg("cx", t));
}
if (op.equals("%")) {
if (op == Op.MOD) {
mov(reg("dx"), reg("ax"));
}
break;
@ -930,6 +930,7 @@ public class CodeGenerator implements IRVisitor<Void,Void>, ELFConstants {
break;
case LSHIFT:
sal(t, cl(), reg("ax", t));
break;
// #@@}
// #@@range/compileBinaryOp_cmpops{
default:

View File

@ -149,8 +149,14 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
public Void visit(BlockNode node) {
for (DefinedVariable var : node.variables()) {
if (var.initializer() != null) {
assign(var.location(), ref(var), transform(var.initializer()));
if (var.hasInitializer()) {
if (var.isPrivate()) {
// static variables
var.setIR(transform(var.initializer()));
}
else {
assign(var.location(), ref(var), transform(var.initializer()));
}
}
}
scopeStack.add(node.scope());
@ -193,25 +199,25 @@ class IRGenerator implements ASTVisitor<Void, Expr> {
Label defaultLabel = endLabel;
Expr cond = transform(node.cond());
pushBreak(endLabel);
for (CaseNode c : node.cases()) {
Label caseLabel = new Label();
label(caseLabel);
transform(c.body());
if (c.isDefault()) {
defaultLabel = caseLabel;
defaultLabel = c.label();
}
else {
for (ExprNode val : c.values()) {
Expr v = transform(val);
cases.add(new Case(((IntValue)v).value(), caseLabel));
cases.add(new Case(((IntValue)v).value(), c.label()));
}
}
}
stmts.add(new Switch(node.location(), cond, cases, defaultLabel, endLabel));
pushBreak(endLabel);
for (CaseNode c : node.cases()) {
label(c.label());
transform(c.body());
}
popBreak();
label(endLabel);
stmts.add(new Switch(node.location(), cond, cases, defaultLabel, endLabel));
return null;
}