Mercurial > projects > ldc
comparison gen/asmstmt.cpp @ 980:ae710cba0884
Clean up the code generated when jumping out of inline asm and make label names more expressive.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Wed, 18 Feb 2009 22:50:22 +0100 |
parents | 523bf4f166bc |
children | 18ad5601dff7 |
comparison
equal
deleted
inserted
replaced
979:523bf4f166bc | 980:ae710cba0884 |
---|---|
538 std::ostringstream asmGotoEndLabel; | 538 std::ostringstream asmGotoEndLabel; |
539 asmGotoEndLabel << "." << fdmangle << "__llvm_asm_end" << uniqueLabelsId++; | 539 asmGotoEndLabel << "." << fdmangle << "__llvm_asm_end" << uniqueLabelsId++; |
540 | 540 |
541 // initialize the setter statement we're going to build | 541 // initialize the setter statement we're going to build |
542 IRAsmStmt* outSetterStmt = new IRAsmStmt; | 542 IRAsmStmt* outSetterStmt = new IRAsmStmt; |
543 std::string asmGotoEnd = "jmp "+asmGotoEndLabel.str()+" ; "; | 543 std::string asmGotoEnd = "\n\tjmp "+asmGotoEndLabel.str()+"\n"; |
544 std::ostringstream code; | 544 std::ostringstream code; |
545 code << asmGotoEnd; | 545 code << asmGotoEnd; |
546 | 546 |
547 int n_goto = 1; | 547 int n_goto = 1; |
548 | 548 |
572 // record that the jump needs to be handled in the post-asm dispatcher | 572 // record that the jump needs to be handled in the post-asm dispatcher |
573 gotoToVal[a->isBranchToLabel] = n_goto; | 573 gotoToVal[a->isBranchToLabel] = n_goto; |
574 | 574 |
575 // provide an in-asm target for the branch and set value | 575 // provide an in-asm target for the branch and set value |
576 Logger::println("statement '%s' references outer label '%s': creating forwarder", a->code.c_str(), a->isBranchToLabel->string); | 576 Logger::println("statement '%s' references outer label '%s': creating forwarder", a->code.c_str(), a->isBranchToLabel->string); |
577 code << fdmangle << '_' << a->isBranchToLabel->string << ": ; "; | 577 code << fdmangle << '_' << a->isBranchToLabel->string << ":\n\t"; |
578 code << "movl $<<in" << n_goto << ">>, $<<out0>> ; "; | 578 code << "movl $<<in" << n_goto << ">>, $<<out0>>\n"; |
579 //FIXME: Store the value -> label mapping somewhere, so it can be referenced later | 579 //FIXME: Store the value -> label mapping somewhere, so it can be referenced later |
580 outSetterStmt->in.push_back(DtoConstUint(n_goto)); | 580 outSetterStmt->in.push_back(DtoConstUint(n_goto)); |
581 outSetterStmt->in_c += "i,"; | 581 outSetterStmt->in_c += "i,"; |
582 code << asmGotoEnd; | 582 code << asmGotoEnd; |
583 | 583 |
585 } | 585 } |
586 if(code.str() != asmGotoEnd) | 586 if(code.str() != asmGotoEnd) |
587 { | 587 { |
588 // finalize code | 588 // finalize code |
589 outSetterStmt->code = code.str(); | 589 outSetterStmt->code = code.str(); |
590 outSetterStmt->code += asmGotoEndLabel.str()+": ; "; | 590 outSetterStmt->code += asmGotoEndLabel.str()+":\n"; |
591 | 591 |
592 // create storage for and initialize the temporary | 592 // create storage for and initialize the temporary |
593 jump_target = DtoAlloca(LLType::Int32Ty, "__llvm_jump_target"); | 593 jump_target = DtoAlloca(LLType::Int32Ty, "__llvm_jump_target"); |
594 gIR->ir->CreateStore(DtoConstUint(0), jump_target); | 594 gIR->ir->CreateStore(DtoConstUint(0), jump_target); |
595 // setup variable for output from asm | 595 // setup variable for output from asm |