/* Time-stamp: $Id$ A Compiler for MiniJava: Intm->Intm Practical on compiler design, LMU 2005/6 Based on Appels book on "Modern Compiler Implementation" Transformations on the intermediate code. This is the top-level module for the code in Chapter 8.2 The steps of the transformation are done in modules: Canon.java BasicBlocks.java TraceSchedule.java Adapted from on-line version by A. Appel. */ import java.util.LinkedList; public class IntmTrafo { public static LinkedList flattenCode(LinkedList> xs) { LinkedList res = new LinkedList(); java.util.Iterator> it = xs.iterator(); while (it.hasNext()){ res.addAll(it.next()); } return res; } public static LinkedList intmTrafo (Stm body) { // Step 1: linearise the SEQ-tree into a list of Stms (Canon.java; Ch 8.1) LinkedList stms = new Canon().linearize(body); System.out.println(".. codeseq after linearize:" + Utils.show_codeseq(stms)); // Step 2: break the list of Stms into a list of basic blocks (BasicBlocks.java; Ch 8.2) BasicBlocks bbs = new BasicBlocks(stms); System.out.println(".. basic blocks:" + Utils.show_codeseq(bbs.getBlocks())); // Step 3: generate traces out of BBS, doing some reordering of BBs (TraceSchedule.java; Ch 8.3) TraceSchedule trs = new TraceSchedule(bbs); // NB: result is in .newBlocks return flattenCode(trs.newBlocks); // flatten list of BBs into list of Stms } }