From a794bbd4afe5d51bafb6d1179cb83d3ff5abf0e6 Mon Sep 17 00:00:00 2001 From: Coby Tayree Date: Mon, 2 Oct 2017 14:36:31 +0000 Subject: [PATCH] [AsmParser] Support GAS's .print directive Differential Revision: https://reviews.llvm.org/D38448 llvm-svn: 314674 --- lib/MC/MCParser/AsmParser.cpp | 18 ++++++++++++++++++ test/MC/AsmParser/directive_print.s | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/MC/AsmParser/directive_print.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 16c6d562a2b..9568394a364 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -538,6 +538,7 @@ private: DK_ERR, DK_ERROR, DK_WARNING, + DK_PRINT, DK_END }; @@ -682,6 +683,9 @@ private: // ".warning" bool parseDirectiveWarning(SMLoc DirectiveLoc); + // .print + bool parseDirectivePrint(SMLoc DirectiveLoc); + void initializeDirectiveKindMap(); }; @@ -2130,6 +2134,8 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info, case DK_DS_P: case DK_DS_X: return parseDirectiveDS(IDVal, 12); + case DK_PRINT: + return parseDirectivePrint(IDLoc); } return Error(IDLoc, "unknown directive"); @@ -5228,6 +5234,7 @@ void AsmParser::initializeDirectiveKindMap() { DirectiveKindMap[".ds.s"] = DK_DS_S; DirectiveKindMap[".ds.w"] = DK_DS_W; DirectiveKindMap[".ds.x"] = DK_DS_X; + DirectiveKindMap[".print"] = DK_PRINT; } MCAsmMacro *AsmParser::parseMacroLikeBody(SMLoc DirectiveLoc) { @@ -5456,6 +5463,17 @@ bool AsmParser::parseDirectiveMSAlign(SMLoc IDLoc, ParseStatementInfo &Info) { return false; } +bool AsmParser::parseDirectivePrint(SMLoc DirectiveLoc) { + const AsmToken StrTok = getTok(); + Lex(); + if (StrTok.isNot(AsmToken::String) || StrTok.getString().front() != '"') + return Error(DirectiveLoc, "expected double quoted string after .print"); + if (parseToken(AsmToken::EndOfStatement, "expected end of statement")) + return true; + llvm::outs() << StrTok.getStringContents() << '\n'; + return false; +} + // We are comparing pointers, but the pointers are relative to a single string. // Thus, this should always be deterministic. static int rewritesSort(const AsmRewrite *AsmRewriteA, diff --git a/test/MC/AsmParser/directive_print.s b/test/MC/AsmParser/directive_print.s new file mode 100644 index 00000000000..9d228440885 --- /dev/null +++ b/test/MC/AsmParser/directive_print.s @@ -0,0 +1,18 @@ +# RUN: not llvm-mc -triple i386-linux-gnu %s 2> %t.err | FileCheck %s +# RUN: FileCheck < %t.err %s --check-prefix=CHECK-ERR + +T1: +# CHECK: e +# CHECK: 2.718281828459045235 +.print "e" +.print "2.718281828459045235" + +T2: +# CHECK-ERR: expected double quoted string after .print +.altmacro +.print +.noaltmacro + +T3: +# CHECK-ERR: expected end of statement +.print "a" "misplaced-string"