[ms-inline asm] Add $$ before numeric constants in the IR.

llvm-svn: 163581
This commit is contained in:
Chad Rosier 2012-09-11 00:51:28 +00:00
parent 7a8e10042f
commit bd7fdadb90
2 changed files with 27 additions and 16 deletions

View File

@ -413,9 +413,9 @@ static void buildMSAsmPieces(std::vector<std::string> &AsmStrings,
buildMSAsmPieces(AsmStrings[i], Pieces[i]); buildMSAsmPieces(AsmStrings[i], Pieces[i]);
} }
// Build the unmodified AsmString used by the IR. Also build the individual // Build the AsmString used by the IR. Also build the individual asm
// asm instruction(s) and place them in the AsmStrings vector; these are fed // instruction(s) and place them in the AsmStrings vector; these are fed to the
// to the AsmParser. // AsmParser.
static std::string buildMSAsmString(Sema &SemaRef, ArrayRef<Token> AsmToks, static std::string buildMSAsmString(Sema &SemaRef, ArrayRef<Token> AsmToks,
std::vector<std::string> &AsmStrings, std::vector<std::string> &AsmStrings,
std::vector<std::pair<unsigned,unsigned> > &AsmTokRanges) { std::vector<std::pair<unsigned,unsigned> > &AsmTokRanges) {
@ -433,9 +433,8 @@ static std::string buildMSAsmString(Sema &SemaRef, ArrayRef<Token> AsmToks,
AsmStrings.push_back(Asm.str()); AsmStrings.push_back(Asm.str());
AsmTokRanges.push_back(std::make_pair(startTok, i-1)); AsmTokRanges.push_back(std::make_pair(startTok, i-1));
startTok = i; startTok = i;
Res += Asm;
Asm.clear(); Asm.clear();
Res += '\n'; Res += "\n\t";
} }
if (AsmToks[i].is(tok::kw_asm)) { if (AsmToks[i].is(tok::kw_asm)) {
i++; // Skip __asm i++; // Skip __asm
@ -443,14 +442,20 @@ static std::string buildMSAsmString(Sema &SemaRef, ArrayRef<Token> AsmToks,
} }
} }
if (i && AsmToks[i].hasLeadingSpace() && !isNewAsm) if (i && AsmToks[i].hasLeadingSpace() && !isNewAsm) {
Asm += ' '; Asm += ' ';
Res += ' ';
}
Asm += getSpelling(SemaRef, AsmToks[i]); if (AsmToks[i].is(tok::numeric_constant))
Res += "$$";
StringRef Spelling = getSpelling(SemaRef, AsmToks[i]);
Asm += Spelling;
Res += Spelling;
} }
AsmStrings.push_back(Asm.str()); AsmStrings.push_back(Asm.str());
AsmTokRanges.push_back(std::make_pair(startTok, AsmToks.size()-1)); AsmTokRanges.push_back(std::make_pair(startTok, AsmToks.size()-1));
Res += Asm;
return Res.str(); return Res.str();
} }

View File

@ -20,7 +20,7 @@ void t2() {
void t3() { void t3() {
// CHECK: @t3 // CHECK: @t3
// CHECK: call void asm sideeffect inteldialect "nop\0Anop\0Anop", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "nop\0A\09nop\0A\09nop", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: ret void // CHECK: ret void
__asm nop __asm nop __asm nop __asm nop __asm nop __asm nop
} }
@ -36,7 +36,7 @@ void t4(void) {
void t5(void) { void t5(void) {
// CHECK: @t5 // CHECK: @t5
// CHECK: call void asm sideeffect inteldialect "mov ebx, eax\0Amov ecx, ebx", "~{ebx},~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "mov ebx, eax\0A\09mov ecx, ebx", "~{ebx},~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: ret void // CHECK: ret void
__asm mov ebx, eax __asm mov ecx, ebx __asm mov ebx, eax __asm mov ecx, ebx
} }
@ -44,7 +44,7 @@ void t5(void) {
void t6(void) { void t6(void) {
__asm int 0x2c __asm int 0x2c
// CHECK: t6 // CHECK: t6
// CHECK: call void asm sideeffect inteldialect "int 0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind
} }
void t7() { void t7() {
@ -53,7 +53,7 @@ void t7() {
} }
__asm {} __asm {}
// CHECK: t7 // CHECK: t7
// CHECK: call void asm sideeffect inteldialect "int 0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
} }
int t8() { int t8() {
@ -62,9 +62,9 @@ int t8() {
__asm int 4 __asm int 4
return 10; return 10;
// CHECK: t8 // CHECK: t8
// CHECK: call void asm sideeffect inteldialect "int 3", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "int $$3", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: call void asm sideeffect inteldialect "int 4", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "int $$4", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: ret i32 10 // CHECK: ret i32 10
} }
void t9() { void t9() {
@ -74,7 +74,7 @@ void t9() {
pop ebx pop ebx
} }
// CHECK: t9 // CHECK: t9
// CHECK: call void asm sideeffect inteldialect "push ebx\0Amov ebx, 0x07\0Apop ebx", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind
} }
unsigned t10(void) { unsigned t10(void) {
@ -88,7 +88,7 @@ unsigned t10(void) {
// CHECK: [[I:%[a-zA-Z0-9]+]] = alloca i32, align 4 // CHECK: [[I:%[a-zA-Z0-9]+]] = alloca i32, align 4
// CHECK: [[J:%[a-zA-Z0-9]+]] = alloca i32, align 4 // CHECK: [[J:%[a-zA-Z0-9]+]] = alloca i32, align 4
// CHECK: store i32 1, i32* [[I]], align 4 // CHECK: store i32 1, i32* [[I]], align 4
// CHECK: call i32 asm sideeffect inteldialect "mov eax, $1\0Amov $0, eax", "=r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}) nounwind // CHECK: call i32 asm sideeffect inteldialect "mov eax, $1\0A\09mov $0, eax", "=r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}) nounwind
// CHECK: [[RET:%[a-zA-Z0-9]+]] = load i32* [[J]], align 4 // CHECK: [[RET:%[a-zA-Z0-9]+]] = load i32* [[J]], align 4
// CHECK: ret i32 [[RET]] // CHECK: ret i32 [[RET]]
} }
@ -121,3 +121,9 @@ void t13(void) {
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
// CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind
} }
void t14(void) {
__asm mov eax, 1
// CHECK: t14
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
}