| 860 | } |
| 861 | |
| 862 | void Function::print(ostream &os, bool print_header) const { |
| 863 | if (!fn_decls.empty()) { |
| 864 | for (auto &decl : fn_decls) { |
| 865 | os << "declare " << *decl.output << ' ' << decl.name << '('; |
| 866 | bool first = true; |
| 867 | for (auto &input : decl.inputs) { |
| 868 | if (!first) |
| 869 | os << ", "; |
| 870 | os << input.second << *input.first; |
| 871 | first = false; |
| 872 | } |
| 873 | if (decl.is_varargs) { |
| 874 | os << (first ? "..." : ", ..."); |
| 875 | } |
| 876 | os << ')' << decl.attrs << '\n'; |
| 877 | } |
| 878 | os << '\n'; |
| 879 | } |
| 880 | |
| 881 | { |
| 882 | const auto &gvars = getGlobalVars(); |
| 883 | if (!gvars.empty()) { |
| 884 | for (auto &v : gvars) { |
| 885 | v->print(os); |
| 886 | os << '\n'; |
| 887 | } |
| 888 | os << '\n'; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | if (print_header) { |
| 893 | os << "define " << getType() << " @" << name << '('; |
| 894 | bool first = true; |
| 895 | for (auto &input : getInputs()) { |
| 896 | if (!first) |
| 897 | os << ", "; |
| 898 | os << input; |
| 899 | first = false; |
| 900 | } |
| 901 | if (isVarArgs()) |
| 902 | os << (first ? "..." : ", ..."); |
| 903 | os << ')' << attrs << " {\n"; |
| 904 | } |
| 905 | |
| 906 | bool first = true; |
| 907 | for (auto bb : BB_order) { |
| 908 | if (!first) |
| 909 | os << '\n'; |
| 910 | os << *bb; |
| 911 | first = false; |
| 912 | } |
| 913 | |
| 914 | if (print_header) |
| 915 | os << "}\n"; |
| 916 | } |
| 917 | |
| 918 | ostream& operator<<(ostream &os, const Function &f) { |
| 919 | f.print(os); |