added Code.java
[org.ibex.classgen.git] / src / org / ibex / classgen / Code.java
1 package org.ibex.classgen;
2 public class Code {
3
4     /**
5      *  This should actually be called "ValueProducer", but that
6      *  requires more typing.
7      *
8      *  A Value is anything that generates an item on the stack.
9      *  Every instruction that causes something new to appear on the
10      *  stack implements Value.  Every instruction that uses
11      *  something(s) on the stack will hold a reference to the thing
12      *  (almost always an instruction) that generates the thing(s) it
13      *  removes from the stack.
14      */
15     public interface Value {
16         // commented out so that the rest of this file compiles
17         // Instruction[] getUsers();
18     }
19
20     /**
21      *  A "nondeterministic box" -- for example when the first
22      *  instruction in a loop reads from a local which could have been
23      *  written to either by some instruction at the end of the
24      *  previous iteration of the loop or by some instruction before
25      *  the loop (on the first iteration).
26      */
27     public class Phi implements Value {
28         public Phi(Value[] inputs) { }
29         public Instruction[] getUsers() { return null; /* FIXME */ }
30     }
31
32     /** any instruction which does not -- by itself -- remove anything from the stack */
33     public class Instruction { }
34
35     /** any instruction that consumes one item from the stack */
36     public class OneOp           extends Instruction { Value in;  }
37
38     /** any instruction that consumes two items from the stack */
39     public class TwoOp           extends Instruction { Value in1, in2; }
40     
41     /** a sequence of instructions */
42     public class Sequence        extends Instruction { Instruction[] code; }
43     public class Monitor         extends Sequence    { Value objectToSynchronizeOn; }
44     public class TryCatchFinally extends Sequence    { OneOp[] catchBodies;  Instruction finallyBody; }
45
46     public class Goto            extends Instruction                  { Instruction target; }
47     public class JSR             extends Instruction implements Value { Instruction target; }
48     public class Ret             extends OneOp                        { }
49     public class Nop             extends Instruction                  { }
50
51     public class Constant        extends Instruction implements Value { /** ??? **/ }
52     public class LDC             extends Instruction implements Value { Type.Class klass; }
53     public class New             extends Instruction implements Value { Type.Ref   type; }
54     public class ArrayLength     extends OneOp       implements Value { }
55     public class ArrayIndex      extends Instruction implements Value { }
56     public class Return          extends OneOp                        { }
57     public class ReturnVoid      extends Instruction                  { }
58     public class CheckCast       extends OneOp       implements Value { Type.Ref   castTarget; }
59     public class Instanceof      extends OneOp       implements Value { Type.Class klass; }
60     public class If              extends OneOp                        { Instruction thenTarget, elseTarget; }
61     public class Switch          extends OneOp {
62         public class Table extends Switch { }
63         public class Lookup extends Switch { }
64     }
65
66     public abstract class Invoke extends Instruction {
67         Value[] arguments;
68         Type.Class.Method method;
69         public class Static  extends Invoke implements Value { }
70         public class Special extends Invoke implements Value { }
71         public class Virtual extends Invoke implements Value { Value instance; }
72     }
73
74 }