Logo Search packages:      
Sourcecode: fauhdlc version File versions

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

Visit a ForLoopStat

Parameters:
node ForLoopStat node that gets visited.

Reimplemented from ast::TopDownVisitor.

Definition at line 661 of file GenCode.cpp.

References ast::DiscreteRange::accept(), ast::ConstantDeclaration::accept(), intermediate::CodeContainer::addCode(), assignExpression, ast::TypeDeclaration::baseType, container, ast::DiscreteRange::direction, ast::DiscreteRange::DIRECTION_UP, ast::LoopRegistry::forgetLoop(), ast::SymbolDeclaration::getICName(), intermediate::RegisterFactory::getRegister(), loopRegistry, ast::LoopStat::loopStats, ast::ForLoopStat::loopVariable, ast::ForLoopStat::range, ast::LoopRegistry::rememberLoop(), ast::RegisterSet::sliceBegin, ast::RegisterSet::sliceEnd, sourceRegs, and ast::ValDeclaration::subtypeIndic.

{
      class LoopImpl : public ForLoopIterate {
      public:
            LoopImpl(
                  intermediate::CodeContainer &container,
                  intermediate::Operand &counter,
                  intermediate::Operand &initializer,
                  intermediate::Operand &rightBound,
                  bool isAscending,
                  GenCode &genCode,
                  ForLoopStat &nd
                  ) :   ForLoopIterate(
                              container,
                              counter,
                              initializer,
                              rightBound,
                              isAscending),
                        gc(genCode),
                        loopNode(nd) {}
      private:
            virtual void loopBody(void) {
                  gc.listTraverse(*this->loopNode.loopStats);
            }


            GenCode &gc;
            ForLoopStat &loopNode;
      };

      assert(node.loopStats != NULL);
      assert(node.range != NULL);
      assert(node.loopVariable != NULL);
      assert(node.loopVariable->subtypeIndic != NULL);
      assert(node.loopVariable->subtypeIndic->baseType 
             == BASE_TYPE_INTEGER);

      // add declaration for loop variable
      node.loopVariable->accept(*this);

      bool asc = node.range->direction == DiscreteRange::DIRECTION_UP;
      this->assignExpression = false;
      
      this->sourceRegs = RegisterSet(*this->container);
      node.range->accept(*this);
      assert(this->sourceRegs.sliceBegin != NULL);
      assert(this->sourceRegs.sliceEnd != NULL);

      Reference *ref = new Reference(node.loopVariable->getICName());
      Register *loopVarP = RegisterFactory::getRegister(OP_TYPE_POINTER);
      Mov *mov = new Mov(ref, loopVarP);
      this->container->addCode(mov);

      Operand *cnt = new IndirectOperand(loopVarP, OP_TYPE_INTEGER);

      Operand *left = this->sourceRegs.sliceBegin;
      Operand *right = this->sourceRegs.sliceEnd;
      this->sourceRegs = RegisterSet(*this->container);
      
      LoopImpl li = LoopImpl(
                  *this->container,
                  *cnt,
                  *left,
                  *right,
                  asc,
                  *this,
                  node);
      this->loopRegistry.rememberLoop(&node, &li);

      li.addIteration();

      this->loopRegistry.forgetLoop(&node);
}


Generated by  Doxygen 1.6.0   Back to index