Logo Search packages:      
Sourcecode: fauhdlc version File versions

void ast::GenCode::visit ( IfStat node  )  [private, virtual]

visit an IfStat

Parameters:
node node that gets visited.

Reimplemented from ast::TopDownVisitor.

Definition at line 557 of file GenCode.cpp.

References ast::AstNode::accept(), intermediate::CodeContainer::addCode(), assignExpression, ast::Expression::baseType, ast::ConditionedStat::condition, container, ast::IfStat::elseStats, intermediate::LabelFactory::getLabel(), ast::RegisterSet::getValue(), ast::Visitor::listTraverse(), sourceRegs, and ast::IfStat::thenStats.

{
      this->assignExpression = false;
      // generate code for condition
      node.condition->accept(*this);

      ImmediateOperand *trueOp = new ImmediateOperand(
                        static_cast<universal_integer>(VHDL_TRUE));

      Label *thenLabel = LabelFactory::getLabel("then");

      Operand *condOp = 
            this->sourceRegs.getValue(node.condition->baseType);

      Je *condJmp = new Je(condOp, trueOp, thenLabel);
      this->container->addCode(condJmp);

      Label *endIf = LabelFactory::getLabel("endif");
      Label *elseLbl = NULL;
      if (node.elseStats != NULL) {
            elseLbl = LabelFactory::getLabel("else");
            Jmp *ej = new Jmp(elseLbl);
            this->container->addCode(ej);
      } else {
            Jmp *out = new Jmp(endIf);
            this->container->addCode(out);
      }

      assert(node.thenStats != NULL);
      this->container->addCode(thenLabel);
      this->listTraverse(*node.thenStats);
      
      if (node.elseStats != NULL) {
            Jmp *out = new Jmp(endIf);
            this->container->addCode(out);
            this->container->addCode(elseLbl);
            this->listTraverse(*node.elseStats);
      }

      this->container->addCode(endIf);
}


Generated by  Doxygen 1.6.0   Back to index