001/*
002 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.phases;
024
025import com.oracle.graal.nodes.*;
026
027/***
028 * This phase serves as a verification, in order to check the graph for certain properties. The
029 * {@link #verify(StructuredGraph, Object)} method will be used as an assertion, and implements the
030 * actual check. Instead of returning false, it is also valid to throw an {@link VerificationError}
031 * in the implemented {@link #verify(StructuredGraph, Object)} method.
032 */
033public abstract class VerifyPhase<C> extends BasePhase<C> {
034
035    /**
036     * Thrown when verification performed by a {@link VerifyPhase} fails.
037     */
038    @SuppressWarnings("serial")
039    public static class VerificationError extends AssertionError {
040
041        public VerificationError(String message) {
042            super(message);
043        }
044
045        public VerificationError(String message, Throwable cause) {
046            super(message, cause);
047        }
048    }
049
050    @Override
051    protected final void run(StructuredGraph graph, C context) {
052        assert verify(graph, context);
053    }
054
055    /**
056     * Performs the actual verification.
057     *
058     * @throws VerificationError if the verification fails
059     */
060    protected abstract boolean verify(StructuredGraph graph, C context);
061}