From 7b9ffe4a6db2e59c18510aac4ba30902653e13eb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 13 Mar 2009 16:09:24 +0000 Subject: [PATCH] give each Record a location. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66897 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/Record.h | 17 +++++++++++------ utils/TableGen/TGParser.cpp | 12 ++++++------ utils/TableGen/TGSourceMgr.h | 4 ++-- utils/TableGen/TableGen.cpp | 11 ++++++++++- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 87a49ee2f84..5eb07eb1e99 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -15,15 +15,13 @@ #ifndef RECORD_H #define RECORD_H +#include "TGSourceMgr.h" #include "llvm/Support/DataTypes.h" -#include -#include #include #include -#include namespace llvm { - + // RecTy subclasses. class BitRecTy; class BitsRecTy; @@ -962,16 +960,20 @@ inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) { class Record { std::string Name; + TGLoc Loc; std::vector TemplateArgs; std::vector Values; std::vector SuperClasses; public: - explicit Record(const std::string &N) : Name(N) {} + explicit Record(const std::string &N, TGLoc loc) : Name(N), Loc(loc) {} ~Record() {} - + const std::string &getName() const { return Name; } void setName(const std::string &Name); // Also updates RecordKeeper. + + TGLoc getLoc() const { return Loc; } + const std::vector &getTemplateArgs() const { return TemplateArgs; } @@ -1198,6 +1200,9 @@ std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK); extern RecordKeeper Records; +void PrintError(TGLoc ErrorLoc, const std::string &Msg); + + } // End llvm namespace #endif diff --git a/utils/TableGen/TGParser.cpp b/utils/TableGen/TGParser.cpp index d3eaa929a07..1fa8272727b 100644 --- a/utils/TableGen/TGParser.cpp +++ b/utils/TableGen/TGParser.cpp @@ -27,7 +27,7 @@ struct MultiClass { Record Rec; // Placeholder for template args and Name. std::vector DefPrototypes; - MultiClass(const std::string &Name) : Rec(Name) {} + MultiClass(const std::string &Name, TGLoc Loc) : Rec(Name, Loc) {} }; struct SubClassReference { @@ -570,7 +570,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) { // Create the new record, set it as CurRec temporarily. static unsigned AnonCounter = 0; - Record *NewRec = new Record("anonymous.val."+utostr(AnonCounter++)); + Record *NewRec = new Record("anonymous.val."+utostr(AnonCounter++),NameLoc); SubClassReference SCRef; SCRef.RefLoc = NameLoc; SCRef.Rec = Class; @@ -1039,7 +1039,7 @@ llvm::Record *TGParser::ParseDef(MultiClass *CurMultiClass) { Lex.Lex(); // Eat the 'def' token. // Parse ObjectName and make a record for it. - Record *CurRec = new Record(ParseObjectName()); + Record *CurRec = new Record(ParseObjectName(), DefLoc); if (!CurMultiClass) { // Top-level def definition. @@ -1093,7 +1093,7 @@ bool TGParser::ParseClass() { return TokError("Class '" + CurRec->getName() + "' already defined"); } else { // If this is the first reference to this class, create and add it. - CurRec = new Record(Lex.getCurStrVal()); + CurRec = new Record(Lex.getCurStrVal(), Lex.getLoc()); Records.addClass(CurRec); } Lex.Lex(); // eat the name. @@ -1232,7 +1232,7 @@ bool TGParser::ParseMultiClass() { if (MultiClasses.count(Name)) return TokError("multiclass '" + Name + "' already defined"); - CurMultiClass = MultiClasses[Name] = new MultiClass(Name); + CurMultiClass = MultiClasses[Name] = new MultiClass(Name, Lex.getLoc()); Lex.Lex(); // Eat the identifier. // If there are template args, parse them. @@ -1299,7 +1299,7 @@ bool TGParser::ParseDefm() { Record *DefProto = MC->DefPrototypes[i]; // Add the suffix to the defm name to get the new name. - Record *CurRec = new Record(DefmPrefix + DefProto->getName()); + Record *CurRec = new Record(DefmPrefix + DefProto->getName(),DefmPrefixLoc); SubClassReference Ref; Ref.RefLoc = DefmPrefixLoc; diff --git a/utils/TableGen/TGSourceMgr.h b/utils/TableGen/TGSourceMgr.h index 6b2dc101ddb..69fb74ca20c 100644 --- a/utils/TableGen/TGSourceMgr.h +++ b/utils/TableGen/TGSourceMgr.h @@ -14,9 +14,9 @@ #ifndef TGSOURCEMGR_H #define TGSOURCEMGR_H -#include -#include #include +#include +#include namespace llvm { class MemoryBuffer; diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 8cbba22069b..1beddf0693d 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -108,8 +108,18 @@ namespace { cl::value_desc("directory"), cl::Prefix); } + +// FIXME: Eliminate globals from tblgen. RecordKeeper llvm::Records; +static TGSourceMgr SrcMgr; + +void PrintError(TGLoc ErrorLoc, const std::string &Msg) { + SrcMgr.PrintError(ErrorLoc, Msg); +} + + + /// ParseFile - this function begins the parsing of the specified tablegen /// file. static bool ParseFile(const std::string &Filename, @@ -139,7 +149,6 @@ int main(int argc, char **argv) { PrettyStackTraceProgram X(argc, argv); cl::ParseCommandLineOptions(argc, argv); - TGSourceMgr SrcMgr; // Parse the input file. if (ParseFile(InputFilename, IncludeDirs, SrcMgr))