Exemple #1
0
void
add_to_procedure_list(list<ProcedureSymbol*> *&procs,
                      SymbolTable *table,
                      bool flag_def_only)
{
  assert( table );
  assert( procs );
  Iter<SymbolTableObject*> symbols_iter =
                                    table->get_symbol_table_object_iterator();

  for ( ; symbols_iter.is_valid(); symbols_iter.next() ) {
    SymbolTableObject* s = symbols_iter.current();
    if (s && s->isKindOf(ProcedureSymbol::get_class_name())) {
      ProcedureSymbol* sym = to<ProcedureSymbol>(s);
      if (flag_def_only && sym->get_definition() == 0) continue;
      // insert sorted
      const char *proc_name = sym->get_name().c_str();
      //list<ProcedureSymbol*>::iterator it = procs->begin();
      unsigned i;
      for (i = 0; i < procs->size(); ++i) {
	if (strcmp((*procs)[i]->get_name().c_str(), proc_name) > 0)
	   break;
      }
      if (i == procs->size()) {
	procs->push_back(sym);
      } else {
        procs->insert(i-1, sym);
      }
    }
  }
}
void NormalizeProcedureReturns::
do_procedure_definition( ProcedureDefinition *pd ) {
  ProcedureSymbol *ps = pd->get_procedure_symbol();
  if (!ps) return;
  ProcedureType *t = to<ProcedureType>(ps->get_type());
  if (!is_kind_of<CProcedureType>(t))
    return;
  CProcedureType *ct = to<CProcedureType>(t);
  DataType *result = ct->get_result_type();
  bool is_void = is_kind_of<VoidType>(result);

  for (Iter<ReturnStatement> iter = object_iterator<ReturnStatement>(pd);
       iter.is_valid(); iter.next()) {
    ReturnStatement *ret = &iter.current();
    if (ret == NULL) continue;
    
    Expression *ret_expr = ret->get_return_value();

    if (is_void) {
      if (ret_expr != NULL) {
	// Should not be here
	trash_it(remove_suif_object(ret_expr));
      }
    } else {
      if (ret_expr == NULL) {
	// build a NULL expression to match the DataType.
	Expression *x = build_empty_expression(result);
	ret->set_return_value(x);
      }
    }
  }
}
CallStatement* IfConversionPass2::CreateBoolCall(VariableSymbol* destVar) 
{
  assert(theEnv != NULL) ;
  assert(tb != NULL) ;
  ProcedureSymbol* procSym = CreateBoolSym(destVar->get_type()) ;
  SymbolAddressExpression* procSymAddr = 
    create_symbol_address_expression(theEnv,
				     tb->get_pointer_type(procSym->get_type()),
				     procSym) ;

  return create_call_statement(theEnv, destVar, procSymAddr) ;
}
bool TransformSystemsToModules::PassedStruct()
{
  assert(procDef != NULL) ;
  ProcedureSymbol* procSym = procDef->get_procedure_symbol() ;
  assert(procSym != NULL) ;
  ProcedureType* procType = procSym->get_type() ;
  assert(procType != NULL) ;
  CProcedureType* cProcType = dynamic_cast<CProcedureType*>(procType) ;
  assert(cProcType != NULL) ;
  
  return ((cProcType->get_argument_count() == 1) &&
	  (dynamic_cast<StructType*>(cProcType->get_argument(0)->get_base_type()))) ;
}
ProcedureSymbol* RemoveModulePass::FindProcedure(String name)
{
    assert(repository != NULL) ;
    SymbolTable* symTab = repository->get_external_symbol_table() ;

    for (int i = 0 ; i < symTab->get_symbol_table_object_count() ; ++i)
    {
        ProcedureSymbol* nextProc =
            dynamic_cast<ProcedureSymbol*>(symTab->get_symbol_table_object(i)) ;
        if (nextProc != NULL && nextProc->get_name() == name)
        {
            return nextProc ;
        }
    }
    return NULL ;
}
ProcedureDefinition* NodeBuilder::new_proc_defn1(LString name,
						 DataType* return_type,
						 ParameterSymbol* arg)
{
  list<QualifiedType*> argtypes;
  argtypes.push_back(to<QualifiedType>(arg->get_type()));
  CProcedureType *cproctype =
    _type_builder->get_c_procedure_type(return_type, argtypes);
  ProcedureSymbol* psym = create_procedure_symbol(_suif_env, cproctype, name);
  _symtab->add_symbol(psym);
  ProcedureDefinition* pdfn =
    create_procedure_definition(_suif_env, psym, 0,
				create_basic_symbol_table(_suif_env, _symtab),
				0);
  pdfn->append_formal_parameter(arg);
  psym->set_definition(pdfn);
  return pdfn;
}
Exemple #7
0
/*--------------------------------------------------------------------
 * add_std_proc_menu
 *
 */
void
add_std_proc_menu(vmenu* root_menu, char* parent_menu)
{
  const unsigned max_procs = 10;
  list<ProcedureSymbol*> *bodies =
                     get_procedure_list(suif_env->get_file_set_block());

  if (bodies->size() <= max_procs) {
    for (s_count_t i = 0; i < bodies->size(); i++) {
      ProcedureSymbol *proc = (*bodies)[i];
      binding *b = new binding((bfun) &do_show_proc, proc);
      root_menu->add_command(b, parent_menu, proc->get_name().c_str() );
    }
    root_menu->add_separator(parent_menu);
  }

  /* add procedure list command to the menu */
  binding *b = new binding((bfun) &do_show_proc_list, 0);
  root_menu->add_command(b, parent_menu, "Procedure List ...");
}
StoreStatement* IfConversionPass2::CreateBoolCall(ArrayReferenceExpression* dest)
{
  assert(tb != NULL) ;
  ProcedureSymbol* procSym = 
    CreateBoolSym(create_qualified_type(theEnv, dest->get_result_type())) ;

  SymbolAddressExpression* procAddress =
    create_symbol_address_expression(theEnv,
				     tb->get_pointer_type(procSym->get_type()),
				     procSym) ;

  CallExpression* callExpr = create_call_expression(theEnv,
						    dest->get_result_type(),
						    procAddress) ;

  dest->set_parent(NULL) ;
  return create_store_statement(theEnv,
				callExpr,
				dest) ;
}
void ExportPass::ConstructSystemSymbols()
{
  ProcedureSymbol* originalSymbol = originalProcedure->get_procedure_symbol() ;
  assert(originalSymbol != NULL) ;
  CProcedureType* originalType = 
    dynamic_cast<CProcedureType*>(originalSymbol->get_type()) ;
  assert(originalType != NULL) ;

  constructedType = create_c_procedure_type(theEnv,
    dynamic_cast<DataType*>(originalType->get_result_type()->deep_clone()),
					    false, // has variable arguments
					    false, // arguments known
					    0) ; // bit alignment

  // The system has been written in one of two ways, either the old
  //  way where there are no arguments, or the new way where everything
  //  is put into the arguments.
  
  if (originalType->get_argument_count() > 0)
  {
    for (int i = 0 ; i < originalType->get_argument_count() ; ++i)
    {
      QualifiedType* originalArgument = originalType->get_argument(i) ;
      DataType* originalBase = originalArgument->get_base_type() ;
      DataType* constructedBase = CloneDataType(originalBase) ;
      QualifiedType* constructedArgument = 
	create_qualified_type(theEnv, constructedBase) ;
      constructedType->append_argument(constructedArgument) ;

      // Go through the symbol table and find the parameter symbol 
      //  that matches the parameter number, and check to see if it
      //  is an output or not...
      SymbolTable* symTab = originalProcedure->get_symbol_table() ;
      ParameterSymbol* correspondingSymbol = NULL ;
      for (int j = 0 ; j < symTab->get_symbol_table_object_count() ; ++j)
      {
	ParameterSymbol* currentSym = 
	  dynamic_cast<ParameterSymbol*>(symTab->get_symbol_table_object(j)) ;
	if (currentSym != NULL)
	{
	  BrickAnnote* orderAnnote = dynamic_cast<BrickAnnote*>(currentSym->lookup_annote_by_name("ParameterOrder")) ;
	  assert(orderAnnote != NULL) ;
	  IntegerBrick* orderBrick = 
	    dynamic_cast<IntegerBrick*>(orderAnnote->get_brick(0)) ;
	  assert(orderBrick != NULL) ;
	  if (orderBrick->get_value().c_int() == i)
	  {
	    correspondingSymbol = currentSym ;
	    break ;
	  }
	}
      }
      if (correspondingSymbol != NULL)
      {
        if (correspondingSymbol->lookup_annote_by_name("OutputScalar") != NULL ||
	    correspondingSymbol->lookup_annote_by_name("OutputVariable") != NULL ||
	    correspondingSymbol->lookup_annote_by_name("OutputFifo") != NULL)
        {
	  constructedArgument->append_annote(create_brick_annote(theEnv,
								 "Output")) ;
        }
      }
      //      if (dynamic_cast<ReferenceType*>(originalBase) != NULL)
      //{
      //	constructedArgument->append_annote(create_brick_annote(theEnv,
      //						       "Output")) ;
      //      }
    }
  }
  else
  {   
    SymbolTable* symTab = originalProcedure->get_symbol_table() ;
    assert(symTab != NULL) ;
    list<VariableSymbol*> inputScalars ;
    list<VariableSymbol*> inputFifos ; 
    list<VariableSymbol*> outputScalars ;
    list<VariableSymbol*> outputFifos ;

    for (int i = 0 ; i < symTab->get_symbol_table_object_count() ; ++i)
    {
      VariableSymbol* currentVar = 
	dynamic_cast<VariableSymbol*>(symTab->get_symbol_table_object(i)) ;
      if (currentVar != NULL &&
	  currentVar->lookup_annote_by_name("InputScalar") != NULL &&
	  currentVar->lookup_annote_by_name("TemporalFeedback") == NULL &&
	  currentVar->lookup_annote_by_name("NormalFeedback") == NULL &&
	  currentVar->lookup_annote_by_name("DebugRegister") == NULL)
      {
	inputScalars.push_back(currentVar) ;
      }
      if (currentVar != NULL &&
	  currentVar->lookup_annote_by_name("InputFifo") != NULL)
      {
	inputFifos.push_back(currentVar) ;
      }
      if (currentVar != NULL &&
	  currentVar->lookup_annote_by_name("OutputVariable") != NULL &&
	  currentVar->lookup_annote_by_name("Dummy") == NULL &&
	  currentVar->lookup_annote_by_name("FeedbackSource") == NULL)
      {
	outputScalars.push_back(currentVar) ;
      }
      if (currentVar != NULL &&
	  currentVar->lookup_annote_by_name("OutputFifo") != NULL)
      {
	outputFifos.push_back(currentVar) ;
      }
    }
    // Add the types of the input scalars, then the input fifos, 
    //  then the output scalars, and finally the output fifos.
    list<VariableSymbol*>::iterator varIter = inputScalars.begin() ;
    while (varIter != inputScalars.end())
    {
      QualifiedType* originalQual = (*varIter)->get_type() ;
      assert(originalQual != NULL) ;
      DataType* originalBase = originalQual->get_base_type() ;
      assert(originalBase != NULL) ;
      DataType* constructedBase = 
	dynamic_cast<DataType*>(originalBase->deep_clone()) ;
      QualifiedType* constructedQual = 
	create_qualified_type(theEnv, constructedBase) ;
      constructedType->append_argument(constructedQual) ;
      ++varIter ;
    }
    varIter = inputFifos.begin() ;
    while (varIter != inputFifos.end())
    {
      QualifiedType* originalQual = (*varIter)->get_type() ;
      assert(originalQual != NULL) ;
      DataType* originalBase = originalQual->get_base_type() ;
      assert(originalBase != NULL) ;
      // Fifos will have pointer types or reference types.  A 
      //  simple deep clone will not suffice, I need to build up a
      //  new type from the bottom up.
      DataType* constructedBase = CloneDataType(originalBase) ;
      assert(constructedBase != NULL) ;
      QualifiedType* constructedQual = 
	create_qualified_type(theEnv, constructedBase) ;
      assert(constructedBase != NULL) ;
      assert(constructedType != NULL) ;
      constructedType->append_argument(constructedQual) ;
      ++varIter ;
    }
    varIter = outputScalars.begin() ;
    while (varIter != outputScalars.end())
    {
      QualifiedType* originalQual = (*varIter)->get_type() ;
      DataType* originalBase = originalQual->get_base_type() ;
      DataType* constructedBase = CloneDataType(originalBase) ;
      QualifiedType* constructedQual = 
	create_qualified_type(theEnv, constructedBase) ;
      constructedQual->append_annote(create_brick_annote(theEnv, "Output")) ;
      constructedType->append_argument(constructedQual) ;
      ++varIter ;
    }
    varIter = outputFifos.begin() ;
    while (varIter != outputFifos.end())
    {
      QualifiedType* originalQual = (*varIter)->get_type() ;
      assert(originalQual != NULL) ;
      DataType* originalBase = originalQual->get_base_type() ;
      assert(originalBase != NULL) ;
      DataType* constructedBase = CloneDataType(originalBase) ;
      assert(constructedBase != NULL) ;
      QualifiedType* constructedQual = 
	create_qualified_type(theEnv, constructedBase) ;
      assert(constructedQual != NULL) ;
      constructedQual->append_annote(create_brick_annote(theEnv, "Output")) ;
      assert(constructedType != NULL) ;
      constructedType->append_argument(constructedQual) ;
      ++varIter ;
    }
    
  }
  constructedSymbol = create_procedure_symbol(theEnv, constructedType,
					      originalProcedure->get_procedure_symbol()->get_name()) ;
}
Exemple #10
0
static String handle_static_procedure_symbol(CPrintStyleModule *map,
					     const SuifObject *obj) {
  ProcedureSymbol *ps = to<ProcedureSymbol>(obj);
  return(String("P:") + ps->get_name());
}
void TransformSystemsToModules::Transform()
{
  assert(procDef != NULL) ;

  // Collect all the input scalars and output scalars
  list<VariableSymbol*> ports ;
  
  SymbolTable* procSymTab = procDef->get_symbol_table() ;
  bool foundInputs = false ;
  bool foundOutputs = false ;
 
  for (int i = 0 ; i < procSymTab->get_symbol_table_object_count() ; ++i)
  {
    SymbolTableObject* nextObject = procSymTab->get_symbol_table_object(i) ;

    if (nextObject->lookup_annote_by_name("InputScalar") != NULL)
    {
      VariableSymbol* toConvert = 
	dynamic_cast<VariableSymbol*>(nextObject) ;
      assert(toConvert != NULL) ;
      LString inputName = toConvert->get_name() ;
      inputName = inputName + "_in" ;
      toConvert->set_name(inputName) ;
      ports.push_back(toConvert) ;
      foundInputs = true ;
    }
    if (nextObject->lookup_annote_by_name("OutputVariable") != NULL)
    {
      VariableSymbol* toConvert = 
	dynamic_cast<VariableSymbol*>(nextObject) ;
      assert(toConvert != NULL) ;
      LString outputName = toConvert->get_name() ;
      outputName = outputName + "_out" ;
      toConvert->set_name(outputName) ;
      ports.push_back(toConvert) ;
      foundOutputs = true ;
    }
  }
  assert(foundInputs && 
	 "Could not identify inputs.  Were they removed via optimizations?") ;
  assert(foundOutputs && 
	 "Could not identify outputs.  Were they removed via optimizations?") ;

  // Determine the bit size and add everything to a new symbol table
  int bitSize = 0 ;
  GroupSymbolTable* structTable = 
    create_group_symbol_table(theEnv,
			      procDef->get_symbol_table()) ;

  std::map<VariableSymbol*, FieldSymbol*> replacementFields ;

  bool portsRemoved = false ;
  // If this was actually a new style module, we should make sure to
  //  put these in the correct order.
  if (isModule(procDef))
  {
    // Go through the original symbol table and remove any parameter 
    //  symbols that originally existed
    SymbolTable* originalSymTab = procDef->get_symbol_table() ;
    Iter<SymbolTableObject*> originalIter = 
      originalSymTab->get_symbol_table_object_iterator() ;
    while (originalIter.is_valid())
    {
      SymbolTableObject* currentObj = originalIter.current() ;
      originalIter.next() ;
      if (dynamic_cast<ParameterSymbol*>(currentObj) != NULL)
      {
	originalSymTab->remove_symbol_table_object(currentObj) ;
      }
    }
    portsRemoved = true ;

    // Sort the variable symbols in parameter order.  This is just an 
    //  insertion sort, so it could be done faster.
    list<VariableSymbol*> sortedPorts ;
    for (int i = 0 ; i < ports.size() ; ++i)
    {
      list<VariableSymbol*>::iterator portIter = ports.begin() ;
      while (portIter != ports.end())
      {
	BrickAnnote* orderAnnote = 
	  dynamic_cast<BrickAnnote*>((*portIter)->
				     lookup_annote_by_name("ParameterOrder")) ;
	if (orderAnnote == NULL)
	{
	  ++portIter ;
	  continue ;
	}
	IntegerBrick* orderBrick = 
	  dynamic_cast<IntegerBrick*>(orderAnnote->get_brick(0)) ;
	assert(orderBrick != NULL) ;
	if (orderBrick->get_value().c_int() == i)
	{
	  sortedPorts.push_back(*portIter) ;
	  break ;
	}
	++portIter ;
      }
    }
    if (sortedPorts.size() != ports.size())
    {
      OutputWarning("Warning! Analysis detected some input scalars not in"
		    " the parameter list") ;
    }
    // Replace ports with sortedPorts
    ports = sortedPorts ;
  }

  list<VariableSymbol*>::iterator portIter = ports.begin() ;  
  while (portIter != ports.end()) 
  {
    bitSize += 
      (*portIter)->get_type()->get_base_type()->get_bit_size().c_int() ;

    LString dupeName = (*portIter)->get_name() ;

    // Create offset expression:
    IntConstant* offset = 
      create_int_constant(theEnv,
			  create_data_type(theEnv,
					   IInteger(32),
					   0),
			  IInteger(bitSize)) ;


    QualifiedType* dupeType = (*portIter)->get_type() ;
    // Deal with the case where reference types were passed in
    ReferenceType* refType = 
      dynamic_cast<ReferenceType*>(dupeType->get_base_type()) ;
    while (refType != NULL)
    {
      dupeType = dynamic_cast<QualifiedType*>(refType->get_reference_type()) ;
      assert(dupeType != NULL) ;
      refType = dynamic_cast<ReferenceType*>(dupeType->get_base_type()) ;
    }

    // Create a new variable symbol clone
    FieldSymbol* dupe = 
      create_field_symbol(theEnv,
			  dupeType,
			  offset,
			  dupeName) ;
        
    structTable->append_symbol_table_object(dupe) ;

    // Make the connection with the duplicated symbol
    replacementFields[(*portIter)] = dupe ;

    // Remove the original variable symbol from the procedure definition
    //  symbol table.
    if (!portsRemoved)
    {
      procDef->get_symbol_table()->remove_symbol_table_object(*portIter) ;
    }
    
    ++portIter ;
  }
  assert(bitSize != 0);

  StructType* moduleStruct = 
    create_struct_type(theEnv,
		       IInteger(bitSize),
		       0, // bit_alignment
		       TempName(procDef->get_procedure_symbol()->get_name()),
		       0, // is_complete
		       structTable) ;

  
  Iter<FileBlock*> fBlocks = 
    theEnv->get_file_set_block()->get_file_block_iterator() ;
  
  assert(fBlocks.is_valid()) ;
  (fBlocks.current())->get_symbol_table()->append_symbol_table_object(moduleStruct) ;
  
  // This is commented out because it is in the file state block
  //procDef->get_symbol_table()->append_symbol_table_object(moduleStruct) ;

  QualifiedType* qualifiedModuleStruct =
    create_qualified_type(theEnv,
			  moduleStruct,
			  TempName(LString("qualifiedModuleStruct"))) ;
  
  procDef->get_symbol_table()->append_symbol_table_object(qualifiedModuleStruct) ;

  // Create an instance of this type and add it to the symbol table.
  ParameterSymbol* structInstance = 
    create_parameter_symbol(theEnv,
			   qualifiedModuleStruct,
			   TempName(LString("structInstance"))) ;

  procDef->get_symbol_table()->append_symbol_table_object(structInstance) ;

  // Now, set up the procedure symbol to take the struct and return the 
  //  struct.
  assert(procDef != NULL) ;
  ProcedureSymbol* procSym = procDef->get_procedure_symbol() ;
  assert(procSym != NULL) ;
  ProcedureType* procType = procSym->get_type() ;
  assert(procType != NULL) ;
  CProcedureType* cProcType = dynamic_cast<CProcedureType*>(procType) ;
  assert(cProcType != NULL) ;

  // Instead of appending the struct argument, we need to replace all of the 
  //  arguments with the struct.

  while (cProcType->get_argument_count() > 0)
  {
    cProcType->remove_argument(0) ;
  }

  cProcType->set_result_type(moduleStruct) ;
  cProcType->append_argument(qualifiedModuleStruct) ;

  // Now go through all load variable expressions and replace them all with
  //  field symbol values if appropriate
  
  list<LoadVariableExpression*>* allLoads = 
    collect_objects<LoadVariableExpression>(procDef->get_body()) ;

  list<LoadVariableExpression*>::iterator loadIter = allLoads->begin() ;
  while (loadIter != allLoads->end())
  {
    VariableSymbol* currentVariable = (*loadIter)->get_source() ;
    if (replacementFields.find(currentVariable) != replacementFields.end())
    {
      (*loadIter)->set_source(replacementFields[currentVariable]) ;
    }
    ++loadIter ;
  }
  delete allLoads ;

  // Also replace all of the definitions with the field symbol
  list<StoreVariableStatement*>* allStoreVars = 
    collect_objects<StoreVariableStatement>(procDef->get_body()) ;
  list<StoreVariableStatement*>::iterator storeVarIter = allStoreVars->begin();
  while (storeVarIter != allStoreVars->end())
  {
    VariableSymbol* currentDest = (*storeVarIter)->get_destination() ;
    if (replacementFields.find(currentDest) != replacementFields.end())
    {
      (*storeVarIter)->set_destination(replacementFields[currentDest]) ;
    }
    ++storeVarIter ;
  }
  delete allStoreVars ;

  list<SymbolAddressExpression*>* allSymAddr = 
    collect_objects<SymbolAddressExpression>(procDef->get_body()) ;
  list<SymbolAddressExpression*>::iterator symAddrIter = allSymAddr->begin() ;
  while (symAddrIter != allSymAddr->end())
  {
    VariableSymbol* currentVar = 
      dynamic_cast<VariableSymbol*>((*symAddrIter)->get_addressed_symbol()) ;
    if (currentVar != NULL &&
	replacementFields.find(currentVar) != replacementFields.end())
    {
      (*symAddrIter)->set_addressed_symbol(replacementFields[currentVar]) ;
    }
    ++symAddrIter ;
  }
  delete allSymAddr ;
  // One final for bool selects
  list<CallStatement*>* allCalls = 
    collect_objects<CallStatement>(procDef->get_body()) ;
  list<CallStatement*>::iterator callIter = allCalls->begin() ;
  while(callIter != allCalls->end())
  {
    VariableSymbol* currentVar = (*callIter)->get_destination() ;
    if (currentVar != NULL &&
	replacementFields.find(currentVar) != replacementFields.end())
    {
      (*callIter)->set_destination(replacementFields[currentVar]) ;
    }
    ++callIter ;
  }
  delete allCalls ;
}
void DismantleStructuredReturns::do_file_set_block( FileSetBlock* file_set_block ) {
    suif_map<CProcedureType *,QualifiedType *> type_map;
    list<ArrayReferenceExpression*> ref_exprs;
    SuifEnv *env = 0;
    TypeBuilder *tb = 0;
    VoidType *vt = 0;
    for (Iter<ProcedureSymbol> iter =
                object_iterator<ProcedureSymbol>(file_set_block);
	iter.is_valid();
	iter.next()) {
	ProcedureSymbol *sym = &iter.current();
	Type *type = sym->get_type();
	if (!is_kind_of<CProcedureType>(type))
	    continue;
	CProcedureType *cp_type = to<CProcedureType>(type);
	type = cp_type->get_result_type();
	if (!env) {
	    env = type->get_suif_env();
	    tb = (TypeBuilder*)
                env->get_object_factory(TypeBuilder::get_class_name());
	    vt = tb->get_void_type();
	    }
	suif_map<CProcedureType *,QualifiedType *>::iterator t_iter = type_map.find(cp_type);

	QualifiedType *qtype;
	
 	if (t_iter == type_map.end()) {
	    if (!is_kind_of<GroupType>(type) && !is_kind_of<ArrayType>(type))
                continue;
	    qtype = tb->get_qualified_type(
                        tb->get_pointer_type(to<DataType>(type)));

	    cp_type->set_result_type(vt);
	    
	    cp_type->insert_argument(0,qtype);
	    type_map.enter_value(cp_type,qtype);
	    }
	else {
	    qtype = (*t_iter).second;
	    }
	ProcedureDefinition *def = sym->get_definition();
	if (!def) 
	    continue;
	ParameterSymbol *par = create_parameter_symbol(env,qtype);
	def->get_symbol_table()->append_symbol_table_object(par);
        def->insert_formal_parameter(0,par);
	//	Convert all returns into assigned and returns
	for (Iter<ReturnStatement> ret_iter = object_iterator<ReturnStatement>(def->get_body());
        	ret_iter.is_valid();
        	ret_iter.next()) {
	    ReturnStatement *ret = &ret_iter.current();
	    Expression *retval = ret->get_return_value();
	    ret->set_return_value(0);
	    retval->set_parent(0);
	    insert_statement_before(ret,
			create_store_statement(env,retval,create_var_use(par)));
	    }
	}
    //	Change all calls to the new form
    for (Iter<CallStatement> cs_iter =
                object_iterator<CallStatement>(file_set_block);
        cs_iter.is_valid();
        cs_iter.next()) {
        CallStatement *call = &cs_iter.current();
	Type *type = call->get_callee_address()->get_result_type();
	Type *p_type = tb->unqualify_type(to<PointerType>(type)->get_reference_type());
        if (!is_kind_of<PointerType>(p_type))
            continue;
        p_type = tb->unqualify_type(to<PointerType>(p_type)->get_reference_type());

	if (!is_kind_of<CProcedureType>(p_type))
	    continue;
	CProcedureType *cp_type = to<CProcedureType>(p_type);
	
	suif_map<CProcedureType *,QualifiedType *>::iterator t_iter = type_map.find(cp_type);
	if (t_iter == type_map.end())
	    continue;
	QualifiedType *qtype = (*t_iter).second;
	DataType *var_type = to<DataType>(tb->unqualify_type(to<PointerType>(qtype->get_base_type())
		->get_reference_type()));
	VariableSymbol *var =
      	    new_anonymous_variable(env,call,tb->get_qualified_type(var_type));
	Expression *exp = create_symbol_address_expression(
		env,
		tb->get_pointer_type(var_type),
		var);
        call->insert_argument(0,exp);
        call->set_destination(0);
	}

    for (Iter<CallExpression> ce_iter =
                object_iterator<CallExpression>(file_set_block);
        ce_iter.is_valid();
        ce_iter.next()) {
        CallExpression *call = &ce_iter.current();
        Type *type = call->get_callee_address()->get_result_type();
        Type *p_type = tb->unqualify_type(to<PointerType>(type)->get_reference_type());
	if (!is_kind_of<PointerType>(p_type))
            continue;
	p_type = tb->unqualify_type(to<PointerType>(p_type)->get_reference_type());
        if (!is_kind_of<CProcedureType>(p_type))
            continue;
        CProcedureType *cp_type = to<CProcedureType>(p_type);
;
        suif_map<CProcedureType *,QualifiedType *>::iterator t_iter = type_map.find(cp_type);
        if (t_iter == type_map.end())
            continue;
        QualifiedType *qtype = (*t_iter).second;
        DataType *var_type = to<DataType>(tb->unqualify_type(to<PointerType>(qtype->get_base_type())
                ->get_reference_type()));
        VariableSymbol *var =
            new_anonymous_variable(env,call,tb->get_qualified_type(var_type));
        Expression *exp = create_symbol_address_expression(
                env,
                tb->get_pointer_type(var_type),
                var);
        call->insert_argument(0,exp);

	Statement *loc = get_expression_owner(call);
	call->get_parent()->replace(call,create_var_use(var));
	call->set_parent(0);
        suif_assert(vt != 0);
        call->set_result_type(vt);

	EvalStatement *es = create_eval_statement(env);
	insert_statement_before(loc,es);
	// Would be better to turn this into a call statement
	es->append_expression(call);
        }
    }