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

Additional Math functions #620

Merged
merged 29 commits into from Apr 1, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

- WIP

  • Loading branch information...
tgiphil committed Mar 19, 2019
commit 455790343a7d172fb3072b7b17be2ea280e08dc3
@@ -54,6 +54,8 @@ public abstract class BaseCompilerStage
/// </summary>
protected CompilationScheduler CompilationScheduler { get { return Compiler.CompilationScheduler; } }

protected MethodScanner MethodScanner { get { return Compiler.MethodScanner; } }

#endregion Properties

/// <summary>
@@ -111,6 +111,11 @@ public abstract class BaseMethodCompilerStage : ITraceFactory
/// </summary>
protected MethodCompiler MethodCompiler { get; private set; }

/// <summary>
/// Hold the method compiler
/// </summary>
protected MethodScanner MethodScanner { get; private set; }

/// <summary>
/// Gets the method data.
/// </summary>
@@ -176,20 +181,22 @@ public abstract class BaseMethodCompilerStage : ITraceFactory
/// <summary>
/// Setups the specified compiler.
/// </summary>
/// <param name="baseCompiler">The base compiler.</param>
public void Initialize(Compiler baseCompiler)
/// <param name="compiler">The base compiler.</param>
public void Initialize(Compiler compiler)
{
Architecture = baseCompiler.Architecture;
TypeSystem = baseCompiler.TypeSystem;
TypeLayout = baseCompiler.TypeLayout;
Architecture = compiler.Architecture;
TypeSystem = compiler.TypeSystem;
TypeLayout = compiler.TypeLayout;

NativePointerSize = Architecture.NativePointerSize;
NativeAlignment = Architecture.NativeAlignment;
NativeInstructionSize = Architecture.NativeInstructionSize;
Is32BitPlatform = Architecture.Is32BitPlatform;
Is64BitPlatform = Architecture.Is64BitPlatform;

CompilerOptions = baseCompiler.CompilerOptions;
CompilerOptions = compiler.CompilerOptions;

MethodScanner = compiler.MethodScanner;

Initialize();
}
@@ -360,7 +360,8 @@ private void ExecuteCompilePass()
if (IsStopped)
return;

CompilerMethodInQueue();
if (CompilerMethodInQueue() == null)
return;
}
}

@@ -81,8 +81,8 @@ protected override void RunPreCompile()

Compiler.PlugSystem.CreatePlug(initializeAssemblyMethod, typeInitializerMethod);

Compiler.MethodScanner.MethodInvoked(initializeAssemblyMethod, initializeAssemblyMethod);
Compiler.MethodScanner.MethodInvoked(typeInitializerMethod, typeInitializerMethod);
MethodScanner.MethodInvoked(initializeAssemblyMethod, initializeAssemblyMethod);
MethodScanner.MethodInvoked(typeInitializerMethod, typeInitializerMethod);

foreach (var type in TypeSystem.AllTypes)
{
@@ -92,7 +92,7 @@ protected override void RunPreCompile()
{
Schedule(method);

Compiler.MethodScanner.MethodInvoked(method, method);
MethodScanner.MethodInvoked(method, method);
}
}
}
@@ -192,6 +192,11 @@ public sealed class MethodCompiler
/// </summary>
public bool IsStopped { get; private set; }

/// <summary>
/// Gets the method scanner.
/// </summary>
public MethodScanner MethodScanner { get; private set; }

#endregion Properties

#region Construction
@@ -216,6 +221,7 @@ public MethodCompiler(Compiler compiler, MosaMethod method, BasicBlocks basicBlo
TypeLayout = compiler.TypeLayout;
Trace = compiler.CompilerTrace;
Linker = compiler.Linker;
MethodScanner = compiler.MethodScanner;

BasicBlocks = basicBlocks ?? new BasicBlocks();
LocalStack = new List<Operand>();
@@ -275,7 +275,7 @@ private BasicBlock GetBlockByLabel(int label)
/// <summary>
/// Gets the type system.
/// </summary>
MethodScanner IInstructionDecoder.MethodScanner { get { return MethodCompiler.Compiler.MethodScanner; } }
MethodScanner IInstructionDecoder.MethodScanner { get { return MethodCompiler.MethodScanner; } }

/// <summary>
/// Gets the Instruction being decoded.
@@ -52,13 +52,13 @@ private List<InstructionNode> ScanForNewOperators()
if (!MosaTypeLayout.IsStoredOnStack(node.Result.Type))
{
list.Add(node);
MethodCompiler.Compiler.MethodScanner.TypeAllocated(node.InvokeMethod.DeclaringType, Method);
MethodScanner.TypeAllocated(node.InvokeMethod.DeclaringType, Method);
}
}
else if (node.Instruction is NewarrInstruction)
{
list.Add(node);
MethodCompiler.Compiler.MethodScanner.TypeAllocated(node.Result.Type, Method);
MethodScanner.TypeAllocated(node.Result.Type, Method);
}
}
}
@@ -950,7 +950,7 @@ private void Ldflda(InstructionNode node)
{
var field = node.MosaField;

MethodCompiler.Compiler.MethodScanner.AccessedField(field);
MethodScanner.AccessedField(field);

int offset = TypeLayout.GetFieldOffset(field);

@@ -975,7 +975,7 @@ private void Ldftn(InstructionNode node)
{
var invokedMethod = node.InvokeMethod;

MethodCompiler.Compiler.MethodScanner.MethodInvoked(invokedMethod, Method);
MethodScanner.MethodInvoked(invokedMethod, Method);

node.SetInstruction(Select(node.Result, IRInstruction.MoveInt32, IRInstruction.MoveInt64), node.Result, Operand.CreateSymbolFromMethod(invokedMethod, TypeSystem));
}
@@ -1034,7 +1034,7 @@ private void Ldsfld(InstructionNode node)
{
var field = node.MosaField;

MethodCompiler.Compiler.MethodScanner.AccessedField(field);
MethodScanner.AccessedField(field);

var fieldType = field.FieldType;
var destination = node.Result;
@@ -1062,7 +1062,7 @@ private void Ldsflda(InstructionNode node)
{
var field = node.MosaField;

MethodCompiler.Compiler.MethodScanner.AccessedField(field);
MethodScanner.AccessedField(field);

var fieldOperand = Operand.CreateStaticField(field, TypeSystem);

@@ -1114,26 +1114,23 @@ private void Ldtoken(Context context)
// TODO: remove VmCall.GetHandleForToken?

Operand source;
Operand runtimeHandle;

if (context.MosaType != null)
{
source = Operand.CreateUnmanagedSymbolPointer(Metadata.TypeDefinition + context.MosaType.FullName, TypeSystem);
runtimeHandle = AllocateVirtualRegister(TypeSystem.GetTypeByName("System", "RuntimeTypeHandle"));
}
else if (context.MosaField != null)
{
source = Operand.CreateUnmanagedSymbolPointer(Metadata.FieldDefinition + context.MosaField.FullName, TypeSystem);
runtimeHandle = AllocateVirtualRegister(TypeSystem.GetTypeByName("System", "RuntimeFieldHandle"));

MethodScanner.AccessedField(context.MosaField);
}
else
{
throw new NotImplementCompilerException();
}

var destination = context.Result;
context.SetInstruction(Select(runtimeHandle, IRInstruction.MoveInt32, IRInstruction.MoveInt64), runtimeHandle, source);
context.AppendInstruction(Select(destination, IRInstruction.MoveInt32, IRInstruction.MoveInt64), destination, runtimeHandle);
context.SetInstruction(Select(context.Result, IRInstruction.MoveInt32, IRInstruction.MoveInt64), context.Result, source);
}

/// <summary>
@@ -1279,16 +1276,6 @@ private void Nop(InstructionNode node)
node.SetInstruction(IRInstruction.Nop);
}

private static BaseIRInstruction Select(Operand operand, BaseIRInstruction instruction32, BaseIRInstruction instruction64)
{
return Select(operand.Is64BitInteger, instruction32, instruction64);
}

private static BaseIRInstruction Select(bool is64Bit, BaseIRInstruction instruction32, BaseIRInstruction instruction64)
{
return !is64Bit ? instruction32 : instruction64;
}

/// <summary>
/// Visitation function for Not instruction.
/// </summary>
@@ -1447,7 +1434,7 @@ private void Stfld(InstructionNode node)
{
var field = node.MosaField;

MethodCompiler.Compiler.MethodScanner.AccessedField(field);
MethodScanner.AccessedField(field);

int offset = TypeLayout.GetFieldOffset(field);
var offsetOperand = CreateConstant(offset);
@@ -1533,7 +1520,7 @@ private void Stsfld(InstructionNode node)
{
var field = node.MosaField;

MethodCompiler.Compiler.MethodScanner.AccessedField(field);
MethodScanner.AccessedField(field);

var fieldOperand = Operand.CreateStaticField(field, TypeSystem);
var fieldType = field.FieldType;
@@ -1669,6 +1656,16 @@ protected override void Run()

#region Internals

private static BaseIRInstruction Select(Operand operand, BaseIRInstruction instruction32, BaseIRInstruction instruction64)
{
return Select(operand.Is64BitInteger, instruction32, instruction64);
}

private static BaseIRInstruction Select(bool is64Bit, BaseIRInstruction instruction32, BaseIRInstruction instruction64)
{
return !is64Bit ? instruction32 : instruction64;
}

private struct ConversionEntry
{
public BaseInstruction Instruction;
@@ -101,7 +101,7 @@ private void CallStatic(InstructionNode node)

Debug.Assert(method == call.Method);

MethodCompiler.Compiler.MethodScanner.MethodDirectInvoked(call.Method, Method);
MethodScanner.MethodDirectInvoked(call.Method, Method);
}

private void CallDynamic(InstructionNode node)
@@ -120,7 +120,7 @@ private void CallDynamic(InstructionNode node)

if (call.Method != null)
{
MethodCompiler.Compiler.MethodScanner.MethodInvoked(call.Method, Method);
MethodScanner.MethodInvoked(call.Method, Method);
}
}

@@ -154,7 +154,7 @@ private void CallVirtual(InstructionNode node)

MakeCall(context, callTarget, result, operands);

MethodCompiler.Compiler.MethodScanner.MethodInvoked(method, Method);
MethodScanner.MethodInvoked(method, Method);
}

private int CalculateInterfaceSlot(MosaType interaceType)
@@ -220,7 +220,7 @@ private void CallInterface(InstructionNode node)

MakeCall(context, callTarget, result, operands);

MethodCompiler.Compiler.MethodScanner.InterfaceMethodInvoked(method, Method);
MethodScanner.InterfaceMethodInvoked(method, Method);
}

