public TestVM ExecuteTestVM(string testCode) { CompilationContext context = CmCompiler.CompileText(testCode); byte[] objectCode; using (var s = new MemoryStream()) { CmCompiler.CreateObjectCode(s, new RIVMArchitecture(), context.GetIR(), context.GetStringConstants(), context.GetGlobalVariables(), context.GetFunctions()); objectCode = s.GetBuffer(); } byte[] executableCode; using (var s = new MemoryStream()) { CmLinker.Link(s, new List <byte[]> { objectCode }, false, SystemMemoryMap.BIOS_ROM_START); executableCode = s.GetBuffer(); } var bios = new BIOS(executableCode); var mmu = new MMU(SystemMemoryMap.BIOS_STACK_END, bios, null, null); var cpu = new CPU(mmu); cpu.Start(); return(new TestVM(cpu)); }
static int Main(string[] args) { try { List <String> objectFilePaths = new List <string>(); int loadAddress = 0; bool hasEntryPoint = false; string outputFilePath = ""; for (int i = 0; i < args.Length; i++) { if (args[i] == "-o") { i++; outputFilePath = args[i]; } else if (args[i] == "-l") { i++; if (args[i].StartsWith("0x")) { loadAddress = Int32.Parse(args[i].Replace("0x", ""), NumberStyles.AllowHexSpecifier); } else { loadAddress = Int32.Parse(args[i]); } } else if (args[i] == "-e") { hasEntryPoint = true; } else { objectFilePaths.Add(args[i]); } } if (objectFilePaths.Count == 0 || String.IsNullOrEmpty(outputFilePath)) { ShowUsage(); return(-1); } using (var fs = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.None)) { CmLinker.Link(fs, objectFilePaths, hasEntryPoint, loadAddress); } return(0); } catch (Exception ex) { Console.WriteLine("Error: " + ex.ToString()); return(-1); } }