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 18, 2019
commit 28da6c1d52e49e82ac5261d2f44cedb815430262
@@ -207,10 +207,10 @@ public Compiler(MosaCompiler mosaCompiler)

TypeSystem = mosaCompiler.TypeSystem;
TypeLayout = mosaCompiler.TypeLayout;
CompilerTrace = mosaCompiler.CompilerTrace;
CompilerOptions = mosaCompiler.CompilerOptions;
CompilationScheduler = mosaCompiler.CompilationScheduler;
Linker = mosaCompiler.Linker;
CompilerTrace = mosaCompiler.CompilerTrace;

MethodScanner = new MethodScanner(this);

@@ -11,6 +11,8 @@ namespace Mosa.Compiler.Framework.Trace
/// </summary>
public static class InstructionLogger
{
private const int TraceLevel = 6;

public static void Run(MethodCompiler methodCompiler, BaseMethodCompilerStage stage)
{
Run(
@@ -23,10 +25,7 @@ public static void Run(MethodCompiler methodCompiler, BaseMethodCompilerStage st

public static void Run(CompilerTrace compilerTrace, string stage, MosaMethod method, BasicBlocks basicBlocks)
{
if (compilerTrace == null)
return;

if (!compilerTrace.IsTraceable(5))
if (!compilerTrace.IsTraceable(TraceLevel))
return;

var traceLog = new TraceLog(TraceType.MethodInstructions, method, stage);
@@ -444,7 +444,7 @@ private void PlugMethod()
if (plugMethod == null)
return;

Compiler.MethodScanner.MethodInvoked(plugMethod, this.Method);
Compiler.MethodScanner.MethodInvoked(plugMethod, Method);

IsMethodPlugged = true;

@@ -4,6 +4,7 @@
using Mosa.Compiler.Framework.Trace;
using Mosa.Compiler.MosaTypeSystem;
using System.Collections.Generic;
using System.Diagnostics;

namespace Mosa.Compiler.Framework
{
@@ -57,7 +58,7 @@ public void Complete()

MoreLogInfo();

//Debug.WriteLine(trace?.ToString()); // REMOVE
Debug.WriteLine(trace?.ToString()); // REMOVE

int totalTypes = 0;
int totalMethods = 0;
@@ -168,11 +169,15 @@ public void InterfaceMethodInvoked(MosaMethod method, MosaMethod source)

lock (_lock)
{
if (invokedMethods.Contains(method))
return;
lock (invokedMethods)
{
if (invokedMethods.Contains(method))
return;

invokedMethods.Add(method);
}

invokedInteraceTypes.Add(method.DeclaringType);
invokedMethods.Add(method);

if (trace != null)
{
@@ -219,10 +224,13 @@ private void MethodInvoked(MosaMethod method, MosaMethod source, bool direct)

lock (_lock)
{
if (invokedMethods.Contains(method))
return;
lock (invokedMethods)
{
if (invokedMethods.Contains(method))
return;

invokedMethods.Add(method);
invokedMethods.Add(method);
}

if (trace != null)
{
@@ -266,7 +274,13 @@ private void ScheduleDerivedMethods(MosaType type, int slot)
{
var derivedMethod = TypeLayout.GetMethodBySlot(derived, slot);

invokedMethods.AddIfNew(derivedMethod);
lock (invokedMethods)
{
if (!invokedMethods.Contains(derivedMethod))
{
invokedMethods.Add(derivedMethod);
}
}

ScheduleMethod(derivedMethod);
}
@@ -285,7 +299,14 @@ private void ScheduleMethods(MosaType type)
{
foreach (var method in currentType.Methods)
{
if (invokedMethods.Contains(method))
bool contains;

lock (invokedMethods)
{
contains = invokedMethods.Contains(method);
}

if (contains)
{
int slot = TypeLayout.GetMethodSlot(method);

@@ -317,6 +338,14 @@ private void ScheduleMethod(MosaMethod method)
}
}

//private bool CheckAddInvokedMethod(MosaMethod method)
//{
// lock (invokedMethods)
// {
// invokedMethods.Add(method)
// }
//}

public void Initialize()
{
if (!IsEnabled)
@@ -10,9 +10,9 @@ namespace Mosa.Compiler.Framework
{
public class MosaCompiler
{
public CompilerOptions CompilerOptions { get; set; } = new CompilerOptions();
public CompilerOptions CompilerOptions { get; }

public CompilerTrace CompilerTrace { get; } = new CompilerTrace();
public CompilerTrace CompilerTrace { get; }

public TypeSystem TypeSystem { get; private set; }

@@ -28,16 +28,24 @@ public class MosaCompiler

protected Compiler Compiler { get; private set; }

private bool preCompileCompleted = false;

public MosaCompiler(List<BaseCompilerExtension> compilerExtensions = null, int maxThreads = 0)
: this(null, compilerExtensions, maxThreads)
{
}

public MosaCompiler(CompilerOptions compilerOptions = null, List<BaseCompilerExtension> compilerExtensions = null, int maxThreads = 0)
{
MaxThreads = (maxThreads == 0) ? Environment.ProcessorCount + 1 : maxThreads;

CompilerOptions = compilerOptions ?? new CompilerOptions();
CompilerTrace = new CompilerTrace(CompilerOptions);

if (compilerExtensions != null)
{
CompilerExtensions.AddRange(compilerExtensions);
}

CompilerTrace.TraceLevel = CompilerOptions.TraceLevel;
}

public void Load()
@@ -92,14 +100,20 @@ public void ExecuteThreaded()

public void Initialize()
{
Linker = new MosaLinker(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.ElfMachineType, CompilerOptions.EmitAllSymbols, CompilerOptions.EmitStaticRelocations, CompilerOptions.LinkerFormatType, CompilerOptions.CreateExtraSections, CompilerOptions.CreateExtraProgramHeaders);

Compiler = new Compiler(this);
if (Linker == null)
{
Linker = new MosaLinker(CompilerOptions.BaseAddress, CompilerOptions.Architecture.Endianness, CompilerOptions.Architecture.ElfMachineType, CompilerOptions.EmitAllSymbols, CompilerOptions.EmitStaticRelocations, CompilerOptions.LinkerFormatType, CompilerOptions.CreateExtraSections, CompilerOptions.CreateExtraProgramHeaders);
Compiler = new Compiler(this);
}
}

public void PreCompile()
{
Compiler.PreCompile();
if (!preCompileCompleted)
{
Compiler.PreCompile();
preCompileCompleted = true;
}
}

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

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

node.SetInstruction(Select(node.Result, IRInstruction.MoveInt32, IRInstruction.MoveInt64), node.Result, Operand.CreateSymbolFromMethod(invokedMethod, TypeSystem));
}
@@ -236,11 +236,6 @@ private void MakeCall(Context context, Operand target, Operand result, List<Oper
// the mov/call two-instructions combo is to help facilitate the register allocator
context.AppendInstruction(IRInstruction.CallDirect, null, target);

//if (target.Method != null)
//{
// MethodCompiler.Compiler.MethodScanner.MethodDirectInvoked(target.Method, this.Method);
//}

GetReturnValue(context, result);
FreeStackAfterCall(context, totalStack);
}
@@ -50,6 +50,8 @@ protected void CheckForReplacement(InstructionNode node)
if (newTarget != null)
{
Replace(node, newTarget);

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

@@ -7,11 +7,14 @@ namespace Mosa.Compiler.Framework.Trace
public class CompilerTrace
{
private ITraceListener TraceListener;
private CompilerOptions CompilerOptions;

public int TraceLevel { get; set; } = 0;
public int TraceLevel { get { return CompilerOptions.TraceLevel; } }

public CompilerTrace()
public CompilerTrace(CompilerOptions compilerOptions)
{
CompilerOptions = compilerOptions;

TraceListener = null;
}

@@ -69,9 +69,6 @@
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Reflection.TypeExtensions, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reflection.TypeExtensions.4.5.0-preview1-26216-02\lib\net461\System.Reflection.TypeExtensions.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
@@ -86,8 +86,7 @@ public void Run(string[] args)
throw new Exception("No input file(s) specified.");
}

compiler = new MosaCompiler(GetCompilerExtensions());
compiler.CompilerOptions = options.CompilerOptions;
compiler = new MosaCompiler(options.CompilerOptions, GetCompilerExtensions());

Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
Debug.AutoFlush = true;
@@ -49,7 +49,7 @@ public MainForm()
{
InitializeComponent();

Compiler.CompilerTrace.TraceLevel = 9;
Compiler.CompilerOptions.TraceLevel = 9;
Compiler.CompilerOptions.LinkerFormatType = LinkerFormatType.Elf32;
Compiler.CompilerTrace.SetTraceListener(this);

@@ -16,6 +16,7 @@ private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

var main = new MainForm();

main.LoadArguments(args);
@@ -10,6 +10,7 @@ internal static class Program
/// <summary>
/// The main entry point for the application.
/// </summary>
/// <param name="args">The arguments.</param>
[STAThread]
private static void Main(string[] args)
{
@@ -88,7 +88,7 @@ public void Compile()
Log.Clear();
Counters.Clear();

var compiler = new MosaCompiler(GetCompilerExtensions());
var compiler = new MosaCompiler(null, GetCompilerExtensions());

try
{
@@ -64,7 +64,7 @@ public UnitTestEngine(bool display = false)
EnableIRLongExpansion = true,
EnableValueNumbering = true,
TwoPassOptimizations = true,
EnableMethodScanner = false,
EnableMethodScanner = true,

UseMultiThreadingCompiler = true,

@@ -35,21 +35,21 @@ private static void Main()
EmitAllSymbols = false,

EmitBinary = false,
TraceLevel = 0
TraceLevel = 0,

EnableStatistics = true,
};

compilerOptions.Architecture = SelectArchitecture(platform);

compilerOptions.AddSourceFile($"Mosa.TestWorld.{platform}.exe");
compilerOptions.AddSourceFile("Mosa.Plug.Korlib.dll");
compilerOptions.AddSourceFile($"Mosa.Plug.Korlib.{platform}.dll");
compilerOptions.TraceLevel = 5;

var stopwatch = new Stopwatch();

var compiler = new MosaCompiler
{
CompilerOptions = compilerOptions
};
var compiler = new MosaCompiler(compilerOptions);

compiler.Load();

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.