aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2009-05-14 21:22:49 +0000
committerDavid Greene <greened@obbligato.org>2009-05-14 21:22:49 +0000
commite6c27de069225e1122c78385ad22a2ff656db8e6 (patch)
treebf1ff9c77caee5b28119d5760b34a6fd530023ed /utils
parentd418c1b768b5ff26afe05a5ce84d920bbbc99583 (diff)
downloadexternal_llvm-e6c27de069225e1122c78385ad22a2ff656db8e6.zip
external_llvm-e6c27de069225e1122c78385ad22a2ff656db8e6.tar.gz
external_llvm-e6c27de069225e1122c78385ad22a2ff656db8e6.tar.bz2
Implement !cast.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71794 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/Record.cpp162
-rw-r--r--utils/TableGen/Record.h80
-rw-r--r--utils/TableGen/TGLexer.cpp2
-rw-r--r--utils/TableGen/TGLexer.h2
-rw-r--r--utils/TableGen/TGParser.cpp62
5 files changed, 154 insertions, 154 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 0f31861..2a8ddaa 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -132,17 +132,17 @@ Init *IntRecTy::convertValue(TypedInit *TI) {
return 0;
}
-// Init *StringRecTy::convertValue(UnOpInit *BO) {
-// if (BO->getOpcode() == UnOpInit::CAST) {
-// Init *L = BO->getOperand()->convertInitializerTo(this);
-// if (L == 0) return 0;
-// if (L != BO->getOperand())
-// return new UnOpInit(UnOpInit::CAST, L, new StringRecTy);
-// return BO;
-// }
+Init *StringRecTy::convertValue(UnOpInit *BO) {
+ if (BO->getOpcode() == UnOpInit::CAST) {
+ Init *L = BO->getOperand()->convertInitializerTo(this);
+ if (L == 0) return 0;
+ if (L != BO->getOperand())
+ return new UnOpInit(UnOpInit::CAST, L, new StringRecTy);
+ return BO;
+ }
-// return convertValue((TypedInit*)BO);
-// }
+ return convertValue((TypedInit*)BO);
+}
Init *StringRecTy::convertValue(BinOpInit *BO) {
if (BO->getOpcode() == BinOpInit::STRCONCAT) {
@@ -212,16 +212,16 @@ Init *DagRecTy::convertValue(TypedInit *TI) {
return 0;
}
-// Init *DagRecTy::convertValue(UnOpInit *BO) {
-// if (BO->getOpcode() == UnOpInit::CAST) {
-// Init *L = BO->getOperand()->convertInitializerTo(this);
-// if (L == 0) return 0;
-// if (L != BO->getOperand())
-// return new UnOpInit(UnOpInit::CAST, L, new DagRecTy);
-// return BO;
-// }
-// return 0;
-// }
+Init *DagRecTy::convertValue(UnOpInit *BO) {
+ if (BO->getOpcode() == UnOpInit::CAST) {
+ Init *L = BO->getOperand()->convertInitializerTo(this);
+ if (L == 0) return 0;
+ if (L != BO->getOperand())
+ return new UnOpInit(UnOpInit::CAST, L, new DagRecTy);
+ return BO;
+ }
+ return 0;
+}
Init *DagRecTy::convertValue(BinOpInit *BO) {
if (BO->getOpcode() == BinOpInit::CONCAT) {
@@ -467,78 +467,78 @@ Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
return 0;
}
-// Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
-// switch (getOpcode()) {
-// default: assert(0 && "Unknown unop");
-// case CAST: {
-// StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
-// if (LHSs) {
-// std::string Name = LHSs->getValue();
-
-// // From TGParser::ParseIDValue
-// if (CurRec) {
-// if (const RecordVal *RV = CurRec->getValue(Name)) {
-// if (RV->getType() != getType()) {
-// throw "type mismatch in nameconcat";
-// }
-// return new VarInit(Name, RV->getType());
-// }
+Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
+ switch (getOpcode()) {
+ default: assert(0 && "Unknown unop");
+ case CAST: {
+ StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
+ if (LHSs) {
+ std::string Name = LHSs->getValue();
+
+ // From TGParser::ParseIDValue
+ if (CurRec) {
+ if (const RecordVal *RV = CurRec->getValue(Name)) {
+ if (RV->getType() != getType()) {
+ throw "type mismatch in nameconcat";
+ }
+ return new VarInit(Name, RV->getType());
+ }
-// std::string TemplateArgName = CurRec->getName()+":"+Name;
-// if (CurRec->isTemplateArg(TemplateArgName)) {
-// const RecordVal *RV = CurRec->getValue(TemplateArgName);
-// assert(RV && "Template arg doesn't exist??");
+ std::string TemplateArgName = CurRec->getName()+":"+Name;
+ if (CurRec->isTemplateArg(TemplateArgName)) {
+ const RecordVal *RV = CurRec->getValue(TemplateArgName);
+ assert(RV && "Template arg doesn't exist??");
-// if (RV->getType() != getType()) {
-// throw "type mismatch in nameconcat";
-// }
+ if (RV->getType() != getType()) {
+ throw "type mismatch in nameconcat";
+ }
-// return new VarInit(TemplateArgName, RV->getType());
-// }
-// }
+ return new VarInit(TemplateArgName, RV->getType());
+ }
+ }
-// if (CurMultiClass) {
-// std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
-// if (CurMultiClass->Rec.isTemplateArg(MCName)) {
-// const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
-// assert(RV && "Template arg doesn't exist??");
+ if (CurMultiClass) {
+ std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
+ if (CurMultiClass->Rec.isTemplateArg(MCName)) {
+ const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
+ assert(RV && "Template arg doesn't exist??");
-// if (RV->getType() != getType()) {
-// throw "type mismatch in nameconcat";
-// }
+ if (RV->getType() != getType()) {
+ throw "type mismatch in nameconcat";
+ }
-// return new VarInit(MCName, RV->getType());
-// }
-// }
+ return new VarInit(MCName, RV->getType());
+ }
+ }
-// if (Record *D = Records.getDef(Name))
-// return new DefInit(D);
+ if (Record *D = Records.getDef(Name))
+ return new DefInit(D);
-// cerr << "Variable not defined: '" + Name + "'\n";
-// assert(0 && "Variable not found");
-// return 0;
-// }
-// break;
-// }
-// }
-// return this;
-// }
+ cerr << "Variable not defined: '" + Name + "'\n";
+ assert(0 && "Variable not found");
+ return 0;
+ }
+ break;
+ }
+ }
+ return this;
+}
-// Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) {
-// Init *lhs = LHS->resolveReferences(R, RV);
+Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) {
+ Init *lhs = LHS->resolveReferences(R, RV);
-// if (LHS != lhs)
-// return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
-// return Fold(&R, 0);
-// }
+ if (LHS != lhs)
+ return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
+ return Fold(&R, 0);
+}
-// std::string UnOpInit::getAsString() const {
-// std::string Result;
-// switch (Opc) {
-// case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
-// }
-// return Result + "(" + LHS->getAsString() + ")";
-// }
+std::string UnOpInit::getAsString() const {
+ std::string Result;
+ switch (Opc) {
+ case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
+ }
+ return Result + "(" + LHS->getAsString() + ")";
+}
Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
switch (getOpcode()) {
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index b0b4ac1..a81b056 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -41,7 +41,7 @@ class IntInit;
class StringInit;
class CodeInit;
class ListInit;
- //class UnOpInit;
+class UnOpInit;
class BinOpInit;
//class TernOpInit;
class DefInit;
@@ -79,9 +79,9 @@ public: // These methods should only be called from subclasses of Init
virtual Init *convertValue( IntInit *II) { return 0; }
virtual Init *convertValue(StringInit *SI) { return 0; }
virtual Init *convertValue( ListInit *LI) { return 0; }
-// virtual Init *convertValue( UnOpInit *UI) {
-// return convertValue((TypedInit*)UI);
-// }
+ virtual Init *convertValue( UnOpInit *UI) {
+ return convertValue((TypedInit*)UI);
+ }
virtual Init *convertValue( BinOpInit *UI) {
return convertValue((TypedInit*)UI);
}
@@ -133,7 +133,7 @@ public:
virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
virtual Init *convertValue( DefInit *DI) { return 0; }
virtual Init *convertValue( DagInit *DI) { return 0; }
- // virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
+ virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
//virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( TypedInit *TI);
@@ -177,7 +177,7 @@ public:
virtual Init *convertValue(VarBitInit *VB) { return 0; }
virtual Init *convertValue( DefInit *DI) { return 0; }
virtual Init *convertValue( DagInit *DI) { return 0; }
- //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
+ virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
//virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( TypedInit *TI);
@@ -217,7 +217,7 @@ public:
virtual Init *convertValue(VarBitInit *VB) { return 0; }
virtual Init *convertValue( DefInit *DI) { return 0; }
virtual Init *convertValue( DagInit *DI) { return 0; }
- //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
+ virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
//virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( TypedInit *TI);
@@ -251,7 +251,7 @@ public:
virtual Init *convertValue( IntInit *II) { return 0; }
virtual Init *convertValue(StringInit *SI) { return (Init*)SI; }
virtual Init *convertValue( ListInit *LI) { return 0; }
- //virtual Init *convertValue( UnOpInit *BO);
+ virtual Init *convertValue( UnOpInit *BO);
virtual Init *convertValue( BinOpInit *BO);
//virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
@@ -301,7 +301,7 @@ public:
virtual Init *convertValue(VarBitInit *VB) { return 0; }
virtual Init *convertValue( DefInit *DI) { return 0; }
virtual Init *convertValue( DagInit *DI) { return 0; }
- //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
+ virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
//virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( TypedInit *TI);
@@ -340,7 +340,7 @@ public:
virtual Init *convertValue(VarBitInit *VB) { return 0; }
virtual Init *convertValue( DefInit *DI) { return 0; }
virtual Init *convertValue( DagInit *DI) { return 0; }
- //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
+ virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
//virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( TypedInit *TI);
@@ -375,7 +375,7 @@ public:
virtual Init *convertValue( CodeInit *CI) { return 0; }
virtual Init *convertValue(VarBitInit *VB) { return 0; }
virtual Init *convertValue( DefInit *DI) { return 0; }
- //virtual Init *convertValue( UnOpInit *BO);
+ virtual Init *convertValue( UnOpInit *BO);
virtual Init *convertValue( BinOpInit *BO);
//virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
virtual Init *convertValue( DagInit *CI) { return (Init*)CI; }
@@ -418,7 +418,7 @@ public:
virtual Init *convertValue( ListInit *LI) { return 0; }
virtual Init *convertValue( CodeInit *CI) { return 0; }
virtual Init *convertValue(VarBitInit *VB) { return 0; }
- //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
+ virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
//virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
virtual Init *convertValue( DefInit *DI);
@@ -740,40 +740,40 @@ public:
/// UnOpInit - !op (X) - Transform an init.
///
-// class UnOpInit : public OpInit {
-// public:
-// enum UnaryOp { CAST };
-// private:
-// UnaryOp Opc;
-// Init *LHS;
-// public:
-// UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) :
-// OpInit(Type), Opc(opc), LHS(lhs) {
-// }
+class UnOpInit : public OpInit {
+public:
+ enum UnaryOp { CAST };
+private:
+ UnaryOp Opc;
+ Init *LHS;
+public:
+ UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) :
+ OpInit(Type), Opc(opc), LHS(lhs) {
+ }
-// // Clone - Clone this operator, replacing arguments with the new list
-// virtual OpInit *clone(std::vector<Init *> &Operands) {
-// assert(Operands.size() == 1 && "Wrong number of operands for unary operation");
-// return new UnOpInit(getOpcode(), *Operands.begin(), getType());
-// }
+ // Clone - Clone this operator, replacing arguments with the new list
+ virtual OpInit *clone(std::vector<Init *> &Operands) {
+ assert(Operands.size() == 1 && "Wrong number of operands for unary operation");
+ return new UnOpInit(getOpcode(), *Operands.begin(), getType());
+ }
-// int getNumOperands(void) const { return 1; }
-// Init *getOperand(int i) {
-// assert(i == 0 && "Invalid operand id for unary operator");
-// return getOperand();
-// }
+ int getNumOperands(void) const { return 1; }
+ Init *getOperand(int i) {
+ assert(i == 0 && "Invalid operand id for unary operator");
+ return getOperand();
+ }
-// UnaryOp getOpcode() const { return Opc; }
-// Init *getOperand() const { return LHS; }
+ UnaryOp getOpcode() const { return Opc; }
+ Init *getOperand() const { return LHS; }
-// // Fold - If possible, fold this to a simpler init. Return this if not
-// // possible to fold.
-// Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
+ // Fold - If possible, fold this to a simpler init. Return this if not
+ // possible to fold.
+ Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
-// virtual Init *resolveReferences(Record &R, const RecordVal *RV);
+ virtual Init *resolveReferences(Record &R, const RecordVal *RV);
-// virtual std::string getAsString() const;
-// };
+ virtual std::string getAsString() const;
+};
/// BinOpInit - !op (X, Y) - Combine two inits.
///
diff --git a/utils/TableGen/TGLexer.cpp b/utils/TableGen/TGLexer.cpp
index 5e96e50..43afae9 100644
--- a/utils/TableGen/TGLexer.cpp
+++ b/utils/TableGen/TGLexer.cpp
@@ -449,7 +449,7 @@ tgtok::TokKind TGLexer::LexExclaim() {
if (Len == 10 && !memcmp(Start, "nameconcat", 10)) return tgtok::XNameConcat;
// if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
// if (Len == 7 && !memcmp(Start, "foreach", 7)) return tgtok::XForEach;
-// if (Len == 4 && !memcmp(Start, "cast", 4)) return tgtok::XCast;
+ if (Len == 4 && !memcmp(Start, "cast", 4)) return tgtok::XCast;
return ReturnError(Start-1, "Unknown operator");
}
diff --git a/utils/TableGen/TGLexer.h b/utils/TableGen/TGLexer.h
index 0f27308..b95ca95 100644
--- a/utils/TableGen/TGLexer.h
+++ b/utils/TableGen/TGLexer.h
@@ -45,7 +45,7 @@ namespace tgtok {
MultiClass, String,
// !keywords.
- XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, //XSubst, XCast,
+ XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, XCast, // XSubst,
//XForEach,
// Integer value.
diff --git a/utils/TableGen/TGParser.cpp b/utils/TableGen/TGParser.cpp
index da2a530..6b4c431 100644
--- a/utils/TableGen/TGParser.cpp
+++ b/utils/TableGen/TGParser.cpp
@@ -680,41 +680,41 @@ Init *TGParser::ParseOperation(Record *CurRec) {
TokError("unknown operation");
return 0;
break;
-// case tgtok::XCast: { // Value ::= !unop '(' Value ')'
-// UnOpInit::UnaryOp Code;
-// RecTy *Type = 0;
+ case tgtok::XCast: { // Value ::= !unop '(' Value ')'
+ UnOpInit::UnaryOp Code;
+ RecTy *Type = 0;
-// switch (Lex.getCode()) {
-// default: assert(0 && "Unhandled code!");
-// case tgtok::XCast:
-// Lex.Lex(); // eat the operation
-// Code = UnOpInit::CAST;
+ switch (Lex.getCode()) {
+ default: assert(0 && "Unhandled code!");
+ case tgtok::XCast:
+ Lex.Lex(); // eat the operation
+ Code = UnOpInit::CAST;
-// Type = ParseOperatorType();
+ Type = ParseOperatorType();
-// if (Type == 0) {
-// TokError("did not get type for binary operator");
-// return 0;
-// }
+ if (Type == 0) {
+ TokError("did not get type for binary operator");
+ return 0;
+ }
-// break;
-// }
-// if (Lex.getCode() != tgtok::l_paren) {
-// TokError("expected '(' after unary operator");
-// return 0;
-// }
-// Lex.Lex(); // eat the '('
+ break;
+ }
+ if (Lex.getCode() != tgtok::l_paren) {
+ TokError("expected '(' after unary operator");
+ return 0;
+ }
+ Lex.Lex(); // eat the '('
-// Init *LHS = ParseValue(CurRec);
-// if (LHS == 0) return 0;
+ Init *LHS = ParseValue(CurRec);
+ if (LHS == 0) return 0;
-// if (Lex.getCode() != tgtok::r_paren) {
-// TokError("expected ')' in unary operator");
-// return 0;
-// }
-// Lex.Lex(); // eat the ')'
-// return (new UnOpInit(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
-// }
+ if (Lex.getCode() != tgtok::r_paren) {
+ TokError("expected ')' in unary operator");
+ return 0;
+ }
+ Lex.Lex(); // eat the ')'
+ return (new UnOpInit(Code, LHS, Type))->Fold(CurRec, CurMultiClass);
+ }
case tgtok::XConcat:
case tgtok::XSRA:
@@ -1029,7 +1029,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')'
Lex.Lex(); // eat the '('
if (Lex.getCode() != tgtok::Id
- // && Lex.getCode() != tgtok::XCast
+ && Lex.getCode() != tgtok::XCast
&& Lex.getCode() != tgtok::XNameConcat) {
TokError("expected identifier in dag init");
return 0;
@@ -1072,7 +1072,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
break;
}
- // case tgtok::XCast: // Value ::= !unop '(' Value ')'
+ case tgtok::XCast: // Value ::= !unop '(' Value ')'
case tgtok::XConcat:
case tgtok::XSRA:
case tgtok::XSRL: