comparison gen/asmstmt.cpp @ 301:f42a1090e895 trunk

[svn r322] More asm-to-outside jumping work. Unfinished.
author ChristianK
date Tue, 24 Jun 2008 22:48:33 +0200
parents 7b1040c76dd2
children bef811104734
comparison
equal deleted inserted replaced
300:7b1040c76dd2 301:f42a1090e895
524 524
525 // create storage for and initialize the temporary 525 // create storage for and initialize the temporary
526 llvm::AllocaInst* jump_target = new llvm::AllocaInst(llvm::IntegerType::get(32), "__llvm_jump_target", p->topallocapoint()); 526 llvm::AllocaInst* jump_target = new llvm::AllocaInst(llvm::IntegerType::get(32), "__llvm_jump_target", p->topallocapoint());
527 gIR->ir->CreateStore(llvm::ConstantInt::get(llvm::IntegerType::get(32), 0), jump_target); 527 gIR->ir->CreateStore(llvm::ConstantInt::get(llvm::IntegerType::get(32), 0), jump_target);
528 528
529 //FIXME: Store the value -> label mapping somewhere, so it can be referenced later 529 IRAsmStmt* outSetterStmt = new IRAsmStmt;
530 std::string asmGotoEnd = "jmp __llvm_asm_end ; "; 530 std::string asmGotoEnd = "jmp __llvm_asm_end ; ";
531 std::string outGotoSetter = asmGotoEnd; 531 outSetterStmt->code = asmGotoEnd;
532 outSetterStmt->out_c = "=*m,";
533 outSetterStmt->out.push_back(jump_target);
534
535 int n_goto = 1;
532 536
533 size_t n = asmblock->s.size(); 537 size_t n = asmblock->s.size();
534 for(size_t i=0; i<n; ++i) 538 for(size_t i=0; i<n; ++i)
535 { 539 {
536 IRAsmStmt* a = asmblock->s[i]; 540 IRAsmStmt* a = asmblock->s[i];
549 if(skip) 553 if(skip)
550 continue; 554 continue;
551 555
552 // provide an in-asm target for the branch and set value 556 // provide an in-asm target for the branch and set value
553 Logger::println("statement '%s' references outer label '%s': creating forwarder", a->code.c_str(), a->isBranchToLabel->string); 557 Logger::println("statement '%s' references outer label '%s': creating forwarder", a->code.c_str(), a->isBranchToLabel->string);
554 outGotoSetter += a->isBranchToLabel->string; 558 outSetterStmt->code += a->isBranchToLabel->string;
555 outGotoSetter += ": ; "; 559 outSetterStmt->code += ": ; ";
556 outGotoSetter += "nop ; "; //FIXME: Change this to set __llvm_jump_target to a unique value 560 outSetterStmt->code += "movl $<<in1>>, $<<out0>> ; ";
557 outGotoSetter += asmGotoEnd; 561 //FIXME: Store the value -> label mapping somewhere, so it can be referenced later
558 } 562 outSetterStmt->in.push_back(llvm::ConstantInt::get(llvm::IntegerType::get(32), n_goto++));
559 if(outGotoSetter != asmGotoEnd) 563 outSetterStmt->in_c += "i,";
560 { 564 outSetterStmt->code += asmGotoEnd;
561 outGotoSetter += "__llvm_asm_end: ; "; 565 }
562 IRAsmStmt* outSetterStmt = new IRAsmStmt; 566 if(outSetterStmt->code != asmGotoEnd)
563 outSetterStmt->code = outGotoSetter; 567 {
564 //FIXME: set other stuff 568 outSetterStmt->code += "__llvm_asm_end: ; ";
565 asmblock->s.push_back(outSetterStmt); 569 asmblock->s.push_back(outSetterStmt);
566 } 570 }
571 else
572 delete outSetterStmt;
567 573
568 574
569 // build asm block 575 // build asm block
570 std::vector<LLValue*> outargs; 576 std::vector<LLValue*> outargs;
571 std::vector<LLValue*> inargs; 577 std::vector<LLValue*> inargs;