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 */
013package org.jikesrvm.compilers.opt.driver;
014
015import org.jikesrvm.compilers.opt.ir.IR;
016
017/**
018 * A trivial phase that can be inserted to dump the IR.
019 */
020public 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  @Override
032  public final String getName() {
033    return "IR_Printer: " + msg;
034  }
035
036  /**
037   * Print an IR
038   * @param ir the IR to print
039   */
040  @Override
041  public final void perform(IR ir) {
042    if (ir.options.getOptLevel() < ir.options.PRINT_IR_LEVEL) {
043      return;
044    }
045
046    if (!ir.options.hasMETHOD_TO_PRINT() || ir.options.fuzzyMatchMETHOD_TO_PRINT(ir.method.toString())) {
047      dumpIR(ir, msg);
048    }
049  }
050
051  /**
052   * Return this instance of this phase
053   * @param ir not used
054   * @return this
055   */
056  @Override
057  public CompilerPhase newExecution(IR ir) {
058    return this;
059  }
060}