Пример #1
0
        public override CILStatement ToCILStatement(CIntermediateLang cil)
        {
            var loop = new CILLoop(SourceInfo, Condition.ToCILExpression(cil));

            loop.Body.AddRange(Body.Select(n => n.ToCILNode(cil)));
            return(loop);
        }
Пример #2
0
        private static void Test1()
        {
            var cil      = new CIntermediateLang();
            var myStruct = cil.CreateStruct(tsi, "String");
            var testFunc = cil.CreateFunction(tsi, "String", 1, "testFunc", new List <CILVariableDecl>());
            var main     = cil.CreateFunction(tsi, "int", 0, "main", new List <CILVariableDecl>
            {
                new CILVariableDecl(tsi, cil.SymTable.LookupType("int"), 0, "argc"),
                new CILVariableDecl(tsi, cil.SymTable.LookupType("char"), 2, "argv"),
            });

            main.AddBodyNode(new CILCall(tsi, new CILIdent(tsi, "testFunc"), new List <CILExpression>()
            {
                new CILIdent(tsi, "argc"),
                new CILIdent(tsi, "argv"),
            }));

            testFunc.AddBodyNode(new CILVariableDecl(tsi, cil.SymTable.LookupType("String"), 1, "testStr"));
            var ret    = new CILReturn(tsi, new CILIdent(tsi, "testStr"));
            var branch = new CILBranch(tsi, new CILIdent(tsi, "testStr"));

            branch.AddTrueBranchStmt(ret);
            var loop = new CILLoop(tsi, new CILInteger(tsi, 42));

            loop.Body.Add(new CILReturn(tsi, new CILIdent(tsi, "testStr")));
            loop.Before.Add(new CILCall(tsi, new CILIdent(tsi, "testFunc"), new List <CILExpression>()));
            loop.After.Add(new CILCall(tsi, new CILIdent(tsi, "testFunc"), new List <CILExpression>()));
            branch.AddFalseBranchStmt(loop);
            branch.AddFalseBranchStmt(ret);
            testFunc.AddBodyNode(branch);

            myStruct.AddMember(
                new CILVariableDecl(
                    tsi,
                    cil.SymTable.LookupType("int"),
                    0,
                    "length"));
            myStruct.AddMember(
                new CILVariableDecl(
                    tsi,
                    cil.SymTable.LookupType("char"),
                    1,
                    "string"));
            myStruct.AddMember(
                new CILVariableDecl(
                    tsi,
                    myStruct,
                    1,
                    "test"));

            testFunc.AddBodyNode(
                new CILAssignment(tsi,
                                  new CILMemberAccess(tsi, new CILMemberAccess(tsi, new CILCall(tsi, new CILIdent(tsi, "testFunc")), "test"), "length"),
                                  new CILInteger(tsi, 42)));
            testFunc.AddBodyNode(
                new CILAssignment(tsi,
                                  new CILMemberAccess(tsi, new CILCall(tsi, new CILIdent(tsi, "testFunc")), "string"),
                                  new CILStringLiteral(tsi, "hello world")));
            Console.WriteLine(cil);
        }
Пример #3
0
        public override CILStatement ToCILStatement(CIntermediateLang cil)
        {
            LllCompiler.SymTable.Push();
            var pre    = Pre.Select(p => p.ToCILNode(cil)).ToList();
            var cond   = Condition.ToCILExpression(cil);
            var update = Update.Select(u => u.ToCILExpression(cil)).ToList();
            var body   = Body.Select(b => b.ToCILNode(cil)).ToList();
            var loop   = new CILLoop(SourceInfo, pre, cond, update, body);

            LllCompiler.SymTable.Push();
            return(loop);
        }