public static void Initialise(Cpu cpu, Instruction[] code = null) { var ms = new MemoryStream(); using (var writer = new CodeWriter(ms)) { Array.ForEach(code ?? Instructions, writer.Write); writer.Close(); var codeBlock = cpu.AllocateCodeBlock(cpu.IdleProcess, (uint )ms.Length); ms.WriteTo(codeBlock); } }
public static uint Compile(this Cpu cpu, ProcessContextBlock pcb, IEnumerable <Instruction> instructions) { var stream = new MemoryStream(); using (var writer = new CodeWriter(stream)) { foreach (var instruction in instructions) { writer.Write(instruction); } writer.Close(); using (var ps = cpu.AllocateCodeBlock(pcb, (uint)stream.Length)) stream.WriteTo(ps); return((uint)stream.Length); } }