[llvm-commits] [llvm] r78639 - in /llvm/trunk: test/MC/AsmParser/directive_file.s test/MC/AsmParser/directive_line.s test/MC/AsmParser/directive_loc.s tools/llvm-mc/AsmParser.cpp tools/llvm-mc/AsmParser.h

Daniel Dunbar daniel at zuster.org
Mon Aug 10 21:24:52 PDT 2009


Author: ddunbar
Date: Mon Aug 10 23:24:50 2009
New Revision: 78639

URL: http://llvm.org/viewvc/llvm-project?rev=78639&view=rev
Log:
llvm-mc: Sketch parsing for .file, .line, and .loc. No streamer hooks for these
yet (I'm not even sure what they do).

Added:
    llvm/trunk/test/MC/AsmParser/directive_file.s
    llvm/trunk/test/MC/AsmParser/directive_line.s
    llvm/trunk/test/MC/AsmParser/directive_loc.s
Modified:
    llvm/trunk/tools/llvm-mc/AsmParser.cpp
    llvm/trunk/tools/llvm-mc/AsmParser.h

Added: llvm/trunk/test/MC/AsmParser/directive_file.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_file.s?rev=78639&view=auto

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_file.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_file.s Mon Aug 10 23:24:50 2009
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s
+# FIXME: Actually test the output.
+
+        .file "hello"
+        .file 1 "world"

Added: llvm/trunk/test/MC/AsmParser/directive_line.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_line.s?rev=78639&view=auto

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_line.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_line.s Mon Aug 10 23:24:50 2009
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s
+# FIXME: Actually test the output.
+
+        .line
+        .line 1

Added: llvm/trunk/test/MC/AsmParser/directive_loc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_loc.s?rev=78639&view=auto

==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_loc.s (added)
+++ llvm/trunk/test/MC/AsmParser/directive_loc.s Mon Aug 10 23:24:50 2009
@@ -0,0 +1,8 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s
+# FIXME: Actually test the output.
+
+        .file 1 "hello"
+        .loc 1
+        .loc 1 2
+        .loc 1 2 3
+

Modified: llvm/trunk/tools/llvm-mc/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/AsmParser.cpp?rev=78639&r1=78638&r2=78639&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.cpp (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.cpp Mon Aug 10 23:24:50 2009
@@ -551,6 +551,7 @@
       return ParseDirectiveSpace();
 
     // Symbol attribute directives
+
     if (IDVal == ".globl" || IDVal == ".global")
       return ParseDirectiveSymbolAttribute(MCStreamer::Global);
     if (IDVal == ".hidden")
@@ -598,6 +599,15 @@
     if (IDVal == ".load")
       return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false);
 
+    // Debugging directives
+
+    if (IDVal == ".file")
+      return ParseDirectiveFile(IDLoc);
+    if (IDVal == ".line")
+      return ParseDirectiveLine(IDLoc);
+    if (IDVal == ".loc")
+      return ParseDirectiveLoc(IDLoc);
+
     Warning(IDLoc, "ignoring directive for now");
     EatToEndOfStatement();
     return false;
@@ -1439,3 +1449,90 @@
 
   return false;
 }
+
+/// ParseDirectiveFile
+/// ::= .file [number] string
+bool AsmParser::ParseDirectiveFile(SMLoc DirectiveLoc) {
+  // FIXME: I'm not sure what this is.
+  int64_t FileNumber = -1;
+  if (Lexer.is(AsmToken::Integer)) {
+    FileNumber = Lexer.getTok().getIntVal();
+    Lexer.Lex();
+    
+    if (FileNumber < 1)
+      return TokError("file number less than one");
+  }
+
+  if (Lexer.isNot(AsmToken::String))
+    return TokError("unexpected token in '.file' directive");
+  
+  StringRef FileName = Lexer.getTok().getString();
+  Lexer.Lex();
+
+  if (Lexer.isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.file' directive");
+
+  // FIXME: Do something with the .file.
+
+  return false;
+}
+
+/// ParseDirectiveLine
+/// ::= .line [number]
+bool AsmParser::ParseDirectiveLine(SMLoc DirectiveLoc) {
+  if (Lexer.isNot(AsmToken::EndOfStatement)) {
+    if (Lexer.isNot(AsmToken::Integer))
+      return TokError("unexpected token in '.line' directive");
+
+    int64_t LineNumber = Lexer.getTok().getIntVal();
+    (void) LineNumber;
+    Lexer.Lex();
+
+    // FIXME: Do something with the .line.
+  }
+
+  if (Lexer.isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.file' directive");
+
+  return false;
+}
+
+
+/// ParseDirectiveLoc
+/// ::= .loc number [number [number]]
+bool AsmParser::ParseDirectiveLoc(SMLoc DirectiveLoc) {
+  if (Lexer.isNot(AsmToken::Integer))
+    return TokError("unexpected token in '.loc' directive");
+
+  // FIXME: What are these fields?
+  int64_t FileNumber = Lexer.getTok().getIntVal();
+  (void) FileNumber;
+  // FIXME: Validate file.
+
+  Lexer.Lex();
+  if (Lexer.isNot(AsmToken::EndOfStatement)) {
+    if (Lexer.isNot(AsmToken::Integer))
+      return TokError("unexpected token in '.loc' directive");
+
+    int64_t Param2 = Lexer.getTok().getIntVal();
+    (void) Param2;
+    Lexer.Lex();
+
+    if (Lexer.isNot(AsmToken::EndOfStatement)) {
+      if (Lexer.isNot(AsmToken::Integer))
+        return TokError("unexpected token in '.loc' directive");
+
+      int64_t Param3 = Lexer.getTok().getIntVal();
+      (void) Param3;
+      Lexer.Lex();
+
+      // FIXME: Do something with the .loc.
+    }
+  }
+
+  if (Lexer.isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.file' directive");
+
+  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=78639&r1=78638&r2=78639&view=diff

==============================================================================
--- llvm/trunk/tools/llvm-mc/AsmParser.h (original)
+++ llvm/trunk/tools/llvm-mc/AsmParser.h Mon Aug 10 23:24:50 2009
@@ -132,6 +132,9 @@
   bool ParseDirectiveElse(SMLoc DirectiveLoc); // ".else"
   bool ParseDirectiveEndIf(SMLoc DirectiveLoc); // .endif
 
+  bool ParseDirectiveFile(SMLoc DirectiveLoc); // ".file"
+  bool ParseDirectiveLine(SMLoc DirectiveLoc); // ".line"
+  bool ParseDirectiveLoc(SMLoc DirectiveLoc); // ".loc"
 };
 
 } // end namespace llvm





More information about the llvm-commits mailing list