Skip to content

Commit

Permalink
huge code cleanup, used roslyn analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaker26 committed May 6, 2020
1 parent 63fe4b2 commit 5eb2515
Show file tree
Hide file tree
Showing 22 changed files with 124 additions and 124 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none
2 changes: 1 addition & 1 deletion SAP1EMU.Assembler/Assemble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace SAP1EMU.Assembler
{
public class Assemble
public static class Assemble
{

public static List<string> ParseFileContents(List<string> unchecked_assembly)
Expand Down
3 changes: 3 additions & 0 deletions SAP1EMU.Assembler/ParseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ public ParseException(string message, Exception innerException) : base(message,
{
}

private ParseException()
{
}
}
}
29 changes: 17 additions & 12 deletions SAP1EMU.Engine-CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class Options
// Frame Support ******************************
// -f and -F are mutually exclusive. And error will appeear if the user tries to use both.
[Option('f', "fframe", SetName = "fframe", Required = false, HelpText = "Include final frame in the output file.")]
#pragma warning disable IDE1006 // Naming Styles
public bool fframe { get; set; }
#pragma warning restore IDE1006 // Naming Styles
[Option('F', "Fframe", SetName = "Fframe", Required = false, HelpText = "Include all frames in the output file.")]
public bool Fframe { get; set; }
// ********************************************
Expand All @@ -62,8 +64,7 @@ static void Main(string[] args)
List<string> source_file_contents = new List<string>(); ;
FileType fileType = FileType.B;


if (o.SourceFile != null || o.SourceFile != "")
if(!string.IsNullOrEmpty(o.SourceFile))
{
if (!File.Exists(o.SourceFile))
{
Expand Down Expand Up @@ -193,12 +194,16 @@ static void Main(string[] args)
engine_output += "\n" + sb.ToString();
}

var standardOutput = new StreamWriter(Console.OpenStandardOutput());
standardOutput.AutoFlush = true;
var standardOutput = new StreamWriter(Console.OpenStandardOutput())
{
AutoFlush = true
};
Console.SetOut(standardOutput);

var standardError = new StreamWriter(Console.OpenStandardError());
standardError.AutoFlush = true;
var standardError = new StreamWriter(Console.OpenStandardError())
{
AutoFlush = true
};
Console.SetError(standardError);


Expand All @@ -216,7 +221,7 @@ static void Main(string[] args)

// Start the Single Stepping Debug Session if Debug Flag is set

Debug_Proc(o, source_file_contents, FrameStack, rmp.RamContents);
Debug_Proc(o, source_file_contents, FrameStack);
Console.Out.WriteLine("Debug Session Complete");

//foreach(Frame f in FrameStack)
Expand All @@ -233,7 +238,7 @@ static void Main(string[] args)
});
}

private static void Debug_Proc(Options o, List<string> source_file_contents, List<Frame> FrameStack, List<string> RamContentsList)
private static void Debug_Proc(Options o, List<string> source_file_contents, List<Frame> FrameStack)
{
if (o.Debug)
{
Expand Down Expand Up @@ -421,14 +426,14 @@ private static bool IsAfterHLT(string s)
{
return (s.ToUpper() == "HLT");
}
private static readonly string Banner =
"*********************************************************\n"+
private const string Banner =
"*********************************************************\n" +
"* ____ _ ____ _ _____ *\n" +
"* / ___| / \\ | _ \\/ | ____|_ __ ___ _ _ *\n" +
"* \\___ \\ / _ \\ | |_) | | _| | '_ ` _ \\| | | | *\n" +
"* ___) / ___ \\| __/| | |___| | | | | | |_| | *\n" +
"* |____/_/ \\_\\_| |_|_____|_| |_| |_|\\__,_| *\n"+
"* *\n"+
"* |____/_/ \\_\\_| |_|_____|_| |_| |_|\\__,_| *\n" +
"* *\n" +
"*********************************************************\n" +
"* CC Bob Baker - 2020 *\n" +
"*********************************************************\n";
Expand Down
10 changes: 5 additions & 5 deletions SAP1EMU.Engine/EngineProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SAP1EMU.Engine
public class EngineProc
{
string OutPutRegContents = "";
private List<Frame> _FrameStack = new List<Frame>();
private readonly List<Frame> _FrameStack = new List<Frame>();

public List<Frame> FrameStack()
{
Expand All @@ -38,14 +38,14 @@ public string GetOutput()
}


private RAMProgram program { get; set; }
private RAMProgram Program { get; set; }
public void Init(RAMProgram program)
{
if (program == null)
{
this.program = new RAMProgram(new List<string>());
this.Program = new RAMProgram(new List<string>());
}
this.program = program;
this.Program = program;
}


Expand Down Expand Up @@ -85,7 +85,7 @@ public void Run()


// Load the program into the RAM
ram.LoadProgram(program);
ram.LoadProgram(Program);



Expand Down
4 changes: 4 additions & 0 deletions SAP1EMU.Engine/EngineRuntimeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public EngineRuntimeException(string message) : base(message)
public EngineRuntimeException(string message, Exception innerException) : base(message, innerException)
{
}

private EngineRuntimeException()
{
}
}
}
6 changes: 3 additions & 3 deletions SAP1EMU.Lib.Test/AssemblerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void TestParseList_Invalid_Code_1()
_ = Assemble.ParseFileContents(asm);
Assert.Fail();
}
catch (ParseException pe)
catch (ParseException)
{
Assert.IsTrue(true);
}
Expand All @@ -383,7 +383,7 @@ public void TestParseList_Invalid_Code_2()
_ = Assemble.ParseFileContents(asm);
Assert.Fail();
}
catch (ParseException pe)
catch (ParseException)
{
Assert.IsTrue(true);
}
Expand All @@ -409,7 +409,7 @@ public void TestParseList_Invalid_Code_3()
_ = Assemble.ParseFileContents(asm);
Assert.Fail();
}
catch (ParseException pe)
catch (ParseException)
{
Assert.IsTrue(true);
}
Expand Down
18 changes: 7 additions & 11 deletions SAP1EMU.Lib/Components/ALU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ namespace SAP1EMU.Lib.Components
{
public class ALU : IObserver<TicTok>
{
// <para> CP EP LM_ CE_ LI_ EI_ LA_ EA SU EU LB_ LO_</para>

private readonly string controlWordMask = "000000001100"; // SU EU
private string RegContent { get; set; }

private AReg areg { get; set; }
private BReg breg { get; set; }
private AReg Areg { get; set; }
private BReg Breg { get; set; }
public ALU(ref AReg areg, ref BReg breg)
{
this.areg = areg;
this.breg = breg;
this.Areg = areg;
this.Breg = breg;
}
//************************************************************************************************************************
private void Exec(TicTok tictok)
Expand All @@ -37,11 +34,11 @@ private void Exec(TicTok tictok)
// Active Hi, SUB on Tic
if (cw[8] == '1' && tictok.ClockState == TicTok.State.Tic)
{
temp = Compute(areg.ToString(), breg.ToString(), false);
temp = Compute(Areg.ToString(), Breg.ToString(), false);
}
else // ADD
{
temp = Compute(areg.ToString(), breg.ToString(), true);
temp = Compute(Areg.ToString(), Breg.ToString(), true);
}

// For Frame ToString support
Expand Down Expand Up @@ -118,13 +115,12 @@ public virtual void Subscribe(IObservable<TicTok> clock)

void IObserver<TicTok>.OnCompleted()
{
Console.WriteLine("The Location Tracker has completed transmitting data to {0}.", "AReg");
this.Unsubscribe();
}

void IObserver<TicTok>.OnError(Exception error)
{
Console.WriteLine("{0}: The TicTok cannot be determined.", "AReg");
throw error;
}

void IObserver<TicTok>.OnNext(TicTok value)
Expand Down
6 changes: 3 additions & 3 deletions SAP1EMU.Lib/Components/Clock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Clock : IObservable<TicTok>
{
public bool IsEnabled { get; set; }

private List<IObserver<TicTok>> observers;
private readonly List<IObserver<TicTok>> observers;

public Clock()
{
Expand All @@ -35,8 +35,8 @@ public IDisposable Subscribe(IObserver<TicTok> observer)

private class Unsubscriber : IDisposable
{
private List<IObserver<TicTok>> _observers;
private IObserver<TicTok> _observer;
private readonly List<IObserver<TicTok>> _observers;
private readonly IObserver<TicTok> _observer;

public Unsubscriber(List<IObserver<TicTok>> observers, IObserver<TicTok> observer)
{
Expand Down
8 changes: 8 additions & 0 deletions SAP1EMU.Lib/Components/ClockException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ public class ClockException : Exception
{
internal ClockException()
{ }

public ClockException(string message) : base(message)
{
}

public ClockException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
9 changes: 1 addition & 8 deletions SAP1EMU.Lib/Components/RAM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class RAM : IObserver<TicTok>
{
private List<string> RamContents = new List<string>();

// CP EP LM_ CE_ LI_ EI_ LA_ EA SU EU LB_ LO_
private readonly string controlWordMask = "000100000000"; // CE_
private string MARContents { get; set; }
private string RAM_Register_Content { get; set; } // For ToString()

Expand All @@ -27,7 +25,6 @@ private void Exec(TicTok tictok)
{
string content = GetWordAt(MARContents);
Wbus.Instance().Value = content;
System.Console.Error.WriteLine($"R Out: {content}");
}

// LR_, Active Low, Pull on Tok
Expand All @@ -36,10 +33,7 @@ private void Exec(TicTok tictok)
string word = Wbus.Instance().Value;
SetWordAt(MARContents, word);
RAM_Register_Content = word;
System.Console.Error.WriteLine($"R In: {word}");
}


}


Expand Down Expand Up @@ -98,13 +92,12 @@ public virtual void Subscribe(IObservable<TicTok> clock)

void IObserver<TicTok>.OnCompleted()
{
Console.WriteLine("The Location Tracker has completed transmitting data to {0}.", "AReg");
this.Unsubscribe();
}

void IObserver<TicTok>.OnError(Exception error)
{
Console.WriteLine("{0}: The TicTok cannot be determined.", "AReg");
throw error;
}

void IObserver<TicTok>.OnNext(TicTok value)
Expand Down
1 change: 1 addition & 0 deletions SAP1EMU.Lib/Components/SEQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public static SEQ Instance()
_instance.SupportedCommandsBinTable.Add("STA", "0011");
_instance.SupportedCommandsBinTable.Add("JMP", "0100");
_instance.SupportedCommandsBinTable.Add("JEQ", "0101");
_instance.SupportedCommandsBinTable.Add("JIC", "1001");
_instance.SupportedCommandsBinTable.Add("OUT", "1110");
_instance.SupportedCommandsBinTable.Add("HLT", "1111");
_instance.SupportedCommandsBinTable.Add("NOP", "0000");
Expand Down
36 changes: 29 additions & 7 deletions SAP1EMU.Lib/Components/TicTok.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace SAP1EMU.Lib.Components
{
/// <summary>
/// This will prevent "RaceCases" on the board.
/// All push functions will happen on Tic and all pull functions will happen on Tok
/// </summary>
public struct TicTok
{
public enum State
Expand All @@ -12,12 +16,7 @@ public enum State
Tok
};

//


// TODO - This will prevent racecases when one reg is pushing to wbus and another is pulling
// All pushing to Wbus will happen on Tic
// All pulling from Wbus will happen on Toc

public State ClockState { get; private set; }

public void ToggleClockState()
Expand All @@ -29,12 +28,35 @@ public void ToggleClockState()
else
{
ClockState = State.Tic;

}
}
public void Init()
{
ClockState = State.Tic;
}



#region Equals Override Sutff
public override bool Equals(object obj)
{
return base.Equals(obj) && this.ClockState == ((TicTok)obj).ClockState;
}

public override int GetHashCode()
{
throw new NotImplementedException();
}

public static bool operator ==(TicTok left, TicTok right)
{
return left.Equals(right);
}

public static bool operator !=(TicTok left, TicTok right)
{
return !(left == right);
}
#endregion
}
}
2 changes: 1 addition & 1 deletion SAP1EMU.Lib/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private string InstuctionDecode(string BinInstruction, int TState)
{
return "???";
}
if (temp != "")
if (!string.IsNullOrEmpty(temp))
{
return temp;
}
Expand Down
2 changes: 1 addition & 1 deletion SAP1EMU.Lib/RAMProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public RAMProgram(List<string> RamContents)
{
this.RamContents.Add(s);
}
for (int i = count; count < 15; count++)
for (int i = count; i < 15; i++)
{
this.RamContents.Add("00000000");
}
Expand Down
Loading

0 comments on commit 5eb2515

Please sign in to comment.