Skip to content

Commit

Permalink
Refactoring Settings (#1078)
Browse files Browse the repository at this point in the history
* - Settings

* - Settings

* - Settings

* - Settings

* - Settings
  • Loading branch information
tgiphil committed Jul 8, 2023
1 parent b275022 commit c902c55
Show file tree
Hide file tree
Showing 117 changed files with 1,890 additions and 7,628 deletions.
6 changes: 3 additions & 3 deletions Source/Docs/command-line-arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ Below are the command line arguments available:
-emit-relocations,Linker.StaticRelocations,true
-emit-relocations-off,Linker.StaticRelocations,false
-emit-static-relocations,Linker.StaticRelocations,true
-emit-drawf,Linker.Drawf,true
-emit-drawf-off,Linker.Drawf,false
-drawf,Linker.Drawf,true
-emit-Dwarf,Linker.Dwarf,true
-emit-Dwarf-off,Linker.Dwarf,false
-Dwarf,Linker.Dwarf,true

Explorer:
-filter,Explorer.Filter,{value}
Expand Down
2 changes: 1 addition & 1 deletion Source/Docs/settings-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Linker Settings
Linker.Format,Type of ELF object file elf32 or elf64
Linker.Symbols,"If true, emits the symbols into the object file"
Linker.StaticRelocations,"If true, emits static relocation information into the object file"
Linker.Drawf,"If true, emits DWARF debug information into the object file"
Linker.Dwarf,"If true, emits DWARF debug information into the object file"
Linker.ShortSymbolNames,"If true, emits short symbol names into the object file"
Linker.CustomSections.{Name}.SectionName,Emits a custom linker section with this section name
Linker.CustomSections.{Name}.SourceFile,Emits a custom linker section using the specific file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Common.Configuration;
using System.Collections.Generic;

namespace Mosa.Utility.Configuration;
namespace Mosa.Compiler.Common.Configuration;

public static class SettingsLoader
public static class Import
{
public static Settings RecursiveReader(string[] args)
public static Settings RecursiveReader(List<Argument> map, string[] args)
{
var commandLineSettings = Reader.ParseArguments(args, CommandLineArguments.Map);
var commandLineSettings = Reader.ParseArguments(args, map);

var final = RecursiveReader(commandLineSettings);

Expand Down
21 changes: 21 additions & 0 deletions Source/Mosa.Compiler.Common/Configuration/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ public long GetValue(string fullname, long defaultValue)
return defaultValue;
}

public ulong GetValue(string fullname, ulong defaultValue)
{
var property = GetProperty(fullname);

if (property == null)
return defaultValue;

if (UInt64.TryParse(property.Value, out ulong result))
{
return result;
}

return defaultValue;
}

public List<string> GetList(string fullname)
{
var property = GetProperty(fullname);
Expand Down Expand Up @@ -232,6 +247,12 @@ public void SetValue(string fullname, long value)
property.Value = value.ToString();
}

public void SetValue(string fullname, ulong value)
{
var property = CreateProperty(fullname);
property.Value = value.ToString();
}

public void AddPropertyListValue(string fullname, string value)
{
if (value == null)
Expand Down
26 changes: 26 additions & 0 deletions Source/Mosa.Compiler.Common/IntegerExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.Compiler.Common;

public static class IntegerExtension
{
public static string ToHex(this int i)
{
return $"0x{i:X}";
}

public static string ToHex(this long i)
{
return $"0x{i:X}";
}

public static string ToHex(this uint i)
{
return $"0x{i:X}";
}

public static string ToHex(this ulong i)
{
return $"0x{i:X}";
}
}
7 changes: 4 additions & 3 deletions Source/Mosa.Compiler.Framework/BaseArchitecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Reflection;
using Mosa.Compiler.Framework.Linker.Elf;
using Mosa.Utility.Configuration;

namespace Mosa.Compiler.Framework;

Expand Down Expand Up @@ -136,14 +137,14 @@ protected BaseArchitecture()
/// Extends the compiler pipeline with architecture specific compiler stages.
/// </summary>
/// <param name="pipeline">The pipeline to extend.</param>
public abstract void ExtendCompilerPipeline(Pipeline<BaseCompilerStage> pipeline, CompilerSettings compilerSettings);
public abstract void ExtendCompilerPipeline(Pipeline<BaseCompilerStage> pipeline, MosaSettings mosaSettings);

/// <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="pipeline">The pipeline of the method compiler to add architecture specific compilation stages to.</param>
/// <param name="compilerSettings">The compiler options.</param>
public abstract void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerStage> pipeline, CompilerSettings compilerSettings);
/// <param name="mosaSettings">The compiler options.</param>
public abstract void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerStage> pipeline, MosaSettings mosaSettings);

/// <summary>
/// Create platform move.
Expand Down
3 changes: 2 additions & 1 deletion Source/Mosa.Compiler.Framework/BaseCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Mosa.Compiler.Framework.Linker;
using Mosa.Compiler.Framework.Trace;
using Mosa.Compiler.MosaTypeSystem;
using Mosa.Utility.Configuration;

namespace Mosa.Compiler.Framework;

Expand Down Expand Up @@ -42,7 +43,7 @@ public abstract class BaseCompilerStage
/// <summary>
/// Holds the compiler options
/// </summary>
protected CompilerSettings CompilerSettings => Compiler.CompilerSettings;
protected MosaSettings MosaSettings => Compiler.MosaSettings;

/// <summary>
/// Holds the compiler scheduler
Expand Down
5 changes: 3 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseMethodCompilerStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Mosa.Compiler.Framework.Linker;
using Mosa.Compiler.Framework.Trace;
using Mosa.Compiler.MosaTypeSystem;
using Mosa.Utility.Configuration;

namespace Mosa.Compiler.Framework;

Expand Down Expand Up @@ -64,7 +65,7 @@ public abstract class BaseMethodCompilerStage
/// <summary>
/// Gets the compiler options.
/// </summary>
protected CompilerSettings CompilerSettings { get; private set; }
protected MosaSettings MosaSettings { get; private set; }

/// <summary>
/// Gets a value indicating whether [is32 bit platform].
Expand Down Expand Up @@ -194,7 +195,7 @@ public void Initialize(Compiler compiler)
TypeSystem = compiler.TypeSystem;
TypeLayout = compiler.TypeLayout;
MethodScheduler = compiler.MethodScheduler;
CompilerSettings = compiler.CompilerSettings;
MosaSettings = compiler.MosaSettings;
MethodScanner = compiler.MethodScanner;

Is32BitPlatform = Architecture.Is32BitPlatform;
Expand Down
83 changes: 42 additions & 41 deletions Source/Mosa.Compiler.Framework/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Mosa.Compiler.Framework.Stages;
using Mosa.Compiler.Framework.Trace;
using Mosa.Compiler.MosaTypeSystem;
using Mosa.Utility.Configuration;

namespace Mosa.Compiler.Framework;

Expand Down Expand Up @@ -58,7 +59,7 @@ public sealed class Compiler
/// <summary>
/// Gets the compiler options.
/// </summary>
public CompilerSettings CompilerSettings { get; }
public MosaSettings MosaSettings { get; }

/// <summary>
/// Gets the method scanner.
Expand Down Expand Up @@ -151,60 +152,60 @@ public sealed class Compiler

#region Static Methods

private static List<BaseCompilerStage> GetDefaultCompilerPipeline(CompilerSettings compilerSettings, bool is32BitPlatform) => new List<BaseCompilerStage>
private static List<BaseCompilerStage> GetDefaultCompilerPipeline(MosaSettings mosaSettings, bool is32BitPlatform) => new List<BaseCompilerStage>
{
new InlinedSetupStage(),
new UnitTestStage(),
new TypeInitializerStage(),
compilerSettings.Devirtualization ? new DevirtualizationStage() : null,
mosaSettings.Devirtualization ? new DevirtualizationStage() : null,
new StaticFieldStage(),
new MethodTableStage(),
new ExceptionTableStage(),
new MetadataStage(),
!string.IsNullOrEmpty(compilerSettings.PreLinkHashFile) ? new PreLinkHashFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.PreLinkHashFile) ? new PreLinkHashFileStage() : null,
new LinkerLayoutStage(),
!string.IsNullOrEmpty(compilerSettings.PostLinkHashFile) ? new PostLinkHashFileStage() : null,
!string.IsNullOrEmpty(compilerSettings.CompileTimeFile) ? new MethodCompileTimeStage() : null,
!string.IsNullOrEmpty(compilerSettings.OutputFile) && compilerSettings.EmitBinary ? new LinkerEmitStage() : null,
!string.IsNullOrEmpty(compilerSettings.MapFile) ? new MapFileStage() : null,
!string.IsNullOrEmpty(compilerSettings.DebugFile) ? new DebugFileStage() : null,
!string.IsNullOrEmpty(compilerSettings.InlinedFile) ? new InlinedFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.PostLinkHashFile) ? new PostLinkHashFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.CompileTimeFile) ? new MethodCompileTimeStage() : null,
!string.IsNullOrEmpty(mosaSettings.OutputFile) && mosaSettings.EmitBinary ? new LinkerEmitStage() : null,
!string.IsNullOrEmpty(mosaSettings.MapFile) ? new MapFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.DebugFile) ? new DebugFileStage() : null,
!string.IsNullOrEmpty(mosaSettings.InlinedFile) ? new InlinedFileStage() : null,
};

