Mercurial > projects > ldc
diff gen/asmstmt.cpp @ 1102:ae950bd712d3
Use stringstream in asm generation instead of OutBuffer.
Besides looking better, this should reduce allocations and copying.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Thu, 12 Mar 2009 14:08:57 +0100 |
parents | 8bf8b058944a |
children | b30fe7e1dbb9 |
line wrap: on
line diff
--- a/gen/asmstmt.cpp Thu Mar 12 14:08:57 2009 +0100 +++ b/gen/asmstmt.cpp Thu Mar 12 14:08:57 2009 +0100 @@ -15,6 +15,8 @@ #include <cassert> #include <deque> #include <cstring> +#include <string> +#include <sstream> //#include "d-lang.h" //#include "d-codegen.h" @@ -54,15 +56,12 @@ }; struct AsmCode { - char * insnTemplate; - unsigned insnTemplateLen; + std::string insnTemplate; std::vector<AsmArg> args; std::vector<bool> regs; unsigned dollarLabel; int clobbersMemory; AsmCode(int n_regs) { - insnTemplate = NULL; - insnTemplateLen = 0; regs.resize(n_regs, false); dollarLabel = 0; clobbersMemory = 0; @@ -314,7 +313,6 @@ clobbers.push_back(memory_name); // } - // Remap argument numbers for (unsigned i = 0; i < code->args.size(); i++) { if (arg_map[i] < 0) @@ -322,8 +320,9 @@ } bool pct = false; - char * p = code->insnTemplate; - char * q = p + code->insnTemplateLen; + std::string::iterator + p = code->insnTemplate.begin(), + q = code->insnTemplate.end(); //printf("start: %.*s\n", code->insnTemplateLen, code->insnTemplate); while (p < q) { if (pct) { @@ -342,7 +341,7 @@ typedef std::vector<std::string>::iterator It; if (Logger::enabled()) { - Logger::println("final asm: %.*s", code->insnTemplateLen, code->insnTemplate); + Logger::cout() << "final asm: " << code->insnTemplate << '\n'; std::ostringstream ss; ss << "GCC-style output constraints: {"; @@ -369,8 +368,6 @@ Logger::println("%s", ss.str().c_str()); } - std::string insnt(code->insnTemplate, code->insnTemplateLen); - // rewrite GCC-style constraints to LLVM-style constraints std::string llvmOutConstraints; std::string llvmInConstraints; @@ -433,7 +430,7 @@ // push asm statement IRAsmStmt* asmStmt = new IRAsmStmt; - asmStmt->code = insnt; + asmStmt->code = code->insnTemplate; asmStmt->out_c = llvmOutConstraints; asmStmt->in_c = llvmInConstraints; asmStmt->out.insert(asmStmt->out.begin(), output_values.begin(), output_values.end()); @@ -825,10 +822,7 @@ AsmCode * code = (AsmCode *) asmcode; // build asm stmt - std::ostringstream& asmstr = p->nakedAsm; - asmstr << "\t"; - asmstr.write(code->insnTemplate, code->insnTemplateLen); - asmstr << std::endl; + p->nakedAsm << "\t" << code->insnTemplate << std::endl; } void AsmBlockStatement::toNakedIR(IRState *p)