private void MakeCall(Context context, Operand target, Operand result, List<Operand> operands)
@@ -60,7 +60,7 @@ private void CallVirtual(InstructionNode node)

node.SetInstruction(IRInstruction.CallStatic, node.Result, symbol, operands);

MethodCompiler.Compiler.MethodScanner.MethodInvoked(method, Method);
MethodScanner.MethodInvoked(method, Method);
}
}
}
@@ -128,7 +128,7 @@ private void FinallyEndInstruction(InstructionNode node)
newBlocks[0].AppendInstruction(Select(exceptionRegister, IRInstruction.MoveInt32, IRInstruction.MoveInt64), exceptionRegister, exceptionVirtualRegister);
newBlocks[0].AppendInstruction(IRInstruction.CallStatic, null, Operand.CreateSymbolFromMethod(method, TypeSystem));

MethodCompiler.Compiler.MethodScanner.MethodInvoked(method, this.Method);
MethodScanner.MethodInvoked(method, Method);
}

private void FinallyStartInstruction(InstructionNode node)
@@ -160,7 +160,7 @@ private void ThrowInstruction(InstructionNode node)
//ctx.AppendInstruction(IRInstruction.KillAllExcept, null, exceptionRegister);
ctx.AppendInstruction(IRInstruction.CallStatic, null, Operand.CreateSymbolFromMethod(method, TypeSystem));

MethodCompiler.Compiler.MethodScanner.MethodInvoked(method, this.Method);
MethodScanner.MethodInvoked(method, Method);
}

