Skip to content

Commit

Permalink
Merge pull request #573 from tgiphil/master
Browse files Browse the repository at this point in the history
Minor refactoring
  • Loading branch information
tgiphil committed Jan 20, 2019
2 parents 4a5d9a4 + c4279d3 commit 1ae814c
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void EmitTypes()
writer.WriteLine(
"{0}\t{1:x8}\t{2}\t{3}\t{4}\t{5}\t{6}",
type.ID,
Linker.GetSymbol(type.FullName + Metadata.TypeDefinition).VirtualAddress,
Linker.GetSymbol(type.FullName).VirtualAddress,
TypeLayout.GetTypeSize(type),
type.FullName,
(type.BaseType != null) ? type.BaseType.ID : 0,
Expand Down Expand Up @@ -139,7 +139,7 @@ private void EmitMethods()
method.ID,
symbol.VirtualAddress,
symbol.Size,
Linker.GetSymbol(method.FullName + Metadata.MethodDefinition).VirtualAddress,
Linker.GetSymbol(Metadata.MethodDefinition + method.FullName).VirtualAddress,
method.FullName,
method.Signature.ReturnType.ID,
methodData.LocalMethodStackSize,
Expand Down Expand Up @@ -196,7 +196,7 @@ private void EmitFields()

foreach (var field in type.Fields)
{
var symbol = Linker.GetSymbol(field.FullName + Metadata.FieldDefinition);
var symbol = Linker.GetSymbol(Metadata.FieldDefinition + field.FullName);

//var datasection = (field.Data != null) ? SectionKind.ROData : SectionKind.BSS; // not used yet

Expand Down
84 changes: 41 additions & 43 deletions Source/Mosa.Compiler.Framework/CompilerStages/MetadataStage.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void CreateMethodExceptionLookupTable()

foreach (var method in methodList)
{
if (method.IsAbstract) // or !HasImplementation
if ((!method.HasImplementation && method.IsAbstract) || method.HasOpenGenericParams || method.DeclaringType.HasOpenGenericParams)
continue;

if (method.ExceptionHandlers.Count == 0)
Expand Down Expand Up @@ -95,11 +95,14 @@ protected void CreateMethodExceptionLookupTable()
writer.WriteZeroBytes(TypeLayout.NativePointerSize);

// 3. Pointer to Method Definition
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, methodLookupTable, (int)writer.Position, method.FullName + Metadata.MethodDefinition, 0);
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, methodLookupTable, (int)writer.Position, Metadata.MethodDefinition + method.FullName, 0);
writer.WriteZeroBytes(TypeLayout.NativePointerSize);
}
}
}

// emit null entry (FUTURE)
//writer.WriteZeroBytes(TypeLayout.NativePointerSize * 3);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override void RunPostCompile()
writer.WriteZeroBytes(TypeLayout.NativePointerSize);

// 3. Pointer to Method Definition
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, methodLookupTable, (int)writer.Position, method.FullName + Metadata.MethodDefinition, 0);
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, methodLookupTable, (int)writer.Position, Metadata.MethodDefinition + method.FullName, 0);
writer.WriteZeroBytes(TypeLayout.NativePointerSize);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework.IR;

namespace Mosa.Compiler.Framework.Intrinsics
{
/// <summary>
/// IntrinsicMethods
/// </summary>
static partial class IntrinsicMethods
{
[IntrinsicMethod("Mosa.Runtime.Intrinsic:GetMethodExceptionLookupTable")]
private static void GetMethodExceptionLookupTable(Context context, MethodCompiler methodCompiler)
{
var move = methodCompiler.Architecture.Is32BitPlatform ? (BaseInstruction)IRInstruction.MoveInt32 : IRInstruction.MoveInt64;

context.SetInstruction(move, context.Result, Operand.CreateUnmanagedSymbolPointer(Metadata.MethodExceptionLookupTable, methodCompiler.TypeSystem));
}
}
}
20 changes: 20 additions & 0 deletions Source/Mosa.Compiler.Framework/Intrinsics/GetMethodLookupTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework.IR;

