Skip to content
Permalink
Browse files

- Refactoring

  • Loading branch information...
tgiphil committed Feb 11, 2019
1 parent af5b0a2 commit 8646f609161aed7918140863b3d9e1225614a8cc
Showing with 280 additions and 145 deletions.
  1. +5 −5 Source/Mosa.Compiler.Framework/BaseArchitecture.cs
  2. +10 −2 Source/Mosa.Compiler.Framework/BaseCompilerStage.cs
  3. +8 −8 Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
  4. +37 −30 Source/Mosa.Compiler.Framework/Compiler.cs
  5. +5 −0 Source/Mosa.Compiler.Framework/CompilerOptions.cs
  6. +58 −0 Source/Mosa.Compiler.Framework/CompilerStages/MethodCompileTimeStage.cs
  7. +1 −1 Source/Mosa.Compiler.Framework/InstructionLogger.cs
  8. +2 −2 Source/Mosa.Compiler.Framework/MethodCompiler.cs
  9. +7 −1 Source/Mosa.Compiler.Framework/MethodScanner.cs
  10. +1 −1 Source/Mosa.Compiler.Framework/Stages/CodeGenerationStage.cs
  11. +3 −3 Source/Mosa.Compiler.Framework/Trace/BuiltIn/ConsoleEventListener.cs
  12. +3 −3 Source/Mosa.Compiler.Framework/Trace/BuiltIn/DebugCompilerEventListener.cs
  13. +6 −6 Source/Mosa.Compiler.Framework/Trace/CompilerTrace.cs
  14. +3 −3 Source/Mosa.Compiler.Framework/Trace/ITraceListener.cs
  15. +7 −7 Source/Mosa.Platform.ARMv6/Architecture.cs
  16. +7 −7 Source/Mosa.Platform.ESP32/Architecture.cs
  17. +11 −11 Source/Mosa.Platform.x64/Architecture.cs
  18. +11 −13 Source/Mosa.Platform.x86/Architecture.cs
  19. +3 −0 Source/Mosa.Tool.Compiler/Options.cs
  20. +34 −0 Source/Mosa.Tool.Explorer/CompilerStage/ExplorerMethodCompileTimeStage.cs
  21. +10 −6 Source/Mosa.Tool.Explorer/ExplorerCompilerExtension.cs
  22. +3 −3 Source/Mosa.Tool.Explorer/MainForm.cs
  23. +1 −0 Source/Mosa.Tool.Explorer/Mosa.Tool.Explorer.csproj
  24. +1 −1 Source/Mosa.Tool.Explorer/Stages/DisassemblyStage.cs
  25. +0 −1 Source/Mosa.Tool.Launcher/MainForm.Designer.cs
  26. +13 −14 Source/Mosa.Tool.Launcher/MainForm.cs
  27. +1 −1 Source/Mosa.Tool.Launcher/MainForm.resx
  28. +9 −3 Source/Mosa.Utility.Launcher/Builder.cs
  29. +3 −3 Source/Mosa.Utility.Launcher/BuilderEventListener.cs
  30. +3 −0 Source/Mosa.Utility.Launcher/Options.cs
  31. +1 −1 Source/Mosa.Utility.Launcher/Starter.cs
  32. +6 −2 Source/Mosa.Utility.UnitTests/Program.cs
  33. +2 −2 Source/Mosa.Utility.UnitTests/UnitTest.cs
  34. +2 −2 Source/Mosa.Utility.UnitTests/UnitTestEngine.cs
  35. +2 −2 Source/Mosa.Utility.UnitTests/UnitTestSystem.cs
  36. +1 −1 Tests/RunAllUnitTests.bat
@@ -133,7 +133,7 @@ public abstract class BaseArchitecture

#region Constructor

public BaseArchitecture()
protected BaseArchitecture()
{
PlatformIntrinsicMethods = GetPlatformIntrinsicMethods();
}
@@ -145,15 +145,15 @@ public BaseArchitecture()
/// <summary>
/// Extends the compiler pipeline with architecture specific compiler stages.
/// </summary>
/// <param name="compilerPipeline">The pipeline to extend.</param>
public abstract void ExtendCompilerPipeline(Pipeline<BaseCompilerStage> compilerPipeline, CompilerOptions compilerOptions);
/// <param name="pipeline">The pipeline to extend.</param>
public abstract void ExtendCompilerPipeline(Pipeline<BaseCompilerStage> pipeline, CompilerOptions compilerOptions);

