Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Type Layout #41

Open
wants to merge 4 commits into
base: metadata-provider
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions MetadataProvider/AssemblyExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ private void ExtractType(SRM.TypeDefinitionHandle typedefHandle)
ExtractType(handle);
}

var layout = typedef.GetLayout();
LayoutInformation layoutInformation;
if (layout.IsDefault)
{
var layoutKind = typedef.Attributes.HasFlag(SR.TypeAttributes.SequentialLayout) ? LayoutKind.SequentialLayout : LayoutKind.AutoLayout;
layoutInformation = new LayoutInformation(layoutKind);
}
else
{
var kind = typedef.Attributes.HasFlag(SR.TypeAttributes.SequentialLayout) ? LayoutKind.SequentialLayout : LayoutKind.ExplicitLayout;
layoutInformation = new LayoutInformation(kind)
{
PackingSize = layout.PackingSize,
ClassSize = layout.Size
};
}

type.LayoutInformation = layoutInformation;

currentType = currentType.ContainingType;
}

Expand Down
25 changes: 24 additions & 1 deletion Model/Types/TypeDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,28 @@ public enum VisibilityKind
Public = 8
}

public enum LayoutKind
{
AutoLayout,
SequentialLayout,
ExplicitLayout
}

public class LayoutInformation
{
public LayoutKind Kind { get; set; }
public int PackingSize { get; set; }
public int ClassSize { get; set; }

public LayoutInformation(LayoutKind kind = LayoutKind.AutoLayout)
{
Kind = kind;
PackingSize = -1;
ClassSize = -1;
}

public bool SpecifiesSizes() => PackingSize != -1 && ClassSize != -1;
}
public class TypeDefinition : IBasicType, IGenericDefinition, ITypeMemberDefinition, ITypeDefinitionContainer
{
public TypeKind TypeKind { get; set; }
Expand All @@ -623,7 +645,7 @@ public class TypeDefinition : IBasicType, IGenericDefinition, ITypeMemberDefinit
public IList<MethodDefinition> Methods { get; private set; }
public IList<TypeDefinition> Types { get; private set; }
public IBasicType UnderlayingType { get; set; }

public LayoutInformation LayoutInformation { get; set; }
public TypeDefinition(string name, TypeKind typeKind = TypeKind.Unknown, TypeDefinitionKind kind = TypeDefinitionKind.Unknown)
{
this.Name = name;
Expand All @@ -635,6 +657,7 @@ public TypeDefinition(string name, TypeKind typeKind = TypeKind.Unknown, TypeDef
this.Fields = new List<FieldDefinition>();
this.Methods = new List<MethodDefinition>();
this.Types = new List<TypeDefinition>();
this.LayoutInformation = new LayoutInformation();
}

public string GenericName
Expand Down