aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-10 04:38:46 +0000
committerChris Lattner <sabre@nondot.org>2009-03-10 04:38:46 +0000
commitf1a08caedb52a3287d38dfff0ac6e1c0a6531c3e (patch)
tree49a088b1f75aa57fee40c250891c1c3f22a6a288 /lib/CodeGen/CGStmt.cpp
parent83d889b6e8b5b0bb7305cc1d1749780d205a6c9b (diff)
slightly simplify some code, pull the 'is simple asm' case up in
ConvertAsmString and shrink it a bit. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66520 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGStmt.cpp')
-rw-r--r--lib/CodeGen/CGStmt.cpp54
1 files changed, 30 insertions, 24 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index f4d6679c93..69ed0803c3 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -680,37 +680,44 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
CaseRangeBlock = SavedCRBlock;
}
-static std::string ConvertAsmString(const AsmStmt& S, bool &Failed)
-{
- // FIXME: No need to create new std::string here, we could just make sure
- // that we don't read past the end of the string data.
- std::string str(S.getAsmString()->getStrData(),
- S.getAsmString()->getByteLength());
- const char *Start = str.c_str();
-
- unsigned NumOperands = S.getNumOutputs() + S.getNumInputs();
- bool IsSimple = S.isSimple();
+/// ConvertAsmString - Convert the GNU-style asm string to the LLVM-style asm
+/// string.
+static std::string ConvertAsmString(const AsmStmt& S, bool &Failed) {
Failed = false;
-
- static unsigned AsmCounter = 0;
- AsmCounter++;
- std::string Result;
- if (IsSimple) {
- while (*Start) {
- switch (*Start) {
- default:
- Result += *Start;
- break;
+
+ const char *StrStart = S.getAsmString()->getStrData();
+ const char *StrEnd = StrStart + S.getAsmString()->getByteLength();
+
+ // "Simple" inline asms have no constraints or operands, just convert the asm
+ // string to escape $'s.
+ if (S.isSimple()) {
+ std::string Result;
+ for (; StrStart != StrEnd; ++StrStart) {
+ switch (*StrStart) {
case '$':
Result += "$$";
break;
+ default:
+ Result += *StrStart;
+ break;
}
- Start++;
}
-
return Result;
}
+ // FIXME: No need to create new std::string here, we could just make sure
+ // that we don't read past the end of the string data.
+ std::string str(StrStart, StrEnd);
+ std::string Result;
+
+ const char *Start = str.c_str();
+
+ unsigned NumOperands = S.getNumOutputs() + S.getNumInputs();
+
+ // FIXME: Static counters are not thread safe or reproducible.
+ static unsigned AsmCounter = 0;
+ AsmCounter++;
+
while (*Start) {
switch (*Start) {
default:
@@ -889,8 +896,7 @@ llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S,
void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
bool Failed;
- std::string AsmString =
- ConvertAsmString(S, Failed);
+ std::string AsmString = ConvertAsmString(S, Failed);
if (Failed) {
ErrorUnsupported(&S, "asm string");