2007-11-22 20:49:04 +00:00
|
|
|
//===- TGParser.h - Parser for TableGen Files -------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-11-22 20:49:04 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class represents the Parser for tablegen files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef TGPARSER_H
|
|
|
|
#define TGPARSER_H
|
|
|
|
|
|
|
|
#include "TGLexer.h"
|
2009-06-21 03:36:54 +00:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2007-11-22 20:49:04 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Record;
|
|
|
|
class RecordVal;
|
2009-01-22 05:10:16 +00:00
|
|
|
struct RecTy;
|
|
|
|
struct Init;
|
2007-11-22 20:49:04 +00:00
|
|
|
struct MultiClass;
|
2009-03-19 23:26:52 +00:00
|
|
|
struct SubClassReference;
|
2009-04-22 16:42:54 +00:00
|
|
|
struct SubMultiClassReference;
|
2007-11-22 20:49:04 +00:00
|
|
|
|
|
|
|
struct LetRecord {
|
|
|
|
std::string Name;
|
|
|
|
std::vector<unsigned> Bits;
|
|
|
|
Init *Value;
|
2009-06-21 03:39:35 +00:00
|
|
|
SMLoc Loc;
|
2007-11-22 20:49:04 +00:00
|
|
|
LetRecord(const std::string &N, const std::vector<unsigned> &B, Init *V,
|
2009-06-21 03:39:35 +00:00
|
|
|
SMLoc L)
|
2007-11-22 20:49:04 +00:00
|
|
|
: 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;
|
|
|
|
public:
|
2009-06-21 03:41:50 +00:00
|
|
|
TGParser(SourceMgr &SrcMgr) : Lex(SrcMgr), CurMultiClass(0) {}
|
2007-11-22 20:49:04 +00:00
|
|
|
|
|
|
|
/// ParseFile - Main entrypoint for parsing a tblgen file. These parser
|
|
|
|
/// routines return true on error, or false on success.
|
|
|
|
bool ParseFile();
|
|
|
|
|
2009-06-21 03:39:35 +00:00
|
|
|
bool Error(SMLoc L, const std::string &Msg) const {
|
2007-11-22 20:49:04 +00:00
|
|
|
Lex.PrintError(L, Msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool TokError(const std::string &Msg) const {
|
|
|
|
return Error(Lex.getLoc(), Msg);
|
|
|
|
}
|
|
|
|
private: // Semantic analysis methods.
|
2009-06-21 03:39:35 +00:00
|
|
|
bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV);
|
|
|
|
bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName,
|
2007-11-22 20:49:04 +00:00
|
|
|
const std::vector<unsigned> &BitList, Init *V);
|
2009-02-14 16:06:42 +00:00
|
|
|
bool AddSubClass(Record *Rec, SubClassReference &SubClass);
|
2009-04-30 18:26:19 +00:00
|
|
|
bool AddSubMultiClass(MultiClass *CurMC,
|
|
|
|
SubMultiClassReference &SubMultiClass);
|
2007-11-22 20:49:04 +00:00
|
|
|
|
|
|
|
private: // Parser methods.
|
|
|
|
bool ParseObjectList();
|
|
|
|
bool ParseObject();
|
|
|
|
bool ParseClass();
|
|
|
|
bool ParseMultiClass();
|
|
|
|
bool ParseMultiClassDef(MultiClass *CurMC);
|
|
|
|
bool ParseDefm();
|
|
|
|
bool ParseTopLevelLet();
|
|
|
|
std::vector<LetRecord> ParseLetList();
|
|
|
|
|
|
|
|
Record *ParseDef(MultiClass *CurMultiClass);
|
|
|
|
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);
|
2009-04-30 18:26:19 +00:00
|
|
|
SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
|
2007-11-22 20:49:04 +00:00
|
|
|
|
|
|
|
Init *ParseIDValue(Record *CurRec);
|
2009-06-21 03:39:35 +00:00
|
|
|
Init *ParseIDValue(Record *CurRec, const std::string &Name, SMLoc NameLoc);
|
2009-06-08 20:23:18 +00:00
|
|
|
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);
|
2007-11-22 20:49:04 +00:00
|
|
|
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();
|
2009-05-14 20:54:48 +00:00
|
|
|
Init *ParseOperation(Record *CurRec);
|
|
|
|
RecTy *ParseOperatorType();
|
2007-11-22 20:49:04 +00:00
|
|
|
std::string ParseObjectName();
|
|
|
|
Record *ParseClassID();
|
2009-04-22 16:42:54 +00:00
|
|
|
MultiClass *ParseMultiClassID();
|
2007-11-22 20:49:04 +00:00
|
|
|
Record *ParseDefmID();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|