| 1103 | return res; |
| 1104 | } |
| 1105 | id define_variable(const location &loc, const type &type, std::string name, bool global, id initializer_value) override |
| 1106 | { |
| 1107 | // Constant variables with a constant initializer can just point to the initializer SSA variable, since they cannot be modified anyway, thus saving an unnecessary assignment |
| 1108 | if (initializer_value != 0 && type.has(type::q_const) && |
| 1109 | std::find_if(_constant_lookup.begin(), _constant_lookup.end(), |
| 1110 | [initializer_value](const auto &x) { |
| 1111 | return initializer_value == std::get<2>(x); |
| 1112 | }) != _constant_lookup.end()) |
| 1113 | return initializer_value; |
| 1114 | |
| 1115 | const id res = make_id(); |
| 1116 | |
| 1117 | if (!name.empty()) |
| 1118 | define_name<naming::general>(res, name); |
| 1119 | |
| 1120 | std::string &code = _blocks.at(_current_block); |
| 1121 | |
| 1122 | write_location(code, loc); |
| 1123 | |
| 1124 | if (!global) |
| 1125 | code += '\t'; |
| 1126 | |
| 1127 | write_type(code, type); |
| 1128 | code += ' ' + id_to_name(res); |
| 1129 | |
| 1130 | if (type.is_array()) |
| 1131 | code += '[' + std::to_string(type.array_length) + ']'; |
| 1132 | |
| 1133 | if (initializer_value != 0) |
| 1134 | code += " = " + id_to_name(initializer_value); |
| 1135 | |
| 1136 | code += ";\n"; |
| 1137 | |
| 1138 | return res; |
| 1139 | } |
| 1140 | id define_function(const location &loc, function &info) override |
| 1141 | { |
| 1142 | const id res = info.id = make_id(); |
no test coverage detected