Ejemplo n.º 1
0
        public override void Emit(Stream stream)
        {
            Byte[] emitCode = new Byte[byteLength];
            emitCode[0] = instruction;
            UInt64 offset = memoryOp.Emit(emitCode, 1);

            offset = op.Emit(emitCode, offset);
            stream.Write(emitCode, 0, emitCode.Length);
        }
Ejemplo n.º 2
0
 public static UInt64 EmitJumpBIfEQ(byte[] byteCode, UInt64 offset, MemoryOp cnd1, Op cnd2, Op jmp)
 {
     byteCode[offset++] = Instructions.JumpBIfEQ;
     offset             = cnd1.Emit(byteCode, offset);
     offset             = cnd2.Emit(byteCode, offset);
     return(jmp.Emit(byteCode, offset));
 }
Ejemplo n.º 3
0
        private void MoveTest(params MemAndValue[] t)
        {
            UInt64 offset;

            memory.Reset();

            //
            // Generate Code
            //
            offset = 0;
            for (int i = 0; i < t.Length; i++)
            {
                offset = ByteCode.EmitAssign(byteCode, offset, t[i].dst, t[i].src);
            }
            byteCode[offset++] = Instructions.Halt;

            //
            // Run Code
            //
            Assert.AreEqual(offset, InstructionProcessor.Execute(byteCode, 0, memory));

            //
            // Test Results
            //
            memory.Print(0, 16);
            for (int i = 0; i < t.Length; i++)
            {
                MemoryOp dst = t[i].dst;
                Op       src = t[i].src;
                Console.WriteLine("Asserting [{0}] EmitMem={1}, EmitVal={2}", i, dst, src);

                Byte[] emitWriteCode = new Byte[dst.byteLength];
                Byte[] emitReadCode  = new Byte[src.byteLength];

                dst.Emit(emitWriteCode, 0);
                src.Emit(emitReadCode, 0);

                offset = 0;
                Memory.ReadOperandLogic emitWriteReadOperand = memory.ParseWriteOperandForReading(emitWriteCode, ref offset);
                Assert.AreEqual((UInt64)emitWriteCode.Length, offset);

                offset = 0;
                Memory.ReadOperandLogic emitReadReadOperand = memory.ParseReadOperand(emitReadCode, ref offset);
                Assert.AreEqual((UInt64)emitReadCode.Length, offset);

                Assert.IsTrue(memory.TestEquals(emitWriteReadOperand, emitReadReadOperand));
            }
        }
Ejemplo n.º 4
0
 public override UInt64 Emit(Byte[] byteCode, UInt64 offset)
 {
     byteCode[offset++] = instruction;
     return(memoryOp.Emit(byteCode, offset));
 }
Ejemplo n.º 5
0
 public static UInt64 EmitDecrement(byte[] byteCode, UInt64 offset, MemoryOp var)
 {
     byteCode[offset++] = Instructions.Decrement;
     return(var.Emit(byteCode, offset));
 }
Ejemplo n.º 6
0
 public static UInt64 EmitAssign(byte[] byteCode, UInt64 offset, MemoryOp dst, Op src)
 {
     byteCode[offset++] = Instructions.Move;
     offset             = dst.Emit(byteCode, offset);
     return(src.Emit(byteCode, offset));
 }