summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2019-10-08 04:39:52 +0000
committerBill Wendling <isanbard@gmail.com>2019-10-08 04:39:52 +0000
commit411f1885b655ea622fe124a87a6eadfd988d7a5e (patch)
treeb3206af8be33871869e33e8139efcc0476bdd6ad /llvm/lib
parent9f41deccc0e648a006c9f38e11919f181b6c7e0a (diff)
downloadbcm5719-llvm-411f1885b655ea622fe124a87a6eadfd988d7a5e.tar.gz
bcm5719-llvm-411f1885b655ea622fe124a87a6eadfd988d7a5e.zip
[IA] Recognize hexadecimal escape sequences
Summary: Implement support for hexadecimal escape sequences to match how GNU 'as' handles them. I.e., read all hexadecimal characters and truncate to the lower 16 bits. Reviewers: nickdesaulniers, jcai19 Subscribers: llvm-commits, hiraditya Tags: #llvm Differential Revision: https://reviews.llvm.org/D68598 llvm-svn: 374018
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/MCParser/AsmParser.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 381bf964161..ca6bc252a0d 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -2914,11 +2914,27 @@ bool AsmParser::parseEscapedString(std::string &Data) {
}
// Recognize escaped characters. Note that this escape semantics currently
- // loosely follows Darwin 'as'. Notably, it doesn't support hex escapes.
+ // loosely follows Darwin 'as'.
++i;
if (i == e)
return TokError("unexpected backslash at end of string");
+ // Recognize hex sequences similarly to GNU 'as'.
+ if (Str[i] == 'x' || Str[i] == 'X') {
+ size_t length = Str.size();
+ if (i + 1 >= length || !isHexDigit(Str[i + 1]))
+ return TokError("invalid hexadecimal escape sequence");
+
+ // Consume hex characters. GNU 'as' reads all hexadecimal characters and
+ // then truncates to the lower 16 bits. Seems reasonable.
+ unsigned Value = 0;
+ while (i + 1 < length && isHexDigit(Str[i + 1]))
+ Value = Value * 16 + hexDigitValue(Str[++i]);
+
+ Data += (unsigned char)(Value & 0xFF);
+ continue;
+ }
+
// Recognize octal sequences.
if ((unsigned)(Str[i] - '0') <= 7) {
// Consume up to three octal characters.
OpenPOWER on IntegriCloud