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");
        }
        private void CheckParse(String str, Boolean success, AdrXOperand expected, String message)
        {
            AdrXOperand actual = OperandTest.CheckParse(
                (lexer) => AdrXOperand.Parse(lexer, Opcode), str, success, message);

            if (success)
            {
                MachineInstructionOperandTest.Check(expected, actual, Check, message);
            }
        }
        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 の値がコードとして生成される");
        }
        public void Parse()
        {
            AdrXOperand DontCare = null;

            // adr のみの場合。
            CheckParse(
                "12345", true,
                AdrXOperand.MakeForUnitTest(Opcode, new DecimalConstant(12345), null),
                "10 進定数");
            CheckParse(
                "#ABCD", true,
                AdrXOperand.MakeForUnitTest(Opcode, new HexaDecimalConstant(0xABCD), null),
                "16 進定数");
            CheckParse(
                LabelTest.ValidLabelName, true,
                AdrXOperand.MakeForUnitTest(Opcode, new AddressConstant(LabelTest.ValidLabelName), null),
                "アドレス定数");
            CheckParse(
                "=12345", true,
                AdrXOperand.MakeForUnitTest(Opcode, Literal.MakeForUnitTest(new DecimalConstant(12345)), null),
                "リテラル");
            CheckParse(
                "'文字定数'", false,
                DontCare,
                "上記以外 => 例外");

            // adr に続く字句要素がある場合
            CheckParse(
                "23456=", true,
                AdrXOperand.MakeForUnitTest(Opcode, new DecimalConstant(23456), null),
                "続きが ',' 以外なら、そこで解釈終了し x なし");
            CheckParse(
                "23456,", false,
                DontCare, "続きが ',' なら、x が必要 => 例外");
            CheckParse(
                "#BCDE,GR1", true,
                AdrXOperand.MakeForUnitTest(Opcode, new HexaDecimalConstant(0xBCDE), RegisterOperandTest.GR1),
                "続きが ',' で x を指定");
            CheckParse(
                "#BCDE,GR0", false,
                DontCare, "GR0 は指標レジスタとして使えない => 例外");
            CheckParse(
                "#CDEF,GR2,", true,
                AdrXOperand.MakeForUnitTest(Opcode, new HexaDecimalConstant(0xCDEF), RegisterOperandTest.GR2),
                "x の後ろがあってもここでは OK");
        }
Beispiel #6
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 つめのオペランドがアドレスでない場合 => 例外");
        }
 public void TestInitialize()
 {
     m_adrOnly  = AdrXOperand.MakeForUnitTest(new DecimalConstant(AdrOnlyValue), null);
     m_adrWithX = AdrXOperand.MakeForUnitTest(new DecimalConstant(AdrWithXValue), X);
 }
 internal static void Check(AdrXOperand expected, AdrXOperand actual, String message)
 {
     CheckAdr(expected.Adr, actual.Adr, "Adr: " + message);
     CheckX(expected.X, actual.X, "X: " + message);
 }
        private void CheckToString(AdrXOperand target, String expected, String message)
        {
            String actual = target.ToString();

            Assert.AreEqual(expected, actual, message);
        }
 private void CheckGenerateCode(AdrXOperand target, UInt16 expected, String message)
 {
     Word[] expectedWords = WordTest.MakeArray(expected);
     ICodeGeneratorTest.CheckGenerateCode(target, expectedWords, message);
 }
        private void CheckGetXR2(AdrXOperand target, UInt16 expected, String message)
        {
            UInt16 actual = target.GetXR2();

            Assert.AreEqual(expected, actual, message);
        }