Esempio n. 1
0
        /// <summary>
        /// Called to emit a list of instructions offered by the instruction provider.
        /// </summary>
        private void EmitInstructions()
        {
            var trace = CreateTraceLog(9);

            MethodData.LabelRegions.Clear();
            int labelCurrent = BasicBlock.ReservedLabel;
            int labelStart   = 0;

            foreach (var block in BasicBlocks)
            {
                BlockStart(block);

                for (var node = block.First; !node.IsBlockEndInstruction; node = node.Next)
                {
                    if (node.IsEmptyOrNop)
                    {
                        continue;
                    }

                    if (node.IsBlockStartInstruction)
                    {
                        trace?.Log($"Block #{block.Sequence} - Label L_{block.Label:X4}" + (block.IsHeadBlock ? " [Header]" : string.Empty));

                        continue;
                    }

                    if (node.Instruction.IgnoreDuringCodeGeneration)
                    {
                        continue;
                    }

                    node.Offset = CodeEmitter.CurrentPosition;

                    if (node.Instruction is BasePlatformInstruction baseInstruction)
                    {
                        if (node.Label != labelCurrent)
                        {
                            if (labelCurrent != BasicBlock.ReservedLabel)
                            {
                                MethodData.AddLabelRegion(labelCurrent, labelStart, CodeEmitter.CurrentPosition - labelStart);
                            }

                            labelCurrent = node.Label;
                            labelStart   = node.Offset;
                        }

                        baseInstruction.Emit(node, CodeEmitter);

                        GeneratedInstructionCount++;

                        trace?.Log($"{node.Offset} - /0x{node.Offset.ToString("X")} : {node}");
                    }
                    else
                    {
                        PostCompilerTraceEvent(CompilerEvent.Error, $"Missing Code Transformation: {node}");
                    }
                }

                block.Last.Offset = CodeEmitter.CurrentPosition;

                BlockEnd(block);
                GeneratedBlockCount++;
            }

            MethodData.AddLabelRegion(labelCurrent, labelStart, CodeEmitter.CurrentPosition - labelStart);
        }