Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6105 from acmyu/r2r
Browse files Browse the repository at this point in the history
Straightforward bugfixes and trivial additions
  • Loading branch information
acmyu committed Jul 18, 2018
2 parents b120c74 + 567420b commit cdd2842
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 59 deletions.
48 changes: 39 additions & 9 deletions src/Common/src/Internal/NativeFormat/NativeFormatWriter.cs
Expand Up @@ -74,6 +74,15 @@ public Vertex Place(Vertex vertex)

return vertex;
}

public Vertex Pop()
{
Vertex vertex = _items[_items.Count - 1];
_items.RemoveAt(_items.Count - 1);
Debug.Assert(vertex._offset == Vertex.Placed);
vertex._offset = Vertex.NotPlaced;
return vertex;
}
}

#if NATIVEFORMAT_PUBLICWRITER
Expand Down Expand Up @@ -1658,12 +1667,24 @@ class VertexTree : Vertex
private Vertex _first;
private Vertex _second;

public VertexTree()
{
_first = null;
_second = null;
}

public VertexTree(Vertex first, Vertex second)
{
_first = first;
_second = second;
}

public void Update(Vertex first, Vertex second)
{
_first = first;
_second = second;
}

internal override void Save(NativeWriter writer)
{
uint value = (_first != null ? 1u : 0u);
Expand Down Expand Up @@ -1701,15 +1722,15 @@ private Vertex ExpandBlock(int index, int depth, bool place, out bool isLeaf)

if (first == null && second == null)
{
isLeaf = false;
isLeaf = true;
return null;
}

if (first == null || second == null)
{
VertexLeaf leaf = new VertexLeaf(
first == null ? second : first,
first == null ? index + 1 : (index & (BlockSize - 1)));
(first == null ? index + 1 : index) & (BlockSize - 1));

if (place)
{
Expand All @@ -1731,20 +1752,31 @@ private Vertex ExpandBlock(int index, int depth, bool place, out bool isLeaf)
}
else
{
VertexTree tree = new VertexTree();
if (place)
_section.Place(tree);

bool firstIsLeaf;
Vertex first = ExpandBlock(index, depth - 1, false, out firstIsLeaf);

bool secondIsLeaf;
Vertex second = ExpandBlock(((index + 1) << (depth - 1)), depth - 1, true, out secondIsLeaf);
Vertex second = ExpandBlock(index + (1 << (depth - 1)), depth - 1, true, out secondIsLeaf);

if (first == null && second == null)
{
isLeaf = false;
if (place)
{
Vertex pop = _section.Pop();
Debug.Assert(pop == tree);
}
isLeaf = true;
return null;
}

if (first == null && secondIsLeaf)
{
Vertex pop = _section.Pop();
Debug.Assert(pop == second);
if (place)
{
_section.Place(second);
Expand All @@ -1758,18 +1790,16 @@ private Vertex ExpandBlock(int index, int depth, bool place, out bool isLeaf)
{
if (place)
{
Vertex pop = _section.Pop();
Debug.Assert(pop == tree);
_section.Place(first);
}

isLeaf = true;
return first;
}

Vertex tree = new VertexTree(first, second);
if (place)
{
_section.Place(tree);
}
tree.Update(first, second);
isLeaf = false;
return tree;
}
Expand Down
Expand Up @@ -19,11 +19,46 @@ public enum CorCompileImportType : byte

public enum CorCompileImportFlags : ushort
{
CORCOMPILE_IMPORT_FLAGS_UNKNOWN = 0x0000, // Apparently used for string fixups by CoreCLR R2R
CORCOMPILE_IMPORT_FLAGS_EAGER = 0x0001, // Section at module load time.
CORCOMPILE_IMPORT_FLAGS_CODE = 0x0002, // Section contains code.
CORCOMPILE_IMPORT_FLAGS_PCODE = 0x0004, // Section contains pointers to code.
};

/// <summary>
/// Constants for method and field encoding
/// </summary>
[Flags]
public enum ReadyToRunMethodSigFlags : byte
{
READYTORUN_METHOD_SIG_None = 0x00,
READYTORUN_METHOD_SIG_UnboxingStub = 0x01,
READYTORUN_METHOD_SIG_InstantiatingStub = 0x02,
READYTORUN_METHOD_SIG_MethodInstantiation = 0x04,
READYTORUN_METHOD_SIG_SlotInsteadOfToken = 0x08,
READYTORUN_METHOD_SIG_MemberRefToken = 0x10,
READYTORUN_METHOD_SIG_Constrained = 0x20,
READYTORUN_METHOD_SIG_OwnerType = 0x40,
};

[Flags]
public enum ReadyToRunFieldSigFlags : byte
{
READYTORUN_FIELD_SIG_IndexInsteadOfToken = 0x08,
READYTORUN_FIELD_SIG_MemberRefToken = 0x10,
READYTORUN_FIELD_SIG_OwnerType = 0x40,
};

[Flags]
public enum ReadyToRunTypeLayoutFlags : byte
{
READYTORUN_LAYOUT_HFA = 0x01,
READYTORUN_LAYOUT_Alignment = 0x02,
READYTORUN_LAYOUT_Alignment_Native = 0x04,
READYTORUN_LAYOUT_GCLayout = 0x08,
READYTORUN_LAYOUT_GCLayout_Empty = 0x10,
};

public enum ReadyToRunFixupKind
{
READYTORUN_FIXUP_ThisObjDictionaryLookup = 0x07,
Expand Down
Expand Up @@ -14,56 +14,6 @@

namespace ILCompiler.DependencyAnalysis.ReadyToRun
{
/// <summary>
/// CorCompileImportSection describes image range with references to other assemblies or runtime data structures
///
/// There is number of different types of these ranges: eagerly initialized at image load vs. lazily initialized at method entry
/// vs. lazily initialized on first use; hot vs. cold, handles vs. code pointers, etc.
/// </summary>
struct CorCompileImportSection
{
public readonly int SectionIndex; // Section containing values to be fixed up
public readonly ushort Flags; // One or more of CorCompileImportFlags
public readonly byte Type; // One of CorCompileImportType
public readonly byte EntrySize;
public readonly ISymbolNode Signatures; // RVA of optional signature descriptors
public readonly ISymbolNode AuxiliaryData; // RVA of optional auxiliary data (typically GC info)

public CorCompileImportSection(
int sectionIndex,
ushort flags,
byte type,
byte entrySize,
ISymbolNode signatures,
ISymbolNode auxiliaryData)
{
SectionIndex = sectionIndex;
Flags = flags;
Type = type;
EntrySize = entrySize;
Signatures = signatures;
AuxiliaryData = auxiliaryData;
}

public enum CorCompileImportType : byte
{
CORCOMPILE_IMPORT_TYPE_UNKNOWN = 0,
CORCOMPILE_IMPORT_TYPE_EXTERNAL_METHOD = 1,
CORCOMPILE_IMPORT_TYPE_STUB_DISPATCH = 2,
CORCOMPILE_IMPORT_TYPE_STRING_HANDLE = 3,
CORCOMPILE_IMPORT_TYPE_TYPE_HANDLE = 4,
CORCOMPILE_IMPORT_TYPE_METHOD_HANDLE = 5,
CORCOMPILE_IMPORT_TYPE_VIRTUAL_METHOD = 6,
};

public enum CorCompileImportFlags : ushort
{
CORCOMPILE_IMPORT_FLAGS_EAGER = 0x0001, // Section at module load time.
CORCOMPILE_IMPORT_FLAGS_CODE = 0x0002, // Section contains code.
CORCOMPILE_IMPORT_FLAGS_PCODE = 0x0004, // Section contains pointers to code.
};
};

public class ImportSectionsTableNode : ArrayOfEmbeddedDataNode<ImportSectionNode>
{
public ImportSectionsTableNode(TargetDetails target)
Expand Down

0 comments on commit cdd2842

Please sign in to comment.