comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/AbstractExecutionContext.java @ 15279:0c6d8a08e31b

Truffle: Major cleanup and extension of the Truffle Instrumentation framework in com.oracle.truffle.api
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Sun, 20 Apr 2014 20:37:27 -0700
parents
children be0c151d912b
comparison
equal deleted inserted replaced
14862:0e713dba33bb 15279:0c6d8a08e31b
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.api.impl;
26
27 import com.oracle.truffle.api.*;
28 import com.oracle.truffle.api.instrument.*;
29 import com.oracle.truffle.api.instrument.impl.*;
30 import com.oracle.truffle.api.source.*;
31
32 public abstract class AbstractExecutionContext implements ExecutionContext {
33
34 private final SourceManager sourceManager = new SourceManager();
35 private final Instrumentation instrumentation;
36 private Visualizer visualizer = new DefaultVisualizer();
37 protected ASTProber astProber = null;
38
39 protected AbstractExecutionContext() {
40 this.instrumentation = InstrumentationFactory.create(this);
41 }
42
43 public final SourceManager getSourceManager() {
44 return sourceManager;
45 }
46
47 public final Instrumentation instrumentation() {
48 return instrumentation;
49 }
50
51 public Visualizer visualizer() {
52 return visualizer;
53 }
54
55 public void addNodeProber(ASTNodeProber nodeProber) {
56 if (astProber == null) {
57 throw new IllegalStateException("No ASTProber installed in context");
58 }
59 astProber.addNodeProber(nodeProber);
60 }
61
62 /**
63 * Assign guest language-specific visualization support for tools. This must be assigned outside
64 * the implementation context to avoid build circularities.
65 */
66 public void setVisualizer(Visualizer visualizer) {
67 this.visualizer = visualizer;
68 }
69
70 /**
71 * Assigns a guest language-specific manager for using {@link ASTNodeProber}s added by tools to
72 * instrument ASTs with {@link Probe}s at specified nodes. This must be assigned outside the
73 * implementation context to avoid build circularities. It must also be set before any
74 * instrumentation probe implementations are assigned.
75 */
76 public void setASTProber(ASTProber astProber) {
77 this.astProber = astProber;
78 }
79
80 /**
81 * Gets a guest language-specific {@link ASTNodeProber} that will apply all that have been
82 * added; {@code null} if no instrumentation in AST.
83 */
84 public ASTNodeProber getCombinedNodeProber() {
85 return astProber == null ? null : astProber.getCombinedNodeProber();
86 }
87
88 public abstract void setInstrumentEventListener(InstrumentEventListener listener);
89
90 public abstract InstrumentEventListener getInstrumentEventListener();
91 }