Example #1
0
void ExportPass::ConstructModuleSymbols()
{
  CProcedureType* originalType = dynamic_cast<CProcedureType*>(originalProcedure->get_procedure_symbol()->get_type()) ;
  assert(originalType != NULL) ;

  // The original type takes and returns a struct.  We need to change this
  //  to a list of arguments.

  VoidType* newReturnType = create_void_type(theEnv, IInteger(0), 0) ;
  constructedType = create_c_procedure_type(theEnv,
					    newReturnType,
					    false, // has varargs
					    true, // arguments_known
					    0, // bit alignment
					    LString("ConstructedType")) ;

  StructType* returnType = 
    dynamic_cast<StructType*>(originalType->get_result_type()) ;
  assert(returnType != NULL) ;

  SymbolTable* structSymTab = returnType->get_group_symbol_table() ;
  assert(structSymTab != NULL) ;

  for (int i = 0 ; i < structSymTab->get_symbol_table_object_count() ; ++i)
  {
    VariableSymbol* nextVariable = 
      dynamic_cast<VariableSymbol*>(structSymTab->get_symbol_table_object(i));
    if (nextVariable != NULL)
    {
      // Check to see if this is an output or not
      QualifiedType* cloneType ;
      DataType* cloneBase = 
	dynamic_cast<DataType*>(nextVariable->get_type()->get_base_type()->deep_clone()) ;
      assert(cloneBase != NULL) ;
      cloneType = create_qualified_type(theEnv, cloneBase) ;
 
      if (nextVariable->lookup_annote_by_name("Output") != NULL)
      {
	cloneType->append_annote(create_brick_annote(theEnv, "Output")) ;
	// Why doesn't this stick around?
      }
      constructedType->append_argument(cloneType) ;
    }
  }

  constructedSymbol = create_procedure_symbol(theEnv,
					      constructedType,
					      originalProcedure->get_procedure_symbol()->get_name()) ;
  constructedSymbol->set_definition(NULL) ;

}
void CopyPropagationPass2::CollectVariables()
{
  assert(procDef != NULL) ;
  if (killMap.empty() == false)
  {
    ClearMap() ;
  }
  assert(killMap.empty() == true) ;
  assert(procDef != NULL) ;
  SymbolTable* symTab = procDef->get_symbol_table() ;
  Iter<SymbolTableObject*> symIter = 
    symTab->get_symbol_table_object_iterator() ;
  while (symIter.is_valid())
  {
    if (is_a<VariableSymbol>(symIter.current()))
    {
      // For each variable symbol, create a new list of statement/int pairs
      //  and add that to the kill map
      list<std::pair<Statement*, int> >* assocList = 
	new list<std::pair<Statement*, int> > ;
      killMap[to<VariableSymbol>(symIter.current())] = assocList ;
    }
    else if (is_a<ParameterSymbol>(symIter.current()))
    {
      // If we are compiling a module, we also have to find the argument
      //  (which should be a struct) and collect all of those variable
      //  symbols..
      ParameterSymbol* nextParm =
	dynamic_cast<ParameterSymbol*>(symIter.current()) ;
      assert(nextParm != NULL) ;

      // Now check that we have a struct type
      DataType* parmType = nextParm->get_type()->get_base_type() ;
      StructType* parmStructType =
        dynamic_cast<StructType*>(parmType) ;

      if (parmStructType == NULL)
      {
	list<std::pair<Statement*, int> >* assocList =
	  new list<std::pair<Statement*, int> > ;
	killMap[dynamic_cast<VariableSymbol*>(symIter.current())] = assocList ;
	symIter.next() ;
	continue ;
      }

      // Go through this symbol table, just like the parent table...
      SymbolTable* structSymTab = parmStructType->get_group_symbol_table() ;

      Iter<SymbolTableObject*> structSymIter =
        structSymTab->get_symbol_table_object_iterator() ;

      while (structSymIter.is_valid())
      {
	// These should all be variable symbols!
	if (is_a<FieldSymbol>(structSymIter.current()))
	{
	  // For each variable symbol, create a new list of statement/int pairs
	  //  and add that to the killMap.
	  list<std::pair<Statement*, int> >* assocList =
	    new list<std::pair<Statement*, int> > ;
	  
	  killMap[to<VariableSymbol>(structSymIter.current())] = assocList ;
	}
	else
	{
	  std::cerr << "Non variable symbol inside a struct!" << std::endl ;
	  assert(0) ;
	}
	
	structSymIter.next() ;
      }
    }
    symIter.next() ;
  }
}