diff --git a/Source/Mosa.Compiler.Framework/MosaCompiler.cs b/Source/Mosa.Compiler.Framework/MosaCompiler.cs
index 9dce67b213..6327a6771c 100644
--- a/Source/Mosa.Compiler.Framework/MosaCompiler.cs
+++ b/Source/Mosa.Compiler.Framework/MosaCompiler.cs
@@ -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;
diff --git a/Source/Mosa.Compiler.Framework/Stages/OptimizationStage.cs b/Source/Mosa.Compiler.Framework/Stages/OptimizationStage.cs
index 991cbbcd8b..7ac11e352f 100644
--- a/Source/Mosa.Compiler.Framework/Stages/OptimizationStage.cs
+++ b/Source/Mosa.Compiler.Framework/Stages/OptimizationStage.cs
@@ -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;
}
diff --git a/Source/Mosa.Compiler.Framework/Transform.cs b/Source/Mosa.Compiler.Framework/Transform.cs
index 612deb0460..273204b7f4 100644
--- a/Source/Mosa.Compiler.Framework/Transform.cs
+++ b/Source/Mosa.Compiler.Framework/Transform.cs
@@ -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
@@ -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
diff --git a/Source/Mosa.Compiler.Framework/TransformStageOption.cs b/Source/Mosa.Compiler.Framework/TransformStageOption.cs
index 323eb7233d..bd06762042 100644
--- a/Source/Mosa.Compiler.Framework/TransformStageOption.cs
+++ b/Source/Mosa.Compiler.Framework/TransformStageOption.cs
@@ -7,4 +7,5 @@ public enum TransformStageOption
{
None,
LowerTo32,
+ ReduceCodeSize,
};
diff --git a/Source/Mosa.Compiler.x86/Mosa.Compiler.x86.csproj b/Source/Mosa.Compiler.x86/Mosa.Compiler.x86.csproj
index 65212e7018..5437a0a4fa 100644
--- a/Source/Mosa.Compiler.x86/Mosa.Compiler.x86.csproj
+++ b/Source/Mosa.Compiler.x86/Mosa.Compiler.x86.csproj
@@ -1,11 +1,13 @@
-
+
+
+
-
+
diff --git a/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/ManualTransforms.cs b/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/ManualTransforms.cs
index 2d8f0d89a3..315a5e7877 100644
--- a/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/ManualTransforms.cs
+++ b/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/ManualTransforms.cs
@@ -32,5 +32,8 @@ public static class ManualTransforms
new StrengthReduction.Mul32WithMov32ByZero(),
new Stack.Add32(),
+
+ new Size.Add32By2ToInc32(),
+ new Size.Lea32By2(),
};
}
diff --git a/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/Size/Add32ToInc32x2.cs b/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/Size/Add32ToInc32x2.cs
new file mode 100644
index 0000000000..86494dbf77
--- /dev/null
+++ b/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/Size/Add32ToInc32x2.cs
@@ -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);
+ }
+}
diff --git a/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/Size/Lea32By2.cs b/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/Size/Lea32By2.cs
new file mode 100644
index 0000000000..2d4e9b4ecd
--- /dev/null
+++ b/Source/Mosa.Compiler.x86/Transforms/Optimizations/Manual/Size/Lea32By2.cs
@@ -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);
+ }
+}
diff --git a/Source/Mosa.Tool.Compiler/Compiler.cs b/Source/Mosa.Tool.Compiler/Compiler.cs
index a2445e4857..72325daefc 100644
--- a/Source/Mosa.Tool.Compiler/Compiler.cs
+++ b/Source/Mosa.Tool.Compiler/Compiler.cs
@@ -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]}");
diff --git a/Source/Mosa.Tool.Debugger/MainForm.cs b/Source/Mosa.Tool.Debugger/MainForm.cs
index 2f8a2e53ea..721ed90ff2 100644
--- a/Source/Mosa.Tool.Debugger/MainForm.cs
+++ b/Source/Mosa.Tool.Debugger/MainForm.cs
@@ -102,7 +102,7 @@ public MainForm()
launchView = new LaunchView(this);
MosaSettings.LoadAppLocations();
- MosaSettings.SetDetfaultSettings();
+ MosaSettings.SetDefaultSettings();
SetDefaultSettings();
diff --git a/Source/Mosa.Tool.Explorer/MainForm.Designer.cs b/Source/Mosa.Tool.Explorer/MainForm.Designer.cs
index 70054b1660..431d4119c7 100644
--- a/Source/Mosa.Tool.Explorer/MainForm.Designer.cs
+++ b/Source/Mosa.Tool.Explorer/MainForm.Designer.cs
@@ -58,6 +58,7 @@ private void InitializeComponent()
cbEnableTwoPassOptimizations = new ToolStripMenuItem();
cbPlatformOptimizations = new ToolStripMenuItem();
cbEnableBinaryCodeGeneration = new ToolStripMenuItem();
+ cbEnableCodeSizeReduction = new ToolStripMenuItem();
displayOptionsToolStripMenuItem = new ToolStripMenuItem();
showOperandTypes = new ToolStripMenuItem();
padInstructions = new ToolStripMenuItem();
@@ -243,7 +244,7 @@ private void InitializeComponent()
//
// optionsToolStripMenuItem
//
- optionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { cbEnableAllOptimizations, cbDisableAllOptimizations, toolStripSeparator4, cbEnableSSA, cbEnableBasicOptimizations, cbEnableValueNumbering, cbEnableSparseConditionalConstantPropagation, cbEnableDevirtualization, cbEnableInline, cbInlineExplicit, cbEnableLongExpansion, cbLoopInvariantCodeMotion, cbEnableBitTracker, cbEnableTwoPassOptimizations, cbPlatformOptimizations, cbEnableBinaryCodeGeneration });
+ optionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { cbEnableAllOptimizations, cbDisableAllOptimizations, toolStripSeparator4, cbEnableSSA, cbEnableBasicOptimizations, cbEnableValueNumbering, cbEnableSparseConditionalConstantPropagation, cbEnableDevirtualization, cbEnableInline, cbInlineExplicit, cbEnableLongExpansion, cbLoopInvariantCodeMotion, cbEnableBitTracker, cbEnableTwoPassOptimizations, cbPlatformOptimizations, cbEnableBinaryCodeGeneration, cbEnableCodeSizeReduction });
optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
optionsToolStripMenuItem.Size = new Size(93, 20);
optionsToolStripMenuItem.Text = "Optimizations";
@@ -384,6 +385,13 @@ private void InitializeComponent()
cbEnableBinaryCodeGeneration.Size = new Size(293, 22);
cbEnableBinaryCodeGeneration.Text = "Enable Binary Code Generation";
//
+ // cbEnableCodeSizeReduction
+ //
+ cbEnableCodeSizeReduction.CheckOnClick = true;
+ cbEnableCodeSizeReduction.Name = "cbEnableCodeSizeReduction";
+ cbEnableCodeSizeReduction.Size = new Size(293, 22);
+ cbEnableCodeSizeReduction.Text = "Enable Code Size Reduction";
+ //
// displayOptionsToolStripMenuItem
//
displayOptionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { showOperandTypes, padInstructions, showSizes, removeIRNop });
@@ -1398,5 +1406,6 @@ private void InitializeComponent()
private CheckBox cbSetBlock;
private Button button1;
private Button button2;
+ private ToolStripMenuItem cbEnableCodeSizeReduction;
}
}
diff --git a/Source/Mosa.Tool.Explorer/MainForm.cs b/Source/Mosa.Tool.Explorer/MainForm.cs
index 363ea6d84f..52116997d5 100644
--- a/Source/Mosa.Tool.Explorer/MainForm.cs
+++ b/Source/Mosa.Tool.Explorer/MainForm.cs
@@ -3,6 +3,7 @@
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;
@@ -10,7 +11,7 @@
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;
@@ -62,7 +63,7 @@ public MainForm()
{
InitializeComponent();
- cbPlatform.SelectedIndex = 0;
+ //cbPlatform.SelectedIndex = 0;
gridMethodCounters.DataSource = MethodCounters;
gridMethodCounters.Columns[0].Width = 370;
@@ -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();
@@ -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);
@@ -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)
@@ -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)
@@ -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)
@@ -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
{
@@ -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;
diff --git a/Source/Mosa.Tool.Launcher.Console/Program.cs b/Source/Mosa.Tool.Launcher.Console/Program.cs
index 7f9103fe4b..bb8f0001b1 100644
--- a/Source/Mosa.Tool.Launcher.Console/Program.cs
+++ b/Source/Mosa.Tool.Launcher.Console/Program.cs
@@ -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();
diff --git a/Source/Mosa.Tool.Launcher/MainWindow.axaml.cs b/Source/Mosa.Tool.Launcher/MainWindow.axaml.cs
index 5bdaee394c..9d4ff227d5 100644
--- a/Source/Mosa.Tool.Launcher/MainWindow.axaml.cs
+++ b/Source/Mosa.Tool.Launcher/MainWindow.axaml.cs
@@ -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();
diff --git a/Source/Mosa.Utility.Configuration/CommandLineArguments.cs b/Source/Mosa.Utility.Configuration/CommandLineArguments.cs
index 719d454175..9784c3bf95 100644
--- a/Source/Mosa.Utility.Configuration/CommandLineArguments.cs
+++ b/Source/Mosa.Utility.Configuration/CommandLineArguments.cs
@@ -54,6 +54,7 @@ private static List GetMap()
new Argument { Name = "-devirtualization-off", Setting = Name.Optimizations_Devirtualization, Value= "false"},
new Argument { Name = "-inline-level", Setting = Name.Optimizations_Inline_Maximum},
new Argument { Name = "-basic-optimization-window", Setting = Name.Optimizations_Basic_Window},
+ new Argument { Name = "-reducesize", Setting = Name.Optimizations_ReduceCodeSize, Value= "true"},
// Compiler - Platforms:
new Argument { Name = "-platform", Setting = Name.Compiler_Platform},
@@ -213,6 +214,7 @@ private static List GetMap()
new Argument { Name = "-o0", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o0", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-o0", Setting = Name.Optimizations_Basic_Window, Value= "1"},
+ new Argument { Name = "-o0", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o1", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o1", Setting = Name.Optimizations_SSA, Value= "false"},
@@ -228,6 +230,7 @@ private static List GetMap()
new Argument { Name = "-o1", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o1", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-o1", Setting = Name.Optimizations_Basic_Window, Value= "1"},
+ new Argument { Name = "-o1", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o2", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o2", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -243,6 +246,7 @@ private static List GetMap()
new Argument { Name = "-o2", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o2", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-o2", Setting = Name.Optimizations_Basic_Window, Value= "1"},
+ new Argument { Name = "-o2", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o3", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o3", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -258,6 +262,7 @@ private static List GetMap()
new Argument { Name = "-o3", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o3", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-o3", Setting = Name.Optimizations_Basic_Window, Value= "5"},
+ new Argument { Name = "-o3", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o4", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o4", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -273,6 +278,7 @@ private static List GetMap()
new Argument { Name = "-o4", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o4", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-o4", Setting = Name.Optimizations_Basic_Window, Value= "5"},
+ new Argument { Name = "-o4", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o5", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o5", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -288,6 +294,7 @@ private static List GetMap()
new Argument { Name = "-o5", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o5", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-o5", Setting = Name.Optimizations_Basic_Window, Value= "5"},
+ new Argument { Name = "-o5", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o6", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o6", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -303,6 +310,7 @@ private static List GetMap()
new Argument { Name = "-o6", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o6", Setting = Name.Optimizations_Inline_Maximum, Value= "5"},
new Argument { Name = "-o6", Setting = Name.Optimizations_Basic_Window, Value= "5"},
+ new Argument { Name = "-o6", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o7", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o7", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -318,6 +326,7 @@ private static List GetMap()
new Argument { Name = "-o7", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o7", Setting = Name.Optimizations_Inline_Maximum, Value= "10"},
new Argument { Name = "-o7", Setting = Name.Optimizations_Basic_Window, Value= "5"},
+ new Argument { Name = "-o7", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o8", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o8", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -333,6 +342,7 @@ private static List GetMap()
new Argument { Name = "-o8", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-o8", Setting = Name.Optimizations_Inline_Maximum, Value= "10"},
new Argument { Name = "-o8", Setting = Name.Optimizations_Basic_Window, Value= "5"},
+ new Argument { Name = "-o8", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-o9", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-o9", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -348,6 +358,7 @@ private static List GetMap()
new Argument { Name = "-o9", Setting = Name.Optimizations_TwoPass, Value= "true"},
new Argument { Name = "-o9", Setting = Name.Optimizations_Inline_Maximum, Value= "12"},
new Argument { Name = "-o9", Setting = Name.Optimizations_Basic_Window, Value= "10"},
+ new Argument { Name = "-o9", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-oNone", Setting = Name.Optimizations_Basic, Value= "false"},
new Argument { Name = "-oNone", Setting = Name.Optimizations_SSA, Value= "false"},
@@ -363,6 +374,7 @@ private static List GetMap()
new Argument { Name = "-oNone", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-oNone", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-oNone", Setting = Name.Optimizations_Basic_Window, Value= "1"},
+ new Argument { Name = "-oNone", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-oMax", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-oMax", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -378,6 +390,7 @@ private static List GetMap()
new Argument { Name = "-oMax", Setting = Name.Optimizations_TwoPass, Value= "true"},
new Argument { Name = "-oMax", Setting = Name.Optimizations_Inline_Maximum, Value= "12"},
new Argument { Name = "-oMax", Setting = Name.Optimizations_Basic_Window, Value= "20"},
+ new Argument { Name = "-oMax", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
new Argument { Name = "-oSize", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-oSize", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -393,6 +406,7 @@ private static List GetMap()
new Argument { Name = "-oSize", Setting = Name.Optimizations_TwoPass, Value= "true"},
new Argument { Name = "-oSize", Setting = Name.Optimizations_Inline_Maximum, Value= "3"},
new Argument { Name = "-oSize", Setting = Name.Optimizations_Basic_Window, Value= "10"},
+ new Argument { Name = "-oSize", Setting = Name.Optimizations_ReduceCodeSize, Value= "true"},
new Argument { Name = "-oFast", Setting = Name.Optimizations_Basic, Value= "true"},
new Argument { Name = "-oFast", Setting = Name.Optimizations_SSA, Value= "true"},
@@ -408,6 +422,7 @@ private static List GetMap()
new Argument { Name = "-oFast", Setting = Name.Optimizations_TwoPass, Value= "false"},
new Argument { Name = "-oFast", Setting = Name.Optimizations_Inline_Maximum, Value= "0"},
new Argument { Name = "-oFast", Setting = Name.Optimizations_Basic_Window, Value= "1"},
+ new Argument { Name = "-oFast", Setting = Name.Optimizations_ReduceCodeSize, Value= "false"},
};
return map;
diff --git a/Source/Mosa.Utility.Configuration/MOSASettings.cs b/Source/Mosa.Utility.Configuration/MOSASettings.cs
index 3483814cdb..76b75b41ba 100644
--- a/Source/Mosa.Utility.Configuration/MOSASettings.cs
+++ b/Source/Mosa.Utility.Configuration/MOSASettings.cs
@@ -1,10 +1,12 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.
+using System.Runtime.InteropServices;
+using Microsoft.Win32;
using Mosa.Compiler.Common.Configuration;
namespace Mosa.Utility.Configuration;
-public class MosaSettings
+public partial class MosaSettings
{
#region Constants
@@ -541,6 +543,12 @@ public bool LongExpansion
set => Settings.SetValue(Name.Optimizations_LongExpansion, value);
}
+ public bool ReduceCodeSize
+ {
+ get => Settings.GetValue(Name.Optimizations_ReduceCodeSize, true);
+ set => Settings.SetValue(Name.Optimizations_ReduceCodeSize, value);
+ }
+
public bool TwoPassOptimization
{
get => Settings.GetValue(Name.Optimizations_TwoPass, true);
@@ -716,13 +724,13 @@ public void LoadArguments(string[] args)
Settings.Merge(settings);
}
- public void SetDetfaultSettings()
+ public void SetDefaultSettings()
{
TemporaryFolder = Path.Combine(Path.GetTempPath(), "MOSA");
MethodScanner = false;
Multithreading = true;
- Platform = "x86";
+ Platform = "%DEFAULT%";
Multithreading = true;
BaseAddress = 0x00400000;
EmitBinary = true;
@@ -755,6 +763,7 @@ public void SetDetfaultSettings()
InlineAggressiveMaximum = 24;
InlineMaximum = 12;
OptimizationBasicWindow = 5;
+ ReduceCodeSize = false;
Emulator = "Qemu";
EmulatorDisplay = false;
@@ -795,16 +804,29 @@ public void SetDetfaultSettings()
EmitShortSymbolNames = false;
LinkerFormat = "elf32";
+
+ ExplorerFilter = "%REGISTRY%";
}
public void NormalizeSettings()
{
- ImageFormat = ImageFormat == null ? string.Empty : ImageFormat.ToLowerInvariant().Trim();
- FileSystem = FileSystem == null ? string.Empty : FileSystem.ToLowerInvariant().Trim();
- EmulatorSerial = EmulatorSerial == null ? string.Empty : EmulatorSerial.ToLowerInvariant().Trim();
- Emulator = Emulator == null ? string.Empty : Emulator.ToLowerInvariant().Trim();
- Platform = Platform == null ? string.Empty : Platform.ToLowerInvariant().Trim();
- LinkerFormat = LinkerFormat == null ? string.Empty : LinkerFormat.ToLowerInvariant().Trim();
+ ImageFormat = ToLower(ImageFormat);
+ FileSystem = ToLower(FileSystem);
+ EmulatorSerial = ToLower(EmulatorSerial);
+ Emulator = ToLower(Emulator);
+ Platform = ToLower(Platform);
+ LinkerFormat = ToLower(LinkerFormat);
+ }
+
+ private string ToLower(string value)
+ {
+ if (value == null)
+ return string.Empty;
+
+ if (value == "%DEFAULT%" || value == "%REGISTRY%")
+ return value;
+
+ return value.ToLowerInvariant().Trim();
}
public void UpdateFileAndPathSettings()
@@ -906,6 +928,30 @@ public void UpdateFileAndPathSettings()
{
NasmFile = Path.Combine(defaultFolder, $"{baseFilename}.nasm");
}
+
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ if (ExplorerFilter == "%REGISTRY%")
+ {
+ ExplorerFilter = (string)Registry.CurrentUser
+ .OpenSubKey(WindowsRegistry.Software)
+ .OpenSubKey(WindowsRegistry.MosaApp)
+ .GetValue(WindowsRegistry.ExplorerFilter, string.Empty);
+ }
+
+ if (Platform == "%REGISTRY%")
+ {
+ Platform = (string)Registry.CurrentUser
+ .OpenSubKey(WindowsRegistry.Software)
+ .OpenSubKey(WindowsRegistry.MosaApp)
+ .GetValue(WindowsRegistry.ExplorerPlatform, string.Empty);
+ }
+ }
+
+ if (string.IsNullOrWhiteSpace(Platform) || Platform == "%DEFAULT%")
+ {
+ Platform = "x86";
+ }
}
public void AddStandardPlugs()
diff --git a/Source/Mosa.Utility.Configuration/Name.cs b/Source/Mosa.Utility.Configuration/Name.cs
index 5e91baabae..ff515ef2b0 100644
--- a/Source/Mosa.Utility.Configuration/Name.cs
+++ b/Source/Mosa.Utility.Configuration/Name.cs
@@ -103,6 +103,7 @@ public static class Name
public const string Optimizations_Inline_Explicit = "Optimizations.Inline.Explicit";
public const string Optimizations_Inline_Maximum = "Optimizations.Inline.Maximum";
public const string Optimizations_LongExpansion = "Optimizations.LongExpansion";
+ public const string Optimizations_ReduceCodeSize = "Optimizations.ReduceCodeSize";
public const string Optimizations_LoopInvariantCodeMotion = "Optimizations.LoopInvariantCodeMotion";
public const string Optimizations_Platform = "Optimizations.Platform";
public const string Optimizations_SCCP = "Optimizations.SCCP";
diff --git a/Source/Mosa.Utility.Configuration/WindowsRegistry.cs b/Source/Mosa.Utility.Configuration/WindowsRegistry.cs
new file mode 100644
index 0000000000..c87c1e24fb
--- /dev/null
+++ b/Source/Mosa.Utility.Configuration/WindowsRegistry.cs
@@ -0,0 +1,18 @@
+// Copyright (c) MOSA Project. Licensed under the New BSD License.
+
+namespace Mosa.Utility.Configuration;
+
+public partial class MosaSettings
+{
+ #region Constants
+
+ public static class WindowsRegistry
+ {
+ public const string Software = "Software";
+ public const string MosaApp = "Mosa";
+ public const string ExplorerFilter = "ExplorerFilter";
+ public const string ExplorerPlatform = "ExplorerPlatform";
+ }
+
+ #endregion Constants
+}
diff --git a/Source/Mosa.Utility.Launcher/BaseLauncher.cs b/Source/Mosa.Utility.Launcher/BaseLauncher.cs
index 1989b242f8..d44751c27e 100644
--- a/Source/Mosa.Utility.Launcher/BaseLauncher.cs
+++ b/Source/Mosa.Utility.Launcher/BaseLauncher.cs
@@ -19,11 +19,11 @@ public BaseLauncher(MosaSettings mosaSettings, CompilerHooks compilerHook)
MosaSettings = new MosaSettings();
MosaSettings.LoadAppLocations();
- MosaSettings.SetDetfaultSettings();
+ MosaSettings.SetDefaultSettings();
MosaSettings.Merge(mosaSettings);
MosaSettings.NormalizeSettings();
- MosaSettings.AddStandardPlugs();
MosaSettings.UpdateFileAndPathSettings();
+ MosaSettings.AddStandardPlugs();
}
protected void OutputStatus(string status)
diff --git a/Source/Mosa.Utility.UnitTests/UnitTestEngine.cs b/Source/Mosa.Utility.UnitTests/UnitTestEngine.cs
index ac989881c1..a7989afc36 100644
--- a/Source/Mosa.Utility.UnitTests/UnitTestEngine.cs
+++ b/Source/Mosa.Utility.UnitTests/UnitTestEngine.cs
@@ -67,13 +67,13 @@ public class UnitTestEngine : IDisposable
public UnitTestEngine(MosaSettings mosaSettings)
{
MosaSettings.LoadAppLocations();
- MosaSettings.SetDetfaultSettings();
+ MosaSettings.SetDefaultSettings();
MosaSettings.Merge(mosaSettings);
- SetRequiredSettings();
- MosaSettings.ExpandSearchPaths();
- MosaSettings.AddStandardPlugs();
MosaSettings.NormalizeSettings();
MosaSettings.UpdateFileAndPathSettings();
+ SetRequiredSettings();
+ MosaSettings.AddStandardPlugs();
+ MosaSettings.ExpandSearchPaths();
Initialize();
}
@@ -96,8 +96,6 @@ private void SetRequiredSettings()
MosaSettings.AddSourceFile("Mosa.UnitTests.dll");
MosaSettings.AddSearchPath(AppContext.BaseDirectory);
- //MosaSettings.AddSearchPath(Environment.CurrentDirectory);
- //MosaSettings.AddSearchPath(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
OutputStatus($"Search Folder(s): {string.Join(", ", new List(MosaSettings.SearchPaths.ToArray()))}");
}