2002-12-02 01:23:04 +00:00
|
|
|
//===-- FileParser.y - Parser for TableGen files ----------------*- C++ -*-===//
|
2003-10-21 15:29:18 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-02 01:23:04 +00:00
|
|
|
//
|
|
|
|
// This file implements the bison parser for Table Generator files...
|
|
|
|
//
|
2003-10-13 03:32:08 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
%{
|
|
|
|
#include "Record.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2002-12-02 01:23:04 +00:00
|
|
|
#include <algorithm>
|
2003-07-30 04:26:44 +00:00
|
|
|
#include <cstdio>
|
2002-12-02 01:23:04 +00:00
|
|
|
#define YYERROR_VERBOSE 1
|
|
|
|
|
|
|
|
int yyerror(const char *ErrorMsg);
|
|
|
|
int yylex();
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
extern int Filelineno;
|
|
|
|
static Record *CurRec = 0;
|
2005-04-19 03:36:21 +00:00
|
|
|
static bool ParsingTemplateArgs = false;
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
|
|
|
|
|
2003-08-04 04:56:53 +00:00
|
|
|
struct LetRecord {
|
2003-08-03 13:58:01 +00:00
|
|
|
std::string Name;
|
|
|
|
std::vector<unsigned> Bits;
|
|
|
|
Init *Value;
|
|
|
|
bool HasBits;
|
2003-08-04 04:56:53 +00:00
|
|
|
LetRecord(const std::string &N, std::vector<unsigned> *B, Init *V)
|
2003-08-03 13:58:01 +00:00
|
|
|
: Name(N), Value(V), HasBits(B != 0) {
|
|
|
|
if (HasBits) Bits = *B;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-08-04 04:56:53 +00:00
|
|
|
static std::vector<std::vector<LetRecord> > LetStack;
|
2003-08-03 13:58:01 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2003-07-30 20:56:47 +00:00
|
|
|
extern std::ostream &err();
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
static void addValue(const RecordVal &RV) {
|
2003-08-03 13:58:01 +00:00
|
|
|
if (RecordVal *ERV = CurRec->getValue(RV.getName())) {
|
|
|
|
// The value already exists in the class, treat this as a set...
|
|
|
|
if (ERV->setValue(RV.getValue())) {
|
|
|
|
err() << "New definition of '" << RV.getName() << "' of type '"
|
|
|
|
<< *RV.getType() << "' is incompatible with previous "
|
|
|
|
<< "definition of type '" << *ERV->getType() << "'!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2003-08-03 13:58:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CurRec->addValue(RV);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addSuperClass(Record *SC) {
|
|
|
|
if (CurRec->isSubClassOf(SC)) {
|
|
|
|
err() << "Already subclass of '" << SC->getName() << "'!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
CurRec->addSuperClass(SC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setValue(const std::string &ValName,
|
2006-01-31 06:02:35 +00:00
|
|
|
std::vector<unsigned> *BitList, Init *V) {
|
2004-02-28 17:31:28 +00:00
|
|
|
if (!V) return;
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
RecordVal *RV = CurRec->getValue(ValName);
|
|
|
|
if (RV == 0) {
|
|
|
|
err() << "Value '" << ValName << "' unknown!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
2004-02-28 17:31:28 +00:00
|
|
|
|
|
|
|
// Do not allow assignments like 'X = X'. This will just cause infinite loops
|
|
|
|
// in the resolution machinery.
|
|
|
|
if (!BitList)
|
|
|
|
if (VarInit *VI = dynamic_cast<VarInit*>(V))
|
|
|
|
if (VI->getName() == ValName)
|
|
|
|
return;
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
// If we are assigning to a subset of the bits in the value... then we must be
|
|
|
|
// assigning to a field of BitsRecTy, which must have a BitsInit
|
|
|
|
// initializer...
|
|
|
|
//
|
|
|
|
if (BitList) {
|
|
|
|
BitsInit *CurVal = dynamic_cast<BitsInit*>(RV->getValue());
|
|
|
|
if (CurVal == 0) {
|
|
|
|
err() << "Value '" << ValName << "' is not a bits type!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert the incoming value to a bits type of the appropriate size...
|
|
|
|
Init *BI = V->convertInitializerTo(new BitsRecTy(BitList->size()));
|
|
|
|
if (BI == 0) {
|
|
|
|
V->convertInitializerTo(new BitsRecTy(BitList->size()));
|
|
|
|
err() << "Initializer '" << *V << "' not compatible with bit range!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We should have a BitsInit type now...
|
|
|
|
assert(dynamic_cast<BitsInit*>(BI) != 0 || &(std::cerr << *BI) == 0);
|
|
|
|
BitsInit *BInit = (BitsInit*)BI;
|
|
|
|
|
|
|
|
BitsInit *NewVal = new BitsInit(CurVal->getNumBits());
|
|
|
|
|
2002-12-06 03:55:39 +00:00
|
|
|
// Loop over bits, assigning values as appropriate...
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = BitList->size(); i != e; ++i) {
|
|
|
|
unsigned Bit = (*BitList)[i];
|
2002-12-06 04:42:16 +00:00
|
|
|
if (NewVal->getBit(Bit)) {
|
|
|
|
err() << "Cannot set bit #" << Bit << " of value '" << ValName
|
2002-12-06 03:55:39 +00:00
|
|
|
<< "' more than once!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-06 03:55:39 +00:00
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
NewVal->setBit(Bit, BInit->getBit(i));
|
|
|
|
}
|
2002-12-06 03:55:39 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = CurVal->getNumBits(); i != e; ++i)
|
|
|
|
if (NewVal->getBit(i) == 0)
|
|
|
|
NewVal->setBit(i, CurVal->getBit(i));
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
V = NewVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RV->setValue(V)) {
|
|
|
|
err() << "Value '" << ValName << "' of type '" << *RV->getType()
|
|
|
|
<< "' is incompatible with initializer '" << *V << "'!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-19 03:36:21 +00:00
|
|
|
// addSubClass - Add SC as a subclass to CurRec, resolving TemplateArgs as SC's
|
|
|
|
// template arguments.
|
2002-12-02 01:23:04 +00:00
|
|
|
static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
|
|
|
|
// Add all of the values in the subclass into the current class...
|
|
|
|
const std::vector<RecordVal> &Vals = SC->getValues();
|
|
|
|
for (unsigned i = 0, e = Vals.size(); i != e; ++i)
|
|
|
|
addValue(Vals[i]);
|
|
|
|
|
|
|
|
const std::vector<std::string> &TArgs = SC->getTemplateArgs();
|
|
|
|
|
|
|
|
// Ensure that an appropriate number of template arguments are specified...
|
|
|
|
if (TArgs.size() < TemplateArgs.size()) {
|
2003-05-20 23:45:36 +00:00
|
|
|
err() << "ERROR: More template args specified than expected!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
} else { // This class expects template arguments...
|
|
|
|
// Loop over all of the template arguments, setting them to the specified
|
2005-04-19 03:36:21 +00:00
|
|
|
// value or leaving them as the default if necessary.
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
|
|
|
|
if (i < TemplateArgs.size()) { // A value is specified for this temp-arg?
|
2005-09-08 18:22:35 +00:00
|
|
|
// Set it now.
|
|
|
|
setValue(TArgs[i], 0, TemplateArgs[i]);
|
2005-04-19 03:36:21 +00:00
|
|
|
|
|
|
|
// Resolve it next.
|
|
|
|
CurRec->resolveReferencesTo(CurRec->getValue(TArgs[i]));
|
|
|
|
|
|
|
|
|
|
|
|
// Now remove it.
|
|
|
|
CurRec->removeValue(TArgs[i]);
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
} else if (!CurRec->getValue(TArgs[i])->getValue()->isComplete()) {
|
2005-09-08 18:22:35 +00:00
|
|
|
err() << "ERROR: Value not specified for template argument #"
|
|
|
|
<< i << " (" << TArgs[i] << ") of subclass '" << SC->getName()
|
|
|
|
<< "'!\n";
|
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since everything went well, we can now set the "superclass" list for the
|
|
|
|
// current record.
|
2004-02-28 17:31:28 +00:00
|
|
|
const std::vector<Record*> &SCs = SC->getSuperClasses();
|
2002-12-02 01:23:04 +00:00
|
|
|
for (unsigned i = 0, e = SCs.size(); i != e; ++i)
|
|
|
|
addSuperClass(SCs[i]);
|
|
|
|
addSuperClass(SC);
|
|
|
|
}
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
using namespace llvm;
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%union {
|
2003-11-11 22:41:34 +00:00
|
|
|
std::string* StrVal;
|
|
|
|
int IntVal;
|
|
|
|
llvm::RecTy* Ty;
|
|
|
|
llvm::Init* Initializer;
|
|
|
|
std::vector<llvm::Init*>* FieldList;
|
|
|
|
std::vector<unsigned>* BitList;
|
|
|
|
llvm::Record* Rec;
|
|
|
|
SubClassRefTy* SubClassRef;
|
|
|
|
std::vector<SubClassRefTy>* SubClassList;
|
|
|
|
std::vector<std::pair<llvm::Init*, std::string> >* DagValueList;
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2003-08-04 04:56:53 +00:00
|
|
|
%token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
|
2005-04-19 01:11:03 +00:00
|
|
|
%token SHLTOK SRATOK SRLTOK
|
2002-12-02 01:23:04 +00:00
|
|
|
%token <IntVal> INTVAL
|
2003-08-10 22:04:25 +00:00
|
|
|
%token <StrVal> ID VARNAME STRVAL CODEFRAGMENT
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
%type <Ty> Type
|
2003-08-03 18:17:22 +00:00
|
|
|
%type <Rec> ClassInst DefInst Object ObjectBody ClassID
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
%type <SubClassRef> SubClassRef
|
|
|
|
%type <SubClassList> ClassList ClassListNE
|
|
|
|
%type <IntVal> OptPrefix
|
2006-03-30 22:50:40 +00:00
|
|
|
%type <Initializer> Value OptValue IDValue
|
2003-08-04 20:44:43 +00:00
|
|
|
%type <DagValueList> DagArgList DagArgListNE
|
2002-12-02 01:23:04 +00:00
|
|
|
%type <FieldList> ValueList ValueListNE
|
|
|
|
%type <BitList> BitList OptBitList RBitList
|
2005-09-30 04:53:04 +00:00
|
|
|
%type <StrVal> Declaration OptID OptVarName ObjectName
|
2002-12-02 01:23:04 +00:00
|
|
|
|
|
|
|
%start File
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
ClassID : ID {
|
|
|
|
$$ = Records.getClass(*$1);
|
|
|
|
if ($$ == 0) {
|
|
|
|
err() << "Couldn't find class '" << *$1 << "'!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
delete $1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TableGen types...
|
|
|
|
Type : STRING { // string type
|
|
|
|
$$ = new StringRecTy();
|
|
|
|
} | BIT { // bit type
|
|
|
|
$$ = new BitRecTy();
|
|
|
|
} | BITS '<' INTVAL '>' { // bits<x> type
|
|
|
|
$$ = new BitsRecTy($3);
|
|
|
|
} | INT { // int type
|
|
|
|
$$ = new IntRecTy();
|
2003-08-03 18:17:22 +00:00
|
|
|
} | LIST '<' Type '>' { // list<x> type
|
2002-12-02 01:23:04 +00:00
|
|
|
$$ = new ListRecTy($3);
|
2003-07-30 21:47:42 +00:00
|
|
|
} | CODE { // code type
|
|
|
|
$$ = new CodeRecTy();
|
2003-08-04 04:50:57 +00:00
|
|
|
} | DAG { // dag type
|
|
|
|
$$ = new DagRecTy();
|
2002-12-02 01:23:04 +00:00
|
|
|
} | ClassID { // Record Type
|
|
|
|
$$ = new RecordRecTy($1);
|
|
|
|
};
|
|
|
|
|
|
|
|
OptPrefix : /*empty*/ { $$ = 0; } | FIELD { $$ = 1; };
|
|
|
|
|
|
|
|
OptValue : /*empty*/ { $$ = 0; } | '=' Value { $$ = $2; };
|
|
|
|
|
2006-03-30 22:50:40 +00:00
|
|
|
IDValue : ID {
|
|
|
|
if (const RecordVal *RV = (CurRec ? CurRec->getValue(*$1) : 0)) {
|
|
|
|
$$ = new VarInit(*$1, RV->getType());
|
|
|
|
} else if (CurRec && CurRec->isTemplateArg(CurRec->getName()+":"+*$1)) {
|
|
|
|
const RecordVal *RV = CurRec->getValue(CurRec->getName()+":"+*$1);
|
|
|
|
assert(RV && "Template arg doesn't exist??");
|
|
|
|
$$ = new VarInit(CurRec->getName()+":"+*$1, RV->getType());
|
|
|
|
} else if (Record *D = Records.getDef(*$1)) {
|
|
|
|
$$ = new DefInit(D);
|
|
|
|
} else {
|
|
|
|
err() << "Variable not defined: '" << *$1 << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete $1;
|
|
|
|
};
|
|
|
|
|
|
|
|
Value : IDValue {
|
|
|
|
$$ = $1;
|
|
|
|
} | INTVAL {
|
2002-12-02 01:23:04 +00:00
|
|
|
$$ = new IntInit($1);
|
|
|
|
} | STRVAL {
|
|
|
|
$$ = new StringInit(*$1);
|
|
|
|
delete $1;
|
2003-07-30 22:15:58 +00:00
|
|
|
} | CODEFRAGMENT {
|
|
|
|
$$ = new CodeInit(*$1);
|
|
|
|
delete $1;
|
2002-12-02 01:23:04 +00:00
|
|
|
} | '?' {
|
|
|
|
$$ = new UnsetInit();
|
|
|
|
} | '{' ValueList '}' {
|
|
|
|
BitsInit *Init = new BitsInit($2->size());
|
|
|
|
for (unsigned i = 0, e = $2->size(); i != e; ++i) {
|
|
|
|
struct Init *Bit = (*$2)[i]->convertInitializerTo(new BitRecTy());
|
|
|
|
if (Bit == 0) {
|
2005-09-08 18:22:35 +00:00
|
|
|
err() << "Element #" << i << " (" << *(*$2)[i]
|
|
|
|
<< ") is not convertable to a bit!\n";
|
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
Init->setBit($2->size()-i-1, Bit);
|
|
|
|
}
|
|
|
|
$$ = Init;
|
|
|
|
delete $2;
|
2005-09-08 18:48:23 +00:00
|
|
|
} | ID '<' ValueListNE '>' {
|
|
|
|
// This is a CLASS<initvalslist> expression. This is supposed to synthesize
|
|
|
|
// a new anonymous definition, deriving from CLASS<initvalslist> with no
|
|
|
|
// body.
|
|
|
|
Record *Class = Records.getClass(*$1);
|
|
|
|
if (!Class) {
|
|
|
|
err() << "Expected a class, got '" << *$1 << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
delete $1;
|
|
|
|
|
|
|
|
static unsigned AnonCounter = 0;
|
|
|
|
Record *OldRec = CurRec; // Save CurRec.
|
|
|
|
|
|
|
|
// Create the new record, set it as CurRec temporarily.
|
|
|
|
CurRec = new Record("anonymous.val."+utostr(AnonCounter++));
|
|
|
|
addSubClass(Class, *$3); // Add info about the subclass to CurRec.
|
|
|
|
delete $3; // Free up the template args.
|
|
|
|
|
|
|
|
CurRec->resolveReferences();
|
|
|
|
|
|
|
|
Records.addDef(CurRec);
|
|
|
|
|
|
|
|
// The result of the expression is a reference to the new record.
|
|
|
|
$$ = new DefInit(CurRec);
|
|
|
|
|
|
|
|
// Restore the old CurRec
|
|
|
|
CurRec = OldRec;
|
2002-12-02 01:23:04 +00:00
|
|
|
} | Value '{' BitList '}' {
|
|
|
|
$$ = $1->convertInitializerBitRange(*$3);
|
|
|
|
if ($$ == 0) {
|
|
|
|
err() << "Invalid bit range for value '" << *$1 << "'!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
delete $3;
|
2003-08-03 18:17:22 +00:00
|
|
|
} | '[' ValueList ']' {
|
2002-12-02 01:23:04 +00:00
|
|
|
$$ = new ListInit(*$2);
|
|
|
|
delete $2;
|
2002-12-02 16:43:43 +00:00
|
|
|
} | Value '.' ID {
|
|
|
|
if (!$1->getFieldType(*$3)) {
|
|
|
|
err() << "Cannot access field '" << *$3 << "' of value '" << *$1 << "!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 16:43:43 +00:00
|
|
|
}
|
|
|
|
$$ = new FieldInit($1, *$3);
|
|
|
|
delete $3;
|
2006-03-30 22:50:40 +00:00
|
|
|
} | '(' IDValue DagArgList ')' {
|
|
|
|
$$ = new DagInit($2, *$3);
|
|
|
|
delete $3;
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
} | Value '[' BitList ']' {
|
|
|
|
std::reverse($3->begin(), $3->end());
|
|
|
|
$$ = $1->convertInitListSlice(*$3);
|
|
|
|
if ($$ == 0) {
|
|
|
|
err() << "Invalid list slice for value '" << *$1 << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
delete $3;
|
2005-04-19 01:11:03 +00:00
|
|
|
} | SHLTOK '(' Value ',' Value ')' {
|
|
|
|
$$ = $3->getBinaryOp(Init::SHL, $5);
|
|
|
|
if ($$ == 0) {
|
|
|
|
err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} | SRATOK '(' Value ',' Value ')' {
|
|
|
|
$$ = $3->getBinaryOp(Init::SRA, $5);
|
|
|
|
if ($$ == 0) {
|
|
|
|
err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} | SRLTOK '(' Value ',' Value ')' {
|
|
|
|
$$ = $3->getBinaryOp(Init::SRL, $5);
|
|
|
|
if ($$ == 0) {
|
|
|
|
err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
2003-08-10 22:14:13 +00:00
|
|
|
OptVarName : /* empty */ {
|
|
|
|
$$ = new std::string();
|
|
|
|
}
|
|
|
|
| ':' VARNAME {
|
|
|
|
$$ = $2;
|
|
|
|
};
|
|
|
|
|
|
|
|
DagArgListNE : Value OptVarName {
|
|
|
|
$$ = new std::vector<std::pair<Init*, std::string> >();
|
|
|
|
$$->push_back(std::make_pair($1, *$2));
|
|
|
|
delete $2;
|
2003-08-04 20:44:43 +00:00
|
|
|
}
|
2003-08-10 22:14:13 +00:00
|
|
|
| DagArgListNE ',' Value OptVarName {
|
|
|
|
$1->push_back(std::make_pair($3, *$4));
|
|
|
|
delete $4;
|
|
|
|
$$ = $1;
|
2003-08-04 20:44:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DagArgList : /*empty*/ {
|
2003-08-10 22:14:13 +00:00
|
|
|
$$ = new std::vector<std::pair<Init*, std::string> >();
|
2003-08-04 20:44:43 +00:00
|
|
|
}
|
|
|
|
| DagArgListNE { $$ = $1; };
|
|
|
|
|
|
|
|
|
2002-12-02 01:23:04 +00:00
|
|
|
RBitList : INTVAL {
|
|
|
|
$$ = new std::vector<unsigned>();
|
|
|
|
$$->push_back($1);
|
|
|
|
} | INTVAL '-' INTVAL {
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($1 < 0 || $3 < 0) {
|
|
|
|
err() << "Invalid range: " << $1 << "-" << $3 << "!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
$$ = new std::vector<unsigned>();
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($1 < $3) {
|
|
|
|
for (int i = $1; i <= $3; ++i)
|
|
|
|
$$->push_back(i);
|
|
|
|
} else {
|
|
|
|
for (int i = $1; i >= $3; --i)
|
|
|
|
$$->push_back(i);
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
} | INTVAL INTVAL {
|
|
|
|
$2 = -$2;
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($1 < 0 || $2 < 0) {
|
|
|
|
err() << "Invalid range: " << $1 << "-" << $2 << "!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
$$ = new std::vector<unsigned>();
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($1 < $2) {
|
|
|
|
for (int i = $1; i <= $2; ++i)
|
|
|
|
$$->push_back(i);
|
|
|
|
} else {
|
|
|
|
for (int i = $1; i >= $2; --i)
|
|
|
|
$$->push_back(i);
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
} | RBitList ',' INTVAL {
|
|
|
|
($$=$1)->push_back($3);
|
|
|
|
} | RBitList ',' INTVAL '-' INTVAL {
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($3 < 0 || $5 < 0) {
|
|
|
|
err() << "Invalid range: " << $3 << "-" << $5 << "!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
$$ = $1;
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($3 < $5) {
|
|
|
|
for (int i = $3; i <= $5; ++i)
|
|
|
|
$$->push_back(i);
|
|
|
|
} else {
|
|
|
|
for (int i = $3; i >= $5; --i)
|
|
|
|
$$->push_back(i);
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
} | RBitList ',' INTVAL INTVAL {
|
|
|
|
$4 = -$4;
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($3 < 0 || $4 < 0) {
|
|
|
|
err() << "Invalid range: " << $3 << "-" << $4 << "!\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|
|
|
|
$$ = $1;
|
Add initial support for list slices. This currently allows you to do stuff
like this:
def B {
list<int> X = [10, 20, 30, 4, 1, 1231, 20] [2-4,2,2,0-6];
}
... which isn't particularly useful, but more is to come.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 23:21:34 +00:00
|
|
|
if ($3 < $4) {
|
|
|
|
for (int i = $3; i <= $4; ++i)
|
|
|
|
$$->push_back(i);
|
|
|
|
} else {
|
|
|
|
for (int i = $3; i >= $4; --i)
|
|
|
|
$$->push_back(i);
|
|
|
|
}
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BitList : RBitList { $$ = $1; std::reverse($1->begin(), $1->end()); };
|
|
|
|
|
|
|
|
OptBitList : /*empty*/ { $$ = 0; } | '{' BitList '}' { $$ = $2; };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ValueList : /*empty*/ {
|
|
|
|
$$ = new std::vector<Init*>();
|
|
|
|
} | ValueListNE {
|
|
|
|
$$ = $1;
|
|
|
|
};
|
|
|
|
|
|
|
|
ValueListNE : Value {
|
|
|
|
$$ = new std::vector<Init*>();
|
|
|
|
$$->push_back($1);
|
|
|
|
} | ValueListNE ',' Value {
|
|
|
|
($$ = $1)->push_back($3);
|
|
|
|
};
|
|
|
|
|
|
|
|
Declaration : OptPrefix Type ID OptValue {
|
2005-04-19 03:36:21 +00:00
|
|
|
std::string DecName = *$3;
|
|
|
|
if (ParsingTemplateArgs)
|
|
|
|
DecName = CurRec->getName() + ":" + DecName;
|
|
|
|
|
|
|
|
addValue(RecordVal(DecName, $2, $1));
|
|
|
|
setValue(DecName, 0, $4);
|
|
|
|
$$ = new std::string(DecName);
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BodyItem : Declaration ';' {
|
|
|
|
delete $1;
|
2003-08-04 04:56:53 +00:00
|
|
|
} | LET ID OptBitList '=' Value ';' {
|
2002-12-02 01:23:04 +00:00
|
|
|
setValue(*$2, $3, $5);
|
|
|
|
delete $2;
|
|
|
|
delete $3;
|
|
|
|
};
|
|
|
|
|
|
|
|
BodyList : /*empty*/ | BodyList BodyItem;
|
|
|
|
Body : ';' | '{' BodyList '}';
|
|
|
|
|
|
|
|
SubClassRef : ClassID {
|
|
|
|
$$ = new SubClassRefTy($1, new std::vector<Init*>());
|
|
|
|
} | ClassID '<' ValueListNE '>' {
|
|
|
|
$$ = new SubClassRefTy($1, $3);
|
|
|
|
};
|
|
|
|
|
|
|
|
ClassListNE : SubClassRef {
|
|
|
|
$$ = new std::vector<SubClassRefTy>();
|
|
|
|
$$->push_back(*$1);
|
|
|
|
delete $1;
|
|
|
|
}
|
|
|
|
| ClassListNE ',' SubClassRef {
|
|
|
|
($$=$1)->push_back(*$3);
|
|
|
|
delete $3;
|
|
|
|
};
|
|
|
|
|
|
|
|
ClassList : /*empty */ {
|
|
|
|
$$ = new std::vector<SubClassRefTy>();
|
|
|
|
}
|
|
|
|
| ':' ClassListNE {
|
|
|
|
$$ = $2;
|
|
|
|
};
|
|
|
|
|
|
|
|
DeclListNE : Declaration {
|
|
|
|
CurRec->addTemplateArg(*$1);
|
|
|
|
delete $1;
|
|
|
|
} | DeclListNE ',' Declaration {
|
|
|
|
CurRec->addTemplateArg(*$3);
|
|
|
|
delete $3;
|
|
|
|
};
|
|
|
|
|
|
|
|
TemplateArgList : '<' DeclListNE '>' {};
|
|
|
|
OptTemplateArgList : /*empty*/ | TemplateArgList;
|
|
|
|
|
2003-07-30 04:26:44 +00:00
|
|
|
OptID : ID { $$ = $1; } | /*empty*/ { $$ = new std::string(); };
|
|
|
|
|
2005-09-30 04:10:49 +00:00
|
|
|
ObjectName : OptID {
|
|
|
|
static unsigned AnonCounter = 0;
|
|
|
|
if ($1->empty())
|
|
|
|
*$1 = "anonymous."+utostr(AnonCounter++);
|
2005-09-30 04:53:04 +00:00
|
|
|
$$ = $1;
|
2005-09-30 04:10:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ClassName : ObjectName {
|
2005-09-30 04:53:04 +00:00
|
|
|
// If a class of this name already exists, it must be a forward ref.
|
|
|
|
if ((CurRec = Records.getClass(*$1))) {
|
|
|
|
// If the body was previously defined, this is an error.
|
|
|
|
if (!CurRec->getValues().empty() ||
|
|
|
|
!CurRec->getSuperClasses().empty() ||
|
|
|
|
!CurRec->getTemplateArgs().empty()) {
|
|
|
|
err() << "Class '" << CurRec->getName() << "' already defined!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If this is the first reference to this class, create and add it.
|
|
|
|
CurRec = new Record(*$1);
|
|
|
|
Records.addClass(CurRec);
|
2005-09-30 04:10:49 +00:00
|
|
|
}
|
2005-09-30 04:53:04 +00:00
|
|
|
delete $1;
|
2005-09-30 04:10:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DefName : ObjectName {
|
2005-09-30 04:53:04 +00:00
|
|
|
CurRec = new Record(*$1);
|
|
|
|
delete $1;
|
|
|
|
|
2005-09-30 04:10:49 +00:00
|
|
|
// Ensure redefinition doesn't happen.
|
|
|
|
if (Records.getDef(CurRec->getName())) {
|
|
|
|
err() << "Def '" << CurRec->getName() << "' already defined!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
Records.addDef(CurRec);
|
|
|
|
};
|
|
|
|
|
2005-09-30 04:42:31 +00:00
|
|
|
ObjectBody : ClassList {
|
|
|
|
for (unsigned i = 0, e = $1->size(); i != e; ++i) {
|
|
|
|
addSubClass((*$1)[i].first, *(*$1)[i].second);
|
2003-07-30 04:56:05 +00:00
|
|
|
// Delete the template arg values for the class
|
2005-09-30 04:42:31 +00:00
|
|
|
delete (*$1)[i].second;
|
2003-07-30 04:56:05 +00:00
|
|
|
}
|
2005-09-30 04:42:31 +00:00
|
|
|
delete $1; // Delete the class list...
|
|
|
|
|
2005-09-08 18:22:35 +00:00
|
|
|
// Process any variables on the set stack...
|
|
|
|
for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
|
2003-08-04 04:56:53 +00:00
|
|
|
for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
|
|
|
|
setValue(LetStack[i][j].Name,
|
|
|
|
LetStack[i][j].HasBits ? &LetStack[i][j].Bits : 0,
|
|
|
|
LetStack[i][j].Value);
|
2002-12-02 01:23:04 +00:00
|
|
|
} Body {
|
2005-04-19 03:36:21 +00:00
|
|
|
$$ = CurRec;
|
|
|
|
CurRec = 0;
|
|
|
|
};
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2005-09-30 04:53:04 +00:00
|
|
|
ClassInst : CLASS ClassName {
|
|
|
|
ParsingTemplateArgs = true;
|
|
|
|
} OptTemplateArgList {
|
|
|
|
ParsingTemplateArgs = false;
|
|
|
|
} ObjectBody {
|
|
|
|
$$ = $6;
|
2005-09-30 04:42:31 +00:00
|
|
|
};
|
2002-12-02 01:23:04 +00:00
|
|
|
|
2005-09-30 04:10:49 +00:00
|
|
|
DefInst : DEF DefName ObjectBody {
|
|
|
|
$3->resolveReferences();
|
2005-04-19 03:36:21 +00:00
|
|
|
|
2005-09-08 18:48:23 +00:00
|
|
|
// If ObjectBody has template arguments, it's an error.
|
2005-09-30 04:42:31 +00:00
|
|
|
assert($3->getTemplateArgs().empty() && "How'd this get template args?");
|
2005-09-30 04:10:49 +00:00
|
|
|
$$ = $3;
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Object : ClassInst | DefInst;
|
|
|
|
|
2003-08-04 04:56:53 +00:00
|
|
|
LETItem : ID OptBitList '=' Value {
|
|
|
|
LetStack.back().push_back(LetRecord(*$1, $2, $4));
|
2003-08-03 13:58:01 +00:00
|
|
|
delete $1; delete $2;
|
2003-07-28 03:49:40 +00:00
|
|
|
};
|
|
|
|
|
2003-08-04 04:56:53 +00:00
|
|
|
LETList : LETItem | LETList ',' LETItem;
|
2003-08-03 13:58:01 +00:00
|
|
|
|
2003-08-04 04:56:53 +00:00
|
|
|
// LETCommand - A 'LET' statement start...
|
|
|
|
LETCommand : LET { LetStack.push_back(std::vector<LetRecord>()); } LETList IN;
|
2003-08-03 13:58:01 +00:00
|
|
|
|
2003-07-28 03:49:40 +00:00
|
|
|
// Support Set commands wrapping objects... both with and without braces.
|
2003-08-04 04:56:53 +00:00
|
|
|
Object : LETCommand '{' ObjectList '}' {
|
|
|
|
LetStack.pop_back();
|
2003-07-28 03:49:40 +00:00
|
|
|
}
|
2003-08-04 04:56:53 +00:00
|
|
|
| LETCommand Object {
|
|
|
|
LetStack.pop_back();
|
2002-12-02 01:23:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ObjectList : Object {} | ObjectList Object {};
|
|
|
|
|
|
|
|
File : ObjectList {};
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
int yyerror(const char *ErrorMsg) {
|
|
|
|
err() << "Error parsing: " << ErrorMsg << "\n";
|
2004-02-13 16:37:43 +00:00
|
|
|
exit(1);
|
2002-12-02 01:23:04 +00:00
|
|
|
}
|