| 393 | } |
| 394 | |
| 395 | void instruction::print(std::ostream& os, |
| 396 | instruction_ref ins, |
| 397 | const std::unordered_map<instruction_ref, std::string>& names) |
| 398 | { |
| 399 | os << names.at(ins) << " = "; |
| 400 | |
| 401 | os << ins->get_operator(); |
| 402 | |
| 403 | if(ins->name() == "@literal") |
| 404 | { |
| 405 | if(ins->get_literal().get_shape().elements() > 10) |
| 406 | os << "{ ... }"; |
| 407 | else |
| 408 | os << "{" << ins->get_literal() << "}"; |
| 409 | } |
| 410 | |
| 411 | if(not ins->inputs().empty()) |
| 412 | { |
| 413 | char delim = '('; |
| 414 | for(auto&& arg : ins->inputs()) |
| 415 | { |
| 416 | std::string arg_name = contains(names, arg) ? names.at(arg) : "?"; |
| 417 | os << delim << arg_name; |
| 418 | delim = ','; |
| 419 | } |
| 420 | os << ")"; |
| 421 | } |
| 422 | |
| 423 | // print module inputs |
| 424 | if(not ins->module_inputs().empty()) |
| 425 | { |
| 426 | std::string delim = ", ["; |
| 427 | for(const const_module_ref& mod_arg : ins->module_inputs()) |
| 428 | { |
| 429 | os << delim << mod_arg->name(); |
| 430 | delim = ", "; |
| 431 | } |
| 432 | os << "]"; |
| 433 | } |
| 434 | |
| 435 | // skip return instruction shape |
| 436 | if(ins->name() != "@return") |
| 437 | os << " -> " << ins->get_shape(); |
| 438 | |
| 439 | // print tid |
| 440 | if(ins->target_id != 0) |
| 441 | os << ", target_id=" << ins->target_id; |
| 442 | } |
| 443 | |
| 444 | static void debug_name(std::ostream& os, const instruction& ins) |
| 445 | { |