#include "Record.h"
#include "llvm/Support/DataTypes.h"
+#include <ios>
+
using namespace llvm;
//===----------------------------------------------------------------------===//
if (Value & ~((1LL << Size)-1))
return 0;
} else {
- if ((Value >> Size) != -1 || ((Value & (1 << (Size-1))) == 0))
+ if ((Value >> Size) != -1 || ((Value & (1LL << (Size-1))) == 0))
return 0;
}
BitsInit *Ret = new BitsInit(Size);
for (unsigned i = 0; i != Size; ++i)
- Ret->setBit(i, new BitInit(Value & (1 << i)));
+ Ret->setBit(i, new BitInit(Value & (1LL << i)));
return Ret;
}
return this;
}
+Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
+ std::vector<Init*> NewArgs;
+ for (unsigned i = 0, e = Args.size(); i != e; ++i)
+ NewArgs.push_back(Args[i]->resolveReferences(R, RV));
+
+ if (Args != NewArgs)
+ return new DagInit(NodeTypeDef, NewArgs, ArgNames);
+
+ return this;
+}
+
void DagInit::print(std::ostream &OS) const {
OS << "(" << NodeTypeDef->getName();
"' does not have a list initializer!";
}
+/// getValueAsListOfDefs - This method looks up the specified field and returns
+/// its value as a vector of records, throwing an exception if the field does
+/// not exist or if the value is not the right type.
+///
+std::vector<Record*>
+Record::getValueAsListOfDefs(const std::string &FieldName) const {
+ ListInit *List = getValueAsListInit(FieldName);
+ std::vector<Record*> Defs;
+ for (unsigned i = 0; i < List->getSize(); i++) {
+ if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
+ Defs.push_back(DI->getDef());
+ } else {
+ throw "Record `" + getName() + "', field `" + FieldName +
+ "' list is not entirely DefInit!";
+ }
+ }
+ return Defs;
+}
+
/// getValueAsInt - This method looks up the specified field and returns its
/// value as an int, throwing an exception if the field does not exist or if
/// the value is not the right type.
if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
return II->getValue();
throw "Record `" + getName() + "', field `" + FieldName +
- "' does not have a list initializer!";
+ "' does not have an int initializer!";
}
/// getValueAsDef - This method looks up the specified field and returns its
if (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
return DI->getDef();
throw "Record `" + getName() + "', field `" + FieldName +
- "' does not have a list initializer!";
+ "' does not have a def initializer!";
}
/// getValueAsBit - This method looks up the specified field and returns its
"' does not have a dag initializer!";
}
+std::string Record::getValueAsCode(const std::string &FieldName) const {
+ const RecordVal *R = getValue(FieldName);
+ if (R == 0 || R->getValue() == 0)
+ throw "Record `" + getName() + "' does not have a field named `" +
+ FieldName + "'!\n";
+
+ if (const CodeInit *CI = dynamic_cast<const CodeInit*>(R->getValue()))
+ return CI->getValue();
+ throw "Record `" + getName() + "', field `" + FieldName +
+ "' does not have a code initializer!";
+}
+
void RecordKeeper::dump() const { std::cerr << *this; }