[llvm-commits] [llvm] r44276 - in /llvm/trunk/utils/TableGen: Record.cpp Record.h
Chris Lattner
sabre at nondot.org
Thu Nov 22 13:05:25 PST 2007
Author: lattner
Date: Thu Nov 22 15:05:25 2007
New Revision: 44276
URL: http://llvm.org/viewvc/llvm-project?rev=44276&view=rev
Log:
change the Init print methods to return strings, and implement
print in terms of that.
Modified:
llvm/trunk/utils/TableGen/Record.cpp
llvm/trunk/utils/TableGen/Record.h
Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=44276&r1=44275&r2=44276&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Thu Nov 22 15:05:25 2007
@@ -244,20 +244,20 @@
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 @@
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 @@
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 @@
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;
- }
- OS << "(";
- LHS->print(OS);
- OS << ", ";
- RHS->print(OS);
- OS << ")";
+ 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;
+ }
+ return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
@@ -579,6 +580,9 @@
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 @@
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 @@
}
-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 @@
}
-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 + ")";
}
Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=44276&r1=44275&r2=44276&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Thu Nov 22 15:05:25 2007
@@ -429,7 +429,10 @@
virtual bool isComplete() const { return true; }
/// print - Print out this value.
- virtual void print(std::ostream &OS) const = 0;
+ void print(std::ostream &OS) const { OS << getAsString(); }
+
+ /// getAsString - Convert this value to a string form.
+ virtual std::string getAsString() const = 0;
/// dump - Debugging method that may be called through a debugger, just
/// invokes print on cerr.
@@ -497,7 +500,7 @@
}
virtual bool isComplete() const { return false; }
- virtual void print(std::ostream &OS) const { OS << "?"; }
+ virtual std::string getAsString() const { return "?"; }
};
@@ -514,7 +517,7 @@
return Ty->convertValue(this);
}
- virtual void print(std::ostream &OS) const { OS << (Value ? "1" : "0"); }
+ virtual std::string getAsString() const { return Value ? "1" : "0"; }
};
/// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
@@ -547,7 +550,7 @@
if (!getBit(i)->isComplete()) return false;
return true;
}
- virtual void print(std::ostream &OS) const;
+ virtual std::string getAsString() const;
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
@@ -573,7 +576,7 @@
}
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
- virtual void print(std::ostream &OS) const { OS << Value; }
+ virtual std::string getAsString() const;
};
@@ -590,7 +593,7 @@
return Ty->convertValue(this);
}
- virtual void print(std::ostream &OS) const { OS << "\"" << Value << "\""; }
+ virtual std::string getAsString() const { return "\"" + Value + "\""; }
};
/// CodeInit - "[{...}]" - Represent a code fragment.
@@ -606,7 +609,7 @@
return Ty->convertValue(this);
}
- virtual void print(std::ostream &OS) const { OS << "[{" << Value << "}]"; }
+ virtual std::string getAsString() const { return "[{" + Value + "}]"; }
};
/// ListInit - [AL, AH, CL] - Represent a list of defs
@@ -639,7 +642,7 @@
///
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
- virtual void print(std::ostream &OS) const;
+ virtual std::string getAsString() const;
};
/// BinOpInit - !op (X, Y) - Combine two inits.
@@ -668,7 +671,7 @@
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
- virtual void print(std::ostream &OS) const;
+ virtual std::string getAsString() const;
};
@@ -728,7 +731,7 @@
///
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
- virtual void print(std::ostream &OS) const { OS << VarName; }
+ virtual std::string getAsString() const { return VarName; }
};
@@ -751,9 +754,7 @@
TypedInit *getVariable() const { return TI; }
unsigned getBitNum() const { return Bit; }
- virtual void print(std::ostream &OS) const {
- TI->print(OS); OS << "{" << Bit << "}";
- }
+ virtual std::string getAsString() const;
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
};
@@ -786,9 +787,7 @@
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
unsigned Elt);
- virtual void print(std::ostream &OS) const {
- TI->print(OS); OS << "[" << Element << "]";
- }
+ virtual std::string getAsString() const;
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
};
@@ -810,7 +809,7 @@
virtual RecTy *getFieldType(const std::string &FieldName) const;
virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
- virtual void print(std::ostream &OS) const;
+ virtual std::string getAsString() const;
};
@@ -836,8 +835,8 @@
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
- virtual void print(std::ostream &OS) const {
- Rec->print(OS); OS << "." << FieldName;
+ virtual std::string getAsString() const {
+ return Rec->getAsString() + "." + FieldName;
}
};
@@ -887,7 +886,7 @@
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
- virtual void print(std::ostream &OS) const;
+ virtual std::string getAsString() const;
};
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list