Mercurial > hg > CbC > CbC_llvm
diff lib/TableGen/TGParser.h @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
line wrap: on
line diff
--- a/lib/TableGen/TGParser.h Sun Dec 23 19:23:36 2018 +0900 +++ b/lib/TableGen/TGParser.h Wed Aug 14 19:46:37 2019 +0900 @@ -1,9 +1,8 @@ //===- TGParser.h - Parser for TableGen Files -------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -27,6 +26,7 @@ class RecordKeeper; class RecTy; class Init; + struct ForeachLoop; struct MultiClass; struct SubClassReference; struct SubMultiClassReference; @@ -41,16 +41,49 @@ } }; + /// RecordsEntry - Can be either a record or a foreach loop. + struct RecordsEntry { + std::unique_ptr<Record> Rec; + std::unique_ptr<ForeachLoop> Loop; + + void dump() const; + + RecordsEntry() {} + RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec)) {} + RecordsEntry(std::unique_ptr<ForeachLoop> Loop) + : Loop(std::move(Loop)) {} + }; + /// ForeachLoop - Record the iteration state associated with a for loop. /// This is used to instantiate items in the loop body. struct ForeachLoop { + SMLoc Loc; VarInit *IterVar; - ListInit *ListValue; + Init *ListValue; + std::vector<RecordsEntry> Entries; + + void dump() const; + + ForeachLoop(SMLoc Loc, VarInit *IVar, Init *LValue) + : Loc(Loc), IterVar(IVar), ListValue(LValue) {} + }; - ForeachLoop(VarInit *IVar, ListInit *LValue) - : IterVar(IVar), ListValue(LValue) {} + struct DefsetRecord { + SMLoc Loc; + RecTy *EltTy; + SmallVector<Init *, 16> Elements; }; +struct MultiClass { + Record Rec; // Placeholder for template args and Name. + std::vector<RecordsEntry> Entries; + + void dump() const; + + MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records) : + Rec(Name, Loc, Records) {} +}; + class TGParser { TGLexer Lex; std::vector<SmallVector<LetRecord, 4>> LetStack; @@ -58,8 +91,9 @@ /// Loops - Keep track of any foreach loops we are within. /// - typedef std::vector<ForeachLoop> LoopVector; - LoopVector Loops; + std::vector<std::unique_ptr<ForeachLoop>> Loops; + + SmallVector<DefsetRecord *, 2> Defsets; /// CurMultiClass - If we are parsing a 'multiclass' definition, this is the /// current value. @@ -68,8 +102,6 @@ // 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 @@ -79,12 +111,12 @@ 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(nullptr), Records(records), AnonCounter(0) {} + TGParser(SourceMgr &SrcMgr, ArrayRef<std::string> Macros, + RecordKeeper &records) + : Lex(SrcMgr, Macros), CurMultiClass(nullptr), Records(records) {} /// ParseFile - Main entrypoint for parsing a tblgen file. These parser /// routines return true on error, or false on success. @@ -107,44 +139,28 @@ ArrayRef<unsigned> BitList, Init *V, bool AllowSelfAssignment = false); bool AddSubClass(Record *Rec, SubClassReference &SubClass); + bool AddSubClass(RecordsEntry &Entry, SubClassReference &SubClass); bool AddSubMultiClass(MultiClass *CurMC, SubMultiClassReference &SubMultiClass); - Init *GetNewAnonymousName(); + using SubstStack = SmallVector<std::pair<Init *, Init *>, 8>; - // 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<IterRecord> IterSet; - - bool ProcessForeachDefs(Record *CurRec, SMLoc Loc); - bool ProcessForeachDefs(Record *CurRec, SMLoc Loc, IterSet &IterVals); + bool addEntry(RecordsEntry E); + bool resolve(const ForeachLoop &Loop, SubstStack &Stack, bool Final, + std::vector<RecordsEntry> *Dest, SMLoc *Loc = nullptr); + bool resolve(const std::vector<RecordsEntry> &Source, SubstStack &Substs, + bool Final, std::vector<RecordsEntry> *Dest, + SMLoc *Loc = nullptr); + bool addDefOne(std::unique_ptr<Record> Rec); private: // Parser methods. bool ParseObjectList(MultiClass *MC = nullptr); bool ParseObject(MultiClass *MC); bool ParseClass(); bool ParseMultiClass(); - Record *InstantiateMulticlassDef(MultiClass &MC, Record *DefProto, - Init *&DefmPrefix, SMRange DefmPrefixRange, - ArrayRef<Init *> TArgs, - ArrayRef<Init *> TemplateVals); - bool ResolveMulticlassDefArgs(MultiClass &MC, Record *DefProto, - SMLoc DefmPrefixLoc, SMLoc SubClassLoc, - ArrayRef<Init *> TArgs, - ArrayRef<Init *> TemplateVals, bool DeleteArgs); - bool ResolveMulticlassDef(MultiClass &MC, - Record *CurRec, - Record *DefProto, - SMLoc DefmPrefixLoc); bool ParseDefm(MultiClass *CurMultiClass); bool ParseDef(MultiClass *CurMultiClass); + bool ParseDefset(); bool ParseForeach(MultiClass *CurMultiClass); bool ParseTopLevelLet(MultiClass *CurMultiClass); void ParseLetList(SmallVectorImpl<LetRecord> &Result); @@ -155,7 +171,7 @@ bool ParseTemplateArgList(Record *CurRec); Init *ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs); - VarInit *ParseForeachDeclaration(ListInit *&ForeachListValue); + VarInit *ParseForeachDeclaration(Init *&ForeachListValue); SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm); SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC); @@ -174,14 +190,17 @@ bool ParseOptionalRangeList(SmallVectorImpl<unsigned> &Ranges); bool ParseOptionalBitList(SmallVectorImpl<unsigned> &Ranges); void ParseRangeList(SmallVectorImpl<unsigned> &Result); - bool ParseRangePiece(SmallVectorImpl<unsigned> &Ranges); + bool ParseRangePiece(SmallVectorImpl<unsigned> &Ranges, + TypedInit *FirstItem = nullptr); RecTy *ParseType(); Init *ParseOperation(Record *CurRec, RecTy *ItemType); + Init *ParseOperationCond(Record *CurRec, RecTy *ItemType); RecTy *ParseOperatorType(); Init *ParseObjectName(MultiClass *CurMultiClass); Record *ParseClassID(); MultiClass *ParseMultiClassID(); bool ApplyLetStack(Record *CurRec); + bool ApplyLetStack(RecordsEntry &Entry); }; } // end namespace llvm