diff options
author | Kevin Enderby <enderby@apple.com> | 2009-07-14 23:21:55 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2009-07-14 23:21:55 +0000 |
commit | 1f049b24c7e520ecfd2291b7d30eb5abc3aee852 (patch) | |
tree | 3d0ccca57a54fe10e39a2325b3acc214c58ad77a | |
parent | 1f318e00bad8b7499ef14d5732bcbda89243ec89 (diff) | |
download | external_llvm-1f049b24c7e520ecfd2291b7d30eb5abc3aee852.zip external_llvm-1f049b24c7e520ecfd2291b7d30eb5abc3aee852.tar.gz external_llvm-1f049b24c7e520ecfd2291b7d30eb5abc3aee852.tar.bz2 |
Added llvm-mc support for parsing the .include directive.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75711 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/MC/MCStreamer.h | 6 | ||||
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 6 | ||||
-rw-r--r-- | test/MC/AsmParser/directive_include.s | 8 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 24 | ||||
-rw-r--r-- | tools/llvm-mc/AsmParser.h | 1 |
5 files changed, 45 insertions, 0 deletions
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index d58c8ba..1327b26 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -160,6 +160,12 @@ namespace llvm { /// @param AbortReason - The reason assembly is terminated, if non-NULL. virtual void AbortAssembly(const char *AbortReason) = 0; + /// SwitchInputAssemblyFile - Assemble the contents of the specified file in + /// @param FileName at this point in the assembly. + /// + /// @param FileName - The file to assemble at this point + virtual void SwitchInputAssemblyFile(const char *FileName) = 0; + /// @} /// @name Generating Data /// @{ diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index ec99b10..2a15783 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -57,6 +57,8 @@ namespace { virtual void AbortAssembly(const char *AbortReason = NULL); + virtual void SwitchInputAssemblyFile(const char *FileName); + virtual void EmitBytes(const char *Data, unsigned Length); virtual void EmitValue(const MCValue &Value, unsigned Size); @@ -137,6 +139,10 @@ void MCAsmStreamer::AbortAssembly(const char *AbortReason) { } +void MCAsmStreamer::SwitchInputAssemblyFile(const char *FileName) { + OS << ".include" << ' ' << FileName << '\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_include.s b/test/MC/AsmParser/directive_include.s new file mode 100644 index 0000000..8c35d2a --- /dev/null +++ b/test/MC/AsmParser/directive_include.s @@ -0,0 +1,8 @@ +# RUN: llvm-mc %s | FileCheck %s + +# CHECK: TEST0: +# CHECK: .include "some/include/file" +# CHECK: .include "mary had a little lamb" +TEST0: + .include "some/include/file" + .include "mary had a little lamb" diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index b4e0f57..1550c69 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -535,6 +535,8 @@ bool AsmParser::ParseStatement() { return ParseDirectiveDarwinSubsectionsViaSymbols(); if (!strcmp(IDVal, ".abort")) return ParseDirectiveAbort(); + if (!strcmp(IDVal, ".include")) + return ParseDirectiveInclude(); Warning(IDLoc, "ignoring directive for now"); EatToEndOfStatement(); @@ -1158,3 +1160,25 @@ bool AsmParser::ParseDirectiveDarwinLsym() { return false; } + +/// ParseDirectiveInclude +/// ::= .include "filename" +bool AsmParser::ParseDirectiveInclude() { + const char *Str; + + if (Lexer.isNot(asmtok::String)) + return TokError("expected string in '.include' directive"); + + Str = Lexer.getCurStrVal(); + + Lexer.Lex(); + + if (Lexer.isNot(asmtok::EndOfStatement)) + return TokError("unexpected token in '.include' directive"); + + Lexer.Lex(); + + Out.SwitchInputAssemblyFile(Str); + + return false; +} diff --git a/tools/llvm-mc/AsmParser.h b/tools/llvm-mc/AsmParser.h index 7d75637..1bb7ca2 100644 --- a/tools/llvm-mc/AsmParser.h +++ b/tools/llvm-mc/AsmParser.h @@ -119,6 +119,7 @@ private: bool ParseDirectiveDarwinSubsectionsViaSymbols(); bool ParseDirectiveAbort(); // ".abort" + bool ParseDirectiveInclude(); // ".include" }; } // end namespace llvm |