3 /* Copyright (C) 2002 by Universitaet Karlsruhe
4 ** All rights reserved.
6 ** Author: Goetz Lindenmaier
10 ** This is an example of how to use the JNI interface of Firm.
15 *** An empty Firm program.
17 *** This file constructs the ir for the following pseudo-program:
26 public static void main (String[] args) {
28 System.out.println("\nCreating an IR graph: EMPTY...");
30 /* init library: Java did not support the callback, so ALWAYS use 0 here */
33 /** Build type information for the procedure. **/
35 /* FIRM was designed for oo languages where all methods belong to a class.
36 * For imperative languages like C we view a file as a large class containing
37 * all functions in this file as methods.
38 * This class is generated automatically. */
39 int owner = Irprog.getGlobType();
41 /* The type of the method */
42 int name = Ident.idFromStr("EMPTY_main", 10);
43 int proc_main = Type.newTypeMethod(name, 0, 0);
44 /* An entity representing the method. Owner of the entity is the global
45 class type mentioned above. */
46 int ent = Entity.newEntity (owner, name, proc_main);
48 /** Build code for the procedure. **/
50 /* Generates the basic graph for the method represented by entity ent, that
51 * is, generates start and end blocks and nodes and a first, initial block.
52 * The constructor needs to know the number of local variables (including
53 * the arguments) in the method.
55 int irg = Irgraph.newIrGraph (ent, 0);
57 /* The constructor new_ir_graph() generated a region to place nodes in.
58 * This region is accessible via the attribut current_block of irg and
60 * Generate the return node into this region. The Return node is needed to
61 * return at least the memory. */
62 int []in = new int[0];
63 int x = Ircons.newReturn (Ircons.getStore(), in.length, in);
65 /* Now we generated all instructions for this block and all its predecessor
66 * blocks so we can mature it. (There are not too much.) */
67 Ircons.matureBlock (Irgraph.getIrgCurrentBlock(irg));
69 /* This adds the in edge of the end block which originates at the return statement.
70 * The return node passes controlflow to the end block. */
71 Ircons.addInEdge (Irgraph.getIrgEndBlock(irg), x);
72 /* Now we can mature the end block as all it's predecessors are known. */
73 Ircons.matureBlock (Irgraph.getIrgEndBlock(irg));
75 /* Verify the graph. Finds some very bad errors in the graph. */
77 Ircons.finalizeCons (irg);
79 System.out.println("Done building the graph. Dumping it.");
80 Irdump.dumpIrBlockGraph (irg);
81 Irdump.dumpAllTypes();
84 System.out.println("use xvcg to view this graph:");
85 System.out.println("/ben/goetz/bin/xvcg GRAPHNAME\n");