Ejemplo n.º 1
0
        public override void Visit(AndExpressionNode node)
        {
            string BooleanExpressionLabel        = BooleanExpressionLabelGenerator.GetNewLabel();
            string BooleanExpressionIsFalseLabel = BooleanExpressionLabel + "IsFalse";
            string BooleanExpressionStoreLabel   = BooleanExpressionLabel + "Store";

            node.expression1.Accept(this);
            Gen("cmp", "eax", "0");
            Gen("je", BooleanExpressionIsFalseLabel);
            node.expression2.Accept(this);
            Gen("cmp", "eax", "0");
            Gen("je", BooleanExpressionIsFalseLabel);
            Gen("mov", "eax", "1");
            Gen("jmp", BooleanExpressionStoreLabel);
            GenText(BooleanExpressionIsFalseLabel + ":");
            Gen("mov", "eax", "0");
            GenText(BooleanExpressionStoreLabel + ":");
        }
Ejemplo n.º 2
0
        public override void Visit(IfStatementNode node)
        {
            string ElseLabel    = ElseLabelGenerator.GetNewLabel();
            string ElseEndLabel = ElseLabel + "End";

            node.expression.Accept(this);
            Gen("cmp", "eax", "0");
            Gen("je", ElseLabel);
            node.thenStatement.Accept(this);
            Gen("jmp", ElseEndLabel);
            GenText(ElseLabel + ":");
            node.elseStatement.Accept(this);
            GenText(ElseEndLabel + ":");
        }
Ejemplo n.º 3
0
        public override void Visit(WhileStatementNode node)
        {
            string WhileLabel     = WhileLabelGenerator.GetNewLabel();
            string WhileLabelLoop = WhileLabel + "Loop";
            string WhileLabelTest = WhileLabel + "Test";

            Gen("jmp", WhileLabelTest);
            GenText(WhileLabelLoop + ":");
            node.statement.Accept(this);
            GenText(WhileLabelTest + ":");
            node.expression.Accept(this);
            Gen("cmp", "eax", "0");
            Gen("jg", WhileLabelLoop);
        }