Exemplo n.º 1
0
void ExprSMTLIBPrinter::printArrayDeclarations() {
  // Assume scan() has been called
  if (humanReadable)
    *o << "; Array declarations" << endl;

  // Declare arrays in a deterministic order.
  std::vector<const Array *> sortedArrays(usedArrays.begin(), usedArrays.end());
  std::sort(sortedArrays.begin(), sortedArrays.end(), ArrayPtrsByName());
  for (std::vector<const Array *>::iterator it = sortedArrays.begin();
       it != sortedArrays.end(); it++) {
    *o << "(declare-fun " << (*it)->name << " () "
                                            "(Array (_ BitVec "
       << (*it)->getDomain() << ") "
                                "(_ BitVec " << (*it)->getRange() << ") ) )"
       << endl;
  }

  // Set array values for constant values
  if (haveConstantArray) {
    if (humanReadable)
      *o << "; Constant Array Definitions" << endl;

    const Array *array;

    // loop over found arrays
    for (std::vector<const Array *>::iterator it = sortedArrays.begin();
         it != sortedArrays.end(); it++) {
      array = *it;
      int byteIndex = 0;
      if (array->isConstantArray()) {
        /*loop over elements in the array and generate an assert statement
          for each one
         */
        for (vector<ref<ConstantExpr> >::const_iterator
                 ce = array->constantValues.begin();
             ce != array->constantValues.end(); ce++, byteIndex++) {
          *p << "(assert (";
          p->pushIndent();
          *p << "= ";
          p->pushIndent();
          printSeperator();

          *p << "(select " << array->name << " (_ bv" << byteIndex << " "
             << array->getDomain() << ") )";
          printSeperator();
          printConstant((*ce));

          p->popIndent();
          printSeperator();
          *p << ")";
          p->popIndent();
          printSeperator();
          *p << ")";

          p->breakLineI();
        }
      }
    }
  }
}
Exemplo n.º 2
0
 void CodeGenerator::printVector(std::ostream &s, const std::string& name,
                                 const vector<double>& v) {
   s << "d " << name << "[] = {";
   for (int i=0; i<v.size(); ++i) {
     if (i!=0) s << ", ";
     printConstant(s, v[i]);
   }
   s << "};" << endl;
 }
Exemplo n.º 3
0
void ExprSMTLIBPrinter::printExpression(
    const ref<Expr> &e, ExprSMTLIBPrinter::SMTLIB_SORT expectedSort) {
  // check if casting might be necessary
  if (getSort(e) != expectedSort) {
    printCastToSort(e, expectedSort);
    return;
  }

  switch (e->getKind()) {
  case Expr::Constant:
    printConstant(cast<ConstantExpr>(e));
    return; // base case

  case Expr::NotOptimized:
    // skip to child
    printExpression(e->getKid(0), expectedSort);
    return;

  case Expr::Read:
    printReadExpr(cast<ReadExpr>(e));
    return;

  case Expr::Extract:
    printExtractExpr(cast<ExtractExpr>(e));
    return;

  case Expr::SExt:
  case Expr::ZExt:
    printCastExpr(cast<CastExpr>(e));
    return;

  case Expr::Ne:
    printNotEqualExpr(cast<NeExpr>(e));
    return;

  case Expr::Select:
    // the if-then-else expression.
    printSelectExpr(cast<SelectExpr>(e), expectedSort);
    return;

  case Expr::Eq:
    /* The "=" operator is special in that it can take any sort but we must
     * enforce that both arguments are the same type. We do this a lazy way
     * by enforcing the second argument is of the same type as the first.
     */
    printSortArgsExpr(e, getSort(e->getKid(0)));

    return;

  case Expr::And:
  case Expr::Or:
  case Expr::Xor:
  case Expr::Not:
    /* These operators have a bitvector version and a bool version.
     * For these operators only (e.g. wouldn't apply to bvult) if the expected
     * sort the
     * expression is T then that implies the arguments are also of type T.
     */
    printLogicalOrBitVectorExpr(e, expectedSort);

    return;

  default:
    /* The remaining operators (Add,Sub...,Ult,Ule,..)
     * Expect SORT_BITVECTOR arguments
     */
    printSortArgsExpr(e, SORT_BITVECTOR);
    return;
  }
}
Exemplo n.º 4
0
void ASTPrint( int lev, ASTNode node )
{
	if (! node)
	{
		indent( lev ); ec_stderr_printf( "NULL" );
		return;
	}

	/* Simplify our lives ... */
	if (currentScope)
	{
		if (currentScope->type == PackageScope)
		{
			currentPackage  = currentScope->target;
			currentBytecode = EC_PACKAGECODE(currentScope->target);
		} else
		{
			currentBytecode = currentScope->target;
		}
		currentLiteral  = EC_COMPILEDLFRAME(currentBytecode);
	}

	switch ( node->type )
	{
	case nullType:
		indent( lev ); ec_stderr_printf( "<nullType>" );
		break;

	case symbolType:
		printSymbol( lev, node );
		break;

	case qualifiedSymbolType:
		printQualifiedSymbol( lev, node );
		break;

	case constExprType:
		printConstant( lev, node );
		break;

	case variableExprType:
		printVariable( lev, node );
		break;

	case arrayConstructionExprType:
		printArrayCons( lev, node );
		break;

	case hashConstructionExprType:
		printHashCons( lev, node );
		break;

	case unaryExprType:
		printUnary( lev, node );
		break;

	case binaryExprType:
		printBinary( lev, node );
		break;

	case conditionalExprType:
		printConditional( lev, node );
		break;

	case orExprType:
		printOr( lev, node );
		break;

	case andExprType:
		printAnd( lev, node );
		break;

	case assignExprType:
		printAssign( lev, node );
		break;

	case simAssignExprType:
		printSimAssign( lev, node );
		break;

	case arrayRefExprType:
		printArrayRef( lev, node );
		break;

	case declNodeType:
		printDecl( lev, node );
		break;

	case declAtomNodeType:
		printDeclAtom( lev, node );
		break;

	case statementType:
		printStatement( lev, node );
		break;

	case labeledStmtType:
		printLabeledStmt( lev, node );
		break;

	case exprStmtType:
		printExprStmt( lev, node );
		break;

	case ifStmtType:
		printIf( lev, node );
		break;

	case whileStmtType:
		printWhile( lev, node );
		break;

	case doStmtType:
		printDo( lev, node );
		break;

	case forStmtType:
		printFor( lev, node );
		break;

	case forInStmtType:
		printForIn( lev, node );
		break;

	case breakStmtType:
		printBreak( lev, node );
		break;

	case continueStmtType:
		printContinue( lev, node );
		break;

	case gotoStmtType:
		printGoto( lev, node );
		break;

	case tryStmtType:
		printTry( lev, node );
		break;

	case catchStmtType:
		printCatch( lev, node );
		break;

	case throwStmtType:
		printThrow( lev, node );
		break;

	case importStmtType:
		printImport( lev, node );
		break;

	case paramNodeType:
		printParam( lev, node );
		break;

	case paramListType:
		printParamList( lev, node );
		break;

	case callNodeType:
		printCall( lev, node );
		break;

	case methodCallNodeType:
		printMethodCall( lev, node );
		break;

	case stmtListType:
		printStmtList( lev, node );
		break;

	case funcNodeType:
		printFunction( lev, node );
		break;

	case returnNodeType:
		printReturn( lev, node );
		break;

	case classNodeType:
		printClass( lev, node );
		break;

	case methodNodeType:
		printMethod( lev, node );
		break;

	case packageNodeType:
		printPackage( lev, node );
		break;
	}
}