/// <summary>
/// Requests the architecture to add architecture specific compilation stages to the pipeline. These
/// may depend upon the current state of the pipeline.</summary>
/// <param name="compilerPipeline">The pipeline of the method compiler to add architecture specific compilation stages to.</param>
/// <param name="pipeline">The pipeline of the method compiler to add architecture specific compilation stages to.</param>
/// <param name="compilerOptions">The compiler options.</param>
public abstract void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerStage> compilerPipeline, CompilerOptions compilerOptions);
public abstract void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerStage> pipeline, CompilerOptions compilerOptions);

/// <summary>
/// Create platform move.
@@ -119,9 +119,17 @@ protected virtual void RunPostCompile()

#region Helper Methods

protected void NewCompilerTraceEvent(CompilerEvent compilerEvent, string message)
protected void PostCompilerTraceEvent(CompilerEvent compilerEvent, string message)
{
CompilerTrace.NewCompilerTraceEvent(compilerEvent, message, 0);
CompilerTrace.PostCompilerTraceEvent(compilerEvent, message, 0);
}

protected void PostTrace(TraceLog traceLog)
{
if (!traceLog.Active)
return;

CompilerTrace.PostTraceLog(traceLog);
}

#endregion Helper Methods
@@ -230,11 +230,11 @@ public void Execute()
catch (Exception ex)
{
MethodCompiler.Stop();
NewCompilerTraceEvent(CompilerEvent.Exception, "Method: " + Method + " -> " + ex);
PostCompilerTraceEvent(CompilerEvent.Exception, "Method: " + Method + " -> " + ex);
MethodCompiler.Compiler.Stop();
}

SubmitTraceLogs(traceLogs);
PostTraceLogs(traceLogs);

Finish();

@@ -679,15 +679,15 @@ public TraceLog CreateTraceLog(int traceLevel, string section)
return traceLog;
}

private void SubmitTraceLog(TraceLog traceLog)
private void PostTraceLog(TraceLog traceLog)
{
if (!traceLog.Active)
return;

MethodCompiler.Trace.NewTraceLog(traceLog);
MethodCompiler.Trace.PostTraceLog(traceLog);
}

private void SubmitTraceLogs(List<TraceLog> traceLogs)
private void PostTraceLogs(List<TraceLog> traceLogs)
{
if (traceLogs == null)
return;
@@ -696,14 +696,14 @@ private void SubmitTraceLogs(List<TraceLog> traceLogs)
{
if (traceLog != null)
{
SubmitTraceLog(traceLog);
PostTraceLog(traceLog);
}
}
}

protected void NewCompilerTraceEvent(CompilerEvent compileEvent, string message)
protected void PostCompilerTraceEvent(CompilerEvent compileEvent, string message)
{
MethodCompiler.Trace.NewCompilerTraceEvent(compileEvent, message, MethodCompiler.ThreadID);
MethodCompiler.Trace.PostCompilerTraceEvent(compileEvent, message, MethodCompiler.ThreadID);
}

