Ejemplo n.º 1
0
static
String handle_static_call_statement(CPrintStyleModule *state,
				    const SuifObject *obj)
{
  CallStatement *expr =
    to<CallStatement>(obj);
  String addr = state->print_to_string(expr->get_callee_address());
  String return_str;
  if (expr->get_destination() != NULL) {
    return_str += state->print_to_string(expr->get_destination());
    return_str += " = ";
  }

  return_str += String("(") + addr + ")(";
  bool needs_comma = false;
  for (Iter<Expression *> iter = expr->get_argument_iterator();
       iter.is_valid();
       iter.next()) {
    Expression *opn = iter.current();
    if (needs_comma) {
      return_str += ",";
    } else {
      needs_comma = true;
    }
    String op = state->print_to_string(opn);
    return_str += op;
  }
  return_str += ")";
  return(return_str);
}
Ejemplo n.º 2
0
// Both the if and then portion are call statements
bool IfConversionPass2::ConvertCallsIf(IfStatement* toConvert)
{
  Statement* thenPart = Denormalize(toConvert->get_then_part()) ;
  Statement* elsePart = Denormalize(toConvert->get_else_part()) ;

  CallStatement* thenCall = dynamic_cast<CallStatement*>(thenPart) ;
  CallStatement* elseCall = dynamic_cast<CallStatement*>(elsePart) ;

  assert(thenCall != NULL) ;
  assert(elseCall != NULL) ;

  CallStatement* boolSelectCall = 
    CreateBoolCall(thenCall->get_destination()) ;

  // Create call expression for each of the call statements
  //  and append them to the boolean select we are creating.

  Expression* thenCallValue = thenCall->get_callee_address() ;
  thenCall->set_callee_address(NULL) ;

  CallExpression* thenCallExp = 
    create_call_expression(theEnv,
			   thenCall->get_destination()->get_type()->get_base_type(),
			   thenCallValue) ;

  // Append all of the call arguments to the expression
  for (int i = 0 ; i < thenCall->get_argument_count() ; ++i)
  {
    Expression* nextArg = thenCall->get_argument(i) ;
    nextArg->set_parent(NULL) ;
    thenCallExp->append_argument(nextArg) ;
  }

  boolSelectCall->append_argument(thenCallExp) ;

  Expression* elseCallValue = elseCall->get_callee_address() ;
  elseCall->set_callee_address(NULL) ;
  CallExpression* elseCallExp =
    create_call_expression(theEnv,
			   thenCall->get_destination()->get_type()->get_base_type(),
			   elseCallValue) ;

  // Append all of the call arguments to the expression
  for (int i = 0 ; i < elseCall->get_argument_count() ; ++i)
  {
    Expression* nextArg = elseCall->get_argument(i) ;
    nextArg->set_parent(NULL) ;
    elseCallExp->append_argument(nextArg) ;
  }

  boolSelectCall->append_argument(elseCallExp) ;

  Expression* condition = toConvert->get_condition() ;
  toConvert->set_condition(NULL) ;
  boolSelectCall->append_argument(condition) ;

  toConvert->get_parent()->replace(toConvert, boolSelectCall) ;  
  return true ;
}
Ejemplo n.º 3
0
bool IfConversionPass2::CorrectTypes(Statement* x, Statement* y)
{
  if (dynamic_cast<StoreStatement*>(x) != NULL &&
      dynamic_cast<StoreStatement*>(y) != NULL)
  {
    return true ;
  }
  if (dynamic_cast<StoreVariableStatement*>(x) != NULL &&
      dynamic_cast<StoreVariableStatement*>(y) != NULL)
  {
    StoreVariableStatement* xStoreVar = 
      dynamic_cast<StoreVariableStatement*>(x) ;
    StoreVariableStatement* yStoreVar = 
      dynamic_cast<StoreVariableStatement*>(y) ;

    return (xStoreVar->get_destination() == yStoreVar->get_destination()) ;
  }
  if (dynamic_cast<CallStatement*>(x) != NULL &&
      dynamic_cast<CallStatement*>(y) != NULL)
  {
    CallStatement* xCall = dynamic_cast<CallStatement*>(x) ;
    CallStatement* yCall = dynamic_cast<CallStatement*>(y) ;
    return ((xCall->get_destination() == yCall->get_destination()) && 
	    (xCall->get_destination() != NULL)) ;
  }

  // Now, the mixtures
  if (dynamic_cast<CallStatement*>(x) != NULL &&
      dynamic_cast<StoreVariableStatement*>(y) != NULL)
  {
    CallStatement* xCall = dynamic_cast<CallStatement*>(x) ;
    StoreVariableStatement* yStoreVar = 
      dynamic_cast<StoreVariableStatement*>(y) ;
    return ((xCall->get_destination() == yStoreVar->get_destination()) &&
	    (xCall->get_destination() != NULL)) ;
  }

  if (dynamic_cast<StoreVariableStatement*>(x) != NULL &&
      dynamic_cast<CallStatement*>(y) != NULL)
  {
    StoreVariableStatement* xStoreVar = 
      dynamic_cast<StoreVariableStatement*>(x) ;
    CallStatement* yCall = dynamic_cast<CallStatement*>(y) ;
    return ((xStoreVar->get_destination() == yCall->get_destination()) &&
	    (xStoreVar->get_destination() != NULL)) ;
  }

  return false ;
}