From 57977cd42017cc6df11a78466c4ee62025c17246 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 24 Jun 2008 22:27:55 +0200 Subject: [PATCH] [svn r321] Fix bug in argument remapping functions. --- gen/asmstmt.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index 61ba554d..266d47dc 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -463,8 +463,11 @@ static void remap_outargs(std::string& insnt, size_t nargs, size_t& idx) char buf[10]; for (unsigned i = 0; i < nargs; i++) { needle = prefix + digits[i] + suffix; - sprintf(buf, "%u", idx++); - insnt.replace(insnt.find(needle), needle.size(), buf); + size_t pos = insnt.find(needle); + if(pos != std::string::npos) { + sprintf(buf, "%u", idx++); + insnt.replace(pos, needle.size(), buf); + } } } @@ -485,8 +488,11 @@ static void remap_inargs(std::string& insnt, size_t nargs, size_t& idx) char buf[10]; for (unsigned i = 0; i < nargs; i++) { needle = prefix + digits[i] + suffix; - sprintf(buf, "%u", idx++); - insnt.replace(insnt.find(needle), needle.size(), buf); + size_t pos = insnt.find(needle); + if(pos != std::string::npos) { + sprintf(buf, "%u", idx++); + insnt.replace(pos, needle.size(), buf); + } } } @@ -515,7 +521,11 @@ void AsmBlockStatement::toIR(IRState* p) // this additional asm code sets the __llvm_jump_target variable // to a unique value that will identify the jump target in // a post-asm switch - //FIXME: Need to init __llvm_jump_target + + // create storage for and initialize the temporary + llvm::AllocaInst* jump_target = new llvm::AllocaInst(llvm::IntegerType::get(32), "__llvm_jump_target", p->topallocapoint()); + gIR->ir->CreateStore(llvm::ConstantInt::get(llvm::IntegerType::get(32), 0), jump_target); + //FIXME: Store the value -> label mapping somewhere, so it can be referenced later std::string asmGotoEnd = "jmp __llvm_asm_end ; "; std::string outGotoSetter = asmGotoEnd; @@ -582,7 +592,7 @@ void AsmBlockStatement::toIR(IRState* p) { out_c += a->out_c; } - remap_outargs(a->code, onn, asmIdx); + remap_outargs(a->code, onn+a->in.size(), asmIdx); } for (size_t i=0; iin_c; } - remap_inargs(a->code, inn, asmIdx); + remap_inargs(a->code, inn+a->out.size(), asmIdx); if (!code.empty()) code += " ; "; code += a->code;