#endregion Trace Helper Methods
@@ -136,6 +136,7 @@ private static List<BaseCompilerStage> GetDefaultCompilerPipeline(CompilerOption
new ExceptionTableStage(),
new MetadataStage(),
new LinkerLayoutStage(),
(compilerOptions.CompileTimeFile != null) ? new MethodCompileTimeStage() : null,
(compilerOptions.OutputFile != null && compilerOptions.EmitBinary) ? new LinkerEmitStage() : null,
(compilerOptions.MapFile != null) ? new MapFileStage() : null,
(compilerOptions.DebugFile != null) ? new DebugFileStage() : null
@@ -263,7 +264,7 @@ public Compiler(MosaCompiler mosaCompiler)
/// <param name="threadID">The thread identifier.</param>
public void CompileMethod(MosaMethod method, BasicBlocks basicBlocks, int threadID = 0)
{
NewCompilerTraceEvent(CompilerEvent.CompilingMethod, method.FullName, threadID);
PostCompilerTraceEvent(CompilerEvent.CompilingMethod, method.FullName, threadID);

var pipeline = GetOrCreateMethodStagePipeline(threadID);

@@ -274,7 +275,7 @@ public void CompileMethod(MosaMethod method, BasicBlocks basicBlocks, int thread

methodCompiler.Compile();

NewCompilerTraceEvent(CompilerEvent.CompiledMethod, method.FullName, threadID);
PostCompilerTraceEvent(CompilerEvent.CompiledMethod, method.FullName, threadID);
CompilerTrace.TraceListener.OnMethodCompiled(method);
}

@@ -332,12 +333,12 @@ internal void PreCompile()

foreach (var stage in CompilerPipeline)
{
NewCompilerTraceEvent(CompilerEvent.PreCompileStageStart, stage.Name);
PostCompilerTraceEvent(CompilerEvent.PreCompileStageStart, stage.Name);

// Execute stage
stage.ExecutePreCompile();

NewCompilerTraceEvent(CompilerEvent.PreCompileStageEnd, stage.Name);
PostCompilerTraceEvent(CompilerEvent.PreCompileStageEnd, stage.Name);
}
}

@@ -392,25 +393,23 @@ private void ExecuteThreadedCompilePass(int threads)

int tid = threadID;

ThreadPool.QueueUserWorkItem(
new WaitCallback(delegate
{
//try
//{
CompileWorker(tid);

//}
//catch (Exception e)
//{
// this.CompilerTrace.NewCompilerTraceEvent(CompilerEvent.Exception, e.ToString(), threadID);
//}
//finally
//{
finished.Signal();

//}
}
));
ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
{
//try
//{
CompileWorker(tid);

//}
//catch (Exception e)
//{
// this.CompilerTrace.NewCompilerTraceEvent(CompilerEvent.Exception, e.ToString(), threadID);
//}
//finally
//{
finished.Signal();

//}
}));
}

finished.Signal();
@@ -448,12 +447,12 @@ internal void PostCompile()
{
foreach (BaseCompilerStage stage in CompilerPipeline)
{
NewCompilerTraceEvent(CompilerEvent.PostCompileStageStart, stage.Name);
PostCompilerTraceEvent(CompilerEvent.PostCompileStageStart, stage.Name);

// Execute stage
stage.ExecutePostCompile();

NewCompilerTraceEvent(CompilerEvent.PostCompileStageEnd, stage.Name);
PostCompilerTraceEvent(CompilerEvent.PostCompileStageEnd, stage.Name);
}

MethodScanner.Complete();
@@ -483,7 +482,7 @@ private void EmitCounters()
{
foreach (var counter in GlobalCounters.Export())
{
NewCompilerTraceEvent(CompilerEvent.Counter, counter);
PostCompilerTraceEvent(CompilerEvent.Counter, counter);
}
}

@@ -495,14 +494,22 @@ private void EmitCounters()

#region Helper Methods

public void PostTrace(TraceLog traceLog)
{
if (!traceLog.Active)
return;

CompilerTrace.PostTraceLog(traceLog);
}

/// <summary>
/// Traces the specified compiler event.
/// </summary>
/// <param name="compilerEvent">The compiler event.</param>
/// <param name="message">The message.</param>
private void NewCompilerTraceEvent(CompilerEvent compilerEvent, string message)
public void PostCompilerTraceEvent(CompilerEvent compilerEvent, string message)
{
CompilerTrace.NewCompilerTraceEvent(compilerEvent, message, 0);
CompilerTrace.PostCompilerTraceEvent(compilerEvent, message, 0);
}

/// <summary>
@@ -511,9 +518,9 @@ private void NewCompilerTraceEvent(CompilerEvent compilerEvent, string message)
/// <param name="compilerEvent">The compiler event.</param>
/// <param name="message">The message.</param>
/// <param name="threadID">The thread identifier.</param>
private void NewCompilerTraceEvent(CompilerEvent compilerEvent, string message, int threadID)
public void PostCompilerTraceEvent(CompilerEvent compilerEvent, string message, int threadID)
{
CompilerTrace.NewCompilerTraceEvent(compilerEvent, message, threadID);
CompilerTrace.PostCompilerTraceEvent(compilerEvent, message, threadID);
}

private MosaType GetPlatformInternalRuntimeType()
@@ -36,6 +36,11 @@ public class CompilerOptions
/// </summary>
public string MapFile { get; set; }

/// <summary>
/// Gets or sets the compile time file.
/// </summary>
public string CompileTimeFile { get; set; }

/// <summary>
/// Gets or sets the map file.
/// </summary>
@@ -0,0 +1,58 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework.Linker;
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

namespace Mosa.Compiler.Framework.CompilerStages
{
/// <summary>
/// An compilation stage, which generates a map file of the built binary file.
/// </summary>
/// <seealso cref="Mosa.Compiler.Framework.BaseCompilerStage" />
public class MethodCompileTimeStage : BaseCompilerStage
{
protected override void RunPostCompile()
{
if (string.IsNullOrEmpty(CompilerOptions.CompileTimeFile))
return;

var methods = GetAndSortMethodData();

using (var writer = new StreamWriter(CompilerOptions.CompileTimeFile))
{
writer.WriteLine("Ticks\tMilliseconds\tCompiler Count\tMethod");

foreach (var data in methods)
{
writer.WriteLine($"{data.ElapsedTicks}{'\t'}{data.ElapsedTicks / TimeSpan.TicksPerMillisecond}{'\t'}{data.CompileCount}{'\t'}{data.Method.FullName}");
}
}
}

protected List<MethodData> GetAndSortMethodData()
{
var methods = new List<MethodData>();

foreach (var type in TypeSystem.AllTypes)
{
foreach (var method in type.Methods)
{
var data = Compiler.CompilerData.GetMethodData(method);

if (data == null)
continue;

methods.Add(data);
}
}

methods.Sort((MethodData x, MethodData y) => (int)(x.ElapsedTicks - y.ElapsedTicks));

return methods;
}
}
}
@@ -54,7 +54,7 @@ public static void Run(CompilerTrace compilerTrace, string stage, MosaMethod met
traceLog.Log("No instructions.");
}

compilerTrace.NewTraceLog(traceLog);
compilerTrace.PostTraceLog(traceLog);
}

