protected override void Finish() { if (counts == null) { return; } int total = 0; for (int op = 0; op < counts.Length; op++) { int count = counts[op]; if (count == 0) { continue; } var cil = CILInstruction.Get((OpCode)op); //UpdateCounter("CILDecodingStage.OpCode." + cil.FullName, count); total += count; } //UpdateCounter("CILDecodingStage.CILInstructions", total); instruction = null; block = null; counts = null; }
/// <summary> /// Decodes the instruction stream of the reader and populates the compiler. /// </summary> /// <exception cref="InvalidMetadataException"></exception> private void DecodeInstructions() { block = null; // Prefix instruction bool prefix = false; for (int i = 0; i < MethodCompiler.Method.Code.Count; i++) { instruction = MethodCompiler.Method.Code[i]; block = BasicBlocks.GetByLabel(instruction.Offset) ?? block; var op = (OpCode)instruction.OpCode; var cil = CILInstruction.Get(op); if (cil == null) { throw new InvalidMetadataException(); } // Create and initialize the corresponding instruction var node = new InstructionNode(); node.Label = instruction.Offset; node.HasPrefix = prefix; node.Instruction = cil; block.BeforeLast.Insert(node); cil.Decode(node, this); prefix = (cil is PrefixInstruction); instructionCount++; bool addjmp = false; var flow = node.Instruction.FlowControl; if (flow == FlowControl.Next || flow == FlowControl.Call || flow == FlowControl.ConditionalBranch || flow == FlowControl.Switch) { var nextInstruction = MethodCompiler.Method.Code[i + 1]; if (BasicBlocks.GetByLabel(nextInstruction.Offset) != null) { var target = GetBlockByLabel(nextInstruction.Offset); var jmpNode = new InstructionNode(IRInstruction.Jmp, target); jmpNode.Label = instruction.Offset; block.BeforeLast.Insert(jmpNode); } } } }
private void DecodeInstructionTargets() { bool branched = false; for (int i = 0; i < MethodCompiler.Method.Code.Count; i++) { instruction = MethodCompiler.Method.Code[i]; if (branched) { GetBlockByLabel(instruction.Offset); branched = false; } var op = (OpCode)instruction.OpCode; var cil = CILInstruction.Get(op); branched = cil.DecodeTargets(this); } }
protected override void Finish() { instruction = null; block = null; }
protected override void Setup() { instruction = null; block = null; }