This class generates code for a given IR tree. @author Norris Boyd @author Roger Lawrence
| 49 | * @author Roger Lawrence |
| 50 | */ |
| 51 | public class Codegen implements Evaluator { |
| 52 | @Override |
| 53 | public void captureStackInfo(RhinoException ex) { |
| 54 | throw new UnsupportedOperationException(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String getSourcePositionFromStack(Context cx, int[] linep) { |
| 59 | throw new UnsupportedOperationException(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public String getPatchedStack(RhinoException ex, String nativeStackTrace) { |
| 64 | throw new UnsupportedOperationException(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public List<String> getScriptStack(RhinoException ex) { |
| 69 | throw new UnsupportedOperationException(); |
| 70 | } |
| 71 | |
| 72 | private static class CodegenCompilationResult<T extends ScriptOrFn<T>> |
| 73 | implements CompilationResult<T> { |
| 74 | final JSDescriptor.Builder<T> builder; |
| 75 | final String className; |
| 76 | final byte[] bytecode; |
| 77 | final OptJSCode.BuilderEnv builderEnv; |
| 78 | |
| 79 | CodegenCompilationResult( |
| 80 | JSDescriptor.Builder<T> builder, |
| 81 | String className, |
| 82 | byte[] bytecode, |
| 83 | OptJSCode.BuilderEnv builderEnv) { |
| 84 | this.builder = builder; |
| 85 | this.className = className; |
| 86 | this.bytecode = bytecode; |
| 87 | this.builderEnv = builderEnv; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public DebuggableScript getDebuggableScript() { |
| 92 | // Can't debug compiled classes |
| 93 | return null; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public CompilationResult<JSScript> compileScript( |
| 99 | CompilerEnvirons compilerEnv, ScriptNode tree, String rawSource) { |
| 100 | return doCompile(compilerEnv, tree, rawSource, false); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public CompilationResult<JSFunction> compileFunction( |
| 105 | CompilerEnvirons compilerEnv, ScriptNode tree, String rawSource) { |
| 106 | return doCompile(compilerEnv, tree, rawSource, true); |
| 107 | } |
| 108 |