private static string ListBlocks(IList<BasicBlock> blocks)
@@ -374,7 +374,7 @@ public void Compile()
{
var log = new TraceLog(TraceType.MethodCounters, Method, string.Empty, Trace.TraceFilter.Active);
log.Log(MethodData.Counters.Export());
Trace.TraceListener.OnNewTraceLog(log);
Trace.TraceListener.OnTraceLog(log);
}
}

@@ -432,7 +432,7 @@ private void ExecutePipeline()

executionTimeLog.Log($"{"****Total Time".PadRight(57)}({totalTicks})");

Trace.TraceListener.OnNewTraceLog(executionTimeLog);
Trace.TraceListener.OnTraceLog(executionTimeLog);
}
}

@@ -76,7 +76,7 @@ public void Complete()
Compiler.GlobalCounters.Update("MethodScanner.ScheduledMethods", scheduledMethods.Count);
Compiler.GlobalCounters.Update("MethodScanner.AccessedFields", accessedFields.Count);

Compiler.CompilerTrace.NewTraceLog(trace, true);
Compiler.PostTrace(trace);
}

public void TypeAllocated(MosaType type, MosaMethod source)
@@ -113,11 +113,17 @@ public void TypeAllocated(MosaType type, MosaMethod source)

public void MethodInvoked(MosaMethod method, MosaMethod source)
{
if (!IsEnabled)
return;

MethodInvoked(method, source, false);
}

public void MethodDirectInvoked(MosaMethod method, MosaMethod source)
{
if (!IsEnabled)
return;

MethodInvoked(method, source, true);
ScheduleMethod(method);
}
@@ -159,7 +159,7 @@ protected virtual void EmitInstructions()
}
else
{
NewCompilerTraceEvent(CompilerEvent.Error, "Missing Code Transformation: " + node);
PostCompilerTraceEvent(CompilerEvent.Error, "Missing Code Transformation: " + node);
}
}

@@ -116,16 +116,16 @@ private void TraceEvent(CompilerEvent compilerStage, string info)
}
}

void ITraceListener.OnNewCompilerTraceEvent(CompilerEvent compilerEvent, string message, int threadID)
void ITraceListener.OnCompilerEvent(CompilerEvent compilerEvent, string message, int threadID)
{
TraceEvent(compilerEvent, message);
}

void ITraceListener.OnUpdatedCompilerProgress(int totalMethods, int completedMethods)
void ITraceListener.OnProgress(int totalMethods, int completedMethods)
{
}

void ITraceListener.OnNewTraceLog(TraceLog traceLog)
void ITraceListener.OnTraceLog(TraceLog traceLog)
{
}

Oops, something went wrong.

0 comments on commit 8646f60

Please sign in to comment.
You can’t perform that action at this time.