3 * File name: firmjni/testprograms/Empty.java
4 * Purpose: This is an example of how to use the JNI interface of Firm.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2002 Universitaet Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
16 *** An empty Firm program.
18 *** This file constructs the ir for the following pseudo-program:
27 public static void main (String[] args) {
29 System.out.println("\nCreating an IR graph: EMPTY...");
31 /* init library: Java did not support the callback, so ALWAYS use 0 here */
34 /** Build type information for the procedure. **/
36 /* FIRM was designed for oo languages where all methods belong to a class.
37 * For imperative languages like C we view a file as a large class containing
38 * all functions in this file as methods.
39 * This class is generated automatically. */
40 int owner = Irprog.getGlobType();
42 /* The type of the method */
43 int name = Ident.newIdFromStr("EMPTY_main");
44 int proc_main = Type.newTypeMethod(name, 0, 0);
45 /* An entity representing the method. Owner of the entity is the global
46 class type mentioned above. */
47 int ent = Entity.newEntity (owner, name, proc_main);
49 /** Build code for the procedure. **/
51 /* Generates the basic graph for the method represented by entity ent, that
52 * is, generates start and end blocks and nodes and a first, initial block.
53 * The constructor needs to know the number of local variables (including
54 * the arguments) in the method.
56 int irg = Irgraph.newIrGraph (ent, 0);
58 /* The constructor new_ir_graph() generated a region to place nodes in.
59 * This region is accessible via the attribut current_block of irg and
61 * Generate the return node into this region. The Return node is needed to
62 * return at least the memory. */
63 int []in = new int[0];
64 int x = Ircons.newReturn (Ircons.getStore(), in.length, in);
66 /* Now we generated all instructions for this block and all its predecessor
67 * blocks so we can mature it. (There are not too much.) */
68 Ircons.matureImmBlock (Irgraph.getIrgCurrentBlock(irg));
70 /* This adds the in edge of the end block which originates at the return statement.
71 * The return node passes controlflow to the end block. */
72 Ircons.addImmBlockPred (Irgraph.getIrgEndBlock(irg), x);
73 /* Now we can mature the end block as all it's predecessors are known. */
74 Ircons.matureImmBlock (Irgraph.getIrgEndBlock(irg));
76 /* Verify the graph. Finds some very bad errors in the graph. */
77 Irvrfy.irgVerify(irg, Irvrfy.VRFY_NORMAL);
78 Irgraph.setIrgPhaseState (irg, Irgraph.phase_high);
80 System.out.println("Done building the graph. Dumping it.");
81 Irdump.dumpIrBlockGraph (irg, "");
82 Irdump.dumpAllTypes("");
85 System.out.println("use xvcg to view this graph:");
86 System.out.println("/ben/goetz/bin/xvcg GRAPHNAME\n");