001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.driver;
014    
015    import org.jikesrvm.compilers.opt.ir.IR;
016    
017    /**
018     * A trivial phase that can be inserted to dump the IR.
019     */
020    public class IRPrinter extends CompilerPhase {
021      protected final String msg;
022    
023      /**
024       * Constuct a phase to print the IR with a message.
025       * @param   m the message
026       */
027      public IRPrinter(String m) {
028        msg = m;
029      }
030    
031      public final String getName() {
032        return "IR_Printer: " + msg;
033      }
034    
035      /**
036       * Print an IR
037       * @param ir the IR to print
038       */
039      public final void perform(IR ir) {
040        if (ir.options.getOptLevel() < ir.options.PRINT_IR_LEVEL) {
041          return;
042        }
043    
044        if (!ir.options.hasMETHOD_TO_PRINT() || ir.options.fuzzyMatchMETHOD_TO_PRINT(ir.method.toString())) {
045          dumpIR(ir, msg);
046        }
047      }
048    
049      /**
050       * Return this instance of this phase
051       * @param ir not used
052       * @return this
053       */
054      public CompilerPhase newExecution(IR ir) {
055        return this;
056      }
057    }