[ms-inline asm] Remove a bunch of parsing code from the front-end, which will be

reimplemented in the AsmParser where it belongs.

llvm-svn: 165752
This commit is contained in:
Chad Rosier 2012-10-11 21:44:41 +00:00
parent e66f42634f
commit dc12c45058
2 changed files with 4 additions and 97 deletions

View File

@ -331,28 +331,6 @@ static bool isMSAsmKeyword(StringRef Name) {
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;
@ -387,8 +365,7 @@ static bool isSimpleMSAsm(std::vector<StringRef> &Pieces,
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;
@ -604,13 +581,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
}
// 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;
@ -669,26 +640,6 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
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) {
@ -704,26 +655,6 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
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;
}
}
}

View File

@ -131,31 +131,7 @@ void t14(void) {
// 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
@ -164,6 +140,6 @@ unsigned t19(void) {
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
}