public void Finalize(BasicBlocks basicBlocks) { foreach (var block in included) { if (!basicBlocks.Contains(block)) continue; Trace(block); } }
private void EmitProtectedRegionTable() { var trace = CreateTraceLog("Regions"); var protectedRegionTableSymbol = MethodCompiler.Linker.CreateSymbol(MethodCompiler.Method.FullName + Metadata.ProtectedRegionTable, SectionKind.ROData, NativeAlignment, 0); var writer = new EndianAwareBinaryWriter(protectedRegionTableSymbol.Stream, Architecture.Endianness); int sectioncount = 0; // 1. Number of Regions (dummy for now) writer.Write((uint)0); foreach (var region in MethodCompiler.ProtectedRegions) { var handler = (uint)codeEmitter.GetPosition(region.Handler.HandlerStart); if (trace.Active) { trace.Log("Handler: " + region.Handler.TryStart.ToString("X4") + " to " + region.Handler.TryEnd.ToString("X4") + " Handler: " + region.Handler.HandlerStart.ToString("X4") + " Offset: [" + handler.ToString("X4") + "]"); } List <Tuple <int, int> > sections = new List <Tuple <int, int> >(); foreach (var block in region.IncludedBlocks) { // Check if block continues to exist if (!BasicBlocks.Contains(block)) { continue; } int start = codeEmitter.GetPosition(block.Label); int end = codeEmitter.GetPosition(block.Label + 0x0F000000); if (trace.Active) { trace.Log(" Block: " + block.ToString() + " [" + start.ToString() + "-" + end.ToString() + "]"); } AddSection(sections, start, end); } foreach (var s in sections) { int start = s.Item1; int end = s.Item2; sectioncount++; var name = MethodCompiler.Method.FullName + Metadata.ProtectedRegionTable + "$" + sectioncount.ToString(); var protectedRegionDefinition = CreateProtectedRegionDefinition(name, (uint)start, (uint)end, handler, region.Handler.HandlerType, region.Handler.Type); MethodCompiler.Linker.Link(LinkType.AbsoluteAddress, NativePatchType, protectedRegionTableSymbol, (int)writer.Position, 0, protectedRegionDefinition, 0); writer.WriteZeroBytes(TypeLayout.NativePointerSize); if (trace.Active) { trace.Log(" Section: [" + start.ToString() + "-" + end.ToString() + "]"); } } } // 1. Number of Regions (now put the real number) writer.Position = 0; writer.Write(sectioncount); }