/// <summary> /// Initializes a new instance of the <see cref="CallContext" /> class. /// </summary> /// <param name="context">Current analyzing context.</param> /// <param name="name">The name.</param> /// <param name="transformProvider">The transform provider.</param> /// <param name="generator">The generator of call's instructions.</param> /// <param name="argumentValues">The argument values.</param> internal CallContext(AnalyzingContext context, MethodID name, CallTransformProvider transformProvider, GeneratorBase generator, Instance[] argumentValues) { _context = context; Caller = context.CurrentCall; ArgumentValues = argumentValues; Name = name; TransformProvider = transformProvider; if (Caller != null) { CallingBlock = Caller.CurrentBlock; } var emitter = new CallEmitter(context); generator.Generate(emitter); Program = emitter.GetEmittedInstructions(); _instructionPointer = 0; if (Program.Instructions.Length <= _instructionPointer) { //cannot run empty program return; } EntryBlock = new ExecutedBlock(Program.Instructions[0].Info, this); CurrentBlock = EntryBlock; }
/// <summary> /// Insert given batch of instructions (as they were emitted). /// </summary> /// <param name="instructions">Inserted instructions.</param> /// <exception cref="System.NotSupportedException">Cannot insert instructions twice.</exception> public override void InsertInstructions(InstructionBatch instructions) { if (_emittedProgram != null) { throw new NotSupportedException("Cannot insert instructions twice."); } _emittedProgram = instructions; }
/// <summary> /// Get emitted program. /// </summary> /// <returns>Program that has been emitted.</returns> public override InstructionBatch GetEmittedInstructions() { if (_emittedProgram == null) { _emittedProgram = new InstructionBatch(_instructions.ToArray()); } return(_emittedProgram); }