mirror of
https://github.com/nasa/trick.git
synced 2025-06-22 08:50:06 +00:00
ICG does not compile using llvm 3.9 #339
The call getRBraceLoc to find the ending source location of things is gone. Replaced it with getting the source range and get the end of that range. Also the way to get clang/llvm 3.9 to process c++11 code required some reordering of calls in main as well as adding some more features to be turned on.
This commit is contained in:
@ -25,13 +25,13 @@
|
||||
#include "PrintAttributesFactory.hh"
|
||||
#include "Utilities.hh"
|
||||
|
||||
// Command line arguments. These work better as globals, as suggested in llvm/CommandLine documentation.
|
||||
/* Command line arguments. These work better as globals, as suggested in llvm/CommandLine documentation */
|
||||
llvm::cl::list<std::string> include_dirs("I", llvm::cl::Prefix, llvm::cl::desc("Include directory"), llvm::cl::value_desc("directory"));
|
||||
llvm::cl::list<std::string> defines("D", llvm::cl::Prefix, llvm::cl::desc("Defines"), llvm::cl::value_desc("define"));
|
||||
llvm::cl::opt<bool> units_truth_is_scary("units-truth-is-scary", llvm::cl::desc("Don't print units conversion messages"));
|
||||
llvm::cl::opt<bool> sim_services_flag("s", llvm::cl::desc("Gernerate io_src for Trick core headers"));
|
||||
llvm::cl::opt<bool> force("f", llvm::cl::desc("Force all io_src files to be generated"));
|
||||
llvm::cl::opt<int> attr_version("v", llvm::cl::desc("Select version of attributes to produce. 10 and 13 are valid"), llvm::cl::init(10));
|
||||
llvm::cl::opt<int> attr_version("v", llvm::cl::desc("Select version of attributes to produce. 10 and 13 are valid"), llvm::cl::init(10));
|
||||
llvm::cl::opt<int> debug_level("d", llvm::cl::desc("Set debug level"), llvm::cl::init(0), llvm::cl::ZeroOrMore);
|
||||
llvm::cl::opt<bool> create_map("m", llvm::cl::desc("Create map files"), llvm::cl::init(false));
|
||||
llvm::cl::opt<std::string> output_dir("o", llvm::cl::desc("Output directory"));
|
||||
@ -40,8 +40,9 @@ llvm::cl::alias force_alias("force" , llvm::cl::desc("Alias for -f") , llvm::cl:
|
||||
llvm::cl::list<std::string> input_file_names(llvm::cl::Positional, llvm::cl::desc("<input_file>"), llvm::cl::ZeroOrMore);
|
||||
llvm::cl::list<std::string> sink(llvm::cl::Sink, llvm::cl::ZeroOrMore);
|
||||
llvm::cl::list<std::string> pre_compiled_headers("include", llvm::cl::Prefix, llvm::cl::desc("pre-compiled headers"), llvm::cl::value_desc("pre_compiled_headers"));
|
||||
llvm::cl::opt<bool> global_compat15("c", llvm::cl::desc("Print the offsetof calculations in attributes"));
|
||||
llvm::cl::alias compat15_alias("compat15", llvm::cl::desc("Alias for -c"), llvm::cl::aliasopt(global_compat15));
|
||||
|
||||
llvm::cl::opt<bool> global_compat15("c", llvm::cl::desc("Print the offsetof calculations in attributes")) ;
|
||||
llvm::cl::alias compat15_alias ("compat15" , llvm::cl::desc("Alias for -c") , llvm::cl::aliasopt(global_compat15)) ;
|
||||
|
||||
/**
|
||||
Most of the main program is pieced together from examples on the web. We are doing the following:
|
||||
@ -72,61 +73,72 @@ int main(int argc, char * argv[]) {
|
||||
std::cerr << "No header file specified" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
clang::CompilerInstance ci ;
|
||||
#if (LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR < 9)
|
||||
clang::CompilerInvocation::setLangDefaults(ci.getLangOpts() , clang::IK_CXX) ;
|
||||
#endif
|
||||
|
||||
clang::CompilerInstance compilerInstance;
|
||||
compilerInstance.createDiagnostics();
|
||||
compilerInstance.getDiagnosticOpts().ShowColors = 1;
|
||||
compilerInstance.getDiagnostics().setIgnoreAllWarnings(true);
|
||||
|
||||
// Set all of the defaults to c++
|
||||
clang::CompilerInvocation::setLangDefaults(compilerInstance.getLangOpts(), clang::IK_CXX);
|
||||
compilerInstance.getLangOpts().CXXExceptions = true;
|
||||
|
||||
ci.createDiagnostics();
|
||||
ci.getDiagnosticOpts().ShowColors = 1 ;
|
||||
ci.getDiagnostics().setIgnoreAllWarnings(true) ;
|
||||
ci.getLangOpts().CXXExceptions = true ;
|
||||
// Activate C++11 parsing
|
||||
compilerInstance.getLangOpts().CPlusPlus11 = true;
|
||||
ci.getLangOpts().Bool = true ;
|
||||
ci.getLangOpts().WChar = true ;
|
||||
ci.getLangOpts().CPlusPlus = true ;
|
||||
ci.getLangOpts().CPlusPlus11 = true ;
|
||||
ci.getLangOpts().CXXOperatorNames = true ;
|
||||
|
||||
// Create all of the necessary managers.
|
||||
ci.createFileManager();
|
||||
ci.createSourceManager(ci.getFileManager());
|
||||
|
||||
// Tell the preprocessor to use its default predefines
|
||||
clang::PreprocessorOptions & ppo = ci.getPreprocessorOpts() ;
|
||||
ppo.UsePredefines = true;
|
||||
|
||||
// Set the default target architecture
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
||||
clang::TargetOptions targetOptions;
|
||||
targetOptions.Triple = llvm::sys::getDefaultTargetTriple();
|
||||
compilerInstance.setTarget(clang::TargetInfo::CreateTargetInfo(compilerInstance.getDiagnostics(), std::make_shared<clang::TargetOptions>(targetOptions)));
|
||||
clang::TargetOptions to;
|
||||
to.Triple = llvm::sys::getDefaultTargetTriple();
|
||||
std::shared_ptr<clang::TargetOptions> shared_to = std::make_shared<clang::TargetOptions>(to) ;
|
||||
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), shared_to);
|
||||
ci.setTarget(pti);
|
||||
ci.createPreprocessor(clang::TU_Complete);
|
||||
#else
|
||||
clang::TargetOptions* targetOptions = new clang::TargetOptions();
|
||||
targetOptions->Triple = llvm::sys::getDefaultTargetTriple();
|
||||
compilerInstance.setTarget(clang::TargetInfo::CreateTargetInfo(compilerInstance.getDiagnostics(), targetOptions));
|
||||
clang::TargetOptions * to = new clang::TargetOptions() ;
|
||||
to->Triple = llvm::sys::getDefaultTargetTriple();
|
||||
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), to);
|
||||
ci.setTarget(pti);
|
||||
ci.createPreprocessor();
|
||||
#endif
|
||||
|
||||
// Create all of the necessary managers
|
||||
compilerInstance.createFileManager();
|
||||
compilerInstance.createSourceManager(compilerInstance.getFileManager());
|
||||
|
||||
// Create the preprocessor
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
||||
compilerInstance.createPreprocessor(clang::TU_Complete);
|
||||
#else
|
||||
compilerInstance.createPreprocessor();
|
||||
// Set all of the defaults to c++
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 9))
|
||||
llvm::Triple trip (to.Triple) ;
|
||||
clang::CompilerInvocation::setLangDefaults(ci.getLangOpts(), clang::IK_CXX, trip, ppo) ;
|
||||
// setting the language defaults clears the c++11 flag.
|
||||
ci.getLangOpts().CPlusPlus11 = true ;
|
||||
#endif
|
||||
clang::Preprocessor& preprocessor = compilerInstance.getPreprocessor();
|
||||
clang::Preprocessor& pp = ci.getPreprocessor();
|
||||
|
||||
// Add all of the include directories to the preprocessor
|
||||
HeaderSearchDirs headerSearchDirs(compilerInstance.getPreprocessor().getHeaderSearchInfo(), compilerInstance.getHeaderSearchOpts(), preprocessor, sim_services_flag);
|
||||
headerSearchDirs.addSearchDirs(include_dirs);
|
||||
HeaderSearchDirs hsd(ci.getPreprocessor().getHeaderSearchInfo(), ci.getHeaderSearchOpts(), pp, sim_services_flag);
|
||||
hsd.addSearchDirs(include_dirs);
|
||||
|
||||
// Tell the preprocessor to use its default predefines
|
||||
compilerInstance.getPreprocessorOpts().UsePredefines = true;
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 8))
|
||||
preprocessor.getBuiltinInfo().initializeBuiltins(preprocessor.getIdentifierTable(), preprocessor.getLangOpts());
|
||||
pp.getBuiltinInfo().initializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
|
||||
#else
|
||||
preprocessor.getBuiltinInfo().InitializeBuiltins(preprocessor.getIdentifierTable(), preprocessor.getLangOpts());
|
||||
pp.getBuiltinInfo().InitializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
|
||||
#endif
|
||||
// Add all of the #define from the command line to the default predefines
|
||||
headerSearchDirs.addDefines(defines);
|
||||
hsd.addDefines(defines);
|
||||
|
||||
// Add our comment saver as a comment handler in the preprocessor
|
||||
CommentSaver commentSaver(compilerInstance, headerSearchDirs);
|
||||
preprocessor.addCommentHandler(&commentSaver);
|
||||
CommentSaver cs(ci, hsd);
|
||||
pp.addCommentHandler(&cs);
|
||||
|
||||
PrintAttributes printAttributes(attr_version, headerSearchDirs, commentSaver, compilerInstance, force, sim_services_flag, output_dir);
|
||||
PrintAttributes printAttributes(attr_version, hsd, cs, ci, force, sim_services_flag, output_dir);
|
||||
|
||||
// Create new class and enum map files
|
||||
if (create_map) {
|
||||
@ -134,14 +146,14 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
|
||||
// Tell the compiler to use our ICGASTconsumer
|
||||
ICGASTConsumer* astConsumer = new ICGASTConsumer(compilerInstance, headerSearchDirs, commentSaver, printAttributes);
|
||||
ICGASTConsumer* astConsumer = new ICGASTConsumer(ci, hsd, cs, printAttributes);
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 6))
|
||||
compilerInstance.setASTConsumer(std::move(std::unique_ptr<clang::ASTConsumer>(astConsumer)));
|
||||
ci.setASTConsumer(std::move(std::unique_ptr<clang::ASTConsumer>(astConsumer)));
|
||||
#else
|
||||
compilerInstance.setASTConsumer(astConsumer);
|
||||
ci.setASTConsumer(astConsumer);
|
||||
#endif
|
||||
compilerInstance.createASTContext();
|
||||
compilerInstance.createSema(clang::TU_Prefix, NULL);
|
||||
ci.createASTContext();
|
||||
ci.createSema(clang::TU_Prefix, NULL);
|
||||
|
||||
// Get the full path of the file to be read
|
||||
char buffer[input_file_names[0].size()];
|
||||
@ -158,16 +170,16 @@ int main(int argc, char * argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
// Open up the input file and parse it
|
||||
const clang::FileEntry* fileEntry = compilerInstance.getFileManager().getFile(inputFilePath);
|
||||
const clang::FileEntry* fileEntry = ci.getFileManager().getFile(inputFilePath);
|
||||
free(inputFilePath);
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
||||
compilerInstance.getSourceManager().setMainFileID(compilerInstance.getSourceManager().createFileID(fileEntry, clang::SourceLocation(), clang::SrcMgr::C_User));
|
||||
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(fileEntry, clang::SourceLocation(), clang::SrcMgr::C_User));
|
||||
#else
|
||||
compilerInstance.getSourceManager().createMainFileID(fileEntry);
|
||||
ci.getSourceManager().createMainFileID(fileEntry);
|
||||
#endif
|
||||
compilerInstance.getDiagnosticClient().BeginSourceFile(compilerInstance.getLangOpts(), &compilerInstance.getPreprocessor());
|
||||
clang::ParseAST(compilerInstance.getSema());
|
||||
compilerInstance.getDiagnosticClient().EndSourceFile();
|
||||
ci.getDiagnosticClient().BeginSourceFile(ci.getLangOpts(), &ci.getPreprocessor());
|
||||
clang::ParseAST(ci.getSema());
|
||||
ci.getDiagnosticClient().EndSourceFile();
|
||||
|
||||
if (!sim_services_flag) {
|
||||
printAttributes.printIOMakefile();
|
||||
|
Reference in New Issue
Block a user