mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-23 02:29:18 +00:00
Add parser support to recognize multidefs. No processing on the multidef is done at this point. The grammar is: MultiDef = MULTIDEF ObjectName < Value, Declaration, Value > ObjectBody The first Value must be resolveable to a list and the second Value must be resolveable to an integer. The Declaration is a temporary value used as an iterator to refer to list items during processing. It may be passed into the ObjectBody where it will be substituted with the list value used to instantiate each def. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141232 91177308-0d34-0410-b5e6-96231b3b80d8
139 lines
4.7 KiB
C++
139 lines
4.7 KiB
C++
//===- 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.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This class represents the Parser for tablegen files.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef TGPARSER_H
|
|
#define TGPARSER_H
|
|
|
|
#include "TGLexer.h"
|
|
#include "llvm/TableGen/Error.h"
|
|
#include "llvm/ADT/Twine.h"
|
|
#include "llvm/Support/SourceMgr.h"
|
|
#include <map>
|
|
|
|
namespace llvm {
|
|
class Record;
|
|
class RecordVal;
|
|
class RecordKeeper;
|
|
class RecTy;
|
|
class Init;
|
|
struct MultiClass;
|
|
struct SubClassReference;
|
|
struct SubMultiClassReference;
|
|
|
|
struct LetRecord {
|
|
std::string Name;
|
|
std::vector<unsigned> Bits;
|
|
Init *Value;
|
|
SMLoc Loc;
|
|
LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
|
|
SMLoc L)
|
|
: Name(N), Bits(B), Value(V), Loc(L) {
|
|
}
|
|
};
|
|
|
|
class TGParser {
|
|
TGLexer Lex;
|
|
std::vector<std::vector<LetRecord> > LetStack;
|
|
std::map<std::string, MultiClass*> MultiClasses;
|
|
|
|
/// CurMultiClass - If we are parsing a 'multiclass' definition, this is the
|
|
/// current value.
|
|
MultiClass *CurMultiClass;
|
|
|
|
// Record tracker
|
|
RecordKeeper &Records;
|
|
public:
|
|
TGParser(SourceMgr &SrcMgr, RecordKeeper &records) :
|
|
Lex(SrcMgr), CurMultiClass(0), Records(records) {}
|
|
|
|
/// 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;
|
|
}
|
|
bool TokError(const Twine &Msg) const {
|
|
return Error(Lex.getLoc(), Msg);
|
|
}
|
|
const std::vector<std::string> &getDependencies() const {
|
|
return Lex.getDependencies();
|
|
}
|
|
private: // Semantic analysis methods.
|
|
bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
|
|
bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName,
|
|
const std::vector<unsigned> &BitList, Init *V);
|
|
bool AddSubClass(Record *Rec, SubClassReference &SubClass);
|
|
bool AddSubMultiClass(MultiClass *CurMC,
|
|
SubMultiClassReference &SubMultiClass);
|
|
|
|
private: // Parser methods.
|
|
bool ParseObjectList(MultiClass *MC = 0);
|
|
bool ParseObject(MultiClass *MC);
|
|
bool ParseClass();
|
|
bool ParseMultiClass();
|
|
Record *InstantiateMulticlassDef(MultiClass &MC,
|
|
Record *DefProto,
|
|
const std::string &DefmPrefix,
|
|
SMLoc DefmPrefixLoc);
|
|
bool ResolveMulticlassDefArgs(MultiClass &MC,
|
|
Record *DefProto,
|
|
SMLoc DefmPrefixLoc,
|
|
SMLoc SubClassLoc,
|
|
const std::vector<std::string> &TArgs,
|
|
std::vector<Init *> &TemplateVals,
|
|
bool DeleteArgs);
|
|
bool ResolveMulticlassDef(MultiClass &MC,
|
|
Record *CurRec,
|
|
Record *DefProto,
|
|
SMLoc DefmPrefixLoc);
|
|
bool ParseDefm(MultiClass *CurMultiClass);
|
|
bool ParseDef(MultiClass *CurMultiClass);
|
|
bool ParseMultiDef(MultiClass *CurMultiClass);
|
|
bool ParseTopLevelLet(MultiClass *CurMultiClass);
|
|
std::vector<LetRecord> ParseLetList();
|
|
|
|
bool ParseObjectBody(Record *CurRec);
|
|
bool ParseBody(Record *CurRec);
|
|
bool ParseBodyItem(Record *CurRec);
|
|
|
|
bool ParseTemplateArgList(Record *CurRec);
|
|
std::string ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
|
|
|
|
SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
|
|
SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
|
|
|
|
Init *ParseIDValue(Record *CurRec);
|
|
Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc);
|
|
Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = 0);
|
|
Init *ParseValue(Record *CurRec, RecTy *ItemType = 0);
|
|
std::vector<Init*> ParseValueList(Record *CurRec, Record *ArgsRec = 0, RecTy *EltTy = 0);
|
|
std::vector<std::pair<llvm::Init*, std::string> > ParseDagArgList(Record *);
|
|
bool ParseOptionalRangeList(std::vector<unsigned> &Ranges);
|
|
bool ParseOptionalBitList(std::vector<unsigned> &Ranges);
|
|
std::vector<unsigned> ParseRangeList();
|
|
bool ParseRangePiece(std::vector<unsigned> &Ranges);
|
|
RecTy *ParseType();
|
|
Init *ParseOperation(Record *CurRec);
|
|
RecTy *ParseOperatorType();
|
|
std::string ParseObjectName();
|
|
Record *ParseClassID();
|
|
MultiClass *ParseMultiClassID();
|
|
Record *ParseDefmID();
|
|
};
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|