Put all LLVM code into the llvm namespace, as per bug 109.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9903 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp
index bd3d2ff..2c3e374 100644
--- a/utils/TableGen/CodeEmitterGen.cpp
+++ b/utils/TableGen/CodeEmitterGen.cpp
@@ -15,6 +15,8 @@
 #include "Record.h"
 #include "Support/Debug.h"
 
+namespace llvm {
+
 void CodeEmitterGen::run(std::ostream &o) {
   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
 
@@ -221,4 +223,8 @@
     << "  }\n"
     << "  return Value;\n"
     << "}\n";
+
+  EmitSourceFileTail(o);
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/CodeEmitterGen.h b/utils/TableGen/CodeEmitterGen.h
index d7b4bc1..19ca545 100644
--- a/utils/TableGen/CodeEmitterGen.h
+++ b/utils/TableGen/CodeEmitterGen.h
@@ -16,6 +16,8 @@
 
 #include "TableGenBackend.h"
 
+namespace llvm {
+
 class CodeEmitterGen : public TableGenBackend {
   RecordKeeper &Records;
 public:
@@ -28,4 +30,6 @@
   void emitGetValueBit(std::ostream &o, const std::string &Namespace);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp
index 5039cca..bf641fa 100644
--- a/utils/TableGen/CodeGenTarget.cpp
+++ b/utils/TableGen/CodeGenTarget.cpp
@@ -17,6 +17,8 @@
 #include "CodeGenWrappers.h"
 #include "Record.h"
 
+namespace llvm {
+
 /// getValueType - Return the MCV::ValueType that the specified TableGen record
 /// corresponds to.
 MVT::ValueType getValueType(Record *Rec) {
@@ -94,3 +96,5 @@
 Record *CodeGenTarget::getInstructionSet() const {
   return TargetRec->getValueAsDef("InstructionSet");
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/CodeGenTarget.h b/utils/TableGen/CodeGenTarget.h
index f0b7200..948360e 100644
--- a/utils/TableGen/CodeGenTarget.h
+++ b/utils/TableGen/CodeGenTarget.h
@@ -21,6 +21,9 @@
 #include <iosfwd>
 #include <string>
 #include <vector>
+
+namespace llvm {
+
 class Record;
 class RecordKeeper;
 
@@ -60,4 +63,6 @@
   // CodeGenInstructionSet *getInstructionSet -
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/CodeGenWrappers.cpp b/utils/TableGen/CodeGenWrappers.cpp
index 5039cca..bf641fa 100644
--- a/utils/TableGen/CodeGenWrappers.cpp
+++ b/utils/TableGen/CodeGenWrappers.cpp
@@ -17,6 +17,8 @@
 #include "CodeGenWrappers.h"
 #include "Record.h"
 
+namespace llvm {
+
 /// getValueType - Return the MCV::ValueType that the specified TableGen record
 /// corresponds to.
 MVT::ValueType getValueType(Record *Rec) {
@@ -94,3 +96,5 @@
 Record *CodeGenTarget::getInstructionSet() const {
   return TargetRec->getValueAsDef("InstructionSet");
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/CodeGenWrappers.h b/utils/TableGen/CodeGenWrappers.h
index f0b7200..948360e 100644
--- a/utils/TableGen/CodeGenWrappers.h
+++ b/utils/TableGen/CodeGenWrappers.h
@@ -21,6 +21,9 @@
 #include <iosfwd>
 #include <string>
 #include <vector>
+
+namespace llvm {
+
 class Record;
 class RecordKeeper;
 
@@ -60,4 +63,6 @@
   // CodeGenInstructionSet *getInstructionSet -
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/FileLexer.l b/utils/TableGen/FileLexer.l
index 0858a8c..48070b34 100644
--- a/utils/TableGen/FileLexer.l
+++ b/utils/TableGen/FileLexer.l
@@ -28,9 +28,13 @@
 
 %{
 #include "Record.h"
-typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
+typedef std::pair<llvm::Record*, std::vector<llvm::Init*>*> SubClassRefTy;
 #include "FileParser.h"
 
+int Fileparse();
+
+namespace llvm {
+
 // Global variable recording the location of the include directory
 std::string IncludeDirectory;
 
@@ -69,7 +73,6 @@
 }
 
 
-int Fileparse();
 
 //
 // Function: ParseFile()
@@ -171,6 +174,10 @@
   return 0;
 }
 
+} // End llvm namespace
+
+using namespace llvm;
+
 %}
 
 Comment      \/\/.*
diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y
index 491cca3..e95e597 100644
--- a/utils/TableGen/FileParser.y
+++ b/utils/TableGen/FileParser.y
@@ -20,6 +20,9 @@
 
 int yyerror(const char *ErrorMsg);
 int yylex();
+
+namespace llvm {
+
 extern int Filelineno;
 static Record *CurRec = 0;
 
@@ -160,20 +163,23 @@
   addSuperClass(SC);
 }
 
+} // End llvm namespace
+
+using namespace llvm;
 
 %}
 
 %union {
-  std::string          *StrVal;
-  int                   IntVal;
-  RecTy                *Ty;
-  Init                 *Initializer;
-  std::vector<Init*>   *FieldList;
-  std::vector<unsigned>*BitList;
-  Record               *Rec;
-  SubClassRefTy        *SubClassRef;
-  std::vector<SubClassRefTy> *SubClassList;
-  std::vector<std::pair<Init*, std::string> > *DagValueList;
+  std::string*                StrVal;
+  int                         IntVal;
+  llvm::RecTy*                Ty;
+  llvm::Init*                 Initializer;
+  std::vector<llvm::Init*>*   FieldList;
+  std::vector<unsigned>*      BitList;
+  llvm::Record*               Rec;
+  SubClassRefTy*              SubClassRef;
+  std::vector<SubClassRefTy>* SubClassList;
+  std::vector<std::pair<llvm::Init*, std::string> >* DagValueList;
 };
 
 %token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
@@ -193,6 +199,7 @@
 %type <StrVal>       Declaration OptID OptVarName
 
 %start File
+
 %%
 
 ClassID : ID {
diff --git a/utils/TableGen/InstrInfoEmitter.cpp b/utils/TableGen/InstrInfoEmitter.cpp
index a11244d..ed040b1 100644
--- a/utils/TableGen/InstrInfoEmitter.cpp
+++ b/utils/TableGen/InstrInfoEmitter.cpp
@@ -16,6 +16,8 @@
 #include "CodeGenWrappers.h"
 #include "Record.h"
 
+namespace llvm {
+
 // runEnums - Print out enum values for all of the instructions.
 void InstrInfoEmitter::runEnums(std::ostream &OS) {
   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
@@ -47,6 +49,7 @@
   OS << "  };\n";
   if (!Namespace.empty())
     OS << "}\n";
+  EmitSourceFileTail(OS);
 }
 
 void InstrInfoEmitter::printDefList(ListInit *LI, const std::string &Name,
@@ -93,6 +96,7 @@
     if (Instructions[i] != PHI)
       emitRecord(Instructions[i], i+1, InstrInfo, OS);
   OS << "};\n";
+  EmitSourceFileTail(OS);
 }
 
 void InstrInfoEmitter::emitRecord(Record *R, unsigned Num, Record *InstrInfo,
@@ -169,3 +173,5 @@
   std::cerr << "Unhandled initializer: " << *Val << "\n";
   throw "In record '" + R->getName() + "' for TSFlag emission.";
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/InstrInfoEmitter.h b/utils/TableGen/InstrInfoEmitter.h
index 4adac31..2a6b063 100644
--- a/utils/TableGen/InstrInfoEmitter.h
+++ b/utils/TableGen/InstrInfoEmitter.h
@@ -16,6 +16,9 @@
 #define INSTRINFO_EMITTER_H
 
 #include "TableGenBackend.h"
+
+namespace llvm {
+
 class StringInit;
 class IntInit;
 class ListInit;
@@ -38,4 +41,6 @@
                         std::ostream &OS);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/InstrSelectorEmitter.cpp b/utils/TableGen/InstrSelectorEmitter.cpp
index 9988d55..5d945bb 100644
--- a/utils/TableGen/InstrSelectorEmitter.cpp
+++ b/utils/TableGen/InstrSelectorEmitter.cpp
@@ -19,6 +19,8 @@
 #include "Support/StringExtras.h"
 #include <set>
 
+namespace llvm {
+
 NodeType::ArgResultTypes NodeType::Translate(Record *R) {
   const std::string &Name = R->getName();
   if (Name == "DNVT_any")  return Any;
@@ -978,9 +980,10 @@
 
   CalculateComputableValues();
   
+  OS << "#include \"llvm/CodeGen/MachineInstrBuilder.h\"\n";
+
   EmitSourceFileHeader("Instruction Selector for the " + Target.getName() +
                        " target", OS);
-  OS << "#include \"llvm/CodeGen/MachineInstrBuilder.h\"\n";
 
   // Output the slot number enums...
   OS << "\nenum { // Slot numbers...\n"
@@ -1290,5 +1293,7 @@
        << "  }\n\n  N->addValue(Val);  // Do not ever recalculate this\n"
        << "  return Val;\n}\n\n";
   }
+  EmitSourceFileTail(OS);
 }
 
+} // End llvm namespace
diff --git a/utils/TableGen/InstrSelectorEmitter.h b/utils/TableGen/InstrSelectorEmitter.h
index 2f9175c..a0fbbcf 100644
--- a/utils/TableGen/InstrSelectorEmitter.h
+++ b/utils/TableGen/InstrSelectorEmitter.h
@@ -21,6 +21,8 @@
 #include <map>
 #include <cassert>
 
+namespace llvm {
+
 class DagInit;
 class Init;
 class InstrSelectorEmitter;
@@ -391,4 +393,6 @@
                             bool PrintArg, std::ostream &OS);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 32ffe62..00751a1 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -16,6 +16,8 @@
 //    Type implementations
 //===----------------------------------------------------------------------===//
 
+namespace llvm {
+
 void RecTy::dump() const { print(std::cerr); }
 
 Init *BitRecTy::convertValue(BitsInit *BI) {
@@ -681,3 +683,5 @@
 
   return Defs;
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index e2233f8..d8a9649 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -21,6 +21,8 @@
 #include <iostream>
 #include <cassert>
 
+namespace llvm {
+
 // RecTy subclasses...
 class BitRecTy;
 class BitsRecTy;
@@ -853,4 +855,6 @@
 
 extern RecordKeeper Records;
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp
index 67acc3f..4e7aa9b 100644
--- a/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/utils/TableGen/RegisterInfoEmitter.cpp
@@ -19,6 +19,8 @@
 #include "Support/StringExtras.h"
 #include <set>
 
+namespace llvm {
+
 // runEnums - Print out enum values for all of the registers.
 void RegisterInfoEmitter::runEnums(std::ostream &OS) {
   std::vector<Record*> Registers = Records.getAllDerivedDefinitions("Register");
@@ -40,6 +42,7 @@
   OS << "  };\n";
   if (!Namespace.empty())
     OS << "}\n";
+  EmitSourceFileTail(OS);
 }
 
 void RegisterInfoEmitter::runHeader(std::ostream &OS) {
@@ -68,6 +71,7 @@
       OS << "  extern TargetRegisterClass *" << Name << "RegisterClass;\n";
   }
   OS << "} // end of namespace " << TargetName << "\n\n";
+  EmitSourceFileTail(OS);
 }
 
 // RegisterInfoEmitter::run - Main register file description emitter.
@@ -240,4 +244,7 @@
   for (unsigned i = 0, e = CSR.size(); i != e; ++i)
     OS << getQualifiedName(CSR[i]) << ", ";  
   OS << " 0\n  };\n  return CalleeSaveRegs;\n}\n\n";
+  EmitSourceFileTail(OS);
 }
+
+} // End llvm namespace
diff --git a/utils/TableGen/RegisterInfoEmitter.h b/utils/TableGen/RegisterInfoEmitter.h
index 22c759f..1e6380b 100644
--- a/utils/TableGen/RegisterInfoEmitter.h
+++ b/utils/TableGen/RegisterInfoEmitter.h
@@ -18,6 +18,8 @@
 
 #include "TableGenBackend.h"
 
+namespace llvm {
+
 class RegisterInfoEmitter : public TableGenBackend {
   RecordKeeper &Records;
 public:
@@ -33,4 +35,6 @@
   void runEnums(std::ostream &o);
 };
 
+} // End llvm namespace
+
 #endif
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index 803d0f0..c05ccb0 100644
--- a/utils/TableGen/TableGen.cpp
+++ b/utils/TableGen/TableGen.cpp
@@ -27,6 +27,8 @@
 #include <cstdio>
 #include <fstream>
 
+namespace llvm {
+
 enum ActionType {
   PrintRecords,
   GenEmitter,
@@ -406,6 +408,9 @@
   }
 }
 
+} // End llvm namespace
+
+using namespace llvm;
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv);
@@ -459,12 +464,17 @@
       InstrSelectorEmitter(Records).run(*Out);
       break;
     case PrintEnums:
+    {
       std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
       for (unsigned i = 0, e = Recs.size(); i != e; ++i)
         *Out << Recs[i] << ", ";
       *Out << "\n";
       break;
     }
+    default:
+      assert(1 && "Invalid Action");
+      return 1;
+    }
   } catch (const std::string &Error) {
     std::cerr << Error << "\n";
     if (Out != &std::cout) {
diff --git a/utils/TableGen/TableGenBackend.cpp b/utils/TableGen/TableGenBackend.cpp
index 161b2ee..67a3788 100644
--- a/utils/TableGen/TableGenBackend.cpp
+++ b/utils/TableGen/TableGenBackend.cpp
@@ -15,12 +15,18 @@
 #include "Record.h"
 #include <iostream>
 
+namespace llvm {
+
 void TableGenBackend::EmitSourceFileHeader(const std::string &Desc,
                                            std::ostream &OS) const {
   OS << "//===- TableGen'erated file -------------------------------------*-"
        " C++ -*-===//\n//\n// " << Desc << "\n//\n// Automatically generate"
        "d file, do not edit!\n//\n//===------------------------------------"
-       "----------------------------------===//\n\n";
+       "----------------------------------===//\n\nnamespace llvm {\n\n";
+}
+
+void TableGenBackend::EmitSourceFileTail( std::ostream& OS ) const {
+  OS << "} // End llvm namespace \n";
 }
 
 /// getQualifiedName - Return the name of the specified record, with a
@@ -32,3 +38,4 @@
   return Namespace + "::" + R->getName();
 }
 
+} // End llvm namespace
diff --git a/utils/TableGen/TableGenBackend.h b/utils/TableGen/TableGenBackend.h
index 23b83ca..869d7e9 100644
--- a/utils/TableGen/TableGenBackend.h
+++ b/utils/TableGen/TableGenBackend.h
@@ -17,6 +17,9 @@
 
 #include <string>
 #include <iosfwd>
+
+namespace llvm {
+
 class Record;
 class RecordKeeper;
 
@@ -33,9 +36,15 @@
   /// ostream.
   void EmitSourceFileHeader(const std::string &Desc, std::ostream &OS) const;
 
+  /// EmitSourceFileTail - Output an LLVm styelf ile tail to the specified
+  /// ostream.
+  void EmitSourceFileTail( std::ostream& OS ) const;
+
   /// getQualifiedName - Return the name of the specified record, with a
   /// namespace qualifier if the record contains one.
   std::string getQualifiedName(Record *R) const;
 };
 
+} // End llvm namespace
+
 #endif