- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
r1abc5ab rad0be81 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Jun 29 15:18:00 201712 // Last Modified On : Fri Jun 30 13:30:00 2017 13 13 // Update Count : 1 14 14 // … … 22 22 #include "SynTree/Attribute.h" 23 23 24 namespace Control Flow{24 namespace ControlStruct { 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 void_func_t(Type::Qualifiers(), false);31 // void (*function)(); 32 static FunctionType try_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); 39 41 40 42 static void init_func_types() { … … 48 50 LinkageSpec::Cforall, 49 51 /*bitfieldWidth*/ NULL, 50 new BasicType( emptyQualifiers, BasicType::UnsignedInt),52 new BasicType( emptyQualifiers, BasicType::SignedInt ), 51 53 /*init*/ NULL 52 );54 ); 53 55 ObjectDecl exception_obj( 54 56 "__exception_inst", … … 56 58 LinkageSpec::Cforall, 57 59 /*bitfieldWidth*/ NULL, 58 new BasicType(emptyQualifiers, BasicType::UnsignedInt), 60 new PointerType( 61 emptyQualifiers, 62 new BasicType( emptyQualifiers, BasicType::SignedInt ) 63 ), 59 64 /*init*/ NULL 60 );65 ); 61 66 ObjectDecl bool_obj( 62 67 "__ret_bool", … … 66 71 new BasicType(emptyQualifiers, BasicType::Bool), 67 72 /*init*/ NULL 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()); 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() ); 76 96 77 97 init_complete = true; … … 114 134 // ThrowStmt Mutation Helpers 115 135 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 ); 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 ) ); 122 152 throwStmt->set_expr( nullptr ); 123 153 delete throwStmt; 124 154 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 ); 125 160 } 126 161 Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) { … … 136 171 Statement * create_resume_throw( ThrowStmt *throwStmt ) { 137 172 // __throw_resume( EXPR ); 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; 173 return create_given_throw( "__cfaehm__throw_resumption", throwStmt ); 145 174 } 146 175 Statement * create_resume_rethrow( ThrowStmt *throwStmt ) { … … 164 193 165 194 return new FunctionDecl( "try", Type::StorageClasses(), 166 LinkageSpec::Cforall, void_func_t.clone(), body );195 LinkageSpec::Cforall, try_func_t.clone(), body ); 167 196 } 168 197 … … 235 264 std::list<Expression *> args; 236 265 args.push_back( number ); 237 args.push_back( nameOf( except_obj ) ); 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 238 273 cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args ); 239 274 } … … 276 311 *it = nullptr; 277 312 } 313 314 body->push_back( new ReturnStmt( noLabels, new ConstantExpr( 315 Constant::from_int( 0 ) ) ) ); 278 316 279 317 return new FunctionDecl("match", Type::StorageClasses(), … … 316 354 } 317 355 handling_code->push_back( new ReturnStmt( noLabels, 318 new ConstantExpr( Constant::from_bool( false ) ) ) );356 new ConstantExpr( Constant::from_bool( true ) ) ) ); 319 357 handler->set_body( handling_code ); 320 358 … … 323 361 *it = nullptr; 324 362 } 363 364 body->push_back( new ReturnStmt( noLabels, new ConstantExpr( 365 Constant::from_bool( false ) ) ) ); 325 366 326 367 return new FunctionDecl("handle", Type::StorageClasses(), … … 364 405 UntypedExpr *setup = new UntypedExpr( new NameExpr( 365 406 "__cfaehm__try_resume_setup" ) ); 366 setup->get_args().push_back( n ameOf( obj) );407 setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) ); 367 408 setup->get_args().push_back( nameOf( resume_handler ) ); 368 409 … … 381 422 382 423 return new FunctionDecl("finally", Type::StorageClasses(), 383 LinkageSpec::Cforall, void_func_t.clone(), body);424 LinkageSpec::Cforall, finally_func_t.clone(), body); 384 425 } 385 426
Note: See TracChangeset
for help on using the changeset viewer.