Skip to content

Commit

Permalink
- Explorer remembers previous settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Nov 11, 2023
1 parent 0b642f7 commit 964ded8
Show file tree
Hide file tree
Showing 20 changed files with 257 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/MosaCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private enum CompileStage
public MosaCompiler(MosaSettings mosaSettings, CompilerHooks compilerHook, IModuleLoader moduleLoader, ITypeResolver typeResolver)
{
MosaSettings = new MosaSettings();
MosaSettings.SetDetfaultSettings();
MosaSettings.SetDefaultSettings();
MosaSettings.Merge(mosaSettings);

CompilerHooks = compilerHook;
Expand Down
7 changes: 6 additions & 1 deletion Source/Mosa.Compiler.Framework/Stages/OptimizationStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ protected override void Setup()

protected override bool SetupPhase(int phase)
{
if (Compiler.MosaSettings.ReduceCodeSize)
{
Transform.SetStageOption(TransformStageOption.ReduceCodeSize);
}

switch (phase)
{
case 0:
return true;

case 1 when LowerTo32:
Transform.SetStageOptions(TransformStageOption.LowerTo32);
Transform.SetStageOption(TransformStageOption.LowerTo32);
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.Framework/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public sealed class Transform

public bool IsLowerTo32 => Options.HasFlag(TransformStageOption.LowerTo32);

public bool IsLowerCodeSize => Options.HasFlag(TransformStageOption.ReduceCodeSize);

#endregion Properties

#region Properties - Indirect
Expand Down Expand Up @@ -181,9 +183,9 @@ public void SetStage(BaseMethodCompilerStage stage)

#endregion Set Contexts

public void SetStageOptions(TransformStageOption options)
public void SetStageOption(TransformStageOption option)
{
Options = options;
Options = option | option;
}

#region Manager
Expand Down
1 change: 1 addition & 0 deletions Source/Mosa.Compiler.Framework/TransformStageOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public enum TransformStageOption
{
None,
LowerTo32,
ReduceCodeSize,
};
6 changes: 4 additions & 2 deletions Source/Mosa.Compiler.x86/Mosa.Compiler.x86.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\Mosa.Compiler.Framework\Mosa.Compiler.Framework.csproj" />
<Compile Remove="Transforms\Optimizations\Manual\Simplification\**" />
<EmbeddedResource Remove="Transforms\Optimizations\Manual\Simplification\**" />
<None Remove="Transforms\Optimizations\Manual\Simplification\**" />
</ItemGroup>

<ItemGroup>
<Folder Include="Transforms\Optimizations\Manual\Simplification\" />
<ProjectReference Include="..\Mosa.Compiler.Framework\Mosa.Compiler.Framework.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ public static class ManualTransforms
new StrengthReduction.Mul32WithMov32ByZero(),

new Stack.Add32(),

new Size.Add32By2ToInc32(),
new Size.Lea32By2(),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

// This code was generated by an automated template.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.x86.Transforms.Optimizations.Manual.Size;

[Transform("x86.Optimizations.Manual.Size")]
public sealed class Add32By2ToInc32 : BaseTransform
{
public Add32By2ToInc32() : base(X86.Add32, TransformType.Manual | TransformType.Optimization)
{
}

public override bool Match(Context context, Transform transform)
{
if (!transform.IsLowerCodeSize)
return false;

if (!context.Operand2.IsResolvedConstant)
return false;

if (context.Operand2.ConstantUnsigned64 != 2)
return false;

if (context.Operand1.Register == CPURegister.ESP)
return false;

if (!AreSame(context.Operand1, context.Result))
return false;

if (AreStatusFlagUsed(context))
return false;

return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;

context.SetInstruction(X86.Inc32, result, result);
context.AppendInstruction(X86.Inc32, result, result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

// This code was generated by an automated template.

using Mosa.Compiler.Framework;

namespace Mosa.Compiler.x86.Transforms.Optimizations.Manual.Size;

[Transform("x86.Optimizations.Manual.Size")]
public sealed class Lea32By2 : BaseTransform
{
public Lea32By2() : base(X86.Lea32, TransformType.Manual | TransformType.Optimization)
{
}

public override bool Match(Context context, Transform transform)
{
if (!transform.IsLowerCodeSize)
return false;

if (!context.Operand2.IsResolvedConstant)
return false;

if (context.Operand2.ConstantUnsigned64 != 2)
return false;

if (context.Operand1.Register == CPURegister.ESP)
return false;

if (!AreSame(context.Operand1, context.Result))
return false;

return true;
}

public override void Transform(Context context, Transform transform)
{
var result = context.Result;

context.SetInstruction(X86.Inc32, result, result);
context.AppendInstruction(X86.Inc32, result, result);
}
}
8 changes: 4 additions & 4 deletions Source/Mosa.Tool.Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public int Run(string[] args)
var mosaSettings = new MosaSettings();

mosaSettings.LoadAppLocations();
mosaSettings.SetDetfaultSettings();
mosaSettings.SetDefaultSettings();
mosaSettings.LoadArguments(args);
SetRequiredSettings(mosaSettings);
mosaSettings.ExpandSearchPaths();
mosaSettings.AddStandardPlugs();
mosaSettings.NormalizeSettings();
mosaSettings.UpdateFileAndPathSettings();
SetRequiredSettings(mosaSettings);
mosaSettings.AddStandardPlugs();
mosaSettings.ExpandSearchPaths();

OutputStatus($"Compiling: {mosaSettings.SourceFiles[0]}");

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Tool.Debugger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public MainForm()
launchView = new LaunchView(this);

MosaSettings.LoadAppLocations();
MosaSettings.SetDetfaultSettings();
MosaSettings.SetDefaultSettings();

SetDefaultSettings();

Expand Down
11 changes: 10 additions & 1 deletion Source/Mosa.Tool.Explorer/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 31 additions & 4 deletions Source/Mosa.Tool.Explorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using Microsoft.Win32;
using Mosa.Compiler.Common;
using Mosa.Compiler.Framework;
using Mosa.Compiler.Framework.CompilerStages;
using Mosa.Compiler.MosaTypeSystem;
using Mosa.Compiler.MosaTypeSystem.CLR;
using Mosa.Tool.Explorer.Stages;
using Mosa.Utility.Configuration;
using Mosa.Utility.Launcher;
using static Mosa.Utility.Configuration.MosaSettings;

namespace Mosa.Tool.Explorer;

Expand Down Expand Up @@ -62,7 +63,7 @@ public MainForm()
{
InitializeComponent();

cbPlatform.SelectedIndex = 0;
//cbPlatform.SelectedIndex = 0;

gridMethodCounters.DataSource = MethodCounters;
gridMethodCounters.Columns[0].Width = 370;
Expand All @@ -78,9 +79,17 @@ public MainForm()

RegisterPlatforms();

CreateRegistry();

Stopwatch.Restart();
}

protected void CreateRegistry()
{
var software = Registry.CurrentUser.OpenSubKey(WindowsRegistry.Software, RegistryKeyPermissionCheck.ReadWriteSubTree);
software.CreateSubKey(WindowsRegistry.MosaApp);
}

public void ClearAllLogs()
{
CompilerData.ClearAllLogs();
Expand All @@ -97,10 +106,15 @@ public void ClearAllLogs()

public void LoadArguments(string[] args)
{
MosaSettings.SetDetfaultSettings();
MosaSettings.LoadArguments(args);
MosaSettings.SetDefaultSettings();
MosaSettings.LoadAppLocations();
MosaSettings.LoadArguments(args);

if (MosaSettings.Platform == "%DEFAULT%" && (MosaSettings.SourceFiles == null || MosaSettings.SourceFiles.Count == 0))
MosaSettings.Platform = "%REGISTRY%";

MosaSettings.NormalizeSettings();
MosaSettings.UpdateFileAndPathSettings();
SetRequiredSettings();

GraphwizFound = File.Exists(MosaSettings.GraphwizApp);
Expand Down Expand Up @@ -383,6 +397,11 @@ private void cbInstructionStages_SelectedIndexChanged(object sender, EventArgs e
private void cbPlatform_SelectedIndexChanged(object sender, EventArgs e)
{
ClearAll();

Registry.CurrentUser
.OpenSubKey(WindowsRegistry.Software)
.OpenSubKey(WindowsRegistry.MosaApp, RegistryKeyPermissionCheck.ReadWriteSubTree)
.SetValue(WindowsRegistry.ExplorerPlatform, cbPlatform.Text);
}

private void cbTransformLabels_SelectedIndexChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -916,6 +935,11 @@ private void tbCompilerCounterFilter_TextChanged(object sender, EventArgs e)
private void tbFilter_TextChanged(object sender, EventArgs e)
{
CreateTree();

Registry.CurrentUser
.OpenSubKey(WindowsRegistry.Software)
.OpenSubKey(WindowsRegistry.MosaApp, RegistryKeyPermissionCheck.ReadWriteSubTree)
.SetValue(WindowsRegistry.ExplorerFilter, tbFilter.Text);
}

private void tbMethodCounterFilter_TextChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -946,6 +970,7 @@ private void ToggleOptimization(bool state)
cbLoopInvariantCodeMotion.Checked = state;
cbPlatformOptimizations.Checked = state;
cbEnableDevirtualization.Checked = state;
cbEnableCodeSizeReduction.Checked = false;
}

private void ToolStripButton1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1051,6 +1076,7 @@ private void UpdateDisplay()
cbEnableMultithreading.Checked = MosaSettings.Multithreading;
tbFilter.Text = MosaSettings.ExplorerFilter; ;
cbEnableDebugDiagnostic.Checked = MosaSettings.DebugDiagnostic;
cbEnableCodeSizeReduction.Checked = MosaSettings.ReduceCodeSize;

cbPlatform.SelectedIndex = MosaSettings.Platform.ToLowerInvariant() switch
{
Expand Down Expand Up @@ -1171,6 +1197,7 @@ private void UpdateSettings()
MosaSettings.PlatformOptimizations = cbPlatformOptimizations.Checked;
MosaSettings.InlineMethods = cbEnableInline.Checked;
MosaSettings.InlineExplicit = cbInlineExplicit.Checked;
MosaSettings.ReduceCodeSize = cbEnableCodeSizeReduction.Checked;

MosaSettings.TraceLevel = 10;
//MosaSettings.InlineMaximum = 12;
Expand Down
8 changes: 4 additions & 4 deletions Source/Mosa.Tool.Launcher.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ internal static int Main(string[] args)
var mosaSettings = new MosaSettings();

mosaSettings.LoadAppLocations();
mosaSettings.SetDetfaultSettings();
mosaSettings.SetDefaultSettings();
mosaSettings.LoadArguments(args);
SetRequiredSettings(mosaSettings);
mosaSettings.ExpandSearchPaths();
mosaSettings.AddStandardPlugs();
mosaSettings.NormalizeSettings();
mosaSettings.UpdateFileAndPathSettings();
SetRequiredSettings(mosaSettings);
mosaSettings.AddStandardPlugs();
mosaSettings.ExpandSearchPaths();

var compilerHooks = CreateCompilerHooks();

Expand Down
8 changes: 4 additions & 4 deletions Source/Mosa.Tool.Launcher/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ private void OutputStatus(string status)
public void Initialize(string[] args)
{
mosaSettings.LoadAppLocations();
mosaSettings.SetDetfaultSettings();
mosaSettings.SetDefaultSettings();
mosaSettings.LoadArguments(args);
SetRequiredSettings();
mosaSettings.ExpandSearchPaths();
mosaSettings.AddStandardPlugs();
mosaSettings.NormalizeSettings();
mosaSettings.UpdateFileAndPathSettings();
SetRequiredSettings();
mosaSettings.AddStandardPlugs();
mosaSettings.ExpandSearchPaths();

UpdateGuiSettings();

Expand Down
Loading

0 comments on commit 964ded8

Please sign in to comment.