[llvm-commits] [llvm] r108655 - in /llvm/trunk: include/llvm/MC/MCParser/MCAsmParser.h lib/MC/MCParser/AsmParser.cpp lib/MC/MCParser/DarwinAsmParser.cpp test/MC/AsmParser/directive_abort.s
Daniel Dunbar
daniel at zuster.org
Sun Jul 18 13:15:59 PDT 2010
Author: ddunbar
Date: Sun Jul 18 15:15:59 2010
New Revision: 108655
URL: http://llvm.org/viewvc/llvm-project?rev=108655&view=rev
Log:
MC/AsmParser: Fix .abort and .secure_log_unique to accept arbitrary token
sequences, not just strings.
Modified:
llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp
llvm/trunk/test/MC/AsmParser/directive_abort.s
Modified: llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h?rev=108655&r1=108654&r2=108655&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h (original)
+++ llvm/trunk/include/llvm/MC/MCParser/MCAsmParser.h Sun Jul 18 15:15:59 2010
@@ -89,6 +89,11 @@
/// and set \arg Res to the identifier contents.
virtual bool ParseIdentifier(StringRef &Res) = 0;
+ /// \brief Parse up to the end of statement and return the contents from the
+ /// current token until the end of the statement; the current token on exit
+ /// will be either the EndOfStatement or EOF.
+ virtual StringRef ParseStringToEndOfStatement() = 0;
+
/// ParseExpression - Parse an arbitrary expression.
///
/// @param Res - The value of the expression. The result is undefined
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=108655&r1=108654&r2=108655&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Sun Jul 18 15:15:59 2010
@@ -153,7 +153,12 @@
void JumpToLoc(SMLoc Loc);
void EatToEndOfStatement();
-
+
+ /// \brief Parse up to the end of statement and a return the contents from the
+ /// current token until the end of the statement; the current token on exit
+ /// will be either the EndOfStatement or EOF.
+ StringRef ParseStringToEndOfStatement();
+
bool ParseAssignment(StringRef Name);
bool ParsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc);
@@ -387,6 +392,16 @@
Lex();
}
+StringRef AsmParser::ParseStringToEndOfStatement() {
+ const char *Start = getTok().getLoc().getPointer();
+
+ while (Lexer.isNot(AsmToken::EndOfStatement) &&
+ Lexer.isNot(AsmToken::Eof))
+ Lex();
+
+ const char *End = getTok().getLoc().getPointer();
+ return StringRef(Start, End - Start);
+}
/// ParseParenExpr - Parse a paren expression and return it.
/// NOTE: This assumes the leading '(' has already been consumed.
@@ -1561,31 +1576,22 @@
}
/// ParseDirectiveAbort
-/// ::= .abort [ "abort_string" ]
+/// ::= .abort [... message ...]
bool AsmParser::ParseDirectiveAbort() {
// FIXME: Use loc from directive.
SMLoc Loc = getLexer().getLoc();
- StringRef Str = "";
- if (getLexer().isNot(AsmToken::EndOfStatement)) {
- if (getLexer().isNot(AsmToken::String))
- return TokError("expected string in '.abort' directive");
-
- Str = getTok().getString();
-
- Lex();
- }
-
+ StringRef Str = ParseStringToEndOfStatement();
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.abort' directive");
-
+
Lex();
- // FIXME: Handle here.
if (Str.empty())
Error(Loc, ".abort detected. Assembly stopping.");
else
Error(Loc, ".abort '" + Str + "' detected. Assembly stopping.");
+ // FIXME: Actually abort assembly here.
return false;
}
Modified: llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp?rev=108655&r1=108654&r2=108655&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp Sun Jul 18 15:15:59 2010
@@ -537,28 +537,22 @@
}
/// ParseDirectiveSecureLogUnique
-/// ::= .secure_log_unique "log message"
+/// ::= .secure_log_unique ... message ...
bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
- std::string LogMessage;
-
- if (getLexer().isNot(AsmToken::String))
- LogMessage = "";
- else{
- LogMessage = getTok().getString();
- Lex();
- }
-
+ StringRef LogMessage = getParser().ParseStringToEndOfStatement();
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.secure_log_unique' directive");
if (getContext().getSecureLogUsed() != false)
return Error(IDLoc, ".secure_log_unique specified multiple times");
- char *SecureLogFile = getContext().getSecureLogFile();
+ // Get the secure log path.
+ const char *SecureLogFile = getContext().getSecureLogFile();
if (SecureLogFile == NULL)
return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE "
"environment variable unset.");
+ // Open the secure log file if we haven't already.
raw_ostream *OS = getContext().getSecureLog();
if (OS == NULL) {
std::string Err;
@@ -571,6 +565,7 @@
getContext().setSecureLog(OS);
}
+ // Write the message.
int CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
*OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
<< ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":"
Modified: llvm/trunk/test/MC/AsmParser/directive_abort.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_abort.s?rev=108655&r1=108654&r2=108655&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_abort.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_abort.s Sun Jul 18 15:15:59 2010
@@ -1,6 +1,6 @@
# RUN: llvm-mc -triple i386-unknown-unknown %s 2> %t
# RUN: FileCheck -input-file %t %s
-# CHECK: .abort "please stop assembing"
-TEST0:
- .abort "please stop assembing"
+# CHECK: error: .abort 'please stop assembing'
+TEST0:
+ .abort please stop assembing
More information about the llvm-commits
mailing list