Clean up the code generated when jumping out of inline asm and make label names more expressive.

This commit is contained in:
Frits van Bommel
2009-02-18 22:50:22 +01:00
parent e3d6b1c051
commit 8ce2c9773e
3 changed files with 8 additions and 8 deletions

View File

@@ -540,7 +540,7 @@ void AsmBlockStatement::toIR(IRState* p)
// initialize the setter statement we're going to build
IRAsmStmt* outSetterStmt = new IRAsmStmt;
std::string asmGotoEnd = "jmp "+asmGotoEndLabel.str()+" ; ";
std::string asmGotoEnd = "\n\tjmp "+asmGotoEndLabel.str()+"\n";
std::ostringstream code;
code << asmGotoEnd;
@@ -574,8 +574,8 @@ void AsmBlockStatement::toIR(IRState* p)
// provide an in-asm target for the branch and set value
Logger::println("statement '%s' references outer label '%s': creating forwarder", a->code.c_str(), a->isBranchToLabel->string);
code << fdmangle << '_' << a->isBranchToLabel->string << ": ; ";
code << "movl $<<in" << n_goto << ">>, $<<out0>> ; ";
code << fdmangle << '_' << a->isBranchToLabel->string << ":\n\t";
code << "movl $<<in" << n_goto << ">>, $<<out0>>\n";
//FIXME: Store the value -> label mapping somewhere, so it can be referenced later
outSetterStmt->in.push_back(DtoConstUint(n_goto));
outSetterStmt->in_c += "i,";
@@ -587,7 +587,7 @@ void AsmBlockStatement::toIR(IRState* p)
{
// finalize code
outSetterStmt->code = code.str();
outSetterStmt->code += asmGotoEndLabel.str()+": ; ";
outSetterStmt->code += asmGotoEndLabel.str()+":\n";
// create storage for and initialize the temporary
jump_target = DtoAlloca(LLType::Int32Ty, "__llvm_jump_target");

View File

@@ -191,7 +191,7 @@ void DtoGoto(Loc* loc, Identifier* target, EnclosingHandler* enclosinghandler, T
std::string labelname = gIR->func()->getScopedLabelName(target->toChars());
llvm::BasicBlock*& targetBB = gIR->func()->labelToBB[labelname];
if (targetBB == NULL)
targetBB = llvm::BasicBlock::Create("label", gIR->topfunc());
targetBB = llvm::BasicBlock::Create("label_" + labelname, gIR->topfunc());
// find finallys between goto and label
EnclosingHandler* endfinally = enclosinghandler;

View File

@@ -1224,13 +1224,13 @@ void LabelStatement::toIR(IRState* p)
llvm::BasicBlock* oldend = gIR->scopeend();
if (labelBB != NULL) {
labelBB->moveBefore(oldend);
labelBB->moveBefore(oldend);
} else {
labelBB = llvm::BasicBlock::Create("label", p->topfunc(), oldend);
labelBB = llvm::BasicBlock::Create("label_" + labelname, p->topfunc(), oldend);
}
if (!p->scopereturned())
llvm::BranchInst::Create(labelBB, p->scopebb());
llvm::BranchInst::Create(labelBB, p->scopebb());
p->scope() = IRScope(labelBB,oldend);
}