Ejemplo n.º 1
0
VariableSymbol *build_initialized_variable(
        SuifEnv *env,
	const LString &name,
	DataType *type,
	ValueBlock *vb,
	bool make_static) {
    TypeBuilder *tb = (TypeBuilder *)
        env->get_object_factory(TypeBuilder::get_class_name());
    FileSetBlock *fsb = env->get_file_set_block();
    suif_assert_message(fsb->get_file_block_count() == 1,("File is ambiguous"));
    FileBlock *fb = fsb->get_file_block(0);
    
    BasicSymbolTable *symtab = to<BasicSymbolTable>(fb->get_symbol_table());
    DefinitionBlock *def  = fb->get_definition_block ();
    QualifiedType *q_type = tb->get_qualified_type(type);

    VariableSymbol *var = create_variable_symbol(
                env,q_type, name, false );
    symtab->append_symbol_table_object(var);
    VariableDefinition *vardef =
            create_variable_definition(env,var,type->get_bit_alignment(),
					vb,make_static);
    def->append_variable_definition(vardef);
    return var;
    }
Ejemplo n.º 2
0
/*--------------------------------------------------------------------
 * add_std_fse_menu
 *
 */
void
add_std_fse_menu(vmenu* root_menu, char* parent_menu)
{
  /* file set entry submenu */
  FileSetBlock *fsb = suif_env->get_file_set_block();
  if (!fsb) return;
  for (int i = 0; i < fsb->get_file_block_count(); ++i) {
    FileBlock *file = fsb->get_file_block(i);
    binding *b = new binding((bfun) &do_show_fse, file);
    const char* name = file->get_source_file_name().c_str();    
    root_menu->add_command(b, parent_menu, name ? name : "<no name>" );
  }
}
ProcedureDefinition *CreateSuifComplexInputPass::build_main( const char *main_file ) {
  DefinitionBlock* file_def_block = create_definition_block( _suif_env );

  SymbolTable *file_symbol_table = create_basic_symbol_table( _suif_env );
  FileSetBlock* fsb = _suif_env -> get_file_set_block();
  //  SymbolTable* ext_table = fsb->get_file_set_symbol_table();

  FileBlock * the_file_block =
    create_file_block( _suif_env, main_file,
		      file_symbol_table,
		      file_def_block);

  fsb->append_file_block(the_file_block);

  ProcedureSymbol *main_symbol =
    create_procedure_symbol( _suif_env,_main_type, "main", true );
  fsb -> get_external_symbol_table() -> add_symbol(main_symbol);

  StatementList *main_body = create_statement_list( _suif_env );
  BasicSymbolTable* main_symbol_table =
    create_basic_symbol_table( _suif_env, file_symbol_table );
  DefinitionBlock* main_def_block = create_definition_block( _suif_env );
  ProcedureDefinition *main_definition =
    create_procedure_definition( _suif_env, main_symbol, main_body,main_symbol_table,main_def_block);

  ParameterSymbol *argc_symbol = create_parameter_symbol( _suif_env, _q_argc_type, "argc", false );


  main_definition->get_symbol_table()->add_symbol(argc_symbol);
  main_definition->append_formal_parameter(argc_symbol);

  ParameterSymbol *argv_symbol = 
    create_parameter_symbol( _suif_env, _q_argv_type, "argv", false );

  main_definition->get_symbol_table()->add_symbol(argv_symbol);
  main_definition->append_formal_parameter(argv_symbol);

  the_file_block->get_definition_block()->
    append_procedure_definition(main_definition);

  return main_definition;
}
Ejemplo n.º 4
0
list<ProcedureSymbol*> *
get_procedure_list(FileSetBlock *file_set,
                   bool flag_exported,
                   bool flag_static,
                   bool flag_nested,
                   bool flag_def_only)
{
  list<ProcedureSymbol*> *procs = new list<ProcedureSymbol*>;
  FileSetBlock *fsb = file_set;

  // no file_set_block sepcified
  if (!fsb) return procs;

  // =============== exported procedures ================
  if (flag_exported)
    add_to_procedure_list(procs,
                          fsb->get_external_symbol_table(), flag_def_only);

  // =============== static procedures ==================
  if (flag_static) {
    // add the symbols in the static fileset symbol table
    add_to_procedure_list(procs,
                          fsb->get_file_set_symbol_table(), flag_def_only);
    // iterate over the files and add their symbol tables
    for (int i = 0; i < fsb->get_file_block_count(); ++i) {
      FileBlock *file_block = fsb->get_file_block(i);
      add_to_procedure_list(procs,
                            file_block->get_symbol_table(), flag_def_only);
    }
  }

  // =============== nested procedures ==================
  if ( flag_nested ) {
    // iterate over the files
    for (int i=0; i < fsb->get_file_block_count(); ++i) {
      FileBlock *file_block = fsb->get_file_block(i);
      DefinitionBlock * def_block = file_block->get_definition_block();
      // iterate over the procedures
      s_count_t count = def_block->get_procedure_definition_count();
      for (s_count_t proc_counter=0; proc_counter < count; ++proc_counter) {
        ProcedureDefinition *proc = def_block->get_procedure_definition(i);
        add_to_procedure_list(procs, proc, flag_def_only );
      }
    }
  }
  return procs;
}
Ejemplo n.º 5
0
/*--------------------------------------------------------------------
 * info_viewer::view
 *
 */
