public static uint Compile(this Cpu cpu, ProcessContextBlock pcb, string source)
        {
            var ms = new MemoryStream();
            using (var writer = new CodeWriter(ms))
            {
                var assembler = new Assembler(source);
                foreach (var i in assembler.Assemble())
                    writer.Write(i);

                writer.Close();

                var codeBlock = cpu.AllocateCodeBlock(pcb, (uint)ms.Length);
                ms.WriteTo(codeBlock);

                return (uint )ms.Length;
            }
        }
Example #2
0
        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;
            }
        }