X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTableGen%2FTGParser.h;h=22a00e5919512609369c4c937d4a32db4acd1610;hb=ac9abe5e992024f905475927ec72c9a19bfcda9c;hp=18aeae22e299ce9d0d7d88881e9fc384083ac25e;hpb=f3744a0cf9f622e0879a80c1fdcb0f6072e5a6c3;p=oota-llvm.git diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 18aeae22e29..22a00e59195 100644 --- a/lib/TableGen/TGParser.h +++ b/lib/TableGen/TGParser.h @@ -11,14 +11,14 @@ // //===----------------------------------------------------------------------===// -#ifndef TGPARSER_H -#define TGPARSER_H +#ifndef LLVM_LIB_TABLEGEN_TGPARSER_H +#define LLVM_LIB_TABLEGEN_TGPARSER_H -#include "llvm/TableGen/Record.h" #include "TGLexer.h" -#include "llvm/TableGen/Error.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/SourceMgr.h" +#include "llvm/TableGen/Error.h" +#include "llvm/TableGen/Record.h" #include namespace llvm { @@ -30,7 +30,7 @@ namespace llvm { struct MultiClass; struct SubClassReference; struct SubMultiClassReference; - + struct LetRecord { std::string Name; std::vector Bits; @@ -41,37 +41,56 @@ namespace llvm { : Name(N), Bits(B), Value(V), Loc(L) { } }; - + + /// ForeachLoop - Record the iteration state associated with a for loop. + /// This is used to instantiate items in the loop body. + struct ForeachLoop { + VarInit *IterVar; + ListInit *ListValue; + + ForeachLoop(VarInit *IVar, ListInit *LValue) + : IterVar(IVar), ListValue(LValue) {} + }; + class TGParser { TGLexer Lex; std::vector > LetStack; - std::map MultiClasses; - - /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the + std::map> MultiClasses; + + /// Loops - Keep track of any foreach loops we are within. + /// + typedef std::vector LoopVector; + LoopVector Loops; + + /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the /// current value. MultiClass *CurMultiClass; // Record tracker RecordKeeper &Records; + unsigned AnonCounter; + // A "named boolean" indicating how to parse identifiers. Usually // identifiers map to some existing object but in special cases // (e.g. parsing def names) no such object exists yet because we are // in the middle of creating in. For those situations, allow the // parser to ignore missing object errors. enum IDParseMode { - ParseValueMode, // We are parsing a value we expect to look up. - ParseNameMode // We are parsing a name of an object that does not yet exist. + ParseValueMode, // We are parsing a value we expect to look up. + ParseNameMode, // We are parsing a name of an object that does not yet + // exist. + ParseForeachMode // We are parsing a foreach init. }; public: - TGParser(SourceMgr &SrcMgr, RecordKeeper &records) : - Lex(SrcMgr), CurMultiClass(0), Records(records) {} - + TGParser(SourceMgr &SrcMgr, RecordKeeper &records) + : Lex(SrcMgr), CurMultiClass(nullptr), Records(records), AnonCounter(0) {} + /// ParseFile - Main entrypoint for parsing a tblgen file. These parser /// routines return true on error, or false on success. bool ParseFile(); - + bool Error(SMLoc L, const Twine &Msg) const { PrintError(L, Msg); return true; @@ -79,14 +98,15 @@ public: bool TokError(const Twine &Msg) const { return Error(Lex.getLoc(), Msg); } - const std::vector &getDependencies() const { + const TGLexer::DependenciesMapTy &getDependencies() const { return Lex.getDependencies(); } + private: // Semantic analysis methods. bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV); - bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName, + bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName, const std::vector &BitList, Init *V); - bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName, + bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName, const std::vector &BitList, Init *V) { return SetValue(TheRec, Loc, StringInit::get(ValName), BitList, V); } @@ -94,15 +114,31 @@ private: // Semantic analysis methods. bool AddSubMultiClass(MultiClass *CurMC, SubMultiClassReference &SubMultiClass); + std::string GetNewAnonymousName(); + + // IterRecord: Map an iterator name to a value. + struct IterRecord { + VarInit *IterVar; + Init *IterValue; + IterRecord(VarInit *Var, Init *Val) : IterVar(Var), IterValue(Val) {} + }; + + // IterSet: The set of all iterator values at some point in the + // iteration space. + typedef std::vector IterSet; + + bool ProcessForeachDefs(Record *CurRec, SMLoc Loc); + bool ProcessForeachDefs(Record *CurRec, SMLoc Loc, IterSet &IterVals); + private: // Parser methods. - bool ParseObjectList(MultiClass *MC = 0); + bool ParseObjectList(MultiClass *MC = nullptr); bool ParseObject(MultiClass *MC); bool ParseClass(); bool ParseMultiClass(); Record *InstantiateMulticlassDef(MultiClass &MC, Record *DefProto, - const std::string &DefmPrefix, - SMLoc DefmPrefixLoc); + Init *&DefmPrefix, + SMRange DefmPrefixRange); bool ResolveMulticlassDefArgs(MultiClass &MC, Record *DefProto, SMLoc DefmPrefixLoc, @@ -116,6 +152,7 @@ private: // Parser methods. SMLoc DefmPrefixLoc); bool ParseDefm(MultiClass *CurMultiClass); bool ParseDef(MultiClass *CurMultiClass); + bool ParseForeach(MultiClass *CurMultiClass); bool ParseTopLevelLet(MultiClass *CurMultiClass); std::vector ParseLetList(); @@ -125,32 +162,33 @@ private: // Parser methods. bool ParseTemplateArgList(Record *CurRec); Init *ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs); + VarInit *ParseForeachDeclaration(ListInit *&ForeachListValue); SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm); SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC); - Init *ParseIDValue(Record *CurRec, IDParseMode Mode = ParseValueMode); Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc, IDParseMode Mode = ParseValueMode); - Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0, + Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = nullptr, IDParseMode Mode = ParseValueMode); - Init *ParseValue(Record *CurRec, RecTy *ItemType = 0, + Init *ParseValue(Record *CurRec, RecTy *ItemType = nullptr, IDParseMode Mode = ParseValueMode); - std::vector ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0); + std::vector ParseValueList(Record *CurRec, Record *ArgsRec = nullptr, + RecTy *EltTy = nullptr); std::vector > ParseDagArgList(Record *); bool ParseOptionalRangeList(std::vector &Ranges); bool ParseOptionalBitList(std::vector &Ranges); std::vector ParseRangeList(); bool ParseRangePiece(std::vector &Ranges); RecTy *ParseType(); - Init *ParseOperation(Record *CurRec); + Init *ParseOperation(Record *CurRec, RecTy *ItemType); RecTy *ParseOperatorType(); - std::string ParseObjectName(); + Init *ParseObjectName(MultiClass *CurMultiClass); Record *ParseClassID(); MultiClass *ParseMultiClassID(); - Record *ParseDefmID(); + bool ApplyLetStack(Record *CurRec); }; - + } // end namespace llvm #endif