Exemplo n.º 1
0
        public void StrAnls_Switch_SingleCase()
        {
            var r1 = m.Reg32("r1", 1);

            m.SideEffect(m.Fn("initialize"));
            m.BranchIf(m.Gt(r1, 3), "finalize");
            m.Switch(r1, "case_0");

            m.Label("case_0");
            m.Assign(r1, 2);
            m.Goto("finalize");

            m.Label("finalize");
            m.SideEffect(m.Fn("finalize"));

            var sExp =
                @"    initialize();
    if (r1 <= 3)
    {
        switch (r1)
        {
        case 0x00:
            r1 = 0x02;
            break;
        }
    }
    finalize();
";

            RunTest(sExp, m.Procedure);
        }
Exemplo n.º 2
0
        public void WriteProcedure_Max()
        {
            var m = new ProcedureBuilder("proc");
            var r1 = m.Register("r1");
            var r2 = m.Register("r2");
            var r3 = m.Register("r3");
            m.BranchIf(m.Gt(r1, r2), "greaterthan");
            m.Assign(r3,r2);
            m.Assign(r2, r1);
            m.Assign(r1, r3);
            m.Label("greaterthan");
            m.Return(r1);

            hcf.Write(m.Procedure);

            var sExp = @"<span class=""kw"">define</span>&nbsp;proc<br />
{<br />
proc_entry:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">goto</span>&nbsp;l1<br />
greaterthan:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">return</span>&nbsp;r1<br />
l1:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">branch</span>&nbsp;r1&nbsp;&gt;&nbsp;r2&nbsp;greaterthan<br />
l2:<br />
&nbsp;&nbsp;&nbsp;&nbsp;r3&nbsp;=&nbsp;r2<br />
&nbsp;&nbsp;&nbsp;&nbsp;r2&nbsp;=&nbsp;r1<br />
&nbsp;&nbsp;&nbsp;&nbsp;r1&nbsp;=&nbsp;r3<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span class=""kw"">goto</span>&nbsp;greaterthan<br />
proc_exit:<br />
}<br />
";
            Debug.Write(sb.ToString());
            Assert.AreEqual(sExp, sb.ToString());
        }