Files
Tony Wasserka 7f931b5623 Thunks/gen: Add detection logic for data layout differences
This runs the data layout analysis pass added in the previous change twice:
Once for the host architecture and once for the guest architecture. This
allows the new DataLayoutCompareAction to query architecture differences for
each type, which can then be used to instruct code generation accordingly.

Currently, type compatibility is classified into 3 categories:
* Fully compatible (same size/alignment for the type itself and any members)
* Repackable (incompatibility can be resolved with emission of automatable
  repacking code, e.g. when struct members are located at differing offsets
  due to padding bytes)
* Incompatible
2023-10-02 22:18:22 +02:00

55 lines
1.4 KiB
C++

#include <clang/Tooling/Tooling.h>
#include <optional>
#include <string>
struct OutputFilenames {
std::string host;
std::string guest;
};
class AnalyzeDataLayoutActionFactory : public clang::tooling::FrontendActionFactory {
std::unique_ptr<struct ABI> abi;
public:
AnalyzeDataLayoutActionFactory();
~AnalyzeDataLayoutActionFactory();
std::unique_ptr<clang::FrontendAction> create() override;
const ABI& GetDataLayout() {
return *abi;
}
std::unique_ptr<ABI> TakeDataLayout() {
return std::move(abi);
}
};
class DataLayoutCompareActionFactory : public clang::tooling::FrontendActionFactory {
const ABI& abi;
public:
DataLayoutCompareActionFactory(const ABI&);
~DataLayoutCompareActionFactory();
std::unique_ptr<clang::FrontendAction> create() override;
};
class GenerateThunkLibsActionFactory : public clang::tooling::ToolAction {
public:
GenerateThunkLibsActionFactory(std::string_view libname_, OutputFilenames output_filenames_, const ABI& abi_)
: libname(std::move(libname_)), output_filenames(std::move(output_filenames_)), abi(abi_) {
}
bool runInvocation(
std::shared_ptr<clang::CompilerInvocation> Invocation, clang::FileManager *Files,
std::shared_ptr<clang::PCHContainerOperations> PCHContainerOps,
clang::DiagnosticConsumer *DiagConsumer) override;
private:
std::string libname;
OutputFilenames output_filenames;
const ABI& abi;
};