Logo Search packages:      
Sourcecode: fauhdlc version File versions

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

Visit an AssertStat

Parameters:
node AssertStat node that get's visited.

Reimplemented from ast::TopDownVisitor.

Definition at line 913 of file GenCode.cpp.

References ast::AstNode::accept(), intermediate::CodeContainer::addCode(), ASSIGN_OPERATION_COPY, ASSIGN_OPERATION_LOG, assignExpression, assignOperation, ast::Expression::baseType, ast::ConditionedStat::condition, container, dataOp, destRegs, intermediate::LabelFactory::getLabel(), ast::RegisterSet::getValue(), ast::AstNode::location, ast::AssertStat::report, ast::AssertStat::severity, sourceRegs, and util::MiscUtil::toString().

{
      assert(node.condition != NULL);

      this->assignExpression = false;
      this->sourceRegs = RegisterSet(*this->container);
      this->destRegs = RegisterSet(*this->container);

      node.condition->accept(*this);

      //evaluate condition 
      Label *assertSuccL = LabelFactory::getLabel("assert_succ");
      Operand *cond = 
            this->sourceRegs.getValue(node.condition->baseType);
      Je *je = new Je(cond, 
                  new ImmediateOperand(
                        static_cast<universal_integer>(VHDL_TRUE)),
                  assertSuccL);
      this->container->addCode(je);

      // severity present? 
      if (node.severity != NULL) {
            this->sourceRegs = RegisterSet(*this->container);
            node.severity->accept(*this);
            this->dataOp = this->sourceRegs.getValue(BASE_TYPE_INTEGER);
      } else {
            // no severity -> error (lrm 8.2)
            this->dataOp = new ImmediateOperand(
                              static_cast<universal_integer>(2));
      }
      Operand *severityOp = this->dataOp;

      // log VHDL position
      std::string loc = util::MiscUtil::toString(node.location);
      loc += ": ";
      for (std::string::const_iterator i = loc.begin(); i != loc.end(); 
            i++) {

            ImmediateOperand *charVal = 
                  new ImmediateOperand(
                        static_cast<universal_integer>(*i));

            Log *l = new Log(this->dataOp, charVal);

            this->dataOp = 
                  new ImmediateOperand(
                        static_cast<universal_integer>(-1));
            this->container->addCode(l);
      }

      if (node.report != NULL) {
            this->assignExpression = true;
            this->assignOperation = ASSIGN_OPERATION_LOG;
            node.report->accept(*this);
            this->assignOperation = ASSIGN_OPERATION_COPY;
            this->assignExpression = false;

            // add a newline
            universal_integer newline = '\n';
            universal_integer mo = -1;
            Log *l = new Log(new ImmediateOperand(mo),
                        new ImmediateOperand(newline));
            this->container->addCode(l);

            // EXTENSION: abort if severity is ERROR or FAILURE
            universal_integer sevError = 2;
            Jb *jb = new Jb(severityOp, new ImmediateOperand(sevError), 
                        assertSuccL);
            Abort *a = new Abort();
            this->container->addCode(jb);
            this->container->addCode(a);

      } else {
            // TODO Log "Assertion violation." 
      }

      this->container->addCode(assertSuccL);
      this->dataOp = NULL;
}


Generated by  Doxygen 1.6.0   Back to index