private static List<BaseMethodCompilerStage> GetDefaultMethodPipeline(CompilerSettings compilerSettings, bool is64BitPlatform) => new List<BaseMethodCompilerStage>
private static List<BaseMethodCompilerStage> GetDefaultMethodPipeline(MosaSettings mosaSettings, bool is64BitPlatform) => new List<BaseMethodCompilerStage>
{
new CILDecoderStage(),
new ExceptionStage(),
new IRTransformsStage(),
compilerSettings.Devirtualization ? new DevirtualizeCallStage() : null,
mosaSettings.Devirtualization ? new DevirtualizeCallStage() : null,
new PlugStage(),
new RuntimeStage(),

compilerSettings.InlineMethods || compilerSettings.InlineExplicit ? new InlineStage() : null,
mosaSettings.InlineMethods || mosaSettings.InlineExplicit ? new InlineStage() : null,

compilerSettings.BasicOptimizations ? new OptimizationStage(false) : null,
compilerSettings.SSA ? new EdgeSplitStage() : null,
compilerSettings.SSA ? new EnterSSAStage() : null,
compilerSettings.BasicOptimizations && compilerSettings.SSA ? new OptimizationStage(false) : null,
compilerSettings.ValueNumbering && compilerSettings.SSA ? new ValueNumberingStage() : null,
compilerSettings.LoopInvariantCodeMotion && compilerSettings.SSA ? new LoopInvariantCodeMotionStage() : null,
compilerSettings.SparseConditionalConstantPropagation && compilerSettings.SSA ? new SparseConditionalConstantPropagationStage() : null,
compilerSettings.BasicOptimizations && compilerSettings.SSA && (compilerSettings.ValueNumbering || compilerSettings.LoopInvariantCodeMotion || compilerSettings.SparseConditionalConstantPropagation) ? new OptimizationStage(false) : null,
compilerSettings.BitTracker ? new BitTrackerStage() : null,
compilerSettings.BasicOptimizations && compilerSettings.BitTracker ? new OptimizationStage(false) : null,
compilerSettings.BasicOptimizations && compilerSettings.LongExpansion ? new OptimizationStage(compilerSettings.LongExpansion) : null,
mosaSettings.BasicOptimizations ? new OptimizationStage(false) : null,
mosaSettings.SSA ? new EdgeSplitStage() : null,
mosaSettings.SSA ? new EnterSSAStage() : null,
mosaSettings.BasicOptimizations && mosaSettings.SSA ? new OptimizationStage(false) : null,
mosaSettings.ValueNumbering && mosaSettings.SSA ? new ValueNumberingStage() : null,
mosaSettings.LoopInvariantCodeMotion && mosaSettings.SSA ? new LoopInvariantCodeMotionStage() : null,
mosaSettings.SparseConditionalConstantPropagation && mosaSettings.SSA ? new SparseConditionalConstantPropagationStage() : null,
mosaSettings.BasicOptimizations && mosaSettings.SSA && (mosaSettings.ValueNumbering || mosaSettings.LoopInvariantCodeMotion || mosaSettings.SparseConditionalConstantPropagation) ? new OptimizationStage(false) : null,
mosaSettings.BitTracker ? new BitTrackerStage() : null,
mosaSettings.BasicOptimizations && mosaSettings.BitTracker ? new OptimizationStage(false) : null,
mosaSettings.BasicOptimizations && mosaSettings.LongExpansion ? new OptimizationStage(mosaSettings.LongExpansion) : null,

compilerSettings.TwoPass && compilerSettings.ValueNumbering && compilerSettings.SSA ? new ValueNumberingStage() : null,
compilerSettings.TwoPass && compilerSettings.LoopInvariantCodeMotion && compilerSettings.SSA ? new LoopInvariantCodeMotionStage() : null,
compilerSettings.TwoPass && compilerSettings.SparseConditionalConstantPropagation && compilerSettings.SSA ? new SparseConditionalConstantPropagationStage() : null,
compilerSettings.TwoPass && compilerSettings.BitTracker ? new BitTrackerStage() : null,
compilerSettings.TwoPass && compilerSettings.BasicOptimizations && compilerSettings.SSA ? new OptimizationStage(compilerSettings.LongExpansion) : null,
mosaSettings.TwoPassOptimization && mosaSettings.ValueNumbering && mosaSettings.SSA ? new ValueNumberingStage() : null,
mosaSettings.TwoPassOptimization && mosaSettings.LoopInvariantCodeMotion && mosaSettings.SSA ? new LoopInvariantCodeMotionStage() : null,
mosaSettings.TwoPassOptimization && mosaSettings.SparseConditionalConstantPropagation && mosaSettings.SSA ? new SparseConditionalConstantPropagationStage() : null,
mosaSettings.TwoPassOptimization && mosaSettings.BitTracker ? new BitTrackerStage() : null,
mosaSettings.TwoPassOptimization && mosaSettings.BasicOptimizations && mosaSettings.SSA ? new OptimizationStage(mosaSettings.LongExpansion) : null,

compilerSettings.SSA ? new ExitSSAStage() : null,
mosaSettings.SSA ? new ExitSSAStage() : null,

new IRCleanupStage(),

compilerSettings.InlineMethods || compilerSettings.InlineExplicit ? new InlineEvaluationStage() : null,
mosaSettings.InlineMethods || mosaSettings.InlineExplicit ? new InlineEvaluationStage() : null,
new NewObjectStage(),
new CallStage(),
new CompoundStage(),
Expand All @@ -220,7 +221,7 @@ public sealed class Compiler
//new PreciseGCStage(),

new CodeGenerationStage(),
compilerSettings.EmitBinary ? new ProtectedRegionLayoutStage() : null,
mosaSettings.EmitBinary ? new ProtectedRegionLayoutStage() : null,
};

