static int show_stmt_condit(ivl_statement_t net, ivl_scope_t sscope)
{
      int rc = 0;
      unsigned lab_false, lab_out;
      ivl_expr_t exp = ivl_stmt_cond_expr(net);
      struct vector_info cond = draw_eval_expr(exp, STUFF_OK_XZ|STUFF_OK_47);

      assert(cond.wid == 1);

      lab_false = local_count++;
      lab_out = local_count++;

      fprintf(vvp_out, "    %%jmp/0xz  T_%d.%d, %u;\n",
	      thread_count, lab_false, cond.base);

	/* Done with the condition expression. */
      if (cond.base >= 8)
	    clr_vector(cond);

      if (ivl_stmt_cond_true(net))
	    rc += show_statement(ivl_stmt_cond_true(net), sscope);


      if (ivl_stmt_cond_false(net)) {
	    fprintf(vvp_out, "    %%jmp T_%d.%d;\n", thread_count, lab_out);
	    fprintf(vvp_out, "T_%d.%u ;\n", thread_count, lab_false);
	    clear_expression_lookaside();

	    rc += show_statement(ivl_stmt_cond_false(net), sscope);

	    fprintf(vvp_out, "T_%d.%u ;\n", thread_count, lab_out);
	    clear_expression_lookaside();

      } else {
	    fprintf(vvp_out, "T_%d.%u ;\n", thread_count, lab_false);
	    clear_expression_lookaside();
      }

      return rc;
}
Example #2
0
static void emit_stmt_condit(ivl_scope_t scope, ivl_statement_t stmt)
{
      ivl_statement_t true_stmt = ivl_stmt_cond_true(stmt);
      ivl_statement_t false_stmt = ivl_stmt_cond_false(stmt);
      unsigned nest = 0;
      fprintf(vlog_out, "%*cif (", get_indent(), ' ');
      emit_expr(scope, ivl_stmt_cond_expr(stmt), 0);
      fprintf(vlog_out, ")");
      emit_stmt_file_line(stmt);
      if (true_stmt) {
	      /* If we have a false statement and the true statement is a
	       * condition that does not have a false clause then we need
	       * to add a begin/end pair to keep the else clause attached
	       * to this condition. */
	    if (false_stmt &&
	        (ivl_statement_type(true_stmt) == IVL_ST_CONDIT) &&
	        (! ivl_stmt_cond_false(true_stmt))) nest = 1;
	    if (nest) {
		  fprintf(vlog_out, " begin\n");
		  indent += indent_incr;
	    } else single_indent = 1;
	    emit_stmt(scope, true_stmt);
      } else {
	    fprintf(vlog_out, ";\n");
      }
      if (false_stmt) {
	    if (nest) {
		  assert(indent >= indent_incr);
		  indent -= indent_incr;
	    }
	    fprintf(vlog_out, "%*c", get_indent(), ' ');
	    if (nest) fprintf(vlog_out, "end ");
	    fprintf(vlog_out, "else");
	    single_indent = 1;
	    emit_stmt(scope, false_stmt);
      }
}
Example #3
0
void clsAnalysis::AnalyzeStatement(clsStatement * pStatement, clsBasicBlock * pBasicBlock, clsEvent * pEvent)
{
  ivl_statement_t                   ivl_Statement;
  vector<clsLValue *>::iterator     it_pLValue;
  vector<clsBasicBlock *>::iterator it_pBasicBlock;
  unsigned int                      iNumberOfParameters;
  unsigned int                      iNumberOfStatements;
  unsigned int                      iIndex;
  
  ivl_Statement = pStatement->m_ivl_Statement;
  it_pBasicBlock = pBasicBlock->m_pSuccessors.begin();
  
  switch (pStatement->m_Type)
  {
  default:
    _DebugPrint("/* Unrecognized statement of type %u is encountered. */\n", ivl_statement_type(ivl_Statement) );
    _Assert(0 && "Frontend Error: Unrecognized statement is encountered.");
    break;
  case CMODELGEN_STATEMENT_NOP:
    break;
  case CMODELGEN_STATEMENT_WAIT:
    if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
    {
      AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
    }
    break;
  case CMODELGEN_STATEMENT_CASE:
  case CMODELGEN_STATEMENT_CASEZ:
  case CMODELGEN_STATEMENT_CASEX:
    AnalyzeExpression(pStatement->m_pExpressions[0], pEvent);
    iNumberOfStatements = ivl_stmt_case_count(ivl_Statement);
    for(iIndex = 0; iIndex < iNumberOfStatements; ++iIndex)
    {
      AnalyzeExpression(pStatement->m_pExpressions[iIndex + 1], pEvent);
      if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
      {
        AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
      }
      if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() )
      {
        ++it_pBasicBlock;
      }
    }
    if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
    {
      AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
    }
    break;
  case CMODELGEN_STATEMENT_COND:
    AnalyzeExpression(pStatement->m_pExpressions[0], pEvent);
    if (0 != ivl_stmt_cond_true(ivl_Statement) )
    {
      if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
      {
        AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
      }
      if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() )
      {
        ++it_pBasicBlock;
      }
    }
    if (0 != ivl_stmt_cond_false(ivl_Statement) )
    {
      if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
      {
        AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
      }
      if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() )
      {
        ++it_pBasicBlock;
      }
    }
    if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
    {
      AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
    }
    break;
  case CMODELGEN_STATEMENT_REPEAT:
  case CMODELGEN_STATEMENT_WHILE:
    AnalyzeExpression(pStatement->m_pExpressions[0], pEvent);
    if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
    {
      AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
    }
    if (it_pBasicBlock != pBasicBlock->m_pSuccessors.end() && *it_pBasicBlock != NULL)
    {
      AnalyzeBasicBlock(*it_pBasicBlock, pEvent);
    }
    break;
  case CMODELGEN_STATEMENT_NB_ASSIGN:
    iIndex = 0;
    for (it_pLValue  = pStatement->m_pLValues.begin();
         it_pLValue != pStatement->m_pLValues.end();
         ++it_pLValue)
    {
      AnalyzeNBLValue(*it_pLValue, pEvent);
      ++iIndex;
    }
    AnalyzeExpression(pStatement->m_pExpressions[0], pEvent);
    break;
  case CMODELGEN_STATEMENT_ASSIGN:
    iIndex = 0;
    for (it_pLValue  = pStatement->m_pLValues.begin();
         it_pLValue != pStatement->m_pLValues.end();
         ++it_pLValue)
    {
      AnalyzeLValue(*it_pLValue, pEvent);
      ++iIndex;
    }
    AnalyzeExpression(pStatement->m_pExpressions[0], pEvent);
    break;
  case CMODELGEN_STATEMENT_STASK:
    iNumberOfParameters = ivl_stmt_parm_count(ivl_Statement);
    for(iIndex = 0; iIndex < iNumberOfParameters; ++iIndex)
    {
      AnalyzeExpression(pStatement->m_pExpressions[iIndex], pEvent);
    }
    break;
  case CMODELGEN_STATEMENT_UTASK:
    break;
  case CMODELGEN_STATEMENT_DISABLE:
    break;
  case CMODELGEN_STATEMENT_ALLOC:
    break;
  case CMODELGEN_STATEMENT_FREE:
    break;
  }
}
Example #4
0
static void show_statement(ivl_statement_t net, unsigned ind)
{
      const ivl_statement_type_t code = ivl_statement_type(net);

      switch (code) {
	  case IVL_ST_ASSIGN:
	    fprintf(out, "%*s", ind, "");
	    show_assign_lvals(net);
	    fprintf(out, " = ");
	    show_expression(ivl_stmt_rval(net));
	    fprintf(out, ";\n");
	    break;

	  case IVL_ST_BLOCK: {
		unsigned cnt = ivl_stmt_block_count(net);
		unsigned idx;
		fprintf(out, "%*sbegin\n", ind, "");
		for (idx = 0 ;  idx < cnt ;  idx += 1) {
		      ivl_statement_t cur = ivl_stmt_block_stmt(net, idx);
		      show_statement(cur, ind+4);
		}
		fprintf(out, "%*send\n", ind, "");
		break;
	  }

	  case IVL_ST_CONDIT: {
		ivl_statement_t t = ivl_stmt_cond_true(net);
		ivl_statement_t f = ivl_stmt_cond_false(net);

		fprintf(out, "%*sif (", ind, "");
		show_expression(ivl_stmt_cond_expr(net));
		fprintf(out, ")\n");

		if (t)
		      show_statement(t, ind+4);
		else
		      fprintf(out, "%*s;\n", ind+4, "");

		if (f) {
		      fprintf(out, "%*selse\n", ind, "");
		      show_statement(f, ind+4);
		}

		break;
	  }

	  case IVL_ST_DELAY:
	    fprintf(out, "%*s#%lu\n", ind, "", ivl_stmt_delay_val(net));
	    show_statement(ivl_stmt_sub_stmt(net), ind+2);
	    break;

	  case IVL_ST_NOOP:
	    fprintf(out, "%*s/* noop */;\n", ind, "");
	    break;

	  case IVL_ST_STASK:
	    if (ivl_stmt_parm_count(net) == 0) {
		  fprintf(out, "%*s%s;\n", ind, "", ivl_stmt_name(net));

	    } else {
		  unsigned idx;
		  fprintf(out, "%*s%s(", ind, "", ivl_stmt_name(net));
		  show_expression(ivl_stmt_parm(net, 0));
		  for (idx = 1 ;  idx < ivl_stmt_parm_count(net) ; idx += 1) {
			fprintf(out, ", ");
			show_expression(ivl_stmt_parm(net, idx));
		  }
		  fprintf(out, ");\n");
	    }
	    break;

	  case IVL_ST_WAIT:
	    fprintf(out, "%*s@(...)\n", ind, "");
	    show_statement(ivl_stmt_sub_stmt(net), ind+2);
	    break;

	  case IVL_ST_WHILE:
	    fprintf(out, "%*swhile (<?>)\n", ind, "");
	    show_statement(ivl_stmt_sub_stmt(net), ind+2);
	    break;

	  default:
	    fprintf(out, "%*sunknown statement type (%d)\n", ind, "", code);
      }
}