3 /* Copyright (C) 2002 by Universitaet Karlsruhe
4 ** All rights reserved.
6 ** Author: Goetz Lindenmaier
8 ** This is an example of how to use the JNI interface of Firm.
13 *** An empty Firm program.
15 *** This file constructs the ir for the following pseudo-program:
24 public static void main (String[] args) {
25 Firm firm = new Firm();
27 System.out.println("\nCreating an IR graph: EMPTY...");
32 /** Build type information for the procedure. **/
34 /* FIRM was designed for oo languages where all methods beint to a class.
35 * For imperative languages like C we view a file as a large class containing
36 * all functions in this file as methods.
37 * This clas is generated automatically.
39 int owner = Irprog.getGlobType();
41 /* The type of the method */
42 int name = Ident.idFromStr("main", 4);
43 int proc_main = Type.newTypeMethod(name, 0, 0);
44 /* An entity representing the method. Owner of the entity is the global class
45 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 //ir_node *in[0]; /* this is the array containing the return parameters */
63 int []in = new int[0];
64 int x = Ircons.newReturn (Ircons.getStore(), in.length, in);
66 /* Test enumerators */
67 if (Irnode.getIrnModecode(x) != Irmode.irm_X)
68 System.out.println(" wrong modecode");
70 System.out.println(" proper modecode Execution.");
72 /* Now we generated all instructions for this block and all its predecessor
73 * blocks so we can mature it. (There are not too much.) */
74 Ircons.matureBlock (Irgraph.getIrgCurrentBlock(irg));
76 /* This adds the in edge of the end block which originates at the return statement.
77 * The return node passes controlflow to the end block. */
78 Ircons.addInEdge (Irgraph.getIrgEndBlock(irg), x);
79 /* Now we can mature the end block as all it's predecessors are known. */
80 Ircons.matureBlock (Irgraph.getIrgEndBlock(irg));
82 /* Verify the graph. Finds some very bad errors in the graph. */
84 Ircons.finalizeCons (irg);
86 System.out.println("Done building the graph. Dumping it.");
87 Irdump.dumpIrBlockGraph (irg);
88 Irdump.dumpAllTypes();
91 System.out.println("use xvcg to view this graph:");
92 System.out.println("/ben/goetz/bin/xvcg GRAPHNAME\n");