24cdc5e1d3
Most of what hipify does is really just replacing CUDA idenitifers with HIP ones. CUDA function calls, preprocessor macro calls, enum references, types, etc. This is problematic: calls/types/enum-refs require name resolution for the AST matcher to work. This fails in the presence of code deleted by the preprocessor, and in two-pass template compilation. Instead, we can simply hook the lexer and have it rewrite the identifiers for us. This approach means identifier transformations will work correctly regardless of where they appear (and we get to delete lots of code) - Fixes #260 - Helps a bit with #207 - it will still fail to translate kernel calls in preprocessor-ignored code, but everything except kerel launches should translate correctly now, even in preprocessor-deleted code.
29 γραμμές
775 B
C++
29 γραμμές
775 B
C++
#pragma once
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
#include "clang/Frontend/FrontendAction.h"
|
|
#include "clang/Tooling/Core/Replacement.h"
|
|
|
|
namespace ct = clang::tooling;
|
|
|
|
|
|
/**
|
|
* A FrontendActionFactory that propagates a set of Replacements into the FrontendAction.
|
|
* This is necessary boilerplate for using a custom FrontendAction with a RefactoringTool.
|
|
*
|
|
* @tparam T The FrontendAction to create.
|
|
*/
|
|
template <typename T>
|
|
class ReplacementsFrontendActionFactory : public ct::FrontendActionFactory {
|
|
ct::Replacements* replacements;
|
|
|
|
public:
|
|
explicit ReplacementsFrontendActionFactory(ct::Replacements* r):
|
|
ct::FrontendActionFactory(),
|
|
replacements(r) {}
|
|
|
|
clang::FrontendAction* create() override {
|
|
return new T(replacements);
|
|
}
|
|
};
|