Skip to content

Commit eaa4f2f

Browse files
committed
[Truffle] -Xtruffle.translator.print_asts= tool.
1 parent 9003bdd commit eaa4f2f

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

core/src/main/java/org/jruby/truffle/translator/MethodTranslator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ public MethodDefinitionNode compileFunctionNode(SourceSection sourceSection, Str
166166
final RubyRootNode rootNode = new RubyRootNode(
167167
context, sourceSection, environment.getFrameDescriptor(), environment.getSharedMethodInfo(), body);
168168

169+
if (PRINT_AST_METHOD_NAMES.contains(methodName)) {
170+
System.err.println(methodName);
171+
NodeUtil.printCompactTree(System.err, rootNode);
172+
}
173+
169174
if (isBlock) {
170175
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
171176
final CallTarget callTargetForMethods = withoutBlockDestructureSemantics(callTarget);

core/src/main/java/org/jruby/truffle/translator/Translator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
import org.jruby.truffle.runtime.RubyContext;
1818
import org.jruby.util.cli.Options;
1919

20+
import java.util.Arrays;
21+
import java.util.HashSet;
22+
import java.util.Set;
23+
2024
public abstract class Translator extends org.jruby.ast.visitor.AbstractNodeVisitor<RubyNode> {
2125

26+
public static final Set<String> PRINT_AST_METHOD_NAMES = new HashSet<>(Arrays.asList(Options.TRUFFLE_TRANSLATOR_PRINT_AST.load().split(",")));
27+
2228
protected final RubyNode currentNode;
2329
protected final RubyContext context;
2430
protected final Source source;

core/src/main/java/org/jruby/util/cli/Options.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public class Options {
152152
public static final Option<Boolean> TRUFFLE_DISPATCH_METAPROGRAMMING_ALWAYS_INDIRECT = bool(TRUFFLE, "truffle.dispatch.metaprogramming_always_indirect", false, "Always use indirect calls for the metaprogramming methods #__send__ and #send, and for any call site that has to use #method_missing or #const_missing.");
153153
public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_CLONED = bool(TRUFFLE, "truffle.call.method_missing_always_cloned", true, "Always clone #method_missing call targets.");
154154
public static final Option<Boolean> TRUFFLE_DISPATCH_METHODMISSING_ALWAYS_INLINED = bool(TRUFFLE, "truffle.call.method_missing_always_inlined", true, "Always inline #method_missing call targets.");
155+
public static final Option<String> TRUFFLE_TRANSLATOR_PRINT_AST = string(TRUFFLE, "truffle.translator.print_asts", "", "Comma delimited list of method names to print the AST of after translation.");
155156

156157
public static final Option<Boolean> NATIVE_ENABLED = bool(NATIVE, "native.enabled", true, "Enable/disable native code, including POSIX features and C exts.");
157158
public static final Option<Boolean> NATIVE_VERBOSE = bool(NATIVE, "native.verbose", false, "Enable verbose logging of native extension loading.");

0 commit comments

Comments
 (0)