void info_viewer::view(vnode* vn)
{
  if ( !vn ) return;

  text->clear();
  text->tag_begin( vn );
  fstream& fout = text->fout();
  char *tag = vn->get_tag();

  text->tag_style(BOLD_BEGIN);
  fout << "Object: 0x" << (void*)vn->get_object() << '(' << tag << ")\n";
  text->tag_style(BOLD_END);

  /* properties */
  text->tag_style( BOLD_BEGIN );
  fout << "Properties:\n";
  text->tag_style( BOLD_END );

  list<vprop *> *plist = vn->get_prop_list();
  if ( !plist || plist->empty() ) {
    fout << "<No properties defined>\n";
  } else {
    for ( s_count_t i = 0; i < plist->size(); i++ ) {
      vprop* p = (*plist)[i];
      if ( p->name() ) {
	  char* desc = p->description();
	  fout << '[' << p->name() << "]: " << (desc ? desc : "") << endl;
      }
    }
  }
  fout << endl;

  SuifObject* obj;
  if ( tag == tag_suif_object ) {
    obj = (SuifObject*) vn->get_object();
  } else if ( tag == tag_code_fragment ) {
      code_fragment* f = (code_fragment*) vn->get_object();
      obj = (SuifObject*) f->node();
  } else {
      suif_assert_message(false, ("Unknown tag"));
  }

  text->tag_style( BOLD_BEGIN );
  const MetaClass *m = obj->get_meta_class();
  fout << "Suif object type: " << m->get_class_name().c_str() << "\n\n";
  text->tag_style( BOLD_END );

  // if obj is a file_set_block => print the whole file_set_block
  //   in all other cases just print the obj
  formater f(suif_env, text, -1 ); //is_file_set_block( obj ) ? -1 : 1 );

  if ( is_kind_of<FileSetBlock>( obj ) ) {
    // print only the annotes
    FileSetBlock *fb = to<FileSetBlock>(obj);
    Iter<Annote*> annote_iter = fb->get_annote_iterator();
    for ( int i = 0; i < (int)fb->get_annote_count(); i++ ) {
      Annote* ann = annote_iter.current();
      annote_iter.next();
      vn = create_vnode( ann );
      text->tag_begin( vn );
      f.print_zot( ann, fout );
      text->tag_end( vn );
      fout << endl;
    }
  } else {
    f.print_zot( obj, fout );
    fout << endl;
  } 

  text->tag_end( vn );
  text->update();
}
Ejemplo n.º 6
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());
}