00001 #ifndef TRANSFORMS__SYMBOL_WALKERS_H 00002 #define TRANSFORMS__SYMBOL_WALKERS_H 00003 00004 #include <common/suif_copyright.h> 00005 00006 // Various walkers on symbols 00007 // 00008 // 1/ Name all symbols 00009 // 2/ Avoid extern collisions 00010 // 3/ Combined pass 00011 00012 #include "suifkernel/suif_env.h" 00013 #include "suifkernel/module_subsystem.h" 00014 #include "suifpasses/suifpasses.h" 00015 #include "suifnodes/suif.h" 00016 00017 // The passes in this file are mainly used to massage 00018 // Suif trees before outputting code as C 00019 00020 // Name anonymous symbols 00021 class NameAllSymbolsPass : public Pass { 00022 public: 00023 Module* clone() const {return (Module*)this;} 00024 00025 void do_file_set_block( FileSetBlock* file_set_block ); 00026 00027 NameAllSymbolsPass(SuifEnv *env, const LString &name = 00028 "name_all_symbols"); 00029 }; 00030 00031 // Make sure that local names do not clash with global names so 00032 // that the globals will not be hidden by C scoping 00033 class AvoidExternCollisions : public Pass { 00034 public: 00035 Module* clone() const {return (Module*)this;} 00036 00037 void do_file_set_block( FileSetBlock* file_set_block ); 00038 00039 AvoidExternCollisions(SuifEnv *env, const LString &name = 00040 "avoid_external_collisions"); 00041 }; 00042 00043 class AvoidFileScopeCollisions : public Pass { 00044 public: 00045 Module* clone() const {return (Module*)this;} 00046 00047 void do_file_set_block( FileSetBlock* file_set_block ); 00048 00049 AvoidFileScopeCollisions(SuifEnv *env, const LString &name = 00050 "avoid_file_scope_collisions"); 00051 }; 00052 00053 class AvoidLabelCollisions : public PipelinablePass { 00054 public: 00055 Module* clone() const {return (Module*)this;} 00056 00057 void do_procedure_definition( ProcedureDefinition* proc_def ); 00058 00059 AvoidLabelCollisions(SuifEnv *env, const LString &name = 00060 "avoid_label_collisions"); 00061 }; 00062 00063 class CombinedPass : public Pass { 00064 public: 00065 Module* clone() const {return (Module*)this;} 00066 00067 void do_file_set_block( FileSetBlock* file_set_block ); 00068 00069 CombinedPass(SuifEnv *env, const LString &name = 00070 "rename_colliding_symbols"); 00071 }; 00072 00073 class CollisionAvoider : public SelectiveWalker { 00074 BasicSymbolTable *external_symbol_table; 00075 list<SymbolTable*> *file_scope_symbol_tables; 00076 LString source_file_name; 00077 bool name_all_symbols; 00078 public: 00079 00080 CollisionAvoider(SuifEnv *env, 00081 BasicSymbolTable *the_external_symbol_table, 00082 list<SymbolTable*> *the_file_scope_symbol_tables, 00083 LString source_file_name, 00084 bool name_all) 00085 : SelectiveWalker(env,Symbol::get_class_name()), 00086 external_symbol_table(the_external_symbol_table), 00087 file_scope_symbol_tables(the_file_scope_symbol_tables), 00088 source_file_name(source_file_name), 00089 name_all_symbols(name_all) {} 00090 00091 ApplyStatus operator () (SuifObject *x); 00092 }; 00093 00094 #endif 00095