| 202 | std::string cpp_generator::str() const { return impl->fs.str(); } |
| 203 | |
| 204 | cpp_generator::function cpp_generator::generate_module(const module& m, |
| 205 | const generate_module_callback& g) |
| 206 | { |
| 207 | function f; |
| 208 | f.set_name(to_c_id(m.name())) |
| 209 | .set_types(m) |
| 210 | .set_body(m, [&](instruction_ref ins, const auto& names) -> std::string { |
| 211 | if(ins->name() == "@literal") |
| 212 | { |
| 213 | std::string string_literal; |
| 214 | ins->get_literal().visit([&](auto v) { |
| 215 | assert(v.size() == 1); |
| 216 | auto x = v.front(); |
| 217 | if(std::isinf(static_cast<double>(x))) |
| 218 | { |
| 219 | string_literal = "__builtin_huge_val()"; |
| 220 | if(x < 0) |
| 221 | string_literal = "-__builtin_huge_val()"; |
| 222 | } |
| 223 | else if(std::isnan(static_cast<double>(x))) |
| 224 | string_literal = "__builtin_nan(\"0\")"; |
| 225 | else |
| 226 | string_literal = ins->get_literal().to_string(); |
| 227 | }); |
| 228 | return shape::cpp_type(ins->get_shape().type()) + "(" + string_literal + ")"; |
| 229 | } |
| 230 | if(ins->name() == "@return") |
| 231 | { |
| 232 | // TODO: Customize the make_tuple call |
| 233 | if(impl->always_return_tuple or ins->inputs().size() != 1) |
| 234 | return "make_tuple(" + join_strings(to_args(ins->inputs(), names), ", ") + ")"; |
| 235 | return names.at(ins->inputs().front()); |
| 236 | } |
| 237 | auto s = g(ins, names); |
| 238 | if(impl->fresult) |
| 239 | return impl->fresult(ins->get_shape()) + '(' + s + ')'; |
| 240 | else |
| 241 | return s; |
| 242 | }); |
| 243 | return f; |
| 244 | } |
| 245 | |
| 246 | std::vector<std::string> |
| 247 | cpp_generator::to_args(const std::vector<instruction_ref>& inputs, |
no test coverage detected