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>
|
||||
|
||||
* net/loveruby/cflat/compiler/IRGenerator.java: do not use
|
||||
|
|
|
@ -642,7 +642,7 @@ public class CodeGenerator
|
|||
* * All arguments are on stack.
|
||||
* * Caller rewinds stack pointer.
|
||||
*/
|
||||
// #@@range/compile_Funcall{
|
||||
// #@@range/Funcall{
|
||||
public Void visit(Call node) {
|
||||
for (Expr arg : ListUtils.reverse(node.args())) {
|
||||
compile(arg);
|
||||
|
@ -661,7 +661,7 @@ public class CodeGenerator
|
|||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/compile_Return{
|
||||
// #@@range/Return{
|
||||
public Void visit(Return node) {
|
||||
if (node.expr() != null) {
|
||||
compile(node.expr());
|
||||
|
@ -686,28 +686,38 @@ public class CodeGenerator
|
|||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/Stmt{
|
||||
public Void visit(ExprStmt stmt) {
|
||||
compile(stmt.expr());
|
||||
return null;
|
||||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/testCond{
|
||||
private void testCond(Type t, Register reg) {
|
||||
as.test(t, reg.forType(t), reg.forType(t));
|
||||
// #@@range/LabelStmt{
|
||||
public Void visit(LabelStmt node) {
|
||||
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) {
|
||||
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.jmp(node.elseLabel());
|
||||
return null;
|
||||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/compile_Switch{
|
||||
public Void visit(Switch node) {
|
||||
compile(node.cond());
|
||||
Type t = node.cond().type();
|
||||
|
@ -719,21 +729,6 @@ public class CodeGenerator
|
|||
as.jmp(node.defaultLabel());
|
||||
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
|
||||
|
@ -873,32 +868,27 @@ public class CodeGenerator
|
|||
|
||||
// #@@range/compile_Uni{
|
||||
public Void visit(Uni node) {
|
||||
Type src = node.expr().type();
|
||||
Type dest = node.type();
|
||||
|
||||
compile(node.expr());
|
||||
switch (node.op()) {
|
||||
case UMINUS:
|
||||
as.neg(node.expr().type(), ax(node.expr().type()));
|
||||
as.neg(src, ax(src));
|
||||
break;
|
||||
case BIT_NOT:
|
||||
as.not(node.expr().type(), ax(node.expr().type()));
|
||||
as.not(src, ax(src));
|
||||
break;
|
||||
case NOT:
|
||||
testCond(node.expr().type(), ax());
|
||||
as.test(src, ax(src), ax(dest));
|
||||
as.sete(al());
|
||||
as.movzbl(al(), ax());
|
||||
break;
|
||||
case S_CAST:
|
||||
{
|
||||
Type src = node.expr().type();
|
||||
Type dest = node.type();
|
||||
as.movsx(src, dest, ax(src), ax(dest));
|
||||
}
|
||||
break;
|
||||
case U_CAST:
|
||||
{
|
||||
Type src = node.expr().type();
|
||||
Type dest = node.type();
|
||||
as.movzx(src, dest, ax(src), ax(dest));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("unknown unary operator: " + node.op());
|
||||
|
|
Loading…
Reference in New Issue