00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 #ifndef goto_conv_INCLUDED
00120 #define goto_conv_INCLUDED "goto_conv.h"
00121
00122 #include "wn.h"
00123 #include "cxx_memory.h"
00124 #include "cxx_template.h"
00125 #include "cxx_hash.h"
00126
00127 class GDESCRIPTOR {
00128 public:
00129 WN *Goto_Wn;
00130 WN *Label_Wn;
00131 INT Goto_Offset;
00132 INT Label_Offset;
00133 BOOL Is_Dismantled;
00134 BOOL Is_Compgoto;
00135 GDESCRIPTOR(WN *goto_wn,WN *label_wn,INT goto_offset, INT label_offset,
00136 BOOL is_compgoto) {
00137 Goto_Wn = goto_wn;
00138 Label_Wn = label_wn;
00139 Goto_Offset = goto_offset;
00140 Label_Offset = label_offset;
00141 Is_Dismantled = FALSE;
00142 Is_Compgoto = is_compgoto;
00143 }
00144 };
00145
00146 class LDESCRIPTOR {
00147 public:
00148 WN *Label_Wn;
00149 INT Offset;
00150 LDESCRIPTOR(WN *label_wn,INT offset) {
00151 Label_Wn = label_wn;
00152 Offset = offset;
00153 }
00154 };
00155
00156 typedef STACK<GDESCRIPTOR> GDESCRIPTOR_STACK;
00157 typedef STACK<LDESCRIPTOR> LDESCRIPTOR_STACK;
00158 typedef STACK<WN *> GTABLE_WN_STACK;
00159
00160 class GTABLE {
00161 GDESCRIPTOR_STACK _gd;
00162 GTABLE_WN_STACK _altentry;
00163 LDESCRIPTOR_STACK _bad_label;
00164 MEM_POOL *_pool;
00165 WN *_func_nd;
00166 HASH_TABLE<INT,LDESCRIPTOR *> *_label_table;
00167 WN_MAP _parent_map;
00168 INT _offset;
00169 BOOL _contains_altentry;
00170 public:
00171 GTABLE(WN *func_nd, MEM_POOL *pool) : _gd(pool), _bad_label(pool),
00172 _altentry(pool), _pool(pool) {
00173 _offset = 0;
00174 _func_nd = func_nd;
00175 _contains_altentry=FALSE;
00176 Build();
00177 }
00178 void Remove_Gotos();
00179 void Print(FILE *fp);
00180 ~GTABLE() {
00181 WN_MAP_Delete(_parent_map);
00182 CXX_DELETE(_label_table,_pool);
00183 }
00184 private:
00185 WN *Get_Parent(WN *wn) const { return (WN *) WN_MAP_Get(_parent_map,wn); }
00186 void Set_Parent(WN *wn, WN *p) { WN_MAP_Set(_parent_map, wn, (void *)p); };
00187 void Build();
00188 void Build_Rec(WN *wn, WN *parent, BOOL inside_compgoto);
00189 void Fixup_Parents(WN *wn, WN *parent);
00190 void Backpatch();
00191 BOOL Sibling(const GDESCRIPTOR *gd) const ;
00192 void Replace_Goto_With_If(GDESCRIPTOR *gd);
00193 BOOL Replace_Goto_With_While(GDESCRIPTOR *gd);
00194 void Create_Truebr(GDESCRIPTOR *gd);
00195 void Promote_Do_While(WN *wn);
00196 void Patch_Do_While(WN *while_wn, WN *parent);
00197 WN *Func_Nd() { return _func_nd;};
00198 BOOL Is_Truebr(const GDESCRIPTOR *gd) const;
00199 BOOL Goto_Is_Noop(const GDESCRIPTOR *gd) const;
00200 INT Find_Level(WN *wn);
00201 WN *Find_Common_Ancestor(WN *wn1, WN *wn2);
00202 void Dismantle(WN *bad, WN *parent);
00203 enum {MAX_GOTO_EXPANDING_TRANSFORMATIONS = 20 };
00204 };
00205 #endif // goto_conv_INCLUDED
00206
00207