MCPcopy Create free account
hub / github.com/mozilla/rhino / CodeGenerator

Class CodeGenerator

rhino/src/main/java/org/mozilla/javascript/CodeGenerator.java:23–2027  ·  view source on GitHub ↗

Generates bytecode for the Interpreter.

Source from the content-addressed store, hash-verified

21
22/** Generates bytecode for the Interpreter. */
23class CodeGenerator<T extends ScriptOrFn<T>> {
24
25 private static final int MIN_LABEL_TABLE_SIZE = 32;
26 private static final int MIN_FIXUP_TABLE_SIZE = 40;
27
28 private CompilerEnvirons compilerEnv;
29
30 private boolean itsInFunctionFlag;
31 private boolean itsInTryFlag;
32
33 private InterpreterData.Builder<T> itsData;
34 private JSDescriptor.Builder<T> builder;
35
36 private ScriptNode scriptOrFn;
37 private int iCodeTop;
38 private int stackDepth;
39 private int lineNumber = -1;
40 private int doubleTableTop;
41
42 private final HashMap<String, Integer> strings = new HashMap<>();
43 private final HashMap<BigInteger, Integer> bigInts = new HashMap<>();
44 private int localTop;
45 private int[] labelTable;
46 private int labelTableTop;
47
48 // fixupTable[i] = (label_index << 32) | fixup_site
49 private long[] fixupTable;
50 private int fixupTableTop;
51 private final ArrayList<Object> literalIds = new ArrayList<>();
52
53 private int exceptionTableTop;
54
55 // ECF_ or Expression Context Flags constants: for now only TAIL
56 private static final int ECF_TAIL = 1 << 0;
57
58 public JSDescriptor<T> compile(
59 CompilerEnvirons compilerEnv,
60 ScriptNode tree,
61 String rawSource,
62 boolean returnFunction) {
63 this.compilerEnv = compilerEnv;
64
65 if (Token.printTrees) {
66 System.out.println("before transform:");
67 System.out.println(tree.toStringTree(tree));
68 }
69
70 new NodeTransformer().transform(tree, compilerEnv);
71
72 if (Token.printTrees) {
73 System.out.println("after transform:");
74 System.out.println(tree.toStringTree(tree));
75 }
76
77 if (returnFunction) {
78 scriptOrFn = tree.getFunctionNode(0);
79 } else {
80 scriptOrFn = tree;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected