return Ret;
}
-// Check to see if the expression is a substring of the asm operand.
-static StringRef getMSInlineAsmExprName(StringRef Name) {
- // Strip off the size directives.
- // E.g., DWORD PTR [V] -> V
- if (Name.startswith("BYTE") || Name.startswith("byte") ||
- Name.startswith("WORD") || Name.startswith("word") ||
- Name.startswith("DWORD") || Name.startswith("dword") ||
- Name.startswith("QWORD") || Name.startswith("qword") ||
- Name.startswith("XWORD") || Name.startswith("xword") ||
- Name.startswith("XMMWORD") || Name.startswith("xmmword") ||
- Name.startswith("YMMWORD") || Name.startswith("ymmword")) {
- std::pair< StringRef, StringRef > SplitName = Name.split(' ');
- assert((SplitName.second.startswith("PTR") ||
- SplitName.second.startswith("ptr")) &&
- "Expected PTR/ptr!");
- SplitName = SplitName.second.split('[');
- SplitName = SplitName.second.split(']');
- return SplitName.first;
- }
- return Name;
-}
-
// getSpelling - Get the spelling of the AsmTok token.
static StringRef getSpelling(Sema &SemaRef, Token AsmTok) {
StringRef Asm;
return false;
for (unsigned i = 1, e = Pieces.size(); i != e; ++i) {
- StringRef Op = getMSInlineAsmExprName(Pieces[i]);
- if (!TI.isValidGCCRegisterName(Op))
+ if (!TI.isValidGCCRegisterName(Pieces[i]))
return false;
}
return true;
}
// Expr/Input or Output.
- StringRef Name = getMSInlineAsmExprName(Pieces[StrIdx][i]);
-
- // The expr may be a register.
- // E.g., DWORD PTR [eax]
- if (Context.getTargetInfo().isValidGCCRegisterName(Name))
- continue;
-
+ StringRef Name = Pieces[StrIdx][i];
if (IdentifierInfo *II = &Context.Idents.get(Name)) {
CXXScopeSpec SS;
UnqualifiedId Id;
Pieces[StrIdx][j] = OutputExprNames[i];
break;
}
- // Check to see if the expression is a substring of the asm piece.
- std::pair< StringRef, StringRef > Split = Pieces[StrIdx][j].split(' ');
- bool isKeyword = llvm::StringSwitch<bool>(Split.first)
- .Cases("BYTE", "byte", "WORD", "word", "DWORD", true)
- .Cases("dword", "QWORD", "qword", "XWORD", "xword", true)
- .Cases("XMMWORD", "xmmword", "YMMWORD", "ymmword", true)
- .Default(false);
- if (isKeyword &&
- Split.second.find_first_of(OutputExprNames[i]) != StringRef::npos) {
- // Is is a substring, do the replacement.
- SmallString<32> Res;
- llvm::raw_svector_ostream OS(Res);
- OS << '$' << OpNum;
- std::string piece = Pieces[StrIdx][j].str();
- size_t found = piece.find(InputExprNames[i]);
- piece.replace(found, InputExprNames[i].size(), OS.str());
- OutputExprNames[i] = piece;
- Pieces[StrIdx][j] = OutputExprNames[i];
- break;
- }
}
}
for (unsigned i = 0, e = InputExprNames.size(); i != e; ++i, ++OpNum) {
Pieces[StrIdx][j] = InputExprNames[i];
break;
}
- // Check to see if the expression is a substring of the asm piece.
- std::pair< StringRef, StringRef > Split = Pieces[StrIdx][j].split(' ');
- bool isKeyword = llvm::StringSwitch<bool>(Split.first)
- .Cases("BYTE", "byte", "WORD", "word", "DWORD", true)
- .Cases("dword", "QWORD", "qword", "XWORD", "xword", true)
- .Cases("XMMWORD", "xmmword", "YMMWORD", "ymmword", true)
- .Default(false);
- if (isKeyword &&
- Split.second.find_first_of(InputExprNames[i]) != StringRef::npos) {
- // It is a substring, do the replacement.
- SmallString<32> Res;
- llvm::raw_svector_ostream OS(Res);
- OS << '$' << OpNum;
- std::string piece = Pieces[StrIdx][j].str();
- size_t found = piece.find(InputExprNames[i]);
- piece.replace(found, InputExprNames[i].size(), OS.str());
- InputExprNames[i] = piece;
- Pieces[StrIdx][j] = InputExprNames[i];
- break;
- }
}
}
// CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
}
-void t15(void) {
- __asm mov eax, DWORD PTR [eax]
-// CHECK: t15
-// CHECK: call void asm sideeffect inteldialect "mov eax, DWORD PTR [eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
-}
-
-void t16(unsigned V) {
- __asm mov eax, DWORD PTR [V]
-// CHECK: t16
-// CHECK: call void asm sideeffect inteldialect "mov eax, DWORD PTR [$0]", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind
-}
-
-void t17(void) {
- __asm mov eax, dword ptr [eax]
-// CHECK: t17
-// CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr [eax]", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
-}
-
-void t18(void) {
- __asm mov dword ptr [eax], eax
-// CHECK: t18
-// CHECK: call void asm sideeffect inteldialect "mov dword ptr [eax], eax", "~{dirflag},~{fpsr},~{flags}"() nounwind
-}
-
-unsigned t19(void) {
+unsigned t15(void) {
unsigned i = 1, j, l = 1, m;
__asm {
mov eax, i
mov m, eax
}
return j + m;
-// CHECK: t19
+// CHECK: t15
// CHECK: call void asm sideeffect inteldialect "mov eax, $2\0A\09mov $0, eax\0A\09mov eax, $3\0A\09mov $1, eax", "=*m,=*m,*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}) nounwind
}