From 7b7d64efd6761d48aabe652945e907e9309bccd0 Mon Sep 17 00:00:00 2001 From: adam Date: Mon, 4 Jul 2005 23:50:51 +0000 Subject: [PATCH] branches pretty much work darcs-hash:20050704235051-5007d-8b7fe14efa9fd22517d281b4b6c8947ae878ba06.gz --- src/org/ibex/classgen/JSSA.java | 108 +++++++++++++++++++++++++-------------- src/org/ibex/classgen/Poop.java | 11 ++-- 2 files changed, 78 insertions(+), 41 deletions(-) diff --git a/src/org/ibex/classgen/JSSA.java b/src/org/ibex/classgen/JSSA.java index 1220b34..2fc521a 100644 --- a/src/org/ibex/classgen/JSSA.java +++ b/src/org/ibex/classgen/JSSA.java @@ -37,6 +37,7 @@ public class JSSA extends MethodGen implements CGConst { ops[numOps] = o; ofs[numOps++] = pc; } + if (o!=null && o instanceof Branch) ((Branch)o).branchTo(); if (o==null || (!(o instanceof Branch))) branchTo(pc+1); } catch(RuntimeException e) { System.err.println("Had a problem at PC: " + pc + " of " + method); @@ -47,12 +48,15 @@ public class JSSA extends MethodGen implements CGConst { } public void branchTo(int newPC) { + System.out.println("!!!branchTo("+newPC+")!!!"); if (stacks[newPC] == null) { stacks[newPC] = new Phi[sp]; for(int i=0; i>"; } } public class New extends Expr { @@ -547,6 +578,7 @@ public class JSSA extends MethodGen implements CGConst { i1 = p.i1; i2 = p.i2; } + if (arg instanceof Number) i1 = ((Integer)arg).intValue(); Label label = (arg instanceof Label) ? (Label)arg : null; switch(op) { @@ -614,26 +646,26 @@ public class JSSA extends MethodGen implements CGConst { // Control and branching ////////////////////////////////////////////////////////////////////////////// - case IFNULL: return new Branch(new Eq(pop(), new Constant(null)), new Label(i1)); - case IFNONNULL: return new Branch(new Not(new Eq(pop(),new Constant(null))),new Label(i1)); - case IFEQ: return new Branch( new Eq(new Constant(0), pop()), label); - case IFNE: return new Branch(new Not(new Eq(new Constant(0), pop())), label); - case IFLT: return new Branch( new Lt(new Constant(0), pop()), label); - case IFGE: return new Branch(new Not(new Lt(new Constant(0), pop())), label); - case IFGT: return new Branch( new Gt(new Constant(0), pop()), label); - case IFLE: return new Branch(new Not(new Gt(new Constant(0), pop())), label); - case IF_ICMPEQ: return new Branch( new Eq(pop(), pop()), label); - case IF_ICMPNE: return new Branch(new Not(new Eq(pop(), pop())), label); - case IF_ICMPLT: return new Branch( new Lt(pop(), pop()), label); - case IF_ICMPGE: return new Branch(new Not(new Lt(pop(), pop())), label); - case IF_ICMPGT: return new Branch( new Gt(pop(), pop()), label); - case IF_ICMPLE: return new Branch(new Not(new Gt(pop(), pop())), label); - case IF_ACMPEQ: return new Branch( new Eq(pop(), pop()), label); - case IF_ACMPNE: return new Branch(new Not(new Eq(pop(), pop())), label); + case IFNULL: return new If(new Eq(pop(), new Constant(null)), new Label(i1)); + case IFNONNULL: return new If(new Not(new Eq(pop(),new Constant(null))),new Label(i1)); + case IFEQ: return new If( new Eq(new Constant(0), pop()), new Label(i1)); + case IFNE: return new If(new Not(new Eq(new Constant(0), pop())), new Label(i1)); + case IFLT: return new If( new Lt(new Constant(0), pop()), new Label(i1)); + case IFGE: return new If(new Not(new Lt(new Constant(0), pop())), new Label(i1)); + case IFGT: return new If( new Gt(new Constant(0), pop()), new Label(i1)); + case IFLE: return new If(new Not(new Gt(new Constant(0), pop())), new Label(i1)); + case IF_ICMPEQ: return new If( new Eq(pop(), pop()), new Label(i1)); + case IF_ICMPNE: return new If(new Not(new Eq(pop(), pop())), new Label(i1)); + case IF_ICMPLT: return new If( new Lt(pop(), pop()), new Label(i1)); + case IF_ICMPGE: return new If(new Not(new Lt(pop(), pop())), new Label(i1)); + case IF_ICMPGT: return new If( new Gt(pop(), pop()), new Label(i1)); + case IF_ICMPLE: return new If(new Not(new Gt(pop(), pop())), new Label(i1)); + case IF_ACMPEQ: return new If( new Eq(pop(), pop()), new Label(i1)); + case IF_ACMPNE: return new If(new Not(new Eq(pop(), pop())), new Label(i1)); case ATHROW: return new Throw(pop()); - case GOTO: return new Branch(locals[pc][i1]); - case JSR: push(new Label(pc+3)); return new JSR(new Label(pc+i1)); - case RET: return new RET(); + case GOTO: return new Goto(locals[pc][i1]); + case JSR: push(new Label(pc)); return new JSR(new Label(i1)); + case RET: return new RET(pop()); case RETURN: return new Return(); case IRETURN: case LRETURN: case FRETURN: case DRETURN: case ARETURN: return new Return(pop()); diff --git a/src/org/ibex/classgen/Poop.java b/src/org/ibex/classgen/Poop.java index d73d3b2..9d06f6b 100644 --- a/src/org/ibex/classgen/Poop.java +++ b/src/org/ibex/classgen/Poop.java @@ -1,12 +1,17 @@ package org.ibex.classgen; public class Poop { public static int i; + public static int q = 0; public static void bar(int k) { i = k+3; } public static void main() { - i = 5; - bar(i-3); - i += 3; + int i; + i = 50; + if (i==3) { + i = 2; + } + bar(i-39); + q = i + 1200; } } -- 1.7.10.4