From 5f1f0b8f7e7087d456ddc3efdb4bed21a4ae359c Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Mon, 13 Jul 2009 23:15:14 +0000 Subject: [PATCH] Added llvm-mc support for parsing the .abort directive. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75545 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCStreamer.h | 7 +++++++ lib/MC/MCAsmStreamer.cpp | 10 ++++++++++ test/MC/AsmParser/directive_abort.s | 8 ++++++++ tools/llvm-mc/AsmParser.cpp | 25 +++++++++++++++++++++++++ tools/llvm-mc/AsmParser.h | 2 ++ 5 files changed, 52 insertions(+) create mode 100644 test/MC/AsmParser/directive_abort.s diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index dc185aecfdf..8ceb7723f93 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -141,6 +141,13 @@ namespace llvm { virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = 0, unsigned Size = 0,unsigned Pow2Alignment = 0) = 0; + /// AbortAssembly - Stop and don't produce output, printing @param + /// AbortReason if non-NULL to indicate the reason the assembly is + /// terminated. + /// + /// @param AbortReason - The reason assembly is terminated, if non-NULL. + virtual void AbortAssembly(const char *AbortReason) = 0; + /// @} /// @name Generating Data /// @{ diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index c0a334adc9e..c79625517d4 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -51,6 +51,8 @@ namespace { virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = NULL, unsigned Size = 0, unsigned Pow2Alignment = 0); + virtual void AbortAssembly(const char *AbortReason = NULL); + virtual void EmitBytes(const char *Data, unsigned Length); virtual void EmitValue(const MCValue &Value, unsigned Size); @@ -123,6 +125,14 @@ void MCAsmStreamer::SubsectionsViaSymbols(void) { OS << ".subsections_via_symbols\n"; } +void MCAsmStreamer::AbortAssembly(const char *AbortReason) { + OS << ".abort"; + if (AbortReason != NULL) + OS << ' ' << AbortReason; + OS << '\n'; + +} + void MCAsmStreamer::EmitAssignment(MCSymbol *Symbol, const MCValue &Value, bool MakeAbsolute) { assert(!Symbol->getSection() && "Cannot assign to a label!"); diff --git a/test/MC/AsmParser/directive_abort.s b/test/MC/AsmParser/directive_abort.s new file mode 100644 index 00000000000..e5b0c9ad926 --- /dev/null +++ b/test/MC/AsmParser/directive_abort.s @@ -0,0 +1,8 @@ +# RUN: llvm-mc %s | FileCheck %s + +# CHECK: TEST0: +# CHECK: .abort "please stop assembing" +# CHECK: .abort +TEST0: + .abort "please stop assembing" +.abort diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index fe9d4f3352f..c1058016328 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -529,6 +529,8 @@ bool AsmParser::ParseStatement() { if (!strcmp(IDVal, ".subsections_via_symbols")) return ParseDirectiveDarwinSubsectionsViaSymbols(); + if (!strcmp(IDVal, ".abort")) + return ParseDirectiveAbort(); Warning(IDLoc, "ignoring directive for now"); EatToEndOfStatement(); @@ -1068,3 +1070,26 @@ bool AsmParser::ParseDirectiveDarwinSubsectionsViaSymbols() { return false; } + +/// ParseDirectiveAbort +/// ::= .abort [ "abort_string" ] +bool AsmParser::ParseDirectiveAbort() { + const char *Str = NULL; + if (Lexer.isNot(asmtok::EndOfStatement)) { + if (Lexer.isNot(asmtok::String)) + return TokError("expected string in '.abort' directive"); + + Str = Lexer.getCurStrVal(); + + Lexer.Lex(); + } + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.abort' directive"); + + Lexer.Lex(); + + Out.AbortAssembly(Str); + + return false; +} diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index fcdd064977c..da546732a71 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -115,6 +115,8 @@ private: // Darwin specific ".subsections_via_symbols" bool ParseDirectiveDarwinSubsectionsViaSymbols(); + + bool ParseDirectiveAbort(); // ".abort" }; } // end namespace llvm -- 2.34.1