[llvm] r190089 - Improve handling of .file, .include and .incbin directives to
Yunzhong Gao
Yunzhong_Gao at playstation.sony.com
Thu Sep 5 12:14:26 PDT 2013
Author: ygao
Date: Thu Sep 5 14:14:26 2013
New Revision: 190089
URL: http://llvm.org/viewvc/llvm-project?rev=190089&view=rev
Log:
Improve handling of .file, .include and .incbin directives to
allow escaped octal character sequences.
The patch was discussed in Phabricator. See:
http://llvm-reviews.chandlerc.com/D1289
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
llvm/trunk/test/MC/AsmParser/directive_file.s
llvm/trunk/test/MC/AsmParser/directive_incbin.s
llvm/trunk/test/MC/AsmParser/directive_include.s
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=190089&r1=190088&r2=190089&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Sep 5 14:14:26 2013
@@ -2550,17 +2550,21 @@ bool AsmParser::ParseDirectiveFile(SMLoc
return TokError("unexpected token in '.file' directive");
// Usually the directory and filename together, otherwise just the directory.
- StringRef Path = getTok().getString();
- Path = Path.substr(1, Path.size()-2);
+ // Allow the strings to have escaped octal character sequence.
+ std::string Path = getTok().getString();
+ if (parseEscapedString(Path))
+ return true;
Lex();
StringRef Directory;
StringRef Filename;
+ std::string FilenameData;
if (getLexer().is(AsmToken::String)) {
if (FileNumber == -1)
return TokError("explicit path specified, but no file number");
- Filename = getTok().getString();
- Filename = Filename.substr(1, Filename.size()-2);
+ if (parseEscapedString(FilenameData))
+ return true;
+ Filename = FilenameData;
Directory = Path;
Lex();
} else {
@@ -3496,16 +3500,16 @@ bool AsmParser::ParseDirectiveInclude()
if (getLexer().isNot(AsmToken::String))
return TokError("expected string in '.include' directive");
- std::string Filename = getTok().getString();
+ // Allow the strings to have escaped octal character sequence.
+ std::string Filename;
+ if (parseEscapedString(Filename))
+ return true;
SMLoc IncludeLoc = getLexer().getLoc();
Lex();
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.include' directive");
- // Strip the quotes.
- Filename = Filename.substr(1, Filename.size()-2);
-
// Attempt to switch the lexer to the included file before consuming the end
// of statement to avoid losing it when we switch.
if (EnterIncludeFile(Filename)) {
@@ -3522,16 +3526,16 @@ bool AsmParser::ParseDirectiveIncbin() {
if (getLexer().isNot(AsmToken::String))
return TokError("expected string in '.incbin' directive");
- std::string Filename = getTok().getString();
+ // Allow the strings to have escaped octal character sequence.
+ std::string Filename;
+ if (parseEscapedString(Filename))
+ return true;
SMLoc IncbinLoc = getLexer().getLoc();
Lex();
if (getLexer().isNot(AsmToken::EndOfStatement))
return TokError("unexpected token in '.incbin' directive");
- // Strip the quotes.
- Filename = Filename.substr(1, Filename.size()-2);
-
// Attempt to process the included file.
if (ProcessIncbinFile(Filename)) {
Error(IncbinLoc, "Could not find incbin file '" + Filename + "'");
Modified: llvm/trunk/test/MC/AsmParser/directive_file.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_file.s?rev=190089&r1=190088&r2=190089&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_file.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_file.s Thu Sep 5 14:14:26 2013
@@ -1,7 +1,7 @@
# RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s
.file "hello"
- .file 1 "world"
+ .file 1 "worl\144" # "\144" is "d"
.file 2 "directory" "file"
# CHECK: .file "hello"
Modified: llvm/trunk/test/MC/AsmParser/directive_incbin.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_incbin.s?rev=190089&r1=190088&r2=190089&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_incbin.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_incbin.s Thu Sep 5 14:14:26 2013
@@ -1,6 +1,6 @@
# RUN: llvm-mc -triple i386-unknown-unknown %s -I %p | FileCheck %s
.data
-.incbin "incbin_abcd"
+.incbin "incbin\137abcd" # "\137" is underscore "_"
# CHECK: .ascii "abcd\n"
Modified: llvm/trunk/test/MC/AsmParser/directive_include.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_include.s?rev=190089&r1=190088&r2=190089&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_include.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_include.s Thu Sep 5 14:14:26 2013
@@ -5,5 +5,5 @@
# CHECK: a = 0
# CHECK: TESTB:
TESTA:
- .include "directive_set.s"
+ .include "directive\137set.s" # "\137" is underscore "_"
TESTB:
More information about the llvm-commits
mailing list