Skip to content

Commit

Permalink
Incorporate llvm 18 changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hchen99 committed Apr 1, 2024
1 parent c6e44c6 commit fc5370a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CMakeTestFiles/TestICGLinkedLibs.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// `llvm/Support/Host.h` is deprecated in favour of `llvm/TargetParser/Host.h` since clang 17
#if LIBCLANG_MAJOR > 16
#include "llvm/TargetParser/Host.h"
#else
#include "llvm/Support/Host.h"
#endif
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"

Expand Down
19 changes: 15 additions & 4 deletions trick_source/codegen/Interface_Code_Gen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
#include <sys/stat.h>
#include <unistd.h>

// `llvm/Support/Host.h` is deprecated in favour of `llvm/TargetParser/Host.h` since clang 17
#if LIBCLANG_MAJOR > 16
#include "llvm/TargetParser/Host.h"
#else
#include "llvm/Support/Host.h"
#endif
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"

Expand Down Expand Up @@ -239,8 +244,10 @@ int main(int argc, char * argv[]) {
#endif
clang::Preprocessor& pp = ci.getPreprocessor();

#if (LIBCLANG_MAJOR >= 10)
#if (LIBCLANG_MAJOR >= 10) && (LIBCLANG_MAJOR < 18)
clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts());
#else
clang::InitializePreprocessor(pp, ppo, ci.getPCHContainerReader(), ci.getFrontendOpts(), ci.getCodeGenOpts());
#endif

// Add all of the include directories to the preprocessor
Expand Down Expand Up @@ -301,16 +308,20 @@ int main(int argc, char * argv[]) {
exit(-1);
}
// Open up the input file and parse it
#if (LIBCLANG_MAJOR >= 10)
#if (LIBCLANG_MAJOR >= 10 && LIBCLANG_MAJOR < 18)
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath).get();
#elif (LIBCLANG_MAJOR >= 18)
clang::FileEntryRef fileEntryRef = llvm::cantFail(ci.getFileManager().getFileRef(inputFilePath));
#else
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath);
#endif
free(inputFilePath);
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
#if (LIBCLANG_MAJOR < 3)
ci.getSourceManager().createMainFileID(fileEntry);
#elif (LIBCLANG_MAJOR > 3 && LIBCLANG_MAJOR < 18) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntry, clang::SourceLocation(), clang::SrcMgr::C_User));
#else
ci.getSourceManager().createMainFileID(fileEntry);
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntryRef, clang::SourceLocation(), clang::SrcMgr::C_User));
#endif
ci.getDiagnosticClient().BeginSourceFile(ci.getLangOpts(), &ci.getPreprocessor());
clang::ParseAST(ci.getSema());
Expand Down

0 comments on commit fc5370a

Please sign in to comment.