116 std::shared_ptr<DAGNode> actualRoot = root;
119 static std::unordered_map<NODE_KIND, const char *> kind_cache;
120 static bool cache_initialized =
false;
122 if (!cache_initialized) {
152 cache_initialized =
true;
161 WorkItem(
DAGNode *n, uint8_t a = 0) : node(n), action(a) {}
165 WorkItem(
const std::string &t, uint8_t a = 4)
166 : node(
nullptr), action(a), text(t) {}
170 std::vector<WorkItem> work_stack;
171 work_stack.reserve(65536);
172 work_stack.emplace_back(actualRoot.get(), 0);
173 while (!work_stack.empty()) {
174 WorkItem item = work_stack.back();
175 work_stack.pop_back();
179 if (item.action == 1) {
183 if (item.action == 2) {
187 if (item.action == 3) {
191 if (item.action == 4) {
211 if (node->
getName() ==
"(fp_bit_representation)" &&
213 auto sign = node->
getChild(0).get();
215 auto mant = node->
getChild(2).get();
217 work_stack.emplace_back(
nullptr, 2);
218 work_stack.emplace_back(mant, 0);
219 work_stack.emplace_back(
nullptr, 1);
220 work_stack.emplace_back(exp, 0);
221 work_stack.emplace_back(
nullptr, 1);
222 work_stack.emplace_back(sign, 0);
234 out <<
"((as const ";
235 out << node->
getSort()->toString();
237 work_stack.emplace_back(
nullptr, 2);
238 work_stack.emplace_back(node->
getChild(0).get(), 0);
253 auto child0 = node->
getChild(0).get();
254 auto child1 = node->
getChild(1).get();
256 const char *op = kind_cache[kind];
257 out <<
"(" << op <<
" ";
260 work_stack.emplace_back(
nullptr, 2);
261 work_stack.emplace_back(child1, 0);
262 work_stack.emplace_back(
nullptr, 1);
263 work_stack.emplace_back(child0, 0);
273 const char *op = kind_cache[kind];
281 work_stack.emplace_back(
nullptr, 2);
284 for (
int i = children.size() - 1; i >= 0; i--) {
285 auto child = children[i].get();
286 work_stack.emplace_back(child, 0);
287 work_stack.emplace_back(
nullptr, 1);
293 auto child0 = node->
getChild(0).get();
294 auto child1 = node->
getChild(1).get();
295 auto child2 = node->
getChild(2).get();
297 out <<
"((_ re.loop ";
300 work_stack.emplace_back(
nullptr, 2);
301 work_stack.emplace_back(child0, 0);
302 work_stack.emplace_back(
nullptr, 3);
303 work_stack.emplace_back(child2, 0);
304 work_stack.emplace_back(
nullptr, 1);
305 work_stack.emplace_back(child1, 0);
311 auto child = node->
getChild(0).get();
312 const char *op = kind_cache[kind];
314 out <<
"(" << op <<
" ";
315 work_stack.emplace_back(
nullptr, 2);
316 work_stack.emplace_back(child, 0);
322 auto child0 = node->
getChild(0).get();
323 auto child1 = node->
getChild(1).get();
324 auto child2 = node->
getChild(2).get();
327 work_stack.emplace_back(
nullptr, 2);
328 work_stack.emplace_back(child2, 0);
329 work_stack.emplace_back(
nullptr, 1);
330 work_stack.emplace_back(child1, 0);
331 work_stack.emplace_back(
nullptr, 1);
332 work_stack.emplace_back(child0, 0);
338 auto child0 = node->
getChild(0).get();
339 auto child1 = node->
getChild(1).get();
340 auto child2 = node->
getChild(2).get();
342 out <<
"((_ extract ";
343 work_stack.emplace_back(
nullptr, 2);
344 work_stack.emplace_back(child0, 0);
345 work_stack.emplace_back(
nullptr, 3);
346 work_stack.emplace_back(child2, 0);
347 work_stack.emplace_back(
nullptr, 1);
348 work_stack.emplace_back(child1, 0);
357 auto child0 = node->
getChild(0).get();
358 auto child1 = node->
getChild(1).get();
361 work_stack.emplace_back(
nullptr, 2);
362 work_stack.emplace_back(child0, 0);
363 work_stack.emplace_back(
nullptr, 3);
364 work_stack.emplace_back(child1, 0);
369 auto child0 = node->
getChild(0).get();
371 out <<
"((_ is " << node->
getName() <<
") ";
372 work_stack.emplace_back(
nullptr, 2);
373 if (child0->isLetBindVar()) {
374 work_stack.emplace_back(child0->getChild(0)->getChild(0).get(), 0);
377 work_stack.emplace_back(child0->getChild(0).get(), 0);
383 auto child0 = node->
getChild(0).get();
384 auto child1 = node->
getChild(1).get();
386 out <<
"((_ update " << node->
getName() <<
") ";
387 work_stack.emplace_back(
nullptr, 2);
388 work_stack.emplace_back(child1, 0);
389 work_stack.emplace_back(
nullptr, 1);
390 work_stack.emplace_back(child0, 0);
397 out <<
"((_ tuple.select ";
398 work_stack.emplace_back(
nullptr, 2);
399 work_stack.emplace_back(t, 0);
400 work_stack.emplace_back(
nullptr, 3);
401 work_stack.emplace_back(idx, 0);
408 out <<
"((_ tuple.update ";
409 work_stack.emplace_back(
nullptr, 2);
410 work_stack.emplace_back(val, 0);
411 work_stack.emplace_back(
nullptr, 1);
412 work_stack.emplace_back(t, 0);
413 work_stack.emplace_back(
nullptr, 3);
414 work_stack.emplace_back(idx, 0);
419 out <<
"((_ tuple.project ";
420 work_stack.emplace_back(
nullptr, 2);
423 work_stack.emplace_back(t, 0);
424 work_stack.emplace_back(
nullptr, 3);
426 for (
int i =
static_cast<int>(node->
getChildrenSize()) - 1; i >= 1; --i) {
428 work_stack.emplace_back(idx, 0);
430 work_stack.emplace_back(
nullptr, 1);
437 work_stack.emplace_back(
nullptr, 2);
438 for (
int i =
static_cast<int>(node->
getChildrenSize()) - 1; i >= 0; --i) {
439 work_stack.emplace_back(node->
getChild(i).get(), 0);
440 work_stack.emplace_back(
nullptr, 1);
520 auto current_child = node->
getChild(i).get();
522 out <<
"(" << current_child->getName() <<
" "
523 << current_child->getSort()->toString() <<
")";
526 out <<
" (" << current_child->getName() <<
" "
527 << current_child->getSort()->toString() <<
")";
531 work_stack.emplace_back(
nullptr, 2);
532 work_stack.emplace_back(node->
getChild(0).get(), 0);
558 work_stack.emplace_back(
nullptr, 2);
560 auto current_child = node->
getChild(i).get();
561 work_stack.emplace_back(current_child, 0);
562 work_stack.emplace_back(
nullptr, 1);
571 if (children.empty()) {
576 work_stack.emplace_back(
nullptr, 2);
577 for (
int i = children.size() - 1; i >= 0; --i) {
578 auto current_child = children[i].get();
579 if (current_child->isLetBindVar()) {
580 work_stack.emplace_back(
")", 4);
582 work_stack.emplace_back(current_child, 0);
583 if (current_child->isLetBindVar()) {
584 work_stack.emplace_back(
"(", 4);
587 work_stack.emplace_back(
nullptr, 1);
589 work_stack.emplace_back(
" (", 4);
596 if (node->
getChild(0)->isLetBindVar()) {
598 work_stack.emplace_back(
")", 4);
600 work_stack.emplace_back(node->
getChild(0).get(), 0);
606 out << node->
getChild(0)->getName();
613 work_stack.emplace_back(
nullptr, 2);
614 for (
int i = children.size() - 1; i >= 0; --i) {
615 if (i && children[i]->isLetBindVar()) {
616 work_stack.emplace_back(
")", 4);
618 auto current_child = children[i].get();
619 work_stack.emplace_back(current_child, 0);
620 if (i && current_child->isLetBindVar()) {
621 work_stack.emplace_back(
"(", 4);
624 work_stack.emplace_back(
nullptr, 1);
632 "NT_LET should have at least one child");
637 work_stack.emplace_back(
")", 4);
638 work_stack.emplace_back(node->
getChild(0).get(), 0);
639 work_stack.emplace_back(
") ", 4);
643 work_stack.emplace_back(
")", 4);
644 work_stack.emplace_back(node->
getChild(i)->getChild(0).get(),
646 work_stack.emplace_back(
" ", 4);
647 work_stack.emplace_back(node->
getChild(i)->getPureName(),
649 work_stack.emplace_back(
"(", 4);
651 work_stack.emplace_back(
" ", 4);
655 work_stack.emplace_back(
"(let (", 4);
665 for (
size_t i = 0; i < num_bindings; i++) {
666 work_stack.emplace_back(
")", 4);
674 for (
int i = num_bindings - 1; i >= 0; i--) {
676 "NT_LET_CHAIN: child is not LET_BIND_VAR_LIST");
679 work_stack.emplace_back(
") ", 4);
682 for (
int j = var_list->getChildrenSize() - 1; j >= 0; j--) {
683 work_stack.emplace_back(
")", 4);
684 work_stack.emplace_back(var_list->getChild(j)->getChild(0).get(),
686 work_stack.emplace_back(
" ", 4);
687 work_stack.emplace_back(var_list->getChild(j)->getPureName(),
689 work_stack.emplace_back(
"(", 4);
691 work_stack.emplace_back(
" ", 4);
695 work_stack.emplace_back(
"(let (", 4);
708 work_stack.emplace_back(
")", 4);
712 work_stack.emplace_back(
")", 4);
713 work_stack.emplace_back(node->
getChild(i)->getChild(0).get(),
715 work_stack.emplace_back(
" ", 4);
716 work_stack.emplace_back(node->
getChild(i)->getPureName(),
718 work_stack.emplace_back(
"(", 4);
720 work_stack.emplace_back(
" ", 4);
724 work_stack.emplace_back(
"( ", 4);
734 if (children.empty()) {
739 work_stack.emplace_back(
nullptr, 2);
740 for (
int i = children.size() - 1; i >= 0; i--) {
741 auto current_child = children[i].get();
742 work_stack.emplace_back(current_child, 0);
743 work_stack.emplace_back(
nullptr, 1);
755 if (children.size() <= 1) {
760 work_stack.emplace_back(
nullptr, 2);
761 for (
int i = children.size() - 1; i >= 1; i--) {
762 auto current_child = children[i].get();
763 work_stack.emplace_back(current_child, 0);
764 work_stack.emplace_back(
nullptr, 1);
779 out <<
"(" << kind_str;
780 work_stack.emplace_back(
nullptr, 2);
782 for (
int i = children.size() - 1; i >= 0; i--) {
783 auto current_child = children[i].get();
784 work_stack.emplace_back(current_child, 0);
785 work_stack.emplace_back(
nullptr, 1);
795 out <<
"(" << kind_str;
796 work_stack.emplace_back(
nullptr, 2);
798 for (
int i = children.size() - 1; i >= 0; i--) {
799 auto current_child = children[i].get();
800 work_stack.emplace_back(current_child, 0);
801 work_stack.emplace_back(
nullptr, 1);
817 auto child = node->
getChild(0).get();
818 out <<
"(" << kind_str <<
" ";
819 work_stack.emplace_back(
nullptr, 2);
820 work_stack.emplace_back(child, 0);
825 auto child0 = node->
getChild(0).get();
826 auto child1 = node->
getChild(1).get();
828 work_stack.emplace_back(
nullptr, 2);
829 work_stack.emplace_back(child1, 0);
830 work_stack.emplace_back(
nullptr, 1);
831 work_stack.emplace_back(child0, 0);
848 out <<
"(" << kind_str;
849 work_stack.emplace_back(
nullptr, 2);
851 for (
int i = children.size() - 1; i >= 0; i--) {
852 auto current_child = children[i].get();
853 work_stack.emplace_back(current_child, 0);
854 work_stack.emplace_back(
nullptr, 1);
865 auto size = node->
getChild(2).get();
866 out <<
"((_ " << kind_str <<
" ";
867 work_stack.emplace_back(
nullptr, 2);
868 work_stack.emplace_back(fp, 0);
869 work_stack.emplace_back(
nullptr, 1);
870 work_stack.emplace_back(rm, 0);
871 work_stack.emplace_back(
nullptr, 3);
872 work_stack.emplace_back(size, 0);
883 auto param = node->
getChild(3).get();
885 work_stack.emplace_back(
nullptr, 2);
886 work_stack.emplace_back(param, 0);
887 work_stack.emplace_back(
nullptr, 1);
888 work_stack.emplace_back(rm, 0);
889 work_stack.emplace_back(
nullptr, 3);
890 work_stack.emplace_back(sb, 0);
891 work_stack.emplace_back(
nullptr, 1);
892 work_stack.emplace_back(eb, 0);
896 auto param = node->
getChild(2).get();
898 work_stack.emplace_back(
nullptr, 2);
899 work_stack.emplace_back(param, 0);
900 work_stack.emplace_back(
nullptr, 3);
901 work_stack.emplace_back(sb, 0);
902 work_stack.emplace_back(
nullptr, 1);
903 work_stack.emplace_back(eb, 0);
907 out <<
"INVALID_FP_TO_FP_NODE";
916 auto param = node->
getChild(3).get();
917 out <<
"((_ to_fp_unsigned ";
918 work_stack.emplace_back(
nullptr, 2);
919 work_stack.emplace_back(param, 0);
920 work_stack.emplace_back(
nullptr, 1);
921 work_stack.emplace_back(rm, 0);
922 work_stack.emplace_back(
nullptr, 3);
923 work_stack.emplace_back(sb, 0);
924 work_stack.emplace_back(
nullptr, 1);
925 work_stack.emplace_back(eb, 0);
930 auto expr = node->
getChild(0).get();
931 auto index = node->
getChild(1).get();
933 work_stack.emplace_back(
nullptr, 2);
934 work_stack.emplace_back(index, 0);
935 work_stack.emplace_back(
nullptr, 1);
936 work_stack.emplace_back(expr, 0);
941 out <<
"(root-of-with-interval (coeffs ";
949 work_stack.emplace_back(
nullptr, 2);
954 work_stack.emplace_back(
nullptr, 1);
959 work_stack.emplace_back(
nullptr, 1);
962 work_stack.emplace_back(
nullptr, 2);
966 work_stack.emplace_back(node->
getChild(i).get(), 0);
967 work_stack.emplace_back(
nullptr, 1);
978 if (children.empty()) {
981 else if (children.size() == 1) {
982 auto child = children[0].get();
983 out <<
"(" << kind_str <<
" ";
984 work_stack.emplace_back(
nullptr, 2);
985 work_stack.emplace_back(child, 0);
988 out <<
"(" << kind_str;
989 work_stack.emplace_back(
nullptr, 2);
990 for (
int i = children.size() - 1; i >= 0; i--) {
991 auto child = children[i].get();
992 work_stack.emplace_back(child, 0);
993 work_stack.emplace_back(
nullptr, 1);