MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / OnAnalysisComplete

Method OnAnalysisComplete

ThunkLibs/Generator/gen.cpp:332–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332void GenerateThunkLibsAction::OnAnalysisComplete(clang::ASTContext& context) {
333 ErrorReporter report_error {context};
334
335 // Compute data layout differences between host and guest
336 auto type_compat = [&]() {
337 std::unordered_map<const clang::Type*, TypeCompatibility> ret;
338 const auto host_abi = ComputeDataLayout(context, types);
339 for (const auto& [type, type_repack_info] : types) {
340 if (type_repack_info.emit_layout_wrappers) {
341 // Assume incompatible, since this annotation is set when
342 // compatibility checks would otherwise fail (e.g. due to
343 // circular references)
344 ret.emplace(type, TypeCompatibility::None);
345 } else if (!type_repack_info.pointers_only) {
346 GetTypeCompatibility(context, type, host_abi, ret);
347 }
348 }
349 return ret;
350 }();
351
352 static auto format_decl = [](clang::QualType type, const std::string_view& name) {
353 clang::QualType innermostPointee = type;
354 while (innermostPointee->isPointerType()) {
355 innermostPointee = innermostPointee->getPointeeType();
356 }
357 if (innermostPointee->isFunctionType()) {
358 // Function pointer declarations (e.g. void (**callback)()) require
359 // the variable name to be prefixed *and* suffixed.
360
361 auto signature = type.getAsString();
362
363 // Search for strings like (*), (**), or (*****). Insert the
364 // variable name before the closing parenthesis
365 auto needle = signature.begin();
366 for (; needle != signature.end(); ++needle) {
367 if (signature.end() - needle < 3 || std::string_view {&*needle, 2} != "(*") {
368 continue;
369 }
370 while (*++needle == '*') {}
371 if (*needle == ')') {
372 break;
373 }
374 }
375 if (needle == signature.end()) {
376 // It's *probably* a typedef, so this should be safe after all
377 return fmt::format("{} {}", signature, name);
378 } else {
379 signature.insert(needle, name.begin(), name.end());
380 return signature;
381 }
382 } else {
383 return type.getAsString() + " " + std::string(name);
384 }
385 };
386
387 auto format_function_params = [](const FunctionParams& params) {
388 std::string ret;
389 for (std::size_t idx = 0; idx < params.param_types.size(); ++idx) {

Callers

nothing calls this directly

Calls 14

ComputeDataLayoutFunction · 0.85
formatFunction · 0.85
printFunction · 0.85
to_stringFunction · 0.85
get_fixed_size_int_nameFunction · 0.85
get_type_nameFunction · 0.85
format_function_argsFunction · 0.85
emplaceMethod · 0.80
atMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected