void MultiDimArrayDismantlerPass::do_file_set_block( FileSetBlock* file_set_block ) {
    SuifEnv *env = get_suif_env();
    TypeBuilder *type_builder = (TypeBuilder *)
          env->get_object_factory(TypeBuilder::get_class_name());
    suif_hash_map<MultiDimArrayType *,Type *> type_map;
    ReplacingWalker walker(env);

    list<MultiDimArrayType *> type_list;

    for (Iter<MultiDimArrayType> titer =
                object_iterator<MultiDimArrayType>(file_set_block);
         titer.is_valid(); titer.next()) 
    {
        MultiDimArrayType *type = &titer.current();
	    type_list.push_back(type);
	}

    for (list<MultiDimArrayType *>::iterator tliter = type_list.begin();tliter != type_list.end();tliter ++) {
	    MultiDimArrayType *type = *tliter;
	    Type *rep_type = disassemble_multi_array_type(env,type_builder,type);
	    type_map.enter_value(type,rep_type);
	    to<BasicSymbolTable>(type->get_parent())->remove_symbol_table_object(type);
	    walker.add_replacement(type,rep_type);
    }

    for (Iter<MultiDimArrayExpression> iter = 
		object_iterator<MultiDimArrayExpression>(file_set_block);
        iter.is_valid(); iter.next()) 
    {
    	MultiDimArrayExpression *expr = &iter.current();
    	dismantle_multi_dim_array_expression(env,expr,type_builder,type_map);
	}
    file_set_block->walk(walker);
};
String ErrorSubSystem::get_location(const SuifObject *obj) const {
  if (obj == NULL) return emptyString;
  LString style = get_default_location_module();
  if (style == emptyLString) {
    return(obj->getClassName());
  }

  ModuleSubSystem *ms = get_suif_env()->get_module_subsystem();
  Module *module = ms->retrieve_module(style);
  LString location_iface = "get_object_location";
  if (!module->supports_interface(location_iface))
    {
      return(obj->getClassName());
    }
  LocationDispatch pfunc = 
    (LocationDispatch)module->get_interface(location_iface);
  //TODO:
#ifdef MSVC
  if((int)pfunc==0x1)pfunc=NULL;
#endif
  if (pfunc)
    {
      return ((*pfunc)(obj).print_to_string());
    }
  else
    {
      //      cerr << "installed location style" 
      //      	     << style.c_str() << "has no valid print function" << endl;
      return(obj->getClassName());
    }
}
Example #3
0
void SuifEnvObjectFactory::information( const char* file_name,
                       int line_number,
                       const char* module_name,
                       int verbosity_level,
                       const char* description, va_list ap ) {
  get_suif_env()->information( file_name, line_number, module_name, verbosity_level, description, ap );
}
Example #4
0
  	virtual void do_procedure_definition(ProcedureDefinition *proc_def)
	    {
	    if ( !proc_def )
        	return;

    	    walker walk(get_suif_env(), proc_def);
    	    proc_def->walk(walk);
    	    }
Example #5
0
void AvoidExternCollisions::do_file_set_block( FileSetBlock* file_set_block ) {
    CollisionAvoider walker(get_suif_env(),
			    file_set_block->get_external_symbol_table(),
			    NULL,
			    (file_set_block->get_file_block(0))->
							get_source_file_name(),
			    false);
    file_set_block->walk(walker);
    }
