[llvm-commits] [llvm] r75711 - in /llvm/trunk: include/llvm/MC/MCStreamer.h lib/MC/MCAsmStreamer.cpp test/MC/AsmParser/directive_include.s tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h

Chris Lattner clattner at apple.com
Tue Jul 14 17:22:28 PDT 2009


On Jul 14, 2009, at 4:21 PM, Kevin Enderby wrote:
> Author: enderby
> Date: Tue Jul 14 18:21:55 2009
> New Revision: 75711
>
> URL: http://llvm.org/viewvc/llvm-project?rev=75711&view=rev
> Log:
> Added llvm-mc support for parsing the .include directive.

Hey Kevin,

I think that the actual parser should handle this directive itself  
instead of sending it through the streamer interface.  We'd want to  
push a new lexer onto the SourceMgr object, which will cause it to lex  
out of that.  Does this make sense to you?  If you want, it might be  
easiest for me to set up the basic skeleton of this.  A related  
question: how does the assembler resolve #includes?  Does it have a -I  
flag or something?

-Chris

>
> Added:
>    llvm/trunk/test/MC/AsmParser/directive_include.s
> Modified:
>    llvm/trunk/include/llvm/MC/MCStreamer.h
>    llvm/trunk/lib/MC/MCAsmStreamer.cpp
>    llvm/trunk/tools/llvm-mc/AsmParser.cpp
>    llvm/trunk/tools/llvm-mc/AsmParser.h
>
> Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=75711&r1=75710&r2=75711&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCStreamer.h Tue Jul 14 18:21:55 2009
> @@ -160,6 +160,12 @@
>     /// @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
>     /// @{
>
> Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=75711&r1=75710&r2=75711&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Tue Jul 14 18:21:55 2009
> @@ -57,6 +57,8 @@
>
>     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::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!");
>
> Added: llvm/trunk/test/MC/AsmParser/directive_include.s
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_include.s?rev=75711&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/test/MC/AsmParser/directive_include.s (added)
> +++ llvm/trunk/test/MC/AsmParser/directive_include.s Tue Jul 14  
> 18:21:55 2009
> @@ -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"
>
> Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=75711&r1=75710&r2=75711&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
> +++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Tue Jul 14 18:21:55 2009
> @@ -535,6 +535,8 @@
>       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 @@
>
>   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;
> +}
>
> Modified: llvm/trunk/tools/llvm-mc/AsmParser.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.h?rev=75711&r1=75710&r2=75711&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
> +++ llvm/trunk/tools/llvm-mc/AsmParser.h Tue Jul 14 18:21:55 2009
> @@ -119,6 +119,7 @@
>   bool ParseDirectiveDarwinSubsectionsViaSymbols();
>
>   bool ParseDirectiveAbort(); // ".abort"
> +  bool ParseDirectiveInclude(); // ".include"
> };
>
> } // end namespace llvm
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list