namespace Mosa.Compiler.Framework.Intrinsics
{
/// <summary>
/// IntrinsicMethods
/// </summary>
static partial class IntrinsicMethods
{
[IntrinsicMethod("Mosa.Runtime.Intrinsic:GetMethodLookupTable")]
private static void GetMethodLookupTable(Context context, MethodCompiler methodCompiler)
{
var move = methodCompiler.Architecture.Is32BitPlatform ? (BaseInstruction)IRInstruction.MoveInt32 : IRInstruction.MoveInt64;

context.SetInstruction(move, context.Result, Operand.CreateUnmanagedSymbolPointer(Metadata.MethodLookupTable, methodCompiler.TypeSystem));
}
}
}
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/Intrinsics/GetStringType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Mosa.Compiler.Framework.Intrinsics
/// </summary>
static partial class IntrinsicMethods
{
private const string StringClassTypeDefinitionSymbolName = "System.String" + Metadata.TypeDefinition;
private const string StringClassTypeDefinitionSymbolName = Metadata.TypeDefinition + "System.String";

[IntrinsicMethod("Mosa.Runtime.Intrinsic:GetStringType")]
private static void GetStringType(Context context, MethodCompiler methodCompiler)
Expand Down
28 changes: 14 additions & 14 deletions Source/Mosa.Compiler.Framework/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ public struct Metadata
{
public const string AssembliesTable = "<$>AssembliesTable";

public const string NameString = "$Name";
public const string NameString = "$Name$";

public const string AssemblyDefinition = "$AssemblyDef";
public const string TypeDefinition = "$TypeDef";
public const string MethodDefinition = "$MethodDef";
public const string FieldDefinition = "$FieldDef";
public const string FieldsTable = "$FieldsTable";
public const string PropertyDefinition = "$PropertyDef";
public const string PropertiesTable = "$PropertiesTable";
public const string AssemblyDefinition = "$AssemblyDef$";
public const string TypeDefinition = "$TypeDef$";
public const string MethodDefinition = "$MethodDef$";
public const string FieldDefinition = "$FieldDef$";
public const string FieldsTable = "$FieldsTable$";
public const string PropertyDefinition = "$PropertyDef$";
public const string PropertiesTable = "$PropertiesTable$";

public const string CustomAttributesTable = "$CustomAttributesTable";
public const string CustomAttribute = "$CustomAttribute";
public const string CustomAttributeArgument = "$CustomAttributeArgument";
public const string CustomAttributesTable = "$CustomAttributesTable$";
public const string CustomAttribute = "$CustomAttribute$";
public const string CustomAttributeArgument = "$CustomAttributeArgument$";

public const string InterfaceMethodTable = "$IMethodTable$";

public const string InterfaceSlotTable = "$InterfaceSlotTable";
public const string InterfaceBitmap = "$InterfaceBitmap";
public const string InterfaceSlotTable = "$InterfaceSlotTable$";
public const string InterfaceBitmap = "$InterfaceBitmap$";

public const string ProtectedRegionTable = "$ProtectedRegionTable";
public const string ProtectedRegionTable = "$ProtectedRegionTable$";

public const string MethodLookupTable = "<$>MethodLookupTable";
public const string MethodExceptionLookupTable = "<$>MethodExceptionLookupTable";
Expand Down
2 changes: 2 additions & 0 deletions Source/Mosa.Compiler.Framework/Mosa.Compiler.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
<Compile Include="ConstantOperand.cs" />
<Compile Include="CIL\IRInstructions.cs" />
<Compile Include="Counter.cs" />
<Compile Include="Intrinsics\GetMethodLookupTable.cs" />
<Compile Include="Intrinsics\GetMethodExceptionLookupTable.cs" />
<Compile Include="Intrinsics\SuppressStackFrame.cs" />
<Compile Include="IR\Add32.cs" />
<Compile Include="IR\Add64.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private string GetTypeDefinition(MosaType allocatedType)
{
if (!allocatedType.IsValueType)
{
return allocatedType.FullName + Metadata.TypeDefinition;
return Metadata.TypeDefinition + allocatedType.FullName;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ private MosaMethod GetMethodOrOverride(MosaType type, MosaMethod method)

private Operand GetRuntimeTypeHandle(MosaType runtimeType)
{
return Operand.CreateSymbol(TypeSystem.GetTypeByName("System", "RuntimeTypeHandle"), runtimeType.FullName + Metadata.TypeDefinition);
return Operand.CreateSymbol(TypeSystem.GetTypeByName("System", "RuntimeTypeHandle"), Metadata.TypeDefinition + runtimeType.FullName);
}

/// <summary>
Expand Down Expand Up @@ -1074,7 +1074,7 @@ private void Ldstr(InstructionNode node)
var stream = symbol.Stream;

// Type Definition and sync block
linker.Link(LinkType.AbsoluteAddress, PatchType.I4, symbol, 0, "System.String" + Metadata.TypeDefinition, 0);
linker.Link(LinkType.AbsoluteAddress, PatchType.I4, symbol, 0, Metadata.TypeDefinition + "System.String", 0);

stream.WriteZeroBytes(NativePointerSize * 2);

Expand All @@ -1100,12 +1100,12 @@ private void Ldtoken(Context context)

if (context.MosaType != null)
{
source = Operand.CreateUnmanagedSymbolPointer(context.MosaType.FullName + Metadata.TypeDefinition, TypeSystem);
source = Operand.CreateUnmanagedSymbolPointer(Metadata.TypeDefinition + context.MosaType.FullName, TypeSystem);
runtimeHandle = AllocateVirtualRegister(TypeSystem.GetTypeByName("System", "RuntimeTypeHandle"));
}
else if (context.MosaField != null)
{
source = Operand.CreateUnmanagedSymbolPointer(context.MosaField.FullName + Metadata.FieldDefinition, TypeSystem);
source = Operand.CreateUnmanagedSymbolPointer(Metadata.FieldDefinition + context.MosaField.FullName, TypeSystem);
runtimeHandle = AllocateVirtualRegister(TypeSystem.GetTypeByName("System", "RuntimeFieldHandle"));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void EmitProtectedRegionTable()
{
var trace = CreateTraceLog("Regions");

var protectedRegionTableSymbol = MethodCompiler.Linker.DefineSymbol(MethodCompiler.Method.FullName + Metadata.ProtectedRegionTable, SectionKind.ROData, NativeAlignment, 0);
var protectedRegionTableSymbol = MethodCompiler.Linker.DefineSymbol(Metadata.ProtectedRegionTable + MethodCompiler.Method.FullName, SectionKind.ROData, NativeAlignment, 0);
var writer = new EndianAwareBinaryWriter(protectedRegionTableSymbol.Stream, Architecture.Endianness);

int sectioncount = 0;
Expand Down Expand Up @@ -84,7 +84,7 @@ private void EmitProtectedRegionTable()

sectioncount++;

var name = MethodCompiler.Method.FullName + Metadata.ProtectedRegionTable + "$" + sectioncount.ToString();
var name = Metadata.ProtectedRegionTable + MethodCompiler.Method.FullName + "$" + sectioncount.ToString();
var protectedRegionDefinition = CreateProtectedRegionDefinition(name, (uint)start, (uint)end, handler, region.Handler.ExceptionHandlerType, region.Handler.Type);
MethodCompiler.Linker.Link(LinkType.AbsoluteAddress, NativePatchType, protectedRegionTableSymbol, (int)writer.Position, protectedRegionDefinition, 0);
writer.WriteZeroBytes(TypeLayout.NativePointerSize);
Expand Down Expand Up @@ -122,7 +122,7 @@ private LinkerSymbol CreateProtectedRegionDefinition(string name, uint start, ui
{
// Store method table pointer of the exception object type
// The VES exception runtime will uses this to compare exception object types
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, protectedRegionDefinitionSymbol, (int)writer1.Position, exceptionType.FullName + Metadata.TypeDefinition, 0);
Linker.Link(LinkType.AbsoluteAddress, NativePatchType, protectedRegionDefinitionSymbol, (int)writer1.Position, Metadata.TypeDefinition + exceptionType.FullName, 0);
}
else if (handlerType == ExceptionHandlerType.Filter)
{
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions Source/Mosa.Platform.x86/Intrinsic/GetMethodLookupTable.cs

This file was deleted.

2 changes: 0 additions & 2 deletions Source/Mosa.Platform.x86/Mosa.Platform.x86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
<Compile Include="Intrinsic\GetCS.cs" />
<Compile Include="Intrinsic\GetFS.cs" />
<Compile Include="Intrinsic\GetExceptionRegister.cs" />
<Compile Include="Intrinsic\GetMethodExceptionLookupTable.cs" />
<Compile Include="Intrinsic\GetMultibootEAX.cs" />
<Compile Include="Intrinsic\GetMultibootEBX.cs" />
<Compile Include="Intrinsic\Int.cs" />
Expand Down Expand Up @@ -313,7 +312,6 @@
<Compile Include="Stages\AddressModeConversionStage.cs" />
<Compile Include="Stages\FixedRegisterAssignmentStage.cs" />
<Compile Include="Intrinsic\GetEBP.cs" />
<Compile Include="Intrinsic\GetMethodLookupTable.cs" />
<Compile Include="Intrinsic\Cli.cs" />
<Compile Include="Intrinsic\GetCR0.cs" />
<Compile Include="Intrinsic\GetCR2.cs" />
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Runtime.x86/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Fault(uint code, uint extra = 0)

public static MethodDefinition GetMethodDefinition(IntPtr address)
{
var table = Native.GetMethodLookupTable();
var table = Intrinsic.GetMethodLookupTable();
uint entries = Intrinsic.Load32(table);

table += IntPtr.Size; // skip count
Expand All @@ -42,7 +42,7 @@ public static MethodDefinition GetMethodDefinition(IntPtr address)

public static MethodDefinition GetMethodDefinitionViaMethodExceptionLookup(IntPtr address)
{
var table = Native.GetMethodExceptionLookupTable();
var table = Intrinsic.GetMethodExceptionLookupTable();

if (table == IntPtr.Zero)
{
Expand Down
6 changes: 0 additions & 6 deletions Source/Mosa.Runtime.x86/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ public static unsafe class Native
[DllImportAttribute("Mosa.Platform.x86.Intrinsic:GetIDTJumpLocation")]
public extern static uint GetIDTJumpLocation(uint irq);

[DllImportAttribute("Mosa.Platform.x86.Intrinsic:GetMethodLookupTable")]
public extern static IntPtr GetMethodLookupTable();

[DllImportAttribute("Mosa.Platform.x86.Intrinsic:GetMethodExceptionLookupTable")]
public extern static IntPtr GetMethodExceptionLookupTable();

[DllImportAttribute("Mosa.Platform.x86.Intrinsic:GetMultibootEAX")]
public extern static uint GetMultibootEAX();

Expand Down
6 changes: 6 additions & 0 deletions Source/Mosa.Runtime/Intrinsic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public static unsafe class Intrinsic
[MethodImpl(MethodImplOptions.InternalCall)]
public extern static void SuppressStackFrame();

[MethodImpl(MethodImplOptions.InternalCall)]
public extern static IntPtr GetMethodLookupTable();

[MethodImpl(MethodImplOptions.InternalCall)]
public extern static IntPtr GetMethodExceptionLookupTable();

#endregion Intrinsic
}
}

0 comments on commit 1ae814c

Please sign in to comment.