fix build bug with current clang/llvm
This commit is contained in:
+38
-38
@@ -229,22 +229,22 @@ namespace {
|
|||||||
DenseMap<StringRef, StringRef> cuda2hipRename;
|
DenseMap<StringRef, StringRef> cuda2hipRename;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HipifyPPCallbacks : public PPCallbacks, public SourceFileCallbacks {
|
struct HipifyPPCallbacks : public PPCallbacks, public SourceFileCallbacks {
|
||||||
HipifyPPCallbacks(Replacements * R)
|
HipifyPPCallbacks(Replacements * R)
|
||||||
: SeenEnd(false), _sm(nullptr), Replace(R)
|
: SeenEnd(false), _sm(nullptr), Replace(R)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool handleBeginSource(CompilerInstance &CI, StringRef Filename) override
|
virtual bool handleBeginSource(CompilerInstance &CI, StringRef Filename) override
|
||||||
{
|
{
|
||||||
Preprocessor &PP = CI.getPreprocessor();
|
Preprocessor &PP = CI.getPreprocessor();
|
||||||
SourceManager & SM = CI.getSourceManager();
|
SourceManager & SM = CI.getSourceManager();
|
||||||
setSourceManager(&SM);
|
setSourceManager(&SM);
|
||||||
PP.addPPCallbacks(std::unique_ptr<HipifyPPCallbacks>(this));
|
PP.addPPCallbacks(std::unique_ptr<HipifyPPCallbacks>(this));
|
||||||
PP.Retain();
|
PP.Retain();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void InclusionDirective(
|
virtual void InclusionDirective(
|
||||||
SourceLocation hash_loc,
|
SourceLocation hash_loc,
|
||||||
const Token &include_token,
|
const Token &include_token,
|
||||||
@@ -254,7 +254,7 @@ namespace {
|
|||||||
const FileEntry *file,
|
const FileEntry *file,
|
||||||
StringRef search_path,
|
StringRef search_path,
|
||||||
StringRef relative_path,
|
StringRef relative_path,
|
||||||
const Module *imported) override
|
const clang::Module *imported) override
|
||||||
{
|
{
|
||||||
if (_sm->isWrittenInMainFile(hash_loc)) {
|
if (_sm->isWrittenInMainFile(hash_loc)) {
|
||||||
if (is_angled) {
|
if (is_angled) {
|
||||||
@@ -265,8 +265,8 @@ namespace {
|
|||||||
llvm::errs() << "\nWill be replaced with " << repName << "\n";
|
llvm::errs() << "\nWill be replaced with " << repName << "\n";
|
||||||
SourceLocation sl = filename_range.getBegin();
|
SourceLocation sl = filename_range.getBegin();
|
||||||
SourceLocation sle = filename_range.getEnd();
|
SourceLocation sle = filename_range.getEnd();
|
||||||
const char* B = _sm->getCharacterData(sl);
|
const char* B = _sm->getCharacterData(sl);
|
||||||
const char* E = _sm->getCharacterData(sle);
|
const char* E = _sm->getCharacterData(sle);
|
||||||
repName = "<" + repName + ">";
|
repName = "<" + repName + ">";
|
||||||
Replacement Rep(*_sm, sl, E - B, repName);
|
Replacement Rep(*_sm, sl, E - B, repName);
|
||||||
Replace->insert(Rep);
|
Replace->insert(Rep);
|
||||||
@@ -300,22 +300,22 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndOfMainFile() override
|
void EndOfMainFile() override
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SeenEnd;
|
bool SeenEnd;
|
||||||
void setSourceManager(SourceManager * sm) { _sm = sm; }
|
void setSourceManager(SourceManager * sm) { _sm = sm; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SourceManager * _sm;
|
SourceManager * _sm;
|
||||||
Replacements * Replace;
|
Replacements * Replace;
|
||||||
struct hipName N;
|
struct hipName N;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Cuda2HipCallback : public MatchFinder::MatchCallback {
|
class Cuda2HipCallback : public MatchFinder::MatchCallback {
|
||||||
public:
|
public:
|
||||||
Cuda2HipCallback(Replacements *Replace) : Replace(Replace) {}
|
Cuda2HipCallback(Replacements *Replace) : Replace(Replace) {}
|
||||||
@@ -452,8 +452,8 @@ class Cuda2HipCallback : public MatchFinder::MatchCallback {
|
|||||||
|
|
||||||
if (const ParmVarDecl * cudaParamDecl = Result.Nodes.getNodeAs<clang::ParmVarDecl>("cudaParamDecl"))
|
if (const ParmVarDecl * cudaParamDecl = Result.Nodes.getNodeAs<clang::ParmVarDecl>("cudaParamDecl"))
|
||||||
{
|
{
|
||||||
QualType QT = cudaParamDecl->getOriginalType();
|
QualType QT = cudaParamDecl->getOriginalType();
|
||||||
std::string name = QT.getAsString();
|
std::string name = QT.getAsString();
|
||||||
std::string repName = N.cuda2hipRename[name];
|
std::string repName = N.cuda2hipRename[name];
|
||||||
SourceLocation sl = cudaParamDecl->getLocStart();
|
SourceLocation sl = cudaParamDecl->getLocStart();
|
||||||
Replacement Rep(*SM, SM->isMacroArgExpansion(sl) ?
|
Replacement Rep(*SM, SM->isMacroArgExpansion(sl) ?
|
||||||
@@ -506,7 +506,7 @@ int main(int argc, const char **argv) {
|
|||||||
Finder.addMatcher(declRefExpr(isExpansionInMainFile(), to(enumConstantDecl(matchesName("cuda.*")))).bind("cudaEnumConstantRef"), &Callback);
|
Finder.addMatcher(declRefExpr(isExpansionInMainFile(), to(enumConstantDecl(matchesName("cuda.*")))).bind("cudaEnumConstantRef"), &Callback);
|
||||||
Finder.addMatcher(varDecl(isExpansionInMainFile(), hasType(enumDecl(matchesName("cuda.*")))).bind("cudaEnumConstantDecl"), &Callback);
|
Finder.addMatcher(varDecl(isExpansionInMainFile(), hasType(enumDecl(matchesName("cuda.*")))).bind("cudaEnumConstantDecl"), &Callback);
|
||||||
Finder.addMatcher(varDecl(isExpansionInMainFile(), hasType(cxxRecordDecl(matchesName("cuda.*")))).bind("cudaStructVar"), &Callback);
|
Finder.addMatcher(varDecl(isExpansionInMainFile(), hasType(cxxRecordDecl(matchesName("cuda.*")))).bind("cudaStructVar"), &Callback);
|
||||||
Finder.addMatcher(parmVarDecl(isExpansionInMainFile(), hasType(namedDecl(matchesName("cuda.*")))).bind("cudaParamDecl"), &Callback);
|
Finder.addMatcher(parmVarDecl(isExpansionInMainFile(), hasType(namedDecl(matchesName("cuda.*")))).bind("cudaParamDecl"), &Callback);
|
||||||
|
|
||||||
auto action = newFrontendActionFactory(&Finder, &PPCallbacks);
|
auto action = newFrontendActionFactory(&Finder, &PPCallbacks);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user