@@ -6415,7 +6415,7 @@ namespace LCompilers {
64156415
64166416 void LLVMSetLinearProbing::resolve_collision_for_read_with_bound_check (
64176417 llvm::Value* set, llvm::Value* el_hash, llvm::Value* el,
6418- llvm::Module& module , ASR::ttype_t * el_asr_type) {
6418+ llvm::Module& module , ASR::ttype_t * el_asr_type, bool throw_key_error ) {
64196419
64206420 /* *
64216421 * C++ equivalent:
@@ -6467,14 +6467,16 @@ namespace LCompilers {
64676467 llvm_utils->create_if_else (is_el_matching, [=]() {
64686468 LLVM::CreateStore (*builder, el_hash, pos_ptr);
64696469 }, [&]() {
6470- std::string message = " The set does not contain the specified element" ;
6471- llvm::Value *fmt_ptr = builder->CreateGlobalStringPtr (" KeyError: %s\n " );
6472- llvm::Value *fmt_ptr2 = builder->CreateGlobalStringPtr (message);
6473- print_error (context, module , *builder, {fmt_ptr, fmt_ptr2});
6474- int exit_code_int = 1 ;
6475- llvm::Value *exit_code = llvm::ConstantInt::get (context,
6476- llvm::APInt (32 , exit_code_int));
6477- exit (context, module , *builder, exit_code);
6470+ if (throw_key_error) {
6471+ std::string message = " The set does not contain the specified element" ;
6472+ llvm::Value *fmt_ptr = builder->CreateGlobalStringPtr (" KeyError: %s\n " );
6473+ llvm::Value *fmt_ptr2 = builder->CreateGlobalStringPtr (message);
6474+ print_error (context, module , *builder, {fmt_ptr, fmt_ptr2});
6475+ int exit_code_int = 1 ;
6476+ llvm::Value *exit_code = llvm::ConstantInt::get (context,
6477+ llvm::APInt (32 , exit_code_int));
6478+ exit (context, module , *builder, exit_code);
6479+ }
64786480 });
64796481 }
64806482 builder->CreateBr (mergeBB);
@@ -6491,20 +6493,22 @@ namespace LCompilers {
64916493 LLVM::is_llvm_struct (el_asr_type)), module , el_asr_type);
64926494
64936495 llvm_utils->create_if_else (is_el_matching, []() {}, [&]() {
6494- std::string message = " The set does not contain the specified element" ;
6495- llvm::Value *fmt_ptr = builder->CreateGlobalStringPtr (" KeyError: %s\n " );
6496- llvm::Value *fmt_ptr2 = builder->CreateGlobalStringPtr (message);
6497- print_error (context, module , *builder, {fmt_ptr, fmt_ptr2});
6498- int exit_code_int = 1 ;
6499- llvm::Value *exit_code = llvm::ConstantInt::get (context,
6500- llvm::APInt (32 , exit_code_int));
6501- exit (context, module , *builder, exit_code);
6496+ if (throw_key_error) {
6497+ std::string message = " The set does not contain the specified element" ;
6498+ llvm::Value *fmt_ptr = builder->CreateGlobalStringPtr (" KeyError: %s\n " );
6499+ llvm::Value *fmt_ptr2 = builder->CreateGlobalStringPtr (message);
6500+ print_error (context, module , *builder, {fmt_ptr, fmt_ptr2});
6501+ int exit_code_int = 1 ;
6502+ llvm::Value *exit_code = llvm::ConstantInt::get (context,
6503+ llvm::APInt (32 , exit_code_int));
6504+ exit (context, module , *builder, exit_code);
6505+ }
65026506 });
65036507 }
65046508
65056509 void LLVMSetSeparateChaining::resolve_collision_for_read_with_bound_check (
65066510 llvm::Value* set, llvm::Value* el_hash, llvm::Value* el,
6507- llvm::Module& module , ASR::ttype_t * el_asr_type) {
6511+ llvm::Module& module , ASR::ttype_t * el_asr_type, bool throw_key_error ) {
65086512 /* *
65096513 * C++ equivalent:
65106514 *
@@ -6532,20 +6536,22 @@ namespace LCompilers {
65326536 );
65336537
65346538 llvm_utils->create_if_else (does_el_exist, []() {}, [&]() {
6535- std::string message = " The set does not contain the specified element" ;
6536- llvm::Value *fmt_ptr = builder->CreateGlobalStringPtr (" KeyError: %s\n " );
6537- llvm::Value *fmt_ptr2 = builder->CreateGlobalStringPtr (message);
6538- print_error (context, module , *builder, {fmt_ptr, fmt_ptr2});
6539- int exit_code_int = 1 ;
6540- llvm::Value *exit_code = llvm::ConstantInt::get (context,
6541- llvm::APInt (32 , exit_code_int));
6542- exit (context, module , *builder, exit_code);
6539+ if (throw_key_error) {
6540+ std::string message = " The set does not contain the specified element" ;
6541+ llvm::Value *fmt_ptr = builder->CreateGlobalStringPtr (" KeyError: %s\n " );
6542+ llvm::Value *fmt_ptr2 = builder->CreateGlobalStringPtr (message);
6543+ print_error (context, module , *builder, {fmt_ptr, fmt_ptr2});
6544+ int exit_code_int = 1 ;
6545+ llvm::Value *exit_code = llvm::ConstantInt::get (context,
6546+ llvm::APInt (32 , exit_code_int));
6547+ exit (context, module , *builder, exit_code);
6548+ }
65436549 });
65446550 }
65456551
65466552 void LLVMSetLinearProbing::remove_item (
65476553 llvm::Value* set, llvm::Value* el,
6548- llvm::Module& module , ASR::ttype_t * el_asr_type) {
6554+ llvm::Module& module , ASR::ttype_t * el_asr_type, bool throw_key_error ) {
65496555 /* *
65506556 * C++ equivalent:
65516557 *
@@ -6555,7 +6561,7 @@ namespace LCompilers {
65556561 */
65566562 llvm::Value* current_capacity = LLVM::CreateLoad (*builder, get_pointer_to_capacity (set));
65576563 llvm::Value* el_hash = get_el_hash (current_capacity, el, el_asr_type, module );
6558- this ->resolve_collision_for_read_with_bound_check (set, el_hash, el, module , el_asr_type);
6564+ this ->resolve_collision_for_read_with_bound_check (set, el_hash, el, module , el_asr_type, throw_key_error );
65596565 llvm::Value* pos = LLVM::CreateLoad (*builder, pos_ptr);
65606566 llvm::Value* el_mask = LLVM::CreateLoad (*builder, get_pointer_to_mask (set));
65616567 llvm::Value* el_mask_i = llvm_utils->create_ptr_gep (el_mask, pos);
@@ -6571,7 +6577,7 @@ namespace LCompilers {
65716577
65726578 void LLVMSetSeparateChaining::remove_item (
65736579 llvm::Value* set, llvm::Value* el,
6574- llvm::Module& module , ASR::ttype_t * el_asr_type) {
6580+ llvm::Module& module , ASR::ttype_t * el_asr_type, bool throw_key_error ) {
65756581 /* *
65766582 * C++ equivalent:
65776583 *
@@ -6593,7 +6599,7 @@ namespace LCompilers {
65936599
65946600 llvm::Value* current_capacity = LLVM::CreateLoad (*builder, get_pointer_to_capacity (set));
65956601 llvm::Value* el_hash = get_el_hash (current_capacity, el, el_asr_type, module );
6596- this ->resolve_collision_for_read_with_bound_check (set, el_hash, el, module , el_asr_type);
6602+ this ->resolve_collision_for_read_with_bound_check (set, el_hash, el, module , el_asr_type, throw_key_error );
65976603 llvm::Value* prev = LLVM::CreateLoad (*builder, chain_itr_prev);
65986604 llvm::Value* found = LLVM::CreateLoad (*builder, chain_itr);
65996605
0 commit comments