Files
FEX-Emu--FEX/ThunkLibs/Generator/interface.h
T
Tony Wasserka 68426735a5 Thunks: Clean up ASTMatcher-based testing helpers
The run_thunkgen* helpers now parse generated source code and return its AST
representation, so HasASTMatching helper calls don't each need to redundantly
compile it themselves. This also ensures the generator output actually compiles
in tests where we didn't explicitly check that before.

This also allows printing the full AST of the generator output on test
failures. This must be enabled manually by changing a variable in the ostream
output operator for SourceWithAST.
2022-02-10 12:11:52 +01:00

57 lines
1.6 KiB
C++

#include <clang/Frontend/FrontendAction.h>
#include <clang/Tooling/Tooling.h>
#include <optional>
#include <string>
struct OutputFilenames {
// Host
std::string function_unpacks;
std::string tab_function_unpacks;
std::string ldr;
std::string ldr_ptrs;
// Guest
std::string thunks;
std::string function_packs;
std::string function_packs_public;
std::string callback_unpacks_header_init;
// Guest + Host
std::string callback_structs;
std::string callback_typedefs;
std::string callback_unpacks_header;
std::string callback_unpacks;
std::string symbol_list;
};
class GenerateThunkLibsAction : public clang::ASTFrontendAction {
public:
GenerateThunkLibsAction(const std::string& libname, const OutputFilenames&);
void EndSourceFileAction() override;
std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance&, clang::StringRef /*file*/) override;
private:
const std::string& libfilename;
std::string libname; // sanitized filename, usable as part of emitted function names
const OutputFilenames& output_filenames;
};
class GenerateThunkLibsActionFactory : public clang::tooling::FrontendActionFactory {
public:
GenerateThunkLibsActionFactory(std::string_view libname_, OutputFilenames output_filenames_)
: libname(std::move(libname_)), output_filenames(std::move(output_filenames_)) {
}
std::unique_ptr<clang::FrontendAction> create() override {
return std::make_unique<GenerateThunkLibsAction>(libname, output_filenames);
}
private:
std::string libname;
OutputFilenames output_filenames;
};