Search in sources :

Example 1 with Code

use of com.github.anba.es6draft.compiler.assembler.Code in project es6draft by anba.

the class Compiler method compile.

/**
 * Compiles a module node to Java bytecode.
 *
 * @param module
 *            the module node
 * @param moduleRecord
 *            the module record
 * @param className
 *            the class name
 * @return the compiled module
 * @throws CompilationException
 *             if the module node could not be compiled
 */
public CompiledModule compile(Module module, SourceTextModuleRecord moduleRecord, String className) throws CompilationException {
    if (!isEnabled(Compiler.Option.NoByteCodeSizeValidation)) {
        CodeSize.analyze(module);
    }
    long startCompile = 0;
    if (MEASURE_COMPILE_TIME) {
        startCompile = System.nanoTime();
    }
    Code code = new Code(Modifier.PUBLIC | Modifier.FINAL, className, ClassSignature.NONE, Types.CompiledModule, Collections.<Type>emptyList(), NodeSourceInfo.create(module, isEnabled(Option.SourceMap)));
    CodeGenerator codegen = new CodeGenerator(context, code, module);
    try {
        codegen.compile(module, moduleRecord);
    } catch (RuntimeException e) {
        throw handleAsmError(e);
    }
    if (MEASURE_COMPILE_TIME) {
        long time = System.nanoTime() - startCompile;
        STATISTICS.compileTime.add(time);
        STATISTICS.compileTimeModule.add(time);
    }
    long startLoad = 0;
    if (MEASURE_LOAD_TIME) {
        startLoad = System.nanoTime();
    }
    CompiledModule compiledModule;
    try {
        if (useAnonymousLoader(code)) {
            compiledModule = defineAndLoad(module, code, AnonymousCodeLoader.MODULE);
        } else {
            compiledModule = defineAndLoad(module, code, className);
        }
    } catch (RuntimeException e) {
        throw handleAsmError(e);
    }
    if (MEASURE_LOAD_TIME) {
        long time = System.nanoTime() - startLoad;
        STATISTICS.loadTime.add(time);
        STATISTICS.loadTimeModule.add(time);
    }
    return compiledModule;
}
Also used : ClassCode(com.github.anba.es6draft.compiler.assembler.Code.ClassCode) Code(com.github.anba.es6draft.compiler.assembler.Code)

Example 2 with Code

use of com.github.anba.es6draft.compiler.assembler.Code in project es6draft by anba.

the class Compiler method compile.

private <FUNCTION extends FunctionNode> CompiledFunction compile(FUNCTION function, String className, BiConsumer<CodeGenerator, FUNCTION> compiler) {
    Script script = functionScript(function);
    if (!isEnabled(Compiler.Option.NoByteCodeSizeValidation)) {
        CodeSize.analyze(function);
    }
    long startCompile = 0;
    if (MEASURE_COMPILE_TIME) {
        startCompile = System.nanoTime();
    }
    Code code = new Code(Modifier.PUBLIC | Modifier.FINAL, className, ClassSignature.NONE, Types.CompiledFunction, Collections.<Type>emptyList(), NodeSourceInfo.create(function, isEnabled(Option.SourceMap)));
    CodeGenerator codegen = new CodeGenerator(context, code, script);
    try {
        compiler.accept(codegen, function);
    } catch (RuntimeException e) {
        throw handleAsmError(e);
    }
    if (MEASURE_COMPILE_TIME) {
        long time = System.nanoTime() - startCompile;
        STATISTICS.compileTime.add(time);
        STATISTICS.compileTimeFunction.add(time);
    }
    long startLoad = 0;
    if (MEASURE_LOAD_TIME) {
        startLoad = System.nanoTime();
    }
    CompiledFunction compiledFunction;
    try {
        if (useAnonymousLoader(code)) {
            compiledFunction = defineAndLoad(script, code, AnonymousCodeLoader.FUNCTION);
        } else {
            compiledFunction = defineAndLoad(script, code, className);
        }
    } catch (RuntimeException e) {
        throw handleAsmError(e);
    }
    if (MEASURE_LOAD_TIME) {
        long time = System.nanoTime() - startLoad;
        STATISTICS.loadTime.add(time);
        STATISTICS.loadTimeFunction.add(time);
    }
    return compiledFunction;
}
Also used : Script(com.github.anba.es6draft.ast.Script) ClassCode(com.github.anba.es6draft.compiler.assembler.Code.ClassCode) Code(com.github.anba.es6draft.compiler.assembler.Code)

