public Object compile(CompilerEnvirons compilerEnv, ScriptOrFnNode tree, String encodedSource, boolean returnFunction) { int serial; synchronized (globalLock) { serial = ++globalSerialClassCounter; } String mainClassName = "org.mozilla.javascript.gen.c"+serial; byte[] mainClassBytes = compileToClassFile(compilerEnv, mainClassName, tree, encodedSource, returnFunction); return new Object[] { mainClassName, mainClassBytes }; }
public Script createScriptObject(Object bytecode, Object staticSecurityDomain) { Class<?> cl = defineClass(bytecode, staticSecurityDomain); Script script; try { script = (Script)cl.newInstance(); } catch (Exception ex) { throw new RuntimeException ("Unable to instantiate compiled class:"+ex.toString()); } return script; }
generateFunctionConstructor(cfw); generateScriptCtor(cfw); generateMain(cfw); generateExecute(cfw); generateCallMethod(cfw); generateResumeGenerator(cfw); generateNativeFunctionOverrides(cfw, encodedSource); bodygen.generateBodyCode(); } catch (ClassFileWriter.ClassFileFormatException e) { throw reportClassFileFormatException(n, e.getMessage()); generateFunctionInit(cfw, ofn); if (ofn.isTargetOfDirectCall()) { emitDirectConstructor(cfw, ofn); emitRegExpInit(cfw); emitConstantDudeInitializers(cfw);
byte[] compileToClassFile(CompilerEnvirons compilerEnv, String mainClassName, ScriptOrFnNode scriptOrFn, String encodedSource, boolean returnFunction) { this.compilerEnv = compilerEnv; transform(scriptOrFn); if (Token.printTrees) { System.out.println(scriptOrFn.toStringTree(scriptOrFn)); } if (returnFunction) { scriptOrFn = scriptOrFn.getFunctionNode(0); } initScriptOrFnNodesData(scriptOrFn); this.mainClassName = mainClassName; mainClassSignature = ClassFileWriter.classNameToSignature(mainClassName); return generateCode(encodedSource); }
byte[] compileToClassFile(CompilerEnvirons compilerEnv, String mainClassName, ScriptOrFnNode scriptOrFn, String encodedSource, boolean returnFunction) { this.compilerEnv = compilerEnv; transform(scriptOrFn); if (Token.printTrees) { System.out.println(scriptOrFn.toStringTree(scriptOrFn)); } if (returnFunction) { scriptOrFn = scriptOrFn.getFunctionNode(0); } initScriptOrFnNodesData(scriptOrFn); this.mainClassName = mainClassName; this.mainClassSignature = ClassFileWriter.classNameToSignature(mainClassName); try { return generateCode(encodedSource); } catch (ClassFileWriter.ClassFileFormatException e) { throw reportClassFileFormatException(scriptOrFn, e.getMessage()); } }
public byte[] compileToClassFile(CompilerEnvirons compilerEnv, String mainClassName, ScriptNode scriptOrFn, String encodedSource, boolean returnFunction) { this.compilerEnv = compilerEnv; transform(scriptOrFn); if (Token.printTrees) { System.out.println(scriptOrFn.toStringTree(scriptOrFn)); } if (returnFunction) { scriptOrFn = scriptOrFn.getFunctionNode(0); } initScriptNodesData(scriptOrFn); this.mainClassName = mainClassName; this.mainClassSignature = ClassFileWriter.classNameToSignature(mainClassName); try { return generateCode(encodedSource); } catch (ClassFileWriter.ClassFileFormatException e) { throw reportClassFileFormatException(scriptOrFn, e.getMessage()); } }
Codegen codegen = new Codegen(); codegen.setMainMethodClass(mainMethodClassName); byte[] scriptClassBytes = codegen.compileToClassFile(compilerEnv, scriptClassName, tree, encodedSource, false);
} else { cfw.addPush(num); addDoubleWrap(cfw); addDoubleWrap(cfw); String constantType = getStaticConstantWrapperType(num); cfw.add(ByteCode.GETSTATIC, mainClassName, constantName, constantType);
private void genSimpleCompare(int type, int trueGOTO, int falseGOTO) { if (trueGOTO == -1) throw Codegen.badTree(); switch (type) { case Token.LE : cfw.add(ByteCode.DCMPG); cfw.add(ByteCode.IFLE, trueGOTO); break; case Token.GE : cfw.add(ByteCode.DCMPL); cfw.add(ByteCode.IFGE, trueGOTO); break; case Token.LT : cfw.add(ByteCode.DCMPG); cfw.add(ByteCode.IFLT, trueGOTO); break; case Token.GT : cfw.add(ByteCode.DCMPL); cfw.add(ByteCode.IFGT, trueGOTO); break; default : throw Codegen.badTree(); } if (falseGOTO != -1) cfw.add(ByteCode.GOTO, falseGOTO); }
if (start == end) throw badTree(); boolean generateSwitch = (2 <= end - start); cfw.addInvoke(ByteCode.INVOKEVIRTUAL, mainClassName, getFunctionInitMethodName(ofn), FUNCTION_INIT_SIGNATURE); cfw.add(ByteCode.RETURN);
if (regexpCount == 0) throw badTree(); cfw.addALoad(scopeArg); cfw.add(ByteCode.GETSTATIC, mainClassName, getCompiledRegexpName(n, i), "Ljava/lang/Object;");
private void visitIfJumpEqOp(Node node, Node child, int trueGOTO, int falseGOTO) if (trueGOTO == -1 || falseGOTO == -1) throw Codegen.badTree(); if (type != Token.EQ) { if (type != Token.NE) throw Codegen.badTree(); int tmp = trueGOTO; trueGOTO = falseGOTO; cfw.add(ByteCode.GOTO, trueGOTO); cfw.markLabel(undefCheckLabel, stack); Codegen.pushUndefined(cfw); cfw.add(ByteCode.IF_ACMPEQ, trueGOTO); break; default: throw Codegen.badTree(); cfw.add(ByteCode.GOTO, falseGOTO); if (stackInitial != cfw.getStackTop()) throw Codegen.badTree();
Codegen codegen = new Codegen(); codegen.setMainMethodClass(mainMethodClassName); byte[] scriptClassBytes = codegen.compileToClassFile(compilerEnv, scriptClassName, tree, encodedSource, false);
public byte[] compileToClassFile(CompilerEnvirons compilerEnv, String mainClassName, ScriptNode scriptOrFn, String encodedSource, boolean returnFunction) { this.compilerEnv = compilerEnv; transform(scriptOrFn); if (Token.printTrees) { System.out.println(scriptOrFn.toStringTree(scriptOrFn)); } if (returnFunction) { scriptOrFn = scriptOrFn.getFunctionNode(0); } initScriptNodesData(scriptOrFn); this.mainClassName = mainClassName; this.mainClassSignature = ClassFileWriter.classNameToSignature(mainClassName); try { return generateCode(encodedSource); } catch (ClassFileWriter.ClassFileFormatException e) { throw reportClassFileFormatException(scriptOrFn, e.getMessage()); } }
} else { cfw.addPush(num); addDoubleWrap(cfw); addDoubleWrap(cfw); String constantType = getStaticConstantWrapperType(num); cfw.add(ByteCode.GETSTATIC, mainClassName, constantName, constantType);
private void genSimpleCompare(int type, int trueGOTO, int falseGOTO) { if (trueGOTO == -1) throw Codegen.badTree(); switch (type) { case Token.LE : cfw.add(ByteCode.DCMPG); cfw.add(ByteCode.IFLE, trueGOTO); break; case Token.GE : cfw.add(ByteCode.DCMPL); cfw.add(ByteCode.IFGE, trueGOTO); break; case Token.LT : cfw.add(ByteCode.DCMPG); cfw.add(ByteCode.IFLT, trueGOTO); break; case Token.GT : cfw.add(ByteCode.DCMPL); cfw.add(ByteCode.IFGT, trueGOTO); break; default : throw Codegen.badTree(); } if (falseGOTO != -1) cfw.add(ByteCode.GOTO, falseGOTO); }
if (start == end) throw badTree(); boolean generateSwitch = (2 <= end - start); cfw.addInvoke(ByteCode.INVOKESPECIAL, mainClassName, getFunctionInitMethodName(ofn), FUNCTION_INIT_SIGNATURE); cfw.add(ByteCode.RETURN);
if (regexpCount == 0) throw badTree(); cfw.addALoad(scopeArg); cfw.add(ByteCode.GETSTATIC, mainClassName, getCompiledRegexpName(n, i), "Ljava/lang/Object;");
private void visitIfJumpEqOp(Node node, Node child, int trueGOTO, int falseGOTO) if (trueGOTO == -1 || falseGOTO == -1) throw Codegen.badTree(); if (type != Token.EQ) { if (type != Token.NE) throw Codegen.badTree(); int tmp = trueGOTO; trueGOTO = falseGOTO; cfw.add(ByteCode.GOTO, trueGOTO); cfw.markLabel(undefCheckLabel, stack); Codegen.pushUndefined(cfw); cfw.add(ByteCode.IF_ACMPEQ, trueGOTO); break; default: throw Codegen.badTree(); cfw.add(ByteCode.GOTO, falseGOTO); if (stackInitial != cfw.getStackTop()) throw Codegen.badTree();
generateFunctionConstructor(cfw); generateScriptCtor(cfw); generateMain(cfw); generateExecute(cfw); generateCallMethod(cfw); generateResumeGenerator(cfw); generateNativeFunctionOverrides(cfw, encodedSource); bodygen.generateBodyCode(); } catch (ClassFileWriter.ClassFileFormatException e) { throw reportClassFileFormatException(n, e.getMessage()); generateFunctionInit(cfw, ofn); if (ofn.isTargetOfDirectCall()) { emitDirectConstructor(cfw, ofn); emitRegExpInit(cfw); emitConstantDudeInitializers(cfw);