- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
rad0be81 r1abc5ab 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Jun 30 13:30:00 201712 // Last Modified On : Thr Jun 29 15:18:00 2017 13 13 // Update Count : 1 14 14 // … … 22 22 #include "SynTree/Attribute.h" 23 23 24 namespace Control Struct{24 namespace ControlFlow { 25 25 26 26 // This (large) section could probably be moved out of the class … … 29 29 // Type(Qualifiers &, false, std::list<Attribute *> &) 30 30 31 // void (*function)() ;32 static FunctionType try_func_t(Type::Qualifiers(), false);31 // void (*function)() 32 static FunctionType void_func_t(Type::Qualifiers(), false); 33 33 // void (*function)(int, exception); 34 34 static FunctionType catch_func_t(Type::Qualifiers(), false); … … 37 37 // bool (*function)(exception); 38 38 static FunctionType handle_func_t(Type::Qualifiers(), false); 39 // void (*function)(__attribute__((unused)) void *);40 static FunctionType finally_func_t(Type::Qualifiers(), false);41 39 42 40 static void init_func_types() { … … 50 48 LinkageSpec::Cforall, 51 49 /*bitfieldWidth*/ NULL, 52 new BasicType( emptyQualifiers, BasicType::SignedInt),50 new BasicType(emptyQualifiers, BasicType::UnsignedInt), 53 51 /*init*/ NULL 54 52 ); 55 53 ObjectDecl exception_obj( 56 54 "__exception_inst", … … 58 56 LinkageSpec::Cforall, 59 57 /*bitfieldWidth*/ NULL, 60 new PointerType( 61 emptyQualifiers, 62 new BasicType( emptyQualifiers, BasicType::SignedInt ) 63 ), 58 new BasicType(emptyQualifiers, BasicType::UnsignedInt), 64 59 /*init*/ NULL 65 60 ); 66 61 ObjectDecl bool_obj( 67 62 "__ret_bool", … … 71 66 new BasicType(emptyQualifiers, BasicType::Bool), 72 67 /*init*/ NULL 73 ); 74 ObjectDecl voidptr_obj( 75 "__hook", 76 Type::StorageClasses(), 77 LinkageSpec::Cforall, 78 NULL, 79 new PointerType( 80 emptyQualifiers, 81 new VoidType( 82 emptyQualifiers 83 ), 84 std::list<Attribute *>{new Attribute("unused")} 85 ), 86 NULL 87 ); 88 89 catch_func_t.get_parameters().push_back( index_obj.clone() ); 90 catch_func_t.get_parameters().push_back( exception_obj.clone() ); 91 match_func_t.get_returnVals().push_back( index_obj.clone() ); 92 match_func_t.get_parameters().push_back( exception_obj.clone() ); 93 handle_func_t.get_returnVals().push_back( bool_obj.clone() ); 94 handle_func_t.get_parameters().push_back( exception_obj.clone() ); 95 finally_func_t.get_parameters().push_back( voidptr_obj.clone() ); 68 ); 69 70 catch_func_t.get_parameters().push_back(index_obj.clone()); 71 catch_func_t.get_parameters().push_back(exception_obj.clone()); 72 match_func_t.get_returnVals().push_back(index_obj.clone()); 73 match_func_t.get_parameters().push_back(exception_obj.clone()); 74 handle_func_t.get_returnVals().push_back(bool_obj.clone()); 75 handle_func_t.get_parameters().push_back(exception_obj.clone()); 96 76 97 77 init_complete = true; … … 134 114 // ThrowStmt Mutation Helpers 135 115 136 Statement * create_given_throw( 137 const char * throwFunc, ThrowStmt * throwStmt ) { 138 // { int NAME = EXPR; throwFunc( &NAME ); } 139 CompoundStmt * result = new CompoundStmt( noLabels ); 140 ObjectDecl * local = new ObjectDecl( 141 "__local_exception_copy", 142 Type::StorageClasses(), 143 LinkageSpec::Cforall, 144 NULL, 145 new BasicType( emptyQualifiers, BasicType::SignedInt ), 146 new SingleInit( throwStmt->get_expr() ) 147 ); 148 appendDeclStmt( result, local ); 149 UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) ); 150 call->get_args().push_back( new AddressExpr( nameOf( local ) ) ); 151 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) ); 116 Statement * create_terminate_throw( ThrowStmt *throwStmt ) { 117 // __throw_terminate( EXPR ); 118 UntypedExpr * call = new UntypedExpr( new NameExpr( 119 "__cfaehm__throw_termination" ) ); 120 call->get_args().push_back( throwStmt->get_expr() ); 121 Statement * result = new ExprStmt( throwStmt->get_labels(), call ); 152 122 throwStmt->set_expr( nullptr ); 153 123 delete throwStmt; 154 124 return result; 155 }156 157 Statement * create_terminate_throw( ThrowStmt *throwStmt ) {158 // { int NAME = EXPR; __throw_terminate( &NAME ); }159 return create_given_throw( "__cfaehm__throw_termination", throwStmt );160 125 } 161 126 Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) { … … 171 136 Statement * create_resume_throw( ThrowStmt *throwStmt ) { 172 137 // __throw_resume( EXPR ); 173 return create_given_throw( "__cfaehm__throw_resumption", throwStmt ); 138 UntypedExpr * call = new UntypedExpr( new NameExpr( 139 "__cfaehm__throw_resumption" ) ); 140 call->get_args().push_back( throwStmt->get_expr() ); 141 Statement * result = new ExprStmt( throwStmt->get_labels(), call ); 142 throwStmt->set_expr( nullptr ); 143 delete throwStmt; 144 return result; 174 145 } 175 146 Statement * create_resume_rethrow( ThrowStmt *throwStmt ) { … … 193 164 194 165 return new FunctionDecl( "try", Type::StorageClasses(), 195 LinkageSpec::Cforall, try_func_t.clone(), body );166 LinkageSpec::Cforall, void_func_t.clone(), body ); 196 167 } 197 168 … … 264 235 std::list<Expression *> args; 265 236 args.push_back( number ); 266 267 std::list<Expression *> rhs_args; 268 rhs_args.push_back( nameOf( except_obj ) ); 269 Expression * rhs = new UntypedExpr( 270 new NameExpr( "*?" ), rhs_args ); 271 args.push_back( rhs ); 272 237 args.push_back( nameOf( except_obj ) ); 273 238 cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args ); 274 239 } … … 311 276 *it = nullptr; 312 277 } 313 314 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(315 Constant::from_int( 0 ) ) ) );316 278 317 279 return new FunctionDecl("match", Type::StorageClasses(), … … 354 316 } 355 317 handling_code->push_back( new ReturnStmt( noLabels, 356 new ConstantExpr( Constant::from_bool( true ) ) ) );318 new ConstantExpr( Constant::from_bool( false ) ) ) ); 357 319 handler->set_body( handling_code ); 358 320 … … 361 323 *it = nullptr; 362 324 } 363 364 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(365 Constant::from_bool( false ) ) ) );366 325 367 326 return new FunctionDecl("handle", Type::StorageClasses(), … … 405 364 UntypedExpr *setup = new UntypedExpr( new NameExpr( 406 365 "__cfaehm__try_resume_setup" ) ); 407 setup->get_args().push_back( n ew AddressExpr( nameOf( obj )) );366 setup->get_args().push_back( nameOf( obj ) ); 408 367 setup->get_args().push_back( nameOf( resume_handler ) ); 409 368 … … 422 381 423 382 return new FunctionDecl("finally", Type::StorageClasses(), 424 LinkageSpec::Cforall, finally_func_t.clone(), body);383 LinkageSpec::Cforall, void_func_t.clone(), body); 425 384 } 426 385
Note: See TracChangeset
for help on using the changeset viewer.