private void GotoLeaveTargetInstruction(InstructionNode node)
@@ -43,7 +43,7 @@ private MosaMethod GetVMCallMethod(VmCall vmcall)

Debug.Assert(method != null, "Cannot find method: " + methodName);

MethodCompiler.Compiler.MethodScanner.MethodInvoked(method, this.Method);
MethodScanner.MethodInvoked(method, this.Method);

return method;
}
@@ -64,7 +64,7 @@ private void NewObject(InstructionNode node)

node.SetInstruction(IRInstruction.CallStatic, node.Result, symbol, node.GetOperands());

MethodCompiler.Compiler.MethodScanner.TypeAllocated(classType, Method);
MethodScanner.TypeAllocated(classType, Method);
}

private void NewArray(InstructionNode node)
@@ -75,7 +75,7 @@ private void NewArray(InstructionNode node)

node.SetInstruction(IRInstruction.CallStatic, node.Result, symbol, node.GetOperands());

MethodCompiler.Compiler.MethodScanner.TypeAllocated(arrayType, method);
MethodScanner.TypeAllocated(arrayType, method);
}

private void MemorySet(InstructionNode node)
@@ -51,7 +51,7 @@ protected void CheckForReplacement(InstructionNode node)
{
Replace(node, newTarget);

//MethodCompiler.Compiler.MethodScanner.MethodInvoked(method, Method);
//methodCompiler.MethodScanner.MethodInvoked(method, Method);
}
}

@@ -100,12 +100,12 @@ protected override void RunPreCompile()

Linker.EntryPoint = Linker.GetSymbol(multibootMethod.FullName);

Compiler.MethodScanner.MethodInvoked(multibootMethod, multibootMethod);
MethodScanner.MethodInvoked(multibootMethod, multibootMethod);

var startUpType = TypeSystem.GetTypeByName("Mosa.Runtime", "StartUp");
var initializeMethod = startUpType.FindMethodByName("Initialize");

Compiler.MethodScanner.MethodInvoked(initializeMethod, multibootMethod);
MethodScanner.MethodInvoked(initializeMethod, multibootMethod);
}

protected override void RunPostCompile()
@@ -18,19 +18,19 @@ protected override void RunPreCompile()

Compiler.PlugSystem.CreatePlug(startUpMethod, TypeSystem.EntryPoint);

Compiler.MethodScanner.MethodInvoked(startUpMethod, startUpMethod);
MethodScanner.MethodInvoked(startUpMethod, startUpMethod);

if (Linker.EntryPoint == null)
{
var initializeMethod = startUpType.FindMethodByName("Initialize");

Linker.EntryPoint = Linker.GetSymbol(initializeMethod.FullName);

Compiler.MethodScanner.MethodInvoked(initializeMethod, initializeMethod);
MethodScanner.MethodInvoked(initializeMethod, initializeMethod);
}
else
{
Compiler.MethodScanner.MethodInvoked(TypeSystem.EntryPoint, TypeSystem.EntryPoint);
MethodScanner.MethodInvoked(TypeSystem.EntryPoint, TypeSystem.EntryPoint);
}
}
}
@@ -46,8 +46,8 @@ protected override void CreateMultibootMethod()

Compiler.CompileMethod(multibootMethod, basicBlocks);

Compiler.MethodScanner.MethodInvoked(initializeMethod, multibootMethod);
Compiler.MethodScanner.MethodInvoked(multibootMethod, multibootMethod);
MethodScanner.MethodInvoked(initializeMethod, multibootMethod);
MethodScanner.MethodInvoked(multibootMethod, multibootMethod);
}
}
}
@@ -42,7 +42,7 @@ private static void GetIDTJumpLocation(Context context, MethodCompiler methodCom

context.SetInstruction(IRInstruction.MoveInt32, context.Result, Operand.CreateSymbolFromMethod(method, methodCompiler.TypeSystem));

methodCompiler.Compiler.MethodScanner.MethodInvoked(method, methodCompiler.Method);
methodCompiler.MethodScanner.MethodInvoked(method, methodCompiler.Method);
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.