public void Parse()
        {
            const MachineInstructionOperand DontCare = null;

            CheckParse(
                "GR0,#ABCD,GR1", true,
                RAdrXOperand.MakeForUnitTest(
                    RAdrXOpcode,
                    RegisterOperandTest.GR0,
                    AdrXOperand.MakeForUnitTest(new HexaDecimalConstant(0xABCD), RegisterOperandTest.GR1)),
                "r,adr,x の場合");
            CheckParse(
                "GR0,GR1", true,
                R1R2Operand.MakeForUnitTest(
                    R1R2Opcode, RegisterOperandTest.GR0, RegisterOperandTest.GR1),
                "r1,r2 の場合");

            CheckParse(
                "NoSuchRegister,GR0", false, DontCare,
                "最初のオペランドがレジスタでない場合 => 例外");
            CheckParse(
                "GR0#GR1", false, DontCare,
                "区切りが ',' でない場合 => 例外、'GR#GR1' は項目の区切りまでラベルとして読み込まれる");
            CheckParse(
                "GR1,#CDEF,GR0", false, DontCare,
                "x に GR0 は使えない => 例外");
            CheckParse(
                "GR0,'abc'", false, DontCare,
                "2 つめのオペランドがレジスタでもアドレスでもない場合 => 例外");
        }
        public void ToStringTest()
        {
            RAdrXOperand target = RAdrXOperand.MakeForUnitTest(
                RegisterOperandTest.GR4,
                AdrXOperand.MakeForUnitTest(
                    Literal.MakeForUnitTest(new StringConstant("abc")), RegisterOperandTest.GR6));
            String actual = target.ToString();

            Assert.AreEqual("GR4,='abc',GR6", actual, "GR4,='abc',GR6");
        }
        public void GenerateCode()
        {
            const UInt16    Adr = 0xABCD;
            RegisterOperand DontCareRegister = RegisterOperandTest.GR1;
            RAdrXOperand    target           = RAdrXOperand.MakeForUnitTest(
                DontCareRegister,
                AdrXOperand.MakeForUnitTest(new HexaDecimalConstant(Adr), DontCareRegister));

            Word[] expectedWords = WordTest.MakeArray(Adr);
            ICodeGeneratorTest.CheckGenerateCode(target, expectedWords, "adr の値がコードとして生成される");
        }
        private void CheckParse(
            String str, Boolean success, RAdrXOperand expected, String message)
        {
            RAdrXOperand actual = OperandTest.CheckParse(
                (lexer) => RAdrXOperand.Parse(lexer, Opcode), str, success, message);

            if (success)
            {
                MachineInstructionOperandTest.Check(expected, actual, Check, message);
            }
        }
Beispiel #5
0
 public void TestInitialize()
 {
     m_GR1_GR2      = R1R2Operand.MakeForUnitTest(RegisterOperandTest.GR1, RegisterOperandTest.GR2);
     m_GR3_1111_GR4 = RAdrXOperand.MakeForUnitTest(
         RegisterOperandTest.GR3,
         AdrXOperand.MakeForUnitTest(new DecimalConstant(1111), RegisterOperandTest.GR4));
     m_GR3_Eq1234_GR4 = RAdrXOperand.MakeForUnitTest(
         RegisterOperandTest.GR3,
         AdrXOperand.MakeForUnitTest(
             Literal.MakeForUnitTest(new DecimalConstant(1234)), RegisterOperandTest.GR4));
     m_GR5_2222 = RAdrXOperand.MakeForUnitTest(
         RegisterOperandTest.GR5,
         AdrXOperand.MakeForUnitTest(new DecimalConstant(2222), null));
     m_3333_GR6  = AdrXOperand.MakeForUnitTest(new DecimalConstant(3333), RegisterOperandTest.GR6);
     m_EqSTR_GR6 = AdrXOperand.MakeForUnitTest(
         Literal.MakeForUnitTest(new StringConstant("STR")), RegisterOperandTest.GR6);
     m_4444      = AdrXOperand.MakeForUnitTest(new DecimalConstant(4444), null);
     m_GR7       = RegisterOperandTest.GR7;
     m_NoOperand = NoOperand.MakeForUnitTest();
 }
        public void Parse()
        {
            const RAdrXOperand DontCare = null;

            CheckParse(
                "GR2,='abc',GR3", true,
                RAdrXOperand.MakeForUnitTest(
                    Opcode,
                    RegisterOperandTest.GR2,
                    AdrXOperand.MakeForUnitTest(
                        Literal.MakeForUnitTest(new StringConstant("abc")),
                        RegisterOperandTest.GR3)),
                "r,adr,x の場合");

            CheckParse(
                "1234,5678", false, DontCare,
                "最初のオペランドがレジスタでない場合 => 例外");
            CheckParse(
                "GR0=#ABCD", false, DontCare,
                "区切りが ',' でない場合 => 例外、'GR0=#ABCD' は項目の区切りまでラベルとして読み込まれる");
            CheckParse(
                "GR0,GR1", false, DontCare,
                "2 つめのオペランドがアドレスでない場合 => 例外");
        }
 internal static void Check(RAdrXOperand expected, RAdrXOperand actual, String message)
 {
     RegisterOperandTest.Check(expected.R, actual.R, "R: " + message);
     AdrXOperandTest.Check(expected.AdrX, actual.AdrX, "AdrX: " + message);
 }