| 154 | } |
| 155 | |
| 156 | ABI GetStableLayout(const clang::ASTContext& context, const std::unordered_map<const clang::Type*, TypeInfo>& data_layout) { |
| 157 | ABI stable_layout; |
| 158 | |
| 159 | for (auto [type, type_info] : data_layout) { |
| 160 | auto type_name = get_type_name(context, type); |
| 161 | if (auto struct_info = type_info.get_if_struct()) { |
| 162 | for (auto& member : struct_info->members) { |
| 163 | if (member.is_integral) { |
| 164 | // Map member types to fixed-size integers |
| 165 | auto alt_type_name = get_fixed_size_int_name(member.is_signed_integer, member.size_bits); |
| 166 | auto alt_type_info = SimpleTypeInfo { |
| 167 | .size_bits = member.size_bits, |
| 168 | .alignment_bits = context.getTypeAlign(context.getIntTypeForBitwidth(member.size_bits, member.is_signed_integer)), |
| 169 | }; |
| 170 | stable_layout.insert(std::pair {alt_type_name, alt_type_info}); |
| 171 | member.type_name = std::move(alt_type_name); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | auto [it, inserted] = stable_layout.insert(std::pair {type_name, std::move(type_info)}); |
| 177 | if (type->isIntegerType()) { |
| 178 | auto alt_type_name = get_fixed_size_int_name(type, context); |
| 179 | stable_layout.insert(std::pair {std::move(alt_type_name), type_info}); |
| 180 | } |
| 181 | |
| 182 | if (!inserted && it->second != type_info && !type->isIntegerType()) { |
| 183 | throw std::runtime_error("Duplicate type information: Tried to re-register type \"" + type_name + "\""); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | stable_layout.pointer_size = context.getTypeSize(context.getUIntPtrType()) / 8; |
| 188 | |
| 189 | return stable_layout; |
| 190 | } |
| 191 | |
| 192 | static std::array<uint8_t, 32> GetSha256(const std::string& function_name) { |
| 193 | std::array<uint8_t, 32> sha256; |
no test coverage detected