#endregion Static Methods
Expand All @@ -231,12 +232,12 @@ public Compiler(MosaCompiler mosaCompiler)
{
TypeSystem = mosaCompiler.TypeSystem;
TypeLayout = mosaCompiler.TypeLayout;
CompilerSettings = mosaCompiler.CompilerSettings;
MosaSettings = mosaCompiler.MosaSettings;
Architecture = mosaCompiler.Platform;
CompilerHooks = mosaCompiler.CompilerHooks;
TraceLevel = CompilerSettings.TraceLevel;
Statistics = CompilerSettings.Statistics;
FullCheckMode = CompilerSettings.FullCheckMode;
TraceLevel = MosaSettings.TraceLevel;
Statistics = MosaSettings.EmitStatistics;
FullCheckMode = MosaSettings.FullCheckMode;

PostEvent(CompilerEvent.CompilerStart);

Expand Down Expand Up @@ -265,12 +266,12 @@ public Compiler(MosaCompiler mosaCompiler)
InternalRuntimeType = GeInternalRuntimeType();

// Build the default compiler pipeline
CompilerPipeline.Add(GetDefaultCompilerPipeline(CompilerSettings, Architecture.Is32BitPlatform));
CompilerPipeline.Add(GetDefaultCompilerPipeline(MosaSettings, Architecture.Is32BitPlatform));

// Call hook to allow for the extension of the pipeline
CompilerHooks.ExtendCompilerPipeline?.Invoke(CompilerPipeline);

Architecture.ExtendCompilerPipeline(CompilerPipeline, CompilerSettings);
Architecture.ExtendCompilerPipeline(CompilerPipeline, MosaSettings);

IsStopped = false;
HasError = false;
Expand Down Expand Up @@ -344,12 +345,12 @@ private Pipeline<BaseMethodCompilerStage> GetOrCreateMethodStagePipeline(int thr

MethodStagePipelines[threadID] = pipeline;

pipeline.Add(GetDefaultMethodPipeline(CompilerSettings, Architecture.Is64BitPlatform));
pipeline.Add(GetDefaultMethodPipeline(MosaSettings, Architecture.Is64BitPlatform));

// Call hook to allow for the extension of the pipeline
CompilerHooks.ExtendMethodCompilerPipeline?.Invoke(pipeline);

Architecture.ExtendMethodCompilerPipeline(pipeline, CompilerSettings);
Architecture.ExtendMethodCompilerPipeline(pipeline, MosaSettings);

foreach (var stage in pipeline)
{
Expand Down Expand Up @@ -593,7 +594,7 @@ private void EmitCounters()

public string SearchPathsForFile(string filename)
{
foreach (var path in CompilerSettings.SearchPaths)
foreach (var path in MosaSettings.SearchPaths)
{
var file = Path.Combine(path, filename);

Expand Down

0 comments on commit c902c55

Please sign in to comment.