summaryrefslogtreecommitdiff
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-22 21:05:25 +0000
committerChris Lattner <sabre@nondot.org>2007-11-22 21:05:25 +0000
commit3aba4d39fd101238ac06871895c28f26736d80cb (patch)
treef80250cad02f099997f5277ee8f3b877bcc03edb /utils/TableGen/Record.cpp
parentbf8644ca1fb960e94d14428adbab8277679e2a9d (diff)
downloadllvm-3aba4d39fd101238ac06871895c28f26736d80cb.tar.gz
llvm-3aba4d39fd101238ac06871895c28f26736d80cb.tar.bz2
llvm-3aba4d39fd101238ac06871895c28f26736d80cb.tar.xz
change the Init print methods to return strings, and implement
print in terms of that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44276 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp70
1 files changed, 39 insertions, 31 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 9d14bc051f..4066f3a88a 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -244,20 +244,20 @@ Init *BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
return BI;
}
-void BitsInit::print(std::ostream &OS) const {
+std::string BitsInit::getAsString() const {
//if (!printInHex(OS)) return;
//if (!printAsVariable(OS)) return;
//if (!printAsUnset(OS)) return;
- OS << "{ ";
+ std::string Result = "{ ";
for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
- if (i) OS << ", ";
+ if (i) Result += ", ";
if (Init *Bit = getBit(e-i-1))
- Bit->print(OS);
+ Result += Bit->getAsString();
else
- OS << "*";
+ Result += "*";
}
- OS << " }";
+ return Result + " }";
}
bool BitsInit::printInHex(std::ostream &OS) const {
@@ -330,6 +330,10 @@ Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) {
return this;
}
+std::string IntInit::getAsString() const {
+ return itostr(Value);
+}
+
Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
BitsInit *BI = new BitsInit(Bits.size());
@@ -382,13 +386,13 @@ Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) {
return this;
}
-void ListInit::print(std::ostream &OS) const {
- OS << "[";
+std::string ListInit::getAsString() const {
+ std::string Result = "[";
for (unsigned i = 0, e = Values.size(); i != e; ++i) {
- if (i) OS << ", ";
- OS << *Values[i];
+ if (i) Result += ", ";
+ Result += Values[i]->getAsString();
}
- OS << "]";
+ return Result + "]";
}
Init *BinOpInit::Fold() {
@@ -464,19 +468,16 @@ Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) {
return Fold();
}
-void BinOpInit::print(std::ostream &OS) const {
+std::string BinOpInit::getAsString() const {
+ std::string Result;
switch (Opc) {
- case CONCAT: OS << "!con"; break;
- case SHL: OS << "!shl"; break;
- case SRA: OS << "!sra"; break;
- case SRL: OS << "!srl"; break;
- case STRCONCAT: OS << "!strconcat"; break;
+ case CONCAT: Result = "!con"; break;
+ case SHL: Result = "!shl"; break;
+ case SRA: Result = "!sra"; break;
+ case SRL: Result = "!srl"; break;
+ case STRCONCAT: Result = "!strconcat"; break;
}
- OS << "(";
- LHS->print(OS);
- OS << ", ";
- RHS->print(OS);
- OS << ")";
+ return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
@@ -579,6 +580,9 @@ Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) {
return this;
}
+std::string VarBitInit::getAsString() const {
+ return TI->getAsString() + "{" + utostr(Bit) + "}";
+}
Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) {
if (Init *I = getVariable()->resolveBitReference(R, RV, getBitNum()))
@@ -586,6 +590,10 @@ Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) {
return this;
}
+std::string VarListElementInit::getAsString() const {
+ return TI->getAsString() + "[" + utostr(Element) + "]";
+}
+
Init *VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) {
if (Init *I = getVariable()->resolveListElementReference(R, RV,
getElementNum()))
@@ -618,8 +626,8 @@ Init *DefInit::getFieldInit(Record &R, const std::string &FieldName) const {
}
-void DefInit::print(std::ostream &OS) const {
- OS << Def->getName();
+std::string DefInit::getAsString() const {
+ return Def->getName();
}
Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
@@ -679,17 +687,17 @@ Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
}
-void DagInit::print(std::ostream &OS) const {
- OS << "(" << *Val;
+std::string DagInit::getAsString() const {
+ std::string Result = "(" + Val->getAsString();
if (Args.size()) {
- OS << " " << *Args[0];
- if (!ArgNames[0].empty()) OS << ":$" << ArgNames[0];
+ Result += " " + Args[0]->getAsString();
+ if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
- OS << ", " << *Args[i];
- if (!ArgNames[i].empty()) OS << ":$" << ArgNames[i];
+ Result += ", " + Args[i]->getAsString();
+ if (!ArgNames[i].empty()) Result += ":$" + ArgNames[i];
}
}
- OS << ")";
+ return Result + ")";
}