Example 3 with Code

use of com.github.anba.es6draft.compiler.assembler.Code in project es6draft by anba.

the class Compiler method compile.

/**
 * Compiles a script node to Java bytecode.
 *
 * @param script
 *            the script node
 * @param className
 *            the class name
 * @return the compiled script
 * @throws CompilationException
 *             if the script node could not be compiled
 */
public CompiledScript compile(Script script, String className) throws CompilationException {
    if (!isEnabled(Compiler.Option.NoByteCodeSizeValidation)) {
        CodeSize.analyze(script);
    }
    if (!isEnabled(Compiler.Option.NoCompletion)) {
        CompletionValueVisitor.performCompletion(script);
    }
    long startCompile = 0;
    if (MEASURE_COMPILE_TIME) {
        startCompile = System.nanoTime();
    }
    Code code = new Code(Modifier.PUBLIC | Modifier.FINAL, className, ClassSignature.NONE, Types.CompiledScript, Collections.<Type>emptyList(), NodeSourceInfo.create(script, isEnabled(Option.SourceMap)));
    CodeGenerator codegen = new CodeGenerator(context, code, script);
    try {
        codegen.compile(script);
    } catch (RuntimeException e) {
        throw handleAsmError(e);
    }
    if (MEASURE_COMPILE_TIME) {
        long time = System.nanoTime() - startCompile;
        STATISTICS.compileTime.add(time);
        STATISTICS.compileTimeScript.add(time);
    }
    long startLoad = 0;
    if (MEASURE_LOAD_TIME) {
        startLoad = System.nanoTime();
    }
    CompiledScript compiledScript;
    try {
        if (useAnonymousLoader(code)) {
            compiledScript = defineAndLoad(script, code, AnonymousCodeLoader.SCRIPT);
        } else {
            compiledScript = defineAndLoad(script, code, className);
        }
    } catch (RuntimeException e) {
        throw handleAsmError(e);
    }
    if (MEASURE_LOAD_TIME) {
        long time = System.nanoTime() - startLoad;
        STATISTICS.loadTime.add(time);
        STATISTICS.loadTimeScript.add(time);
    }
    return compiledScript;
}
Also used : ClassCode(com.github.anba.es6draft.compiler.assembler.Code.ClassCode) Code(com.github.anba.es6draft.compiler.assembler.Code)

Example 4 with Code

use of com.github.anba.es6draft.compiler.assembler.Code in project es6draft by anba.

the class Compiler method compile.

private CompiledFunction compile(FunctionNode function, String className) {
    Script script = functionScript(function);
    if (!isEnabled(Compiler.Option.NoByteCodeSizeValidation)) {
        try {
            CodeSize.analyze(function);
        } catch (CodeSizeException e) {
            throw new CompilationException(e.getMessage());
        }
    }
    Code code = new Code(Modifier.PUBLIC | Modifier.FINAL, className, ClassSignature.NONE, Types.CompiledFunction, Collections.<Type>emptyList(), NodeSourceInfo.create(function, compilerOptions));
    CodeGenerator codegen = new CodeGenerator(code, script, executor, compilerOptions);
    codegen.compileFunction(function);
    return defineAndLoad(code, className);
}
Also used : Script(com.github.anba.es6draft.ast.Script) CodeSizeException(com.github.anba.es6draft.compiler.analyzer.CodeSizeException) ClassCode(com.github.anba.es6draft.compiler.assembler.Code.ClassCode) Code(com.github.anba.es6draft.compiler.assembler.Code)

Aggregations

Code (com.github.anba.es6draft.compiler.assembler.Code)4 ClassCode (com.github.anba.es6draft.compiler.assembler.Code.ClassCode)4 Script (com.github.anba.es6draft.ast.Script)2 CodeSizeException (com.github.anba.es6draft.compiler.analyzer.CodeSizeException)1