mirror of https://github.com/aamine/cbc
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring: reorder methods.
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring: inlining #testCond. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4248 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
b9ad38ef16
commit
64e91a4737
|
@ -1,3 +1,11 @@
|
||||||
|
Sun May 24 22:44:07 2009 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring:
|
||||||
|
reorder methods.
|
||||||
|
|
||||||
|
* net/loveruby/cflat/sysdep/x86/CodeGenerator.java: refactoring:
|
||||||
|
inlining #testCond.
|
||||||
|
|
||||||
Sun May 24 21:57:04 2009 Minero Aoki <aamine@loveruby.net>
|
Sun May 24 21:57:04 2009 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* net/loveruby/cflat/compiler/IRGenerator.java: do not use
|
* net/loveruby/cflat/compiler/IRGenerator.java: do not use
|
||||||
|
|
|
@ -642,7 +642,7 @@ public class CodeGenerator
|
||||||
* * All arguments are on stack.
|
* * All arguments are on stack.
|
||||||
* * Caller rewinds stack pointer.
|
* * Caller rewinds stack pointer.
|
||||||
*/
|
*/
|
||||||
// #@@range/compile_Funcall{
|
// #@@range/Funcall{
|
||||||
public Void visit(Call node) {
|
public Void visit(Call node) {
|
||||||
for (Expr arg : ListUtils.reverse(node.args())) {
|
for (Expr arg : ListUtils.reverse(node.args())) {
|
||||||
compile(arg);
|
compile(arg);
|
||||||
|
@ -661,7 +661,7 @@ public class CodeGenerator
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
|
|
||||||
// #@@range/compile_Return{
|
// #@@range/Return{
|
||||||
public Void visit(Return node) {
|
public Void visit(Return node) {
|
||||||
if (node.expr() != null) {
|
if (node.expr() != null) {
|
||||||
compile(node.expr());
|
compile(node.expr());
|
||||||
|
@ -686,28 +686,38 @@ public class CodeGenerator
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
|
|
||||||
|
// #@@range/Stmt{
|
||||||
public Void visit(ExprStmt stmt) {
|
public Void visit(ExprStmt stmt) {
|
||||||
compile(stmt.expr());
|
compile(stmt.expr());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// #@@}
|
||||||
|
|
||||||
// #@@range/testCond{
|
// #@@range/LabelStmt{
|
||||||
private void testCond(Type t, Register reg) {
|
public Void visit(LabelStmt node) {
|
||||||
as.test(t, reg.forType(t), reg.forType(t));
|
as.label(node.label());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
|
|
||||||
// #@@range/compile_CJump{
|
// #@@range/Jump{
|
||||||
|
public Void visit(Jump node) {
|
||||||
|
as.jmp(node.label());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// #@@}
|
||||||
|
|
||||||
|
// #@@range/CJump{
|
||||||
public Void visit(CJump node) {
|
public Void visit(CJump node) {
|
||||||
compile(node.cond());
|
compile(node.cond());
|
||||||
testCond(node.cond().type(), ax());
|
Type t = node.cond().type();
|
||||||
|
as.test(t, ax(t), ax(t));
|
||||||
as.jnz(node.thenLabel());
|
as.jnz(node.thenLabel());
|
||||||
as.jmp(node.elseLabel());
|
as.jmp(node.elseLabel());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// #@@}
|
// #@@}
|
||||||
|
|
||||||
// #@@range/compile_Switch{
|
|
||||||
public Void visit(Switch node) {
|
public Void visit(Switch node) {
|
||||||
compile(node.cond());
|
compile(node.cond());
|
||||||
Type t = node.cond().type();
|
Type t = node.cond().type();
|
||||||
|
@ -719,21 +729,6 @@ public class CodeGenerator
|
||||||
as.jmp(node.defaultLabel());
|
as.jmp(node.defaultLabel());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// #@@}
|
|
||||||
|
|
||||||
// #@@range/compile_LabelStmt{
|
|
||||||
public Void visit(LabelStmt node) {
|
|
||||||
as.label(node.label());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// #@@}
|
|
||||||
|
|
||||||
// #@@range/compile_Jump{
|
|
||||||
public Void visit(Jump node) {
|
|
||||||
as.jmp(node.label());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// #@@}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Expressions
|
// Expressions
|
||||||
|
@ -873,32 +868,27 @@ public class CodeGenerator
|
||||||
|
|
||||||
// #@@range/compile_Uni{
|
// #@@range/compile_Uni{
|
||||||
public Void visit(Uni node) {
|
public Void visit(Uni node) {
|
||||||
|
Type src = node.expr().type();
|
||||||
|
Type dest = node.type();
|
||||||
|
|
||||||
compile(node.expr());
|
compile(node.expr());
|
||||||
switch (node.op()) {
|
switch (node.op()) {
|
||||||
case UMINUS:
|
case UMINUS:
|
||||||
as.neg(node.expr().type(), ax(node.expr().type()));
|
as.neg(src, ax(src));
|
||||||
break;
|
break;
|
||||||
case BIT_NOT:
|
case BIT_NOT:
|
||||||
as.not(node.expr().type(), ax(node.expr().type()));
|
as.not(src, ax(src));
|
||||||
break;
|
break;
|
||||||
case NOT:
|
case NOT:
|
||||||
testCond(node.expr().type(), ax());
|
as.test(src, ax(src), ax(dest));
|
||||||
as.sete(al());
|
as.sete(al());
|
||||||
as.movzbl(al(), ax());
|
as.movzbl(al(), ax());
|
||||||
break;
|
break;
|
||||||
case S_CAST:
|
case S_CAST:
|
||||||
{
|
as.movsx(src, dest, ax(src), ax(dest));
|
||||||
Type src = node.expr().type();
|
|
||||||
Type dest = node.type();
|
|
||||||
as.movsx(src, dest, ax(src), ax(dest));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case U_CAST:
|
case U_CAST:
|
||||||
{
|
as.movzx(src, dest, ax(src), ax(dest));
|
||||||
Type src = node.expr().type();
|
|
||||||
Type dest = node.type();
|
|
||||||
as.movzx(src, dest, ax(src), ax(dest));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("unknown unary operator: " + node.op());
|
throw new Error("unknown unary operator: " + node.op());
|
||||||
|
|
Loading…
Reference in New Issue