static bool _multiscript(cmdln_pack p) { if (p.action != ProgramAction.ExecuteConsole) { Console.Error.WriteLine($"{p.args[p.i]}: Already specified mode"); return(false); } p.action = ProgramAction.ExecuteConsoleMultiscript; return(true); }
static bool _rootdir(cmdln_pack p) { if (p.rootdir != null) { Console.Error.WriteLine($"{p.args[p.i]}: Already specified root directory"); return(false); } if (p.i + 1 >= p.args.Length) { Console.Error.WriteLine($"{p.args[p.i]}: Expected root directory"); return(false); } p.rootdir = p.args[++p.i]; return(true); }
static bool _entry(cmdln_pack p) { if (p.entry_point != null) { Console.Error.WriteLine($"{p.args[p.i]}: Already specified entry point"); return(false); } if (p.i + 1 >= p.args.Length) { Console.Error.WriteLine($"{p.args[p.i]}: Expected entry point"); return(false); } p.entry_point = p.args[++p.i]; return(true); }
static bool _out(cmdln_pack p) { if (p.output != null) { Console.Error.WriteLine($"{p.args[p.i]}: Already specified output path"); return(false); } if (p.i + 1 >= p.args.Length) { Console.Error.WriteLine($"{p.args[p.i]}: Expected output path"); return(false); } p.output = p.args[++p.i]; return(true); }
private static unsafe int Main(string[] args) { try { if (!BitConverter.IsLittleEndian) { Console.Error.WriteLine( @"(Uhoh!! Looks like this platform isn't little-endian! Most everything in CSX64 assumes little-endian, so most of it won't work on this system! )"); return(-1); } // ------------------------------------- // // set up initilization thingys for graphical stuff Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // run statics fom client sources GraphicalComputer.InitStatics(); // ------------------------------------- // cmdln_pack dat = new cmdln_pack(); if (!dat.parse(args)) { return(0); } // ------------------------------------- // // perform the action switch (dat.action) { case ProgramAction.ExecuteConsole: { if (dat.pathspec.Count == 0) { Console.Error.WriteLine("Expected a file to execute"); return(0); } Executable exe = new Executable(); int res = LoadExecutable(dat.pathspec[0], exe); return(res != 0 ? res : RunConsole(exe, dat.pathspec.ToArray(), dat.fsf, dat.time)); } case ProgramAction.ExecuteGraphical: { if (dat.pathspec.Count == 0) { Console.Error.WriteLine("Expected a file to execute"); return(0); } Executable exe = new Executable(); int res = LoadExecutable(dat.pathspec[0], exe); return(res != 0 ? res : RunGraphical(exe, dat.pathspec.ToArray(), dat.fsf)); } case ProgramAction.ExecuteConsoleScript: { if (dat.pathspec.Count == 0) { Console.Error.WriteLine("Expected a file to assemble, link, and execute"); return(0); } AddPredefines(); Executable exe = new Executable(); int res = Link(exe, new List <string>() { dat.pathspec[0] }, dat.entry_point ?? "main", dat.rootdir); return(res != 0 ? res : RunConsole(exe, dat.pathspec.ToArray(), dat.fsf, dat.time)); } case ProgramAction.ExecuteConsoleMultiscript: { if (dat.pathspec.Count == 0) { Console.Error.WriteLine("Expected 1+ files to assemble, link, and execute"); return(0); } AddPredefines(); Executable exe = new Executable(); int res = Link(exe, dat.pathspec, dat.entry_point ?? "main", dat.rootdir); return(res != 0 ? res : RunConsole(exe, new string[] { "<script>" }, dat.fsf, dat.time)); } case ProgramAction.Assemble: { if (dat.pathspec.Count == 0) { Console.Error.WriteLine("Expected 1+ files to assemble"); return(0); } AddPredefines(); ObjectFile obj = new ObjectFile(); // if no explicit output is provided, batch process each pathspec if (dat.output == null) { foreach (string path in dat.pathspec) { int res = Assemble(path, obj); if (res != 0) { return(res); } res = SaveObjectFile(Path.ChangeExtension(path, ".o"), obj); if (res != 0) { return(res); } } return(0); } // otherwise, we're expecting only one input with a named output else { if (dat.pathspec.Count != 1) { Console.Error.WriteLine("Assembler with an explicit output expected only one input"); return(0); } int res = Assemble(dat.pathspec[0], obj); return(res != 0 ? res : SaveObjectFile(dat.output, obj)); } } case ProgramAction.Link: { if (dat.pathspec.Count == 0) { Console.Error.WriteLine("Linker expected 1+ files to link"); return(0); } AddPredefines(); Executable exe = new Executable(); int res = Link(exe, dat.pathspec, dat.entry_point ?? "main", dat.rootdir); return(res != 0 ? res : SaveExecutable(dat.output ?? "a.out", exe)); } } // end switch return(0); } catch (Exception ex) { Console.Error.WriteLine($"UNHANDLED EXCEPTION:\n{ex}"); return(-666); } }
static bool _unsafe(cmdln_pack p) { p.fsf = true; return(true); }
static bool _end(cmdln_pack p) { p.accepting_options = false; return(true); }
static bool _time(cmdln_pack p) { p.time = true; return(true); }
static bool _fs(cmdln_pack p) { p.fsf = true; return(true); }
static bool _help(cmdln_pack p) { Console.Write(HelpMessage); return(false); }