Example #1
0
        public override VariableType CodeGen(CodeGenPass pass)
        {
            BasicBlock thenBB      = pass.Constructor.AddBasicBlock(pass.Constructor.CurrentMethod);
            BasicBlock otherwiseBB = pass.Constructor.AddBasicBlock(pass.Constructor.CurrentMethod);
            BasicBlock afterBB     = pass.Constructor.AddBasicBlock(pass.Constructor.CurrentMethod);

            // cond
            Cond.CodeGen(pass);
            pass.Constructor.AddJCond(thenBB, otherwiseBB);

            // then
            pass.Constructor.CurrentBasicBlock = thenBB;
            Then.CodeGen(pass);
            if (pass.Constructor.CurrentBasicBlock.Instructions.Last?.Value.IsBranch != true)
            {
                pass.Constructor.AddJmp(afterBB);
            }

            // otherwise
            pass.Constructor.CurrentBasicBlock = otherwiseBB;
            Otherwise?.CodeGen(pass);
            if (pass.Constructor.CurrentBasicBlock.Instructions.Last?.Value.IsBranch != true)
            {
                pass.Constructor.AddJmp(afterBB);
            }

            // after
            pass.Constructor.CurrentBasicBlock = afterBB;

            return(null);
        }