final ABCEmitter emitter = (ABCEmitter)global_scope.getEmitter();
// CG targets the latest version - these ABCs can be postprocessed to downgrade to previous versions
emitter.visit(ABCConstants.VERSION_ABC_MAJOR_FP10, ABCConstants.VERSION_ABC_MINOR_FP10);
IScriptVisitor sv = emitter.visitScript();
sv.visit();
MethodInfo init_method = new MethodInfo();
sv.visitInit(init_method);
MethodBodyInfo init_body = new MethodBodyInfo();
init_body.setMethodInfo(init_method);
IMethodVisitor mv = emitter.visitMethod(init_method);
mv.visit();
IMethodBodyVisitor mbv = mv.visitBody(init_body);
mbv.visit();
global_scope.traitsVisitor = sv.visitTraits();
global_scope.setMethodInfo(init_method);
global_scope.methodBodyVisitor = mbv;
global_scope.setInitialControlFlowRegionNode(root_node);
// Process global directives.
GlobalDirectiveProcessor top_level_processor = new GlobalDirectiveProcessor(executorService, useParallelCodegen, global_scope, emitter);
boolean fatal_error_encountered = false;
try
{
top_level_processor.traverse(root_node);
}
catch (MissingBuiltinException e)
{
global_scope.addProblem(new MissingBuiltinProblem(root_node, e.getBuiltinName()));
fatal_error_encountered = true;
}
catch (CodegenInterruptedException e)
{
// Unwrap the InterruptedException and rethrow it.
throw e.getException();
}
top_level_processor.finish();
byte[] generatedBytes = IABCBytesRequestResult.ZEROBYTES;
if ( !fatal_error_encountered )
{
// Initialize the init script.
InstructionList script_init_insns = new InstructionList();
script_init_insns.addInstruction(OP_getlocal0);
script_init_insns.addInstruction(OP_pushscope);
script_init_insns.addAll(global_scope.getInitInstructions());
script_init_insns.addAll(top_level_processor.directiveInsns);
if ( script_init_insns.canFallThrough() || script_init_insns.hasPendingLabels() )
script_init_insns.addInstruction(OP_returnvoid);
// Allocate temps beginning with register 1,
// register 0 is reserved for "this" global.
global_scope.initializeTempRegisters(1);
// Make any vistEnd method calls
// that were deferred.
// callVisitEnds must be called on the same thread
// that original called ABCGenerator.generate ( this method ).
global_scope.callVisitEnds();
mbv.visitInstructionList(script_init_insns);
mbv.visitEnd();
mv.visitEnd();
global_scope.traitsVisitor.visitEnd();
sv.visitEnd();
try
{
generatedBytes = emitter.emit();
}