Adjust #includes to compensate for lost of DerivedTypes.h in
[oota-llvm.git] / utils / TableGen / FileLexer.l.cvs
index d0457eaa3d454c64c919993c6e6aa8e63b8fd013..cc6825f5e07e1c29546cb2d5bc2517499656fb11 100644 (file)
@@ -27,6 +27,8 @@
 %x comment
 
 %{
+#include "llvm/Config/config.h"
+#include "llvm/Support/Streams.h"
 #include "Record.h"
 typedef std::pair<llvm::Record*, std::vector<llvm::Init*>*> SubClassRefTy;
 #include "FileParser.h"
@@ -36,14 +38,14 @@ int Fileparse();
 namespace llvm {
 
 // Global variable recording the location of the include directory
-std::string IncludeDirectory;
+std::vector<std::string> IncludeDirectories;
 
 /// ParseInt - This has to handle the special case of binary numbers 0b0101
 ///
 static int ParseInt(const char *Str) {
   if (Str[0] == '0' && Str[1] == 'b')
-    return strtol(Str+2, 0, 2);
-  return strtol(Str, 0, 0); 
+    return strtoll(Str+2, 0, 2);
+  return strtoll(Str, 0, 0); 
 }
 
 static int CommentDepth = 0;
@@ -62,25 +64,29 @@ struct IncludeRec {
 static std::vector<IncludeRec> IncludeStack;
 
 std::ostream &err() {
-  if (IncludeStack.empty())
-    return std::cerr << "At end of input: ";
+  if (IncludeStack.empty()) {
+    cerr << "At end of input: ";
+    return *cerr.stream();
+  }
 
   for (unsigned i = 0, e = IncludeStack.size()-1; i != e; ++i)
-    std::cerr << "Included from " << IncludeStack[i].Filename << ":"
-              << IncludeStack[i].LineNo << ":\n";
-  return std::cerr << "Parsing " << IncludeStack.back().Filename << ":"
-                   << Filelineno << ": ";
+    cerr << "Included from " << IncludeStack[i].Filename << ":"
+         << IncludeStack[i].LineNo << ":\n";
+  cerr << "Parsing " << IncludeStack.back().Filename << ":"
+       << Filelineno << ": ";
+  return *cerr.stream();
 }
 
 /// ParseFile - this function begins the parsing of the specified tablegen file.
 ///
-void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
+void ParseFile(const std::string &Filename, 
+               const std::vector<std::string> &IncludeDirs) {
   FILE *F = stdin;
   if (Filename != "-") {
     F = fopen(Filename.c_str(), "r");
 
     if (F == 0) {
-      std::cerr << "Could not open input file '" + Filename + "'!\n";
+      cerr << "Could not open input file '" + Filename + "'!\n";
       exit (1);
     }
     IncludeStack.push_back(IncludeRec(Filename, F));
@@ -90,7 +96,7 @@ void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
 
   // Record the location of the include directory so that the lexer can find
   // it later.
-  IncludeDirectory = IncludeDir;
+  IncludeDirectories = IncludeDirs;
  
   Filein = F;
   Filelineno = 1;
@@ -112,7 +118,7 @@ static void HandleInclude(const char *Buffer) {
   }
   assert(Length >= 2 && "Double quotes not found?");
   std::string Filename(Buffer+1, Buffer+Length-1);
-  //std::cerr << "Filename = '" << Filename << "'\n";
+  //cerr << "Filename = '" << Filename << "'\n";
 
   // Save the line number and lex buffer of the includer...
   IncludeStack.back().LineNo = Filelineno;
@@ -124,10 +130,13 @@ static void HandleInclude(const char *Buffer) {
     // If we couldn't find the file in the current directory, look for it in
     // the include directories.
     //
-    // NOTE: Right now, there is only one directory.  We need to eventually add
-    // support for more.
-    std::string NextFilename = IncludeDirectory + "/" + Filename;
-    yyin = fopen(NextFilename.c_str(), "r");
+    std::string NextFilename;
+    for (unsigned i = 0, e = IncludeDirectories.size(); i != e; ++i) {
+      NextFilename = IncludeDirectories[i] + "/" + Filename;
+      if ((yyin = fopen(NextFilename.c_str(), "r")))
+        break;
+    }
+    
     if (yyin == 0) {
       err() << "Could not find include file '" << Filename << "'!\n";
       exit(1);
@@ -191,6 +200,8 @@ dag            { return DAG; }
 
 class          { return CLASS; }
 def            { return DEF; }
+defm           { return DEFM; }
+multiclass     { return MULTICLASS; }
 field          { return FIELD; }
 let            { return LET; }
 in             { return IN; }
@@ -198,6 +209,7 @@ in             { return IN; }
 !sra           { return SRATOK; }
 !srl           { return SRLTOK; }
 !shl           { return SHLTOK; }
+!strconcat     { return STRCONCATTOK; }
 
 
 {Identifier}   { Filelval.StrVal = new std::string(yytext, yytext+yyleng);