Mercurial > hg > truffle
annotate graal/com.oracle.graal.java.decompiler.test/src/com/oracle/graal/java/decompiler/test/TestUtil.java @ 10482:3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Contributed-by: Matthias Grimmer (mgrimmer)
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 23 Jun 2013 21:04:34 +0200 |
parents | |
children | 9c7d9e2c8326 |
rev | line source |
---|---|
10482
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.java.decompiler.test; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 import static com.oracle.graal.api.code.CodeUtil.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.graal.api.code.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.api.code.CallingConvention.Type; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.graal.api.meta.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.graal.api.runtime.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.graal.compiler.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.compiler.target.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.java.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
34 import com.oracle.graal.nodes.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.nodes.spi.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 import com.oracle.graal.phases.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 import com.oracle.graal.phases.PhasePlan.PhasePosition; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 import com.oracle.graal.phases.tiers.*; |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 public class TestUtil { |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 public static void compileMethod(ResolvedJavaMethod method) { |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
43 GraalCodeCacheProvider runtime = Graal.getRequiredCapability(GraalCodeCacheProvider.class); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
44 Replacements replacements = Graal.getRequiredCapability(Replacements.class); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 Suites suites = Graal.getRequiredCapability(SuitesProvider.class).createSuites(); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 StructuredGraph graph = new StructuredGraph(method); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getEagerDefault(), OptimisticOptimizations.ALL).apply(graph); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 PhasePlan phasePlan = new PhasePlan(); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 CallingConvention cc = getCallingConvention(runtime, Type.JavaCallee, graph.method(), false); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 Backend backend = Graal.getRequiredCapability(Backend.class); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 GraalCompiler.compileGraph(graph, cc, method, runtime, replacements, backend, runtime.getTarget(), null, phasePlan, OptimisticOptimizations.ALL, new SpeculationLog(), suites); |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 } |
3e34b0318de6
Experimental decompiler that outputs Java source code from Graal IR for debug purposes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 } |