|
21 | 21 | #include "llvm-dialects/TableGen/Format.h" |
22 | 22 | #include "llvm-dialects/TableGen/Predicates.h" |
23 | 23 |
|
| 24 | +#include "llvm/Support/Debug.h" |
24 | 25 | #include "llvm/TableGen/Record.h" |
25 | 26 |
|
26 | 27 | using namespace llvm; |
@@ -60,6 +61,16 @@ Variable *Scope::createVariable(StringRef name, Predicate *predicate) { |
60 | 61 | return variable; |
61 | 62 | } |
62 | 63 |
|
| 64 | +void ConstraintSystem::print(raw_ostream &out, StringRef prefix) const { |
| 65 | + for (const auto &constraintPtr : m_constraints) |
| 66 | + constraintPtr->print(out, prefix); |
| 67 | +} |
| 68 | + |
| 69 | +void ConstraintSystem::dump() const { |
| 70 | + dbgs() << "Constraint system:\n"; |
| 71 | + print(dbgs(), " "); |
| 72 | +} |
| 73 | + |
63 | 74 | bool ConstraintSystem::addConstraint(raw_ostream &errs, Init *init, |
64 | 75 | Variable *self) { |
65 | 76 | if (!addConstraintImpl(errs, init, self)) { |
@@ -232,11 +243,48 @@ std::string Constraint::toString() const { |
232 | 243 | return (Twine(m_init->getAsString()) + ":" + m_self->toString()).str(); |
233 | 244 | } |
234 | 245 |
|
| 246 | +void Constraint::printVariables(raw_ostream &out) const { |
| 247 | + bool isFirst = true; |
| 248 | + for (const Variable *var : m_variables) { |
| 249 | + if (!isFirst) |
| 250 | + out << ", "; |
| 251 | + out << var->toString(); |
| 252 | + isFirst = false; |
| 253 | + } |
| 254 | +} |
| 255 | + |
235 | 256 | void Constraint::addVariable(Variable *variable) { |
236 | 257 | if (!llvm::is_contained(m_variables, variable)) |
237 | 258 | m_variables.push_back(variable); |
238 | 259 | } |
239 | 260 |
|
| 261 | +void Apply::print(raw_ostream &out, StringRef prefix) const { |
| 262 | + out << prefix << "apply " << m_predicate->getInit()->getAsString() << ": "; |
| 263 | + bool isFirst = true; |
| 264 | + for (Variable *var : m_arguments) { |
| 265 | + if (!isFirst) |
| 266 | + out << ", "; |
| 267 | + if (var) |
| 268 | + out << var->toString(); |
| 269 | + else |
| 270 | + out << "(null)"; |
| 271 | + isFirst = false; |
| 272 | + } |
| 273 | + out << '\n'; |
| 274 | + |
| 275 | + out << prefix << " free variables: "; |
| 276 | + printVariables(out); |
| 277 | + out << '\n'; |
| 278 | +} |
| 279 | + |
| 280 | +void LogicOr::print(raw_ostream &out, StringRef prefix) const { |
| 281 | + out << prefix << "or, free variables: "; |
| 282 | + printVariables(out); |
| 283 | + out << '\n'; |
| 284 | + for (const auto &branch : m_branches) |
| 285 | + branch.print(out, (Twine(prefix) + " ").str()); |
| 286 | +} |
| 287 | + |
240 | 288 | MetaType *MetaType::type() { |
241 | 289 | static MetaType typeMetaType(Kind::Type); |
242 | 290 | return &typeMetaType; |
|
0 commit comments