void Function::dump(std::ostream& out) { auto it = begin(); while (it != end()) { auto block = *it++; auto nextBlock = it != end() ? *it : nullptr; out << ".L" << block->index << ":"; for (auto s: *block) { if (s->asTerminator()) break; out << '\t'; s->dump(out); } auto t = block->terminator(); assert(t); auto j = t->asJump(); auto cj = t->asCJump(); if (j && j->target() == nextBlock) { // nothing to do out << std::endl; } else if (cj && cj->iffalse() == nextBlock) { out << "\tif ("; cj->expr()->dump(out); out << ") goto .L" << cj->iftrue()->index << ';' << std::endl; } else if (cj && cj->iftrue() == nextBlock) { out << "\tiffalse ("; cj->expr()->dump(out); out << ") goto .L" << cj->iffalse()->index << ';' << std::endl; } else { out << '\t'; t->dump(out); } } }
void do_if (int sharp) { char c; char d; #ifdef DEBUG_IF if (debugging) { outputc('<'); outputc(sharp ? '#' : '@'); outputs("if: "); // fflush(outfile); } #endif if (in_false_if()) { n_skipped_ifs ++; #ifdef DEBUG_IF if (debugging) { outputs("in-false, skipped>"); // fflush(outfile); } #endif if (sharp) { d = '\0'; do { c = d; d = Get(); } while ((c == '\\') || (d != '\n')); } return ; } if (! sharp) { c = getnonspace(); if (c != '(') { err_head(); fprintf(stderr, "@if must have ()s\n"); Push(c); iffalse(); #ifdef DEBUG_IF if (debugging) { outputc('>'); // fflush(outfile); } #endif return ; } } if (eval_expr(sharp, 0)) { iftrue(); } else { iffalse(); } #ifdef DEBUG_IF if (debugging) { outputc('>'); // fflush(outfile); } #endif }
void do_ifndef (int sharp) { char *w; #ifdef DEBUG_IF if (debugging) { outputc('<'); outputc(sharp ? '#' : '@'); outputs("ifndef: "); // fflush(outfile); } #endif if (in_false_if()) { n_skipped_ifs ++; #ifdef DEBUG_IF if (debugging) { outputs("in-false, skipped>"); // fflush(outfile); } #endif } else { w = read_ident(); if (! w) { #ifdef DEBUG_IF if (debugging) { outputs("no ident "); // fflush(outfile); } #endif iftrue(); } else { #ifdef DEBUG_IF if (debugging) { outputs(w); outputc(' '); // fflush(outfile); } #endif if (find_def(w)) { iffalse(); } else { iftrue(); } os_free(w); } #ifdef DEBUG_IF if (debugging) { outputc('>'); // fflush(outfile); } #endif } if (sharp) { flush_sharp_line(); } }
void CJump::dump(std::ostream& out) const { out << "if ("; expr()->dump(out); out << ") goto .L" << iftrue()->index << "; else goto .L" << iffalse()->index << ';' << std::endl; }