aboutsummaryrefslogtreecommitdiff
path: root/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-02-05 23:18:57 +0000
committerAnders Carlsson <andersca@mac.com>2008-02-05 23:18:57 +0000
commit2abd25f29658880f53baf557d51cd1246484ab50 (patch)
treee4296520d6e3b11525d415ecacfe3f98bdabd05a /CodeGen
parent0806acf6a197ac7bd5c87649c0429e64e5d0db06 (diff)
Improvements to inline asm code generation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen')
-rw-r--r--CodeGen/CGStmt.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/CodeGen/CGStmt.cpp b/CodeGen/CGStmt.cpp
index c651970850..557588e9ac 100644
--- a/CodeGen/CGStmt.cpp
+++ b/CodeGen/CGStmt.cpp
@@ -506,13 +506,30 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
}
static inline std::string ConvertAsmString(const char *Start,
- unsigned NumOperands)
+ unsigned NumOperands,
+ bool IsSimple)
{
static unsigned AsmCounter = 0;
AsmCounter++;
std::string Result;
+ if (IsSimple) {
+ while (*Start) {
+ switch (*Start) {
+ default:
+ Result += *Start;
+ break;
+ case '$':
+ Result += "$$";
+ break;
+ }
+
+ Start++;
+ }
+
+ return Result;
+ }
while (*Start) {
switch (*Start) {
@@ -552,6 +569,21 @@ static inline std::string ConvertAsmString(const char *Start,
}
Result += '$' + llvm::utostr(n);
+ Start = End;
+ } else if (isalpha(EscapedChar)) {
+ char *End;
+
+ unsigned long n = strtoul(Start + 1, &End, 10);
+ if (Start == End) {
+ // FIXME: This should be caught during Sema.
+ assert(0 && "Missing operand!");
+ } else if (n >= NumOperands) {
+ // FIXME: This should be caught during Sema.
+ assert(0 && "Operand number out of range!");
+ }
+
+ Result += "${" + llvm::utostr(n) + ':' + EscapedChar + '}';
+ Start = End;
} else {
assert(0 && "Unhandled asm escaped character!");
}
@@ -591,7 +623,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
std::string AsmString =
ConvertAsmString(std::string(S.getAsmString()->getStrData(),
S.getAsmString()->getByteLength()).c_str(),
- S.getNumOutputs() + S.getNumInputs());
+ S.getNumOutputs() + S.getNumInputs(), S.isSimple());
std::string Constraints;