llvm-mc: Sketch parsing for .file, .line, and .loc. No streamer hooks for these
authorDaniel Dunbar <daniel@zuster.org>
Tue, 11 Aug 2009 04:24:50 +0000 (04:24 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 11 Aug 2009 04:24:50 +0000 (04:24 +0000)
yet (I'm not even sure what they do).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78639 91177308-0d34-0410-b5e6-96231b3b80d8

test/MC/AsmParser/directive_file.s [new file with mode: 0644]
test/MC/AsmParser/directive_line.s [new file with mode: 0644]
test/MC/AsmParser/directive_loc.s [new file with mode: 0644]
tools/llvm-mc/AsmParser.cpp
tools/llvm-mc/AsmParser.h

diff --git a/test/MC/AsmParser/directive_file.s b/test/MC/AsmParser/directive_file.s
new file mode 100644 (file)
index 0000000..ec0b954
--- /dev/null
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s
+# FIXME: Actually test the output.
+
+        .file "hello"
+        .file 1 "world"
diff --git a/test/MC/AsmParser/directive_line.s b/test/MC/AsmParser/directive_line.s
new file mode 100644 (file)
index 0000000..94ce446
--- /dev/null
@@ -0,0 +1,5 @@
+# RUN: llvm-mc -triple i386-unknown-unknown %s
+# FIXME: Actually test the output.
+
+        .line
+        .line 1
diff --git a/test/MC/AsmParser/directive_loc.s b/test/MC/AsmParser/directive_loc.s
new file mode 100644 (file)
index 0000000..b122fdc
--- /dev/null
@@ -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
+
index b4fdd83f7bbd533eeda8221ef6aeffbfec7c896c..b766830bf148ebe330554e3e714a35b026becd6d 100644 (file)
@@ -551,6 +551,7 @@ bool AsmParser::ParseStatement() {
       return ParseDirectiveSpace();
 
     // Symbol attribute directives
+
     if (IDVal == ".globl" || IDVal == ".global")
       return ParseDirectiveSymbolAttribute(MCStreamer::Global);
     if (IDVal == ".hidden")
@@ -598,6 +599,15 @@ bool AsmParser::ParseStatement() {
     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 @@ bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) {
 
   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;
+}
+
index 646001ce7acfd35a6480b2e2edba9dbbcdd7eee4..55efa84bc7b091fcc7c6ccd505a355a3ec366279 100644 (file)
@@ -132,6 +132,9 @@ private:
   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