Exemple #1
0
        public void GenerateLiteralDc()
        {
            ProgramInstruction target   = ProgramInstructionTest.Make(MnemonicDef.LD, "GR1,=1234,GR2");
            LabelTable         lblTable = new LabelTable();
            String             actual   = target.GenerateLiteralDc(lblTable);
            String             expected = ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "1234");

            Assert.AreEqual(expected, actual, "リテラルの DC 命令が生成される");
        }
 public void ProcessSourceText_LiteralDcUniqueLabel()
 {
     CheckProcess(
         TestUtils.MakeArray(
             "LTRL0001 START",
             "         LD GR0,=-9876,GR1",
             "         END"),
         TestUtils.MakeArray(
             "LTRL0001 START",
             "         LD GR0,=-9876,GR1",
             ProgramLineTest.MakeGeneratedLine("LTRL0002", "DC", "-9876"),
             "         END"),
         "リテラルの DC 命令のラベルはプログラムのものと重ならない一意のものが生成される");
 }
Exemple #3
0
 public void GenerateLiteralDc()
 {
     CheckGenerateLiteralDc(
         Literal.MakeForUnitTest(new DecimalConstant(12345)),
         ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "12345"),
         "10 進定数 => 10 進定数の DC 命令が生成される。");
     CheckGenerateLiteralDc(
         Literal.MakeForUnitTest(new HexaDecimalConstant(0xFEDC)),
         ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "#FEDC"),
         "16 進定数 => 16 進定数の DC 命令が生成される。");
     CheckGenerateLiteralDc(
         Literal.MakeForUnitTest(new StringConstant("!@#$%")),
         ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "'!@#$%'"),
         "文字定数 => 文字定数の DC 命令が生成される。");
 }
        private void CheckProcess(String[] textLines, String[] expectedProcessedText, String message)
        {
            LabelTable lblTable = new LabelTable();

            try
            {
                IEnumerable <ProgramLine> processedLines = TextLineProcessor.Process(textLines, lblTable);
                Assert.IsNotNull(expectedProcessedText, message);
                ProgramLineTest.CheckProgramLines(processedLines, expectedProcessedText, message);
            }
            catch (Casl2SimulatorException)
            {
                Assert.IsNull(expectedProcessedText, message);
            }
        }
Exemple #5
0
        public void ExpandMacro()
        {
            MacroRpopInstruction target = new MacroRpopInstruction();

            String[] actual = target.ExpandMacro(new Label("LBL001"));

            String[] expected = TestUtils.MakeArray(
                ProgramLineTest.MakeGeneratedLine("LBL001", "POP", "GR7"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR6"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR5"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR4"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR3"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR2"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR1"));
            TestUtils.CheckEnumerable(expected, actual, "マクロ命令 RPOP の展開結果");
        }
Exemple #6
0
 public void GenerateLiteralDc()
 {
     CheckGenerateLiteralDc(
         m_GR1_GR2, null,
         "r1,r2 => DC 命令は生成されない");
     CheckGenerateLiteralDc(
         m_GR3_1111_GR4, null,
         "r,adr[,x] で adr がリテラルでない => DC 命令は生成されない");
     CheckGenerateLiteralDc(
         m_GR3_Eq1234_GR4,
         ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "1234"),
         "r,adr[,x] で adr がリテラル => DC 命令が生成される");
     CheckGenerateLiteralDc(
         m_3333_GR6, null,
         "adr[,x] で adr がリテラルでない => DC 命令は生成されない");
     CheckGenerateLiteralDc(
         m_EqSTR_GR6,
         ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "'STR'"),
         "adr[,x] で adr がリテラル => DC 命令が生成される");
 }
 public void ProcessSourceText_GenerateLiteralDc()
 {
     CheckProcess(
         TestUtils.MakeArray(
             "ENTRY  START",
             "       LD GR0,=1234,GR1",
             "       LD GR2,=#ABCD,GR3",
             "       PUSH ='!@#$%',GR4",
             "       END"),
         TestUtils.MakeArray(
             "ENTRY  START",
             "       LD GR0,=1234,GR1",
             "       LD GR2,=#ABCD,GR3",
             "       PUSH ='!@#$%',GR4",
             ProgramLineTest.MakeGeneratedLine("LTRL0001", "DC", "1234"),
             ProgramLineTest.MakeGeneratedLine("LTRL0002", "DC", "#ABCD"),
             ProgramLineTest.MakeGeneratedLine("LTRL0003", "DC", "'!@#$%'"),
             "       END"),
         "リテラルの定数をオペランドとする DC 命令が生成され、END 命令の直前に配置される");
 }
        private void CheckExpandMacro(MacroInOutInstruction target, Int32 svcOperand, String message)
        {
            const String BufferName = "BUF";
            const String LengthName = "LEN";
            const String LabelName  = "LBL001";

            target.SetLabelsForUnitTest(BufferName, LengthName);
            Label label = new Label(LabelName);

            String[] actual = target.ExpandMacro(label);

            String[] expected = TestUtils.MakeArray(
                ProgramLineTest.MakeGeneratedLine(LabelName, "PUSH", "0,GR1"),
                ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR2"),
                ProgramLineTest.MakeGeneratedLine("", "LAD", "GR1," + BufferName),
                ProgramLineTest.MakeGeneratedLine("", "LAD", "GR2," + LengthName),
                ProgramLineTest.MakeGeneratedLine("", "SVC", svcOperand.ToString()),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR2"),
                ProgramLineTest.MakeGeneratedLine("", "POP", "GR1"));
            TestUtils.CheckEnumerable(expected, actual, message);
        }
 public void ProcessSourceText_ExpandMacro()
 {
     CheckProcess(
         TestUtils.MakeArray(
             "ENTRY  START",
             "LBL001 RPUSH   ; マクロ命令",
             "       DC 123  ; マクロでない命令",
             "; コメント行",
             "       END"),
         TestUtils.MakeArray(
             "ENTRY  START",
             ProgramLineTest.MakeGeneratedLine("LBL001", "PUSH", "0,GR1"),
             ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR2"),
             ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR3"),
             ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR4"),
             ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR5"),
             ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR6"),
             ProgramLineTest.MakeGeneratedLine("", "PUSH", "0,GR7"),
             "       DC 123  ; マクロでない命令",
             "; コメント行",
             "       END"),
         "マクロ命令が展開された内容に置き換えられる。マクロ命令以外はそのまま");
 }