public Debugger(List <int> instructions) { Instructions = instructions; SourceLines = null; Statements = new Dictionary <int, int>(); Symbols = new Dictionary <int, string>(); Interpreter = new CardiacInterpreter(instructions); Interpreter.Output += (o, e) => { OutputItems.Add(e); }; }
static void Main(string[] args) { if (args.Length == 0) { Banner(); Console.WriteLine("Error: Input file not specified"); return; } else if (args[0] == "/?") { Banner(); DisplayHelp(); return; } else { var options = ParseArguments(args); if (!options.IsValid) { return; } string fileName = options.ImageFile; if (File.Exists(fileName)) { var inputText = File.ReadAllLines(fileName); var instructions = inputText.Select(line => int.Parse(line)).ToList(); if (options.args.Count > 0) { instructions.AddRange(options.args); } CardiacInterpreter c = new CardiacInterpreter(instructions); StreamWriter writer = null; if (options.profile) { DateTime dt = DateTime.Now; string dateTimeString = string.Format("{0}{1}{2}{3}{4}{5}", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); string profileFileName = Path.GetFileNameWithoutExtension(options.ImageFile) + "_" + dateTimeString + ".cardiprof"; writer = File.CreateText(profileFileName); TraceSource ts = new TraceSource("cardiac"); ts.Switch.Level = SourceLevels.Information; ts.Listeners.Add(new TextWriterTraceListener(writer)); c.Trace = ts; } c.Output += (o, e) => { Console.WriteLine(e); }; c.Start(); if (writer != null) { writer.Close(); } } else { Console.WriteLine("Error: File '{0}' does not exist", fileName); } } }