Clean up assembly statement separator support.

The MC asm lexer wasn't honoring a non-default (anything but ';') statement
separator. Fix that, and generalize a bit to support multi-character
statement separators.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128227 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach
2011-03-24 18:46:34 +00:00
parent b4ac342ea0
commit d31d304f83
5 changed files with 25 additions and 14 deletions

View File

@@ -66,10 +66,9 @@ namespace llvm {
/// relative expressions. /// relative expressions.
const char *PCSymbol; // Defaults to "$". const char *PCSymbol; // Defaults to "$".
/// SeparatorChar - This character, if specified, is used to separate /// SeparatorString - This string, if specified, is used to separate
/// instructions from each other when on the same line. This is used to /// instructions from each other when on the same line.
/// measure inline asm instructions. const char *SeparatorString; // Defaults to ';'
char SeparatorChar; // Defaults to ';'
/// CommentColumn - This indicates the comment num (zero-based) at /// CommentColumn - This indicates the comment num (zero-based) at
/// which asm comments should be printed. /// which asm comments should be printed.
@@ -350,8 +349,8 @@ namespace llvm {
const char *getPCSymbol() const { const char *getPCSymbol() const {
return PCSymbol; return PCSymbol;
} }
char getSeparatorChar() const { const char *getSeparatorString() const {
return SeparatorChar; return SeparatorString;
} }
unsigned getCommentColumn() const { unsigned getCommentColumn() const {
return CommentColumn; return CommentColumn;

View File

@@ -49,6 +49,7 @@ public:
virtual StringRef LexUntilEndOfStatement(); virtual StringRef LexUntilEndOfStatement();
bool isAtStartOfComment(char Char); bool isAtStartOfComment(char Char);
bool isAtStatementSeparator(const char *Ptr);
const MCAsmInfo &getMAI() const { return MAI; } const MCAsmInfo &getMAI() const { return MAI; }

View File

@@ -26,7 +26,7 @@ MCAsmInfo::MCAsmInfo() {
LinkerRequiresNonEmptyDwarfLines = false; LinkerRequiresNonEmptyDwarfLines = false;
MaxInstLength = 4; MaxInstLength = 4;
PCSymbol = "$"; PCSymbol = "$";
SeparatorChar = ';'; SeparatorString = ";";
CommentColumn = 40; CommentColumn = 40;
CommentString = "#"; CommentString = "#";
LabelSuffix = ":"; LabelSuffix = ":";

View File

@@ -324,8 +324,8 @@ AsmToken AsmLexer::LexQuote() {
StringRef AsmLexer::LexUntilEndOfStatement() { StringRef AsmLexer::LexUntilEndOfStatement() {
TokStart = CurPtr; TokStart = CurPtr;
while (!isAtStartOfComment(*CurPtr) && // Start of line comment. while (!isAtStartOfComment(*CurPtr) && // Start of line comment.
*CurPtr != ';' && // End of statement marker. !isAtStatementSeparator(CurPtr) && // End of statement marker.
*CurPtr != '\n' && *CurPtr != '\n' &&
*CurPtr != '\r' && *CurPtr != '\r' &&
(*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) { (*CurPtr != 0 || CurPtr != CurBuf->getBufferEnd())) {
@@ -339,6 +339,11 @@ bool AsmLexer::isAtStartOfComment(char Char) {
return Char == *MAI.getCommentString(); return Char == *MAI.getCommentString();
} }
bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
return strncmp(Ptr, MAI.getSeparatorString(),
strlen(MAI.getSeparatorString())) == 0;
}
AsmToken AsmLexer::LexToken() { AsmToken AsmLexer::LexToken() {
TokStart = CurPtr; TokStart = CurPtr;
// This always consumes at least one character. // This always consumes at least one character.
@@ -346,6 +351,11 @@ AsmToken AsmLexer::LexToken() {
if (isAtStartOfComment(CurChar)) if (isAtStartOfComment(CurChar))
return LexLineComment(); return LexLineComment();
if (isAtStatementSeparator(TokStart)) {
CurPtr += strlen(MAI.getSeparatorString()) - 1;
return AsmToken(AsmToken::EndOfStatement,
StringRef(TokStart, strlen(MAI.getSeparatorString())));
}
switch (CurChar) { switch (CurChar) {
default: default:
@@ -362,8 +372,8 @@ AsmToken AsmLexer::LexToken() {
// Ignore whitespace. // Ignore whitespace.
return LexToken(); return LexToken();
case '\n': // FALL THROUGH. case '\n': // FALL THROUGH.
case '\r': // FALL THROUGH. case '\r':
case ';': return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1)); return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1)); case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1)); case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
case '-': return AsmToken(AsmToken::Minus, StringRef(TokStart, 1)); case '-': return AsmToken(AsmToken::Minus, StringRef(TokStart, 1));

View File

@@ -149,10 +149,10 @@ bool TargetInstrInfo::isUnpredicatedTerminator(const MachineInstr *MI) const {
/// Measure the specified inline asm to determine an approximation of its /// Measure the specified inline asm to determine an approximation of its
/// length. /// length.
/// Comments (which run till the next SeparatorChar or newline) do not /// Comments (which run till the next SeparatorString or newline) do not
/// count as an instruction. /// count as an instruction.
/// Any other non-whitespace text is considered an instruction, with /// Any other non-whitespace text is considered an instruction, with
/// multiple instructions separated by SeparatorChar or newlines. /// multiple instructions separated by SeparatorString or newlines.
/// Variable-length instructions are not handled here; this function /// Variable-length instructions are not handled here; this function
/// may be overloaded in the target code to do that. /// may be overloaded in the target code to do that.
unsigned TargetInstrInfo::getInlineAsmLength(const char *Str, unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
@@ -163,7 +163,8 @@ unsigned TargetInstrInfo::getInlineAsmLength(const char *Str,
bool atInsnStart = true; bool atInsnStart = true;
unsigned Length = 0; unsigned Length = 0;
for (; *Str; ++Str) { for (; *Str; ++Str) {
if (*Str == '\n' || *Str == MAI.getSeparatorChar()) if (*Str == '\n' || strncmp(Str, MAI.getSeparatorString(),
strlen(MAI.getSeparatorString())) == 0)
atInsnStart = true; atInsnStart = true;
if (atInsnStart && !std::isspace(*Str)) { if (atInsnStart && !std::isspace(*Str)) {
Length += MAI.getMaxInstLength(); Length += MAI.getMaxInstLength();