Пример #1
0
        public void TestMemoryOpAndValue(OpAndValue[] memoryOpAndValues)
        {
            for (int i = 0; i < memoryOpAndValues.Length; i++)
            {
                UInt64 offset = memoryOpAndValues[i].op.Emit(byteCode, 0);

                UInt64 processOffset = 0;
                Memory.ReadOperandLogic readLogic = memory.ParseWriteOperandForReading(byteCode, ref processOffset);

                Assert.AreEqual(offset, processOffset);
                Assert.AreEqual(memoryOpAndValues[i].value, readLogic.readLogic(readLogic.op));
            }
        }
Пример #2
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));
            }
        }