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 #include "c_breeze.h"
00043 #include "dismantle.h"
00044 #include "semcheck.h"
00045 #include "ref_clone_changer.h"
00046
00047 op_id_map DismantleUtil::not_relop;
00048
00049 void DismantleUtil::init() {
00050 if ( not_relop.empty() ) {
00051 not_relop['<'] = Operator::GE;
00052 not_relop[Operator::GE] = '<';
00053 not_relop['>'] = Operator::LE;
00054 not_relop[Operator::LE] = '>';
00055 not_relop[Operator::EQ] = Operator::NE;
00056 not_relop[Operator::NE] = Operator::EQ;
00057 }
00058 }
00059
00060 exprNode * DismantleUtil::Not(exprNode * the_expr) {
00061 if ( the_expr->typ() == Binary ) {
00062 binaryNode * the_binary = (binaryNode *) the_expr;
00063 if ( not_relop.find(the_binary->op()->id()) != not_relop.end() ) {
00064 the_binary->op(Operators::table[not_relop[the_binary->op()->id()]]);
00065 return the_binary;
00066 }
00067 } else if ( the_expr->typ() == Unary ) {
00068 unaryNode * the_unary = (unaryNode *) the_expr;
00069 if ( the_unary->op()->id() == '!' )
00070 return the_unary->expr();
00071 }
00072 unaryNode * ret = new unaryNode('!', the_expr, the_expr->coord());
00073 ret->type(the_expr->type());
00074 return ret;
00075 }
00076
00077 declNode * DismantleUtil::new_temp_decl(typeNode * the_type,
00078 Coord coord) {
00079 typeNode * decl_type = NULL;
00080 if ( the_type->is_pointer() ) {
00081 decl_type =
00082 new ptrNode(typeNode::NONE,
00083 (typeNode *) ref_clone_changer::clone(the_type->type(),
00084 false));
00085 } else {
00086 decl_type = (typeNode *) ref_clone_changer::clone(the_type, false);
00087 }
00088 declNode * ret = new declNode(DismantleUtil::new_id(),
00089 declNode::NONE,
00090 decl_type,
00091 NULL,
00092 NULL,
00093 coord);
00094 ret->decl_location(declNode::BLOCK);
00095 return ret;
00096 }
00097
00098 labelNode * DismantleUtil::new_label(Coord coord) {
00099 return new labelNode(new_id(), empty_block(), coord);
00100 }
00101
00102 Dismantle::Dismantle(int flags):
00103 Changer(Preorder, Subtree, false),
00104 _flags(flags)
00105 {}
00106
00107 void Dismantle::dismantle_control(unitNode * the_unit) {
00108 Dismantle tad(DISMANTLE_CONTROL);
00109 the_unit->change(tad);
00110 }
00111
00112 void Dismantle::dismantle(unitNode * the_unit) {
00113 Dismantle tad(DISMANTLE_CONTROL | DISMANTLE_EXPRS);
00114 the_unit->change(tad);
00115 }
00116
00117 Node * Dismantle::at_unit(unitNode * the_unit, Order ord) {
00118 DismantleUtil::init();
00119
00120
00121 StaticToGlobalDismantle stgd;
00122 the_unit->change(stgd);
00123
00124
00125
00126 InitializerDismantle id;
00127 the_unit->change(id);
00128
00129 semcheck_walker::check(the_unit, false);
00130
00131 return the_unit;
00132 }
00133
00134 Node * Dismantle::at_proc(procNode * the_proc, Order ord) {
00135
00136 LabelDismantle ld;
00137 the_proc->change(ld);
00138
00139
00140 ControlDismantle cd;
00141 the_proc->change(cd);
00142
00143
00144 if ( _flags & DISMANTLE_EXPRS ) {
00145 ExpressionDismantle::init();
00146 ExpressionDismantle ed;
00147 the_proc->change(ed);
00148 }
00149
00150
00151 FlattenDismantle fd;
00152 the_proc->change(fd);
00153
00154 return the_proc;
00155 }