public Set<CompilerPassListener> getListeners() { // FIXME: This is ugly but we want to conditionalize output based on JRuby module setting/unsetting if (RubyInstanceConfig.IR_COMPILER_DEBUG) { addListener(defaultListener); } else { removeListener(defaultListener); } return passListeners; }
private boolean hasListener() { return manager.getIRScopeListener() != null; }
private void initInstrs() { instrs = new ArrayList<>(); if (RubyInstanceConfig.IR_COMPILER_DEBUG || RubyInstanceConfig.IR_DEBUG_IGV != null) { IRManager irManager = cfg.getManager(); InstructionsListener listener = irManager.getInstructionsListener(); if (listener != null) { instrs = new InstructionsListenerDecorator(this, instrs, listener); } } }
public Operand buildOpElementAsgn(OpElementAsgnNode node) { // Translate "a[x] ||= n" --> "a[x] = n if !is_true(a[x])" if (node.isOr()) return buildOpElementAsgnWith(node, manager.getTrue()); // Translate "a[x] &&= n" --> "a[x] = n if is_true(a[x])" if (node.isAnd()) return buildOpElementAsgnWith(node, manager.getFalse()); // a[i] *= n, etc. anything that is not "a[i] &&= .. or a[i] ||= .." return buildOpElementAsgnWithMethod(node); }
private void setupLexicalContainment() { if (manager.isDryRun() || RubyInstanceConfig.IR_WRITING || RubyInstanceConfig.RECORD_LEXICAL_HIERARCHY) { lexicalChildren = new ArrayList<>(1); if (lexicalParent != null) lexicalParent.addChildScope(this); } }
private Operand dynamicPiece(Node pieceNode) { Operand piece = pieceNode instanceof StrNode ? buildStrRaw((StrNode) pieceNode) : build(pieceNode); if (piece instanceof StringLiteral) { piece = ((StringLiteral)piece).frozenString; } return piece == null ? manager.getNil() : piece; }
public Operand buildToAry(ToAryNode node, IRScope s) { Operand array = build(node.getValue(), s); Variable result = s.getNewTemporaryVariable(); s.addInstr(new ToAryInstr(result, array, manager.getFalse())); return result; }
public Operand buildTrue() { return manager.getTrue(); }
protected Object run(IRScope scope, boolean childScope) { List<Class<? extends CompilerPass>> dependencies = getDependencies(); Object data[] = new Object[dependencies.size()]; for (int i = 0; i < data.length; i++) { data[i] = makeSureDependencyHasRunOnce(dependencies.get(i), scope, childScope); } for (CompilerPassListener listener: scope.getManager().getListeners()) { listener.startExecute(this, scope, childScope); } Object passData = execute(scope, data); for (CompilerPassListener listener: scope.getManager().getListeners()) { listener.endExecute(this, scope, passData, childScope); } return passData; }
public static IRScope createScope(IRManager manager, IRScopeType type, RubySymbol name, int line, IRScope lexicalParent, Signature signature, StaticScope staticScope) { switch (type) { case CLASS_BODY: return new IRClassBody(manager, lexicalParent, name, line, staticScope); case METACLASS_BODY: return new IRMetaClassBody(manager, lexicalParent, manager.getMetaClassName(), line, staticScope); case INSTANCE_METHOD: return new IRMethod(manager, lexicalParent, null, name, true, line, staticScope, false); case CLASS_METHOD: return new IRMethod(manager, lexicalParent, null, name, false, line, staticScope, false); case MODULE_BODY: return new IRModuleBody(manager, lexicalParent, name, line, staticScope); case SCRIPT_BODY: return new IRScriptBody(manager, name, staticScope); case FOR: return new IRFor(manager, lexicalParent, line, staticScope, signature); case CLOSURE: return new IRClosure(manager, lexicalParent, line, staticScope, signature); case EVAL_SCRIPT: // SSS FIXME: This is broken right now -- the isModuleEval arg has to be persisted and then read back. return new IREvalScript(manager, lexicalParent, lexicalParent.getFileName(), line, staticScope, EvalType.NONE); } throw new RuntimeException("No such scope type: " + type); } }
private static IRScriptBody compileIR(ThreadContext context, IRubyObject[] args, Block block) { RootNode node = (RootNode) parseImpl(context, args, block); IRManager manager = new IRManager(context.runtime, context.runtime.getInstanceConfig()); manager.setDryRun(true); IRScriptBody scope = (IRScriptBody) IRBuilder.buildRoot(manager, node).getScope(); scope.setScriptDynamicScope(node.getScope()); return scope; }
public InterpreterContext buildEvalRoot(RootNode rootNode) { needsCodeCoverage = false; // Assuming there is no path into build eval root without actually being an eval. addInstr(manager.newLineNumber(scope.getLine())); prepareImplicitState(); // recv_self, add frame block, etc) addCurrentScopeAndModule(); // %current_scope/%current_module Operand returnValue = rootNode.getBodyNode() == null ? manager.getNil() : build(rootNode.getBodyNode()); addInstr(new ReturnInstr(returnValue)); return scope.allocateInterpreterContext(instructions); }
irManager = new IRManager();
private final void setupLexicalContainment() { if (manager.isDryRun()) { lexicalChildren = new ArrayList<IRScope>(); if (lexicalParent != null) lexicalParent.addChildScope(this); } }
public Operand run(Object[] args) { // Nothing to do -- ignore the exception, and restore stashed error info! IRScope m = (IRScope)args[0]; m.addInstr(new RestoreErrorInfoInstr((Operand) args[1])); return manager.getNil(); } };
@Override public void buildVersionSpecificAssignment(Node node, IRScope s, Variable v) { switch (node.getNodeType()) { case MULTIPLEASGN19NODE: { s.addInstr(new ToAryInstr(v, v, manager.getFalse())); buildMultipleAsgn19Assignment((MultipleAsgn19Node)node, s, null, v); break; } default: throw new NotCompilableException("Can't build assignment node: " + node); } }
public Operand buildTrue() { return manager.getTrue(); }
protected Object run(IRScope scope, boolean childScope) { List<Class<? extends CompilerPass>> dependencies = getDependencies(); Object data[] = new Object[dependencies.size()]; for (int i = 0; i < data.length; i++) { data[i] = makeSureDependencyHasRunOnce(dependencies.get(i), scope, childScope); } for (CompilerPassListener listener: scope.getManager().getListeners()) { listener.startExecute(this, scope, childScope); } Object passData = execute(scope, data); for (CompilerPassListener listener: scope.getManager().getListeners()) { listener.endExecute(this, scope, passData, childScope); } return passData; }
public static IRScope createScope(IRManager manager, IRScopeType type, RubySymbol name, int line, IRScope lexicalParent, Signature signature, StaticScope staticScope) { switch (type) { case CLASS_BODY: return new IRClassBody(manager, lexicalParent, name, line, staticScope); case METACLASS_BODY: return new IRMetaClassBody(manager, lexicalParent, manager.getMetaClassName(), line, staticScope); case INSTANCE_METHOD: return new IRMethod(manager, lexicalParent, null, name, true, line, staticScope, false); case CLASS_METHOD: return new IRMethod(manager, lexicalParent, null, name, false, line, staticScope, false); case MODULE_BODY: return new IRModuleBody(manager, lexicalParent, name, line, staticScope); case SCRIPT_BODY: return new IRScriptBody(manager, name, staticScope); case FOR: return new IRFor(manager, lexicalParent, line, staticScope, signature); case CLOSURE: return new IRClosure(manager, lexicalParent, line, staticScope, signature); case EVAL_SCRIPT: // SSS FIXME: This is broken right now -- the isModuleEval arg has to be persisted and then read back. return new IREvalScript(manager, lexicalParent, lexicalParent.getFileName(), line, staticScope, EvalType.NONE); } throw new RuntimeException("No such scope type: " + type); } }