forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRManager.java
More file actions
99 lines (79 loc) · 3.26 KB
/
Copy pathIRManager.java
File metadata and controls
99 lines (79 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package org.jruby.ir;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jruby.RubyInstanceConfig;
import org.jruby.ir.operands.BooleanLiteral;
import org.jruby.ir.operands.Nil;
import org.jruby.ir.passes.BasicCompilerPassListener;
import org.jruby.ir.passes.CompilerPass;
import org.jruby.ir.passes.CompilerPassListener;
/**
*/
public class IRManager {
public static String DEFAULT_COMPILER_PASSES = "OptimizeTempVarsPass,LocalOptimizationPass,LinearizeCFG";
public static String DEFAULT_INLINING_COMPILER_PASSES = "LocalOptimizationPass";
private int dummyMetaClassCount = 0;
private final IRModuleBody classMetaClass = new IRMetaClassBody(this, null, getMetaClassName(), "", 0, null);
private final IRModuleBody object = new IRClassBody(this, null, "Object", "", 0, null);
private final Nil nil = new Nil();
private final BooleanLiteral trueObject = new BooleanLiteral(true);
private final BooleanLiteral falseObject = new BooleanLiteral(false);
private Set<CompilerPassListener> passListeners = new HashSet<CompilerPassListener>();
private CompilerPassListener defaultListener = new BasicCompilerPassListener();
// FIXME: Eventually make these attrs into either a) set b) part of state machine
private List<CompilerPass> compilerPasses = new ArrayList<CompilerPass>();
private List<CompilerPass> inliningCompilerPasses = new ArrayList<CompilerPass>();
// If true then code will not execute (see ir/ast tool)
private boolean dryRun = false;
public IRManager() {
compilerPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_COMPILER_PASSES, DEFAULT_COMPILER_PASSES);
inliningCompilerPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_COMPILER_PASSES, DEFAULT_INLINING_COMPILER_PASSES);
}
public boolean isDryRun() {
return dryRun;
}
public void setDryRun(boolean value) {
this.dryRun = value;
}
public Nil getNil() {
return nil;
}
public BooleanLiteral getTrue() {
return trueObject;
}
public BooleanLiteral getFalse() {
return falseObject;
}
public IRModuleBody getObject() {
return object;
}
public List<CompilerPass> getCompilerPasses(IRScope scope) {
return compilerPasses;
}
public List<CompilerPass> getInliningCompilerPasses(IRScope scope) {
return inliningCompilerPasses;
}
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;
}
public void addListener(CompilerPassListener listener) {
passListeners.add(listener);
}
public void removeListener(CompilerPassListener listener) {
passListeners.remove(listener);
}
public IRModuleBody getClassMetaClass() {
return classMetaClass;
}
public String getMetaClassName() {
return "<DUMMY_MC:" + dummyMetaClassCount++ + ">";
}
}