void DoWhileToWhileTransformPass::do_procedure_definition(ProcedureDefinition* proc_def)
{
  OutputInformation("Do...while to while loop transformation begins") ;
  if (proc_def)
  {
    dw2wtp_do_while_statement_walker walker(get_suif_env());
    proc_def->walk(walker);
  }
  OutputInformation("Do...while to while loop transformation ends") ;
}
Example #7
0
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void SuifPrinterModule::initialize()
{
   Module::initialize();
   // register as a listener
   ModuleSubSystem *ms = get_suif_env()->get_module_subsystem();
   ms->register_interface_listener(this, "print_init");
   //   ms->register_interface_producer(this, "print");
   set_interface("print", (Address)SuifPrinterModule::print_dispatch);
   
   init();
}
void LoopInfoPass::do_procedure_definition(ProcedureDefinition* proc_def){
    if (proc_def){
	annote_c_for_statements walker(get_suif_env());
	proc_def->walk(walker);

	loop_level = 0;

	Statement *proc_def_body = to<Statement>(proc_def->get_body());
	solve_li_statement(proc_def_body);
    }
}
void HW_SW_BoundaryMarkPass::do_procedure_definition(ProcedureDefinition* proc_def)
{
  OutputInformation("Determination of Hardware/Software boundary pass begins");
    if (proc_def){
	SuifEnv *env = get_suif_env();

        if(proc_def->lookup_annote_by_name("begin_hw"))
           delete (to<BrickAnnote>(proc_def->remove_annote_by_name("begin_hw")));
        if(proc_def->lookup_annote_by_name("end_hw"))
           delete (to<BrickAnnote>(proc_def->remove_annote_by_name("end_hw")));

        BrickAnnote *ba = create_brick_annote(env, "begin_hw");
        proc_def->append_annote(ba);
        ba = create_brick_annote(env, "end_hw");
        proc_def->append_annote(ba);

	hsbm_call_statement_walker walker(get_suif_env());
	proc_def->walk(walker);
    }
  OutputInformation("Determination of Hardware/Software boundary pass ends");
}
Example #10
0
void CPrintStyleModule::initialize() {
  Module::initialize();

  _print_map = 
    new CascadingMap<string_gen_fn>(get_suif_env(), default_string_gen_fn);
  
#define HANDLE_DISPATCH(lower, name) \
  set_print_function( name ## ::get_class_name(), \
		     handle_static_ ## lower ## );
#include "obj.defs"
#undef HANDLE_DISPATCH
 set_interface("print", (Address)CPrintStyleModule::print_dispatch);

}
Example #11
0
  void do_file_set_block(FileSetBlock *fsb) {
    String output_file_name = 
      _output_file_name_argument->get_string()->get_string();
    c_file = open_c_file(output_file_name);

    SuifEnv *s = get_suif_env();
    MacroObjectBuilder builder;
    MacroObjectPtr root =  builder.build_macro_object((Address)fsb,fsb->get_meta_class());

    char *text = get_file_text(_macro_file_name.c_str());
    if (text == NULL)
    {
      suif_error(s, "could not open macro file %s\n",_macro_file_name.c_str());
      //        fprintf(stderr,"could not open macro file %s\n",macro_filename);
      return;
      //        return -1;
    }
    size_t i;
    for (i = 0;i < _d_opts.size(); i++)
      AddDefine(root,_d_opts[i]);

    int len = strlen(text);
    S2CMacroExpansion expand(s,len);

    for (i = 0;i < _i_opts.size(); i++)
    {
      String value = _i_opts[i];
      expand.add_include(value);
    }

    // root->Print(0);

    expand.set_debug(debug_it);
    expand.Expand(_macro_file_name,text,root);
    for (int j=1;j<expand.file_count();j++) {
	const String x = expand.get_file_text(j);
        write_text(expand.get_file_name(j),x);
	}

    const String def = expand.get_file_text(0);
    if (def.length() > 0)
        fprintf(c_file,"%s",def.c_str());
    root->perform_final_cleanup();
    if (c_file  && c_file != stdout) 
      fclose(c_file);
    delete [] text;
    }
Example #12
0
void AvoidFileScopeCollisions::do_file_set_block( FileSetBlock* file_set_block ) {
    list<SymbolTable*> file_scope_tables;
    for (Iter<FileBlock*> iter = file_set_block->get_file_block_iterator();
	 iter.is_valid(); iter.next()) 
      {
	file_scope_tables.push_back(iter.current()->get_symbol_table());
      }
    file_scope_tables.push_back(file_set_block->get_file_set_symbol_table());
    
    CollisionAvoider walker(get_suif_env(),
			    file_set_block->get_external_symbol_table(),
			    &file_scope_tables,
			    (file_set_block->get_file_block(0))->
				get_source_file_name(),
			    false);
    file_set_block->walk(walker);
    }
void NonConstBoundDismantlerPass::do_file_set_block( FileSetBlock* file_set_block ) {
    SuifEnv *env = get_suif_env();
    ReplacingWalker walker(env);
    ReverseMap rev_map;
    NonConstDimExpressionWalker ew1(env,walker,rev_map,MultiDimArrayExpression::get_class_name());
    NonConstDimExpressionWalker ew2(env,walker,rev_map,ArrayReferenceExpression::get_class_name());

    NonConstBoundArrayTypeWalker  aw1(env,rev_map,MultiDimArrayType::get_class_name());
    NonConstBoundArrayTypeWalker  aw2(env,rev_map,ArrayType::get_class_name());
    walker.append_walker(ew1);
    walker.append_walker(ew2);
    file_set_block->walk(walker);
    ReplacingWalker type_walker(env);
    type_walker.append_walker(aw1);
    type_walker.append_walker(aw2);

    file_set_block->walk(type_walker);
}
Example #14
0
void SuifCFGraphPass::do_procedure_definition(ProcedureDefinition *proc_def )
  {
    CFGraphQuery q(get_suif_env(), proc_def);

    //    bool verbose = _verbose_output->is_set();
    bool dot_output = _dot_output->is_set();
    if (dot_output) {
      const char *fname = 
	(String(proc_def->get_procedure_symbol()->get_name()) + ".dot").c_str();
      FILE *fp = fopen(fname, "w");
      if (!fp) {
	suif_warning("Could not open file '%s'\n", fname);
      } else {
	file_ion the_ion(fp);
	q.print_dot(&the_ion);
	fclose(fp);
      }
    }
  }
void RequireProcedureReturns::
do_procedure_definition( ProcedureDefinition *pd) {
  if (is_kind_of<Statement>(pd->get_body())) {
    Statement *st = to<Statement>(pd->get_body());
    Statement *last_st = find_last_statement(st);
    suif_assert_message(last_st != NULL,
			("Only found a NULL last statement for procedure body"));
    
    if (is_kind_of<ReturnStatement>(last_st))
      return;
    // If it is a Statement List, add a new return into the
    // statement.
    ReturnStatement *ret = 
      create_return_statement(get_suif_env(), NULL);
    // We leave the "expression" blank here. 
    // Use the normalize_procedure_returns pass to add the value.
    insert_statement_after(last_st, ret);
  }
}
void ConstQualedVarPropagationPass::do_procedure_definition(ProcedureDefinition* proc_def)
{
  OutputInformation("Constant qualified variable propagation pass begins");

  suif_map<VariableSymbol*, ValueBlock*> temp_const_defs;
    if (proc_def){
        DefinitionBlock *proc_def_block = proc_def->get_definition_block();
        for(Iter<VariableDefinition*> iter = proc_def_block->get_variable_definition_iterator();
            iter.is_valid(); iter.next()){
            VariableDefinition *var_def = iter.current();
            VariableSymbol *var_sym = var_def->get_variable_symbol();
            QualifiedType *qualed_var_type = var_sym->get_type();
            if(is_a<IntegerType>(qualed_var_type->get_base_type())){
               bool found = 0;
               for(Iter<LString> iter2 = qualed_var_type->get_qualification_iterator();
                   iter2.is_valid(); iter2.next())
                   if(iter2.current() == LString("const"))
                      found = 1;
               if(found){
                  temp_const_defs.enter_value(var_sym, var_def->get_initialization());
               }
            }
        }
        for(Iter<StoreVariableStatement> iter = object_iterator<StoreVariableStatement>(proc_def->get_body());
            iter.is_valid(); iter.next()){
            StoreVariableStatement *store_var_stmt = &iter.current();
            Expression *store_var_value = store_var_stmt->get_value();
            if(!is_a<IntConstant>(store_var_value))
               continue;
            VariableSymbol *store_var_destination = store_var_stmt->get_destination();
            if(!is_a<IntegerType>(store_var_destination->get_type()->get_base_type()))  
               continue;
            suif_map<VariableSymbol*,ValueBlock*>::iterator iter2 =
                        temp_const_defs.find(to<LoadVariableExpression>(store_var_value)->get_source());
            if(iter2 != temp_const_defs.end())
               const_qualified_scalars.enter_value(store_var_destination, (*iter2).second);
        }
        cqvp_load_variable_expression_walker walker(get_suif_env());
        proc_def->walk(walker);
    }
  OutputInformation("Constant qualified variable propagation pass ends");
}
CallExpression* CfeNodeBuilder::call(Expression* callee_addr,
				  suif_vector<Expression*>* args)
{
  CProcedureType* ctype =
    to_ref_type<CProcedureType>(this, callee_addr->get_result_type());
  if (ctype == 0) {
    trash(callee_addr);
    for (unsigned i = 0; i<args->length(); i++) {
      trash(args->at(i));
    }
    SUIF_THROW(SuifException(String("Type error in CallExpression ") + 
			     to_id_string(callee_addr)));
  }
  DataType* rtype = to<CProcedureType>(ctype)->get_result_type();
  CallExpression* exp = create_call_expression(get_suif_env(), rtype, callee_addr);
  for (unsigned i = 0; i<args->length(); i++) {
    exp->append_argument(args->at(i));
  }
  return exp;
}
Example #18
0
void PrintDotSuifCFGraphPass::do_procedure_definition(ProcedureDefinition *pd) 
{
  CFGraphQuery q(get_suif_env(), pd);
  q.print_dot(stdout_ion);
}
void UnrollPass::do_procedure_definition(ProcedureDefinition* proc_def) {
    if (proc_def) {
        c_for_statement_walker walker(get_suif_env(), unroll_count, loop_level);
        proc_def->walk(walker);
    }
}
Example #20
0
 virtual Module *clone() const { 
   return(new S2CPass(get_suif_env(), get_module_name()));
 }
void StripMinePass::do_procedure_definition(ProcedureDefinition* proc_def) {
    if (proc_def) {
        smp_c_for_statement_walker walker(get_suif_env(), loop_label_argument, strip_size_argument);
        proc_def->walk(walker);
    }
}
Example #22
0
void FrontendPass::execute() {
  FileSetBlock *fsb = build_file_set_block();
  get_suif_env()->set_file_set_block( fsb );
}
void FlattenScopeStatementsPass::do_procedure_definition(ProcedureDefinition *proc_def){
    if(proc_def){
        fssp_scope_statement_walker walker(get_suif_env());
        proc_def->walk(walker);
    }
}
void EliminateArrayConvertsPass::do_procedure_definition(ProcedureDefinition* proc_def){
    suif_hash_map<ParameterSymbol*, Type*> params;
    TypeBuilder *tb = (TypeBuilder*)
         get_suif_env()->get_object_factory(TypeBuilder::get_class_name());

    // collect all procedure parameters of pointer type into params list
    for(Iter<ParameterSymbol*> iter = proc_def->get_formal_parameter_iterator();
        iter.is_valid(); iter.next())
    {
        ParameterSymbol* par_sym = iter.current();
        Type* par_type = tb->unqualify_type(par_sym->get_type());

        if(is_kind_of<PointerType>(par_type)){
            // put NULLs into the map at first,
            // they will later be overwritten
            params[par_sym] = NULL;
        }
    }
    if(params.size()==0) return;    // nothing to do
    
    // walk thru all AREs and look for arrays that are in the param list
    {for(Iter<ArrayReferenceExpression> iter =
        object_iterator<ArrayReferenceExpression>(proc_def);
            iter.is_valid(); iter.next())
        {
            ArrayReferenceExpression* are = &iter.current();
            if(is_kind_of<UnaryExpression>(are->get_base_array_address())){
                UnaryExpression* ue = to<UnaryExpression>(are->get_base_array_address());
                if(ue->get_opcode() == k_convert){
                    if(is_kind_of<LoadVariableExpression>(ue->get_source())){
                        LoadVariableExpression* lve = 
                            to<LoadVariableExpression>(ue->get_source());
                        VariableSymbol* array = lve->get_source();
            
                        for(suif_hash_map<ParameterSymbol*, Type*>::iterator iter = params.begin();
                            iter!=params.end();iter++)
                        {
                            ParameterSymbol* par_sym = (*iter).first;
                            if(par_sym == array){
                                // match!
                                Type* array_type;
                                suif_hash_map<ParameterSymbol*, Type*>::iterator iter =
                                    params.find(par_sym);
                                
                                if(iter==params.end() || (*iter).second==NULL){
                                    //array_type = to<PointerType>(ue->get_result_type())->get_reference_type();
                                    array_type = tb->get_qualified_type(ue->get_result_type());
                                    params[par_sym] = array_type;
                                    //printf("%s has type ",par_sym->get_name().c_str());
                                    //array_type->print_to_default();
                                }else{
                                    array_type = params[par_sym].second;
                                    suif_assert(is_kind_of<QualifiedType>(array_type));
                                }

                                array->replace(array->get_type(), array_type);
                                remove_suif_object(ue);
                                remove_suif_object(lve);
                                lve->replace(lve->get_result_type(), tb->unqualify_type(array_type));
                                // put the LoadVar directly under ARE
                                are->set_base_array_address(lve);
                                //are->print_to_default();
                            }
                        }
                    } else {
                        suif_warning(ue->get_source(),
                            ("Expecting a LoadVariableExpression here"));
                    }
                } else {
                    suif_warning(ue, ("Disallow converts in AREs for "
                            "things other than procedure parameters"));
                }
            }
        }
    }
}
Example #25
0
void NameAllSymbolsPass::do_file_set_block( FileSetBlock* file_set_block ) {
    SymbolNamer walker(get_suif_env(),(file_set_block->get_file_block(0))->
					get_source_file_name());
    file_set_block->walk(walker);
    }
Example #26
0
void GCSymbolTablePass::execute(void)
{
  // Let's try a little optimization.
  // we'll do GC like the trash_it routine.
  // walk through all of the owned objects in the program.
  // for the non-symbols, walk through their sub-objects and
  // find any referenced symbols
  // throw away any that are not needed.
  FileSetBlock *fsb = get_suif_env()->get_file_set_block();
  if (fsb == NULL) return;

  static LString k_trash = "trash";
  // remove the trash annote.  we'll replace it later
  Annote *trash_annote = fsb->take_annote(k_trash);


  suif_hash_map<SymbolTableObject*,bool> referenced_map;
  suif_list<SymbolTableObject*> live_symbols;

  // Now we have a map of Object->parent object
  // We need another one for object -> referenced
  for (Iter<SuifObject> all_iter1 = object_iterator<SuifObject>(fsb);
       all_iter1.is_valid(); all_iter1.next()) {
    SuifObject *obj = &all_iter1.current();

    // for the ownership links of symbols:
    if (is_kind_of<SymbolTable>(obj)) continue;

    if (is_kind_of<SymbolTableObject>(obj)) {
      SymbolTableObject *sym = to<SymbolTableObject>(obj);
      //sym->print_to_default();

      if (referenced_map.find(sym) == referenced_map.end()) {
	//fprintf(stderr, "Found unreferenced Symbol:");
	// referenced_map[sym] = false;
	referenced_map.enter_value(sym, false);
      }
      // we will check these later.
      continue;
    }

    for (Iter<SymbolTableObject> ref_iter = 
	   suif_object_ref_iterator<SymbolTableObject>(obj, 
					    SuifObject::get_class_name());
	 ref_iter.is_valid(); ref_iter.next()) {
      SymbolTableObject *sym_ref = &ref_iter.current();
      
      suif_hash_map<SymbolTableObject*,bool>::iterator find =
	referenced_map.find(sym_ref);
      if (find == referenced_map.end()
	  || (*find).second == false) {
	//fprintf(stderr, "Found Symbol Reference:");
	//sym_ref->print_to_default();
	//referenced_map[sym_ref] = true;
	referenced_map.enter_value(sym_ref, true);
	live_symbols.push_back(sym_ref);
      }
    }
  }

  // Now we have to do a worklist algorithm with the live symbols.
  // any symbol they own or reference must also be live
  while (!live_symbols.empty()) {
    SymbolTableObject *obj = live_symbols.back();
    live_symbols.pop_back();
    // Implicit assumption:
    // it will NEVER OWN another symbol.
    // If it did, we just need to use the object_instance_iterator
    // to add these.
    
    // Everything it references is live.
    for (Iter<SymbolTableObject> ref_iter = 
	   suif_object_ref_iterator<SymbolTableObject>(obj, 
					    SuifObject::get_class_name());
	 ref_iter.is_valid(); ref_iter.next()) {
      SymbolTableObject *sym_ref = &ref_iter.current();
      
      suif_hash_map<SymbolTableObject*,bool>::iterator find =
	referenced_map.find(sym_ref);
      if (find == referenced_map.end()
	  || (*find).second == false) {
	//fprintf(stderr, "Found Symbol reference:");
	//sym_ref->print_to_default();
	// referenced_map[sym_ref] = true;
	referenced_map.enter_value(sym_ref, true);
	live_symbols.push_back(sym_ref);
      }
    }
  }

  if (trash_annote != NULL)
    fsb->append_annote(trash_annote);


  // walk over all of the reference
  // and delete or put back
  for (suif_hash_map<SymbolTableObject*, bool>::iterator obj_iter = 
	 referenced_map.begin();
       obj_iter != referenced_map.end(); obj_iter++) {
    bool is_referenced = (*obj_iter).second;
    if (!is_referenced) {
      SymbolTableObject *sym = (*obj_iter).first;
      //fprintf(stderr, "Trashing unused symbol:");
      //sym->print_to_default();
      SymbolTable *st = sym->get_symbol_table();
      if (st != NULL) {
	if (sym->get_name() != emptyLString) {
	  st->remove_all_from_lookup_table(sym);
	}
	st->remove_symbol_table_object(sym);
      }
      remove_suif_object(sym);
      trash_it(_suif_env, sym);
      //      delete sym;
    }
  }
  //  SuifGC::collect(_suif_env->get_file_set_block());
}
Example #27
0
void SuifEnvObjectFactory::warning( const char* file_name,
                       int line_number,
                       const char* module_name,
                       const char* description, va_list ap ) {
  get_suif_env()->warning( file_name, line_number, module_name, description, ap );
}
FileSetBlock *CreateSuifComplexInputPass::build_file_set_block() {
    SuifEnv *suif = get_suif_env();

    // Build a blank fileset
    FileSetBlock *the_file_set_block = build_the_file_set_block(suif);
    _suif_env->set_file_set_block( the_file_set_block );

    SymbolTable* ext_table = the_file_set_block->get_external_symbol_table();

    _tb = (TypeBuilder*)suif->get_object_factory(TypeBuilder::get_class_name());
    suif_assert_message(_tb, ("Could not initialize typebuilder"));

    // build the types
    _char_type =
      _tb->get_integer_type( sizeof(char),sizeof(char),true);
    //    ext_table -> append_symbol_table_object( _char_type );
    _q_char_type = _tb->get_qualified_type(_char_type);

    _fpt = _tb->get_floating_point_type( 64 ,64);
    _q_fpt = _tb->get_qualified_type(_fpt);
    //    ext_table -> append_symbol_table_object( _fpt );

    _argc_type = _tb->get_integer_type(sizeof(int),sizeof(int)*8,true);
    _q_argc_type = _tb->get_qualified_type(_argc_type);

    list<QualifiedType *> ql;
    _printf_type =
      _tb->get_c_procedure_type(_argc_type, ql, false,true,sizeof(int));
    //     ext_table -> append_symbol_table_object( _printf_type );


    //    Expression *i0 = create_int_constant(suif, 0, 0);
    //    Expression *i1 = create_int_constant(suif, 0, strlen(HELLO_STRING) + 1);
    _string_literal_type =
      _tb->get_array_type( //IInteger((strlen(HELLO_STRING) + 1) * sizeof(char)),
			  //			   (int)sizeof(char),
			   _q_char_type,
			   0, strlen(HELLO_STRING)+1);
    //			   i0,i1);
    //    ext_table -> append_symbol_table_object( _string_literal_type );

    //    _argc_type = create_integer_type(suif, sizeof(int),sizeof(int)*8,true);
    //    ext_table -> append_symbol_table_object( _argc_type );
    //    _q_argc_type = tb->get_qualified_type(_argc_type);

    _argv_type = _tb->get_pointer_type(_tb->get_pointer_type(_char_type));
    _q_argv_type = _tb->get_qualified_type(_argv_type);


    list<QualifiedType *> qlist;
    qlist.push_back(_q_argc_type);
    qlist.push_back(_q_argv_type);

    _main_type =
      _tb->get_c_procedure_type( _argc_type, qlist, false,true,sizeof(int));
    //    _main_type->append_argument( _q_argc_type );
    //    _main_type->append_argument( _q_argv_type );
    //    ext_table -> append_symbol_table_object( _main_type );


    // Build a blank main routine.
    ProcedureDefinition *main_definition =
      build_main( "complex_input.c");

    // Pull info out of main.
    ParameterSymbol *argc_symbol =
      main_definition->get_formal_parameter(0);

    CProcedureType *main_type =
      to<CProcedureType>(main_definition->get_procedure_symbol()->get_type());
    StatementList *main_body =
      to<StatementList>(main_definition->get_body());


    // Now create the printf statement and add it in
    main_type->append_argument(_tb->get_qualified_type(_tb->get_pointer_type(_char_type)));

    ProcedureSymbol *printf_symbol =
      create_procedure_symbol(suif, _printf_type, "printf", true );
    the_file_set_block->get_external_symbol_table()->
      add_symbol(printf_symbol);


    VariableSymbol *float_literal_symbol =
      create_variable_symbol( suif, _q_fpt, " float symbol", true );
    ext_table -> add_symbol(float_literal_symbol );

    MultiValueBlock *float_literal_initialization =
      create_multi_value_block( _suif_env, _fpt);
    float_literal_initialization->add_sub_block(0,
		create_expression_value_block( _suif_env,
					    create_float_constant(_suif_env, _fpt, 7.0)));

    VariableDefinition *float_literal_definition =
      create_variable_definition(suif, float_literal_symbol,sizeof(float),
				 float_literal_initialization, true);

    main_definition->get_definition_block()->
            append_variable_definition(float_literal_definition);





    VariableSymbol *string_literal_symbol =
      create_variable_symbol(suif, _q_string_literal_type, emptyLString, true );
    main_definition->get_symbol_table()->append_symbol_table_object(string_literal_symbol);
    MultiValueBlock *string_literal_initialization =
      create_multi_value_block(suif, _string_literal_type);
    for (size_t char_num = 0; char_num <= strlen(HELLO_STRING); ++char_num)
      {
        string_literal_initialization->
	  add_sub_block(char_num,
     create_expression_value_block( _suif_env,
	    create_int_constant( _suif_env, _char_type, HELLO_STRING[char_num] )));
      }
    VariableDefinition *string_literal_definition =
      create_variable_definition( _suif_env, string_literal_symbol,sizeof(char),
                                    string_literal_initialization, true);

    main_definition->get_definition_block()->
            append_variable_definition(string_literal_definition);

    SymbolAddressExpression* printf_address_expression =
      create_symbol_address_expression( _suif_env,
                                      pointer_to( _suif_env, _printf_type),
                                      printf_symbol );

    SymbolAddressExpression* printf_argument_expression =
      create_symbol_address_expression( _suif_env,
				      pointer_to(_suif_env, _char_type),
				      string_literal_symbol );
    CallStatement *printf_call =
      create_call_statement( _suif_env,
			     NULL, 
			     //			     _argc_type,
			     printf_address_expression );

    printf_call->append_argument(printf_argument_expression);

    //    EvalStatement *printf_statement = create_eval_statement( _suif_env );
    //    printf_statement->append_expression(printf_call);

    main_body->append_statement(printf_call);

    Expression *condition = 
      create_load_variable_expression(_suif_env, 
				      unqualify_data_type(argc_symbol->get_type()),
				      argc_symbol);

    StatementList *then_part =
      create_statement_list(suif);

    Statement* s = deep_suif_clone( _suif_env, printf_call);

    then_part->append_statement( s );

    StatementList *else_part = create_statement_list( _suif_env );
    else_part->append_statement(deep_suif_clone<Statement>( _suif_env, printf_call));
    else_part->append_statement(deep_suif_clone<Statement>( _suif_env, printf_call));


    IfStatement *the_if =
      create_if_statement( _suif_env,
			  condition,
			  then_part,
			  else_part);

    main_body->append_statement(the_if);

    return the_file_set_block;
}
Example #29
0
FileSetBlock* SimpleModule::get_file_set_block(void)
{
  return get_suif_env()->get_file_set_block();
}