forked from OSchip/llvm-project
[ms-inline asm] Simplify more logic by using the Token::hasLeadingSpace() and
Token::isAtStartOfLine() APIs. llvm-svn: 161898
This commit is contained in:
parent
1af8aadf11
commit
a6e89aac91
|
@ -2759,41 +2759,6 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
|
||||||
return Owned(NS);
|
return Owned(NS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// needSpaceAsmToken - This function handles whitespace around asm punctuation.
|
|
||||||
// Returns true if a space should be emitted.
|
|
||||||
static inline bool needSpaceAsmToken(Token currTok) {
|
|
||||||
static Token prevTok;
|
|
||||||
|
|
||||||
// No need for space after prevToken.
|
|
||||||
switch(prevTok.getKind()) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
case tok::l_square:
|
|
||||||
case tok::r_square:
|
|
||||||
case tok::l_brace:
|
|
||||||
case tok::r_brace:
|
|
||||||
case tok::colon:
|
|
||||||
prevTok = currTok;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No need for a space before currToken.
|
|
||||||
switch(currTok.getKind()) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
case tok::l_square:
|
|
||||||
case tok::r_square:
|
|
||||||
case tok::l_brace:
|
|
||||||
case tok::r_brace:
|
|
||||||
case tok::comma:
|
|
||||||
case tok::colon:
|
|
||||||
prevTok = currTok;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
prevTok = currTok;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
|
static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
|
||||||
SourceLocation AsmLoc,
|
SourceLocation AsmLoc,
|
||||||
ArrayRef<Token> AsmToks,
|
ArrayRef<Token> AsmToks,
|
||||||
|
@ -2812,14 +2777,17 @@ static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
|
||||||
if (i != 0 && AsmToks[i].isAtStartOfLine())
|
if (i != 0 && AsmToks[i].isAtStartOfLine())
|
||||||
AsmStrings[NumAsmStrings++] = Asm.c_str();
|
AsmStrings[NumAsmStrings++] = Asm.c_str();
|
||||||
|
|
||||||
|
if (i && AsmToks[i].isAtStartOfLine())
|
||||||
|
Asm += '\n';
|
||||||
|
|
||||||
// Start a new asm string with the opcode.
|
// Start a new asm string with the opcode.
|
||||||
if (i == 0 || AsmToks[i].isAtStartOfLine()) {
|
if (i == 0 || AsmToks[i].isAtStartOfLine()) {
|
||||||
Asm = AsmToks[i].getIdentifierInfo()->getName().str();
|
Asm = AsmToks[i].getIdentifierInfo()->getName().str();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needSpaceAsmToken(AsmToks[i]))
|
if (i && AsmToks[i].hasLeadingSpace())
|
||||||
Asm += " ";
|
Asm += ' ';
|
||||||
|
|
||||||
// Check the operand(s).
|
// Check the operand(s).
|
||||||
switch (AsmToks[i].getKind()) {
|
switch (AsmToks[i].getKind()) {
|
||||||
|
@ -2862,24 +2830,19 @@ static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
|
||||||
|
|
||||||
// Build the unmodified MSAsmString.
|
// Build the unmodified MSAsmString.
|
||||||
static std::string buildMSAsmString(Sema &SemaRef,
|
static std::string buildMSAsmString(Sema &SemaRef,
|
||||||
ArrayRef<Token> AsmToks,
|
ArrayRef<Token> AsmToks) {
|
||||||
ArrayRef<unsigned> LineEnds) {
|
|
||||||
assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
|
assert (!AsmToks.empty() && "Didn't expect an empty AsmToks!");
|
||||||
SmallString<512> Asm;
|
SmallString<512> Asm;
|
||||||
SmallString<512> TokenBuf;
|
SmallString<512> TokenBuf;
|
||||||
TokenBuf.resize(512);
|
TokenBuf.resize(512);
|
||||||
unsigned AsmLineNum = 0;
|
|
||||||
for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
|
for (unsigned i = 0, e = AsmToks.size(); i < e; ++i) {
|
||||||
bool StringInvalid = false;
|
bool StringInvalid = false;
|
||||||
if (i && (!AsmLineNum || i != LineEnds[AsmLineNum-1]) &&
|
if (i && AsmToks[i].isAtStartOfLine())
|
||||||
needSpaceAsmToken(AsmToks[i]))
|
Asm += '\n';
|
||||||
|
else if (i && AsmToks[i].hasLeadingSpace())
|
||||||
Asm += ' ';
|
Asm += ' ';
|
||||||
Asm += SemaRef.PP.getSpelling(AsmToks[i], TokenBuf, &StringInvalid);
|
Asm += SemaRef.PP.getSpelling(AsmToks[i], TokenBuf, &StringInvalid);
|
||||||
assert (!StringInvalid && "Expected valid string!");
|
assert (!StringInvalid && "Expected valid string!");
|
||||||
if (i + 1 == LineEnds[AsmLineNum] && i + 1 != AsmToks.size()) {
|
|
||||||
Asm += '\n';
|
|
||||||
++AsmLineNum;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Asm.c_str();
|
return Asm.c_str();
|
||||||
}
|
}
|
||||||
|
@ -2902,7 +2865,7 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
|
||||||
return Owned(NS);
|
return Owned(NS);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AsmString = buildMSAsmString(*this, AsmToks, LineEnds);
|
std::string AsmString = buildMSAsmString(*this, AsmToks);
|
||||||
|
|
||||||
bool IsSimple;
|
bool IsSimple;
|
||||||
std::vector<std::string> PatchedAsmStrings;
|
std::vector<std::string> PatchedAsmStrings;
|
||||||
|
|
Loading…
Reference in New Issue