mirror of
https://github.com/nasa/trick.git
synced 2025-04-18 16:17:43 +00:00
Backport better clang support from 17 to 15 for ICG #376
Backported the changes in 17 that supports clang versions >= 3.8.
This commit is contained in:
parent
dc2effe6b7
commit
bc9102c208
trick_source/codegen/Interface_Code_Gen
@ -38,11 +38,9 @@ void HeaderSearchDirs::AddCompilerBuiltInSearchDirs () {
|
||||
#if __linux
|
||||
std::stringstream icg_dir ;
|
||||
icg_dir << LLVM_HOME << "/lib/clang/" ;
|
||||
icg_dir << __clang_major__ << "." << __clang_minor__ ;
|
||||
#if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ >= 4))
|
||||
#ifdef __clang_patchlevel__
|
||||
icg_dir << "." << __clang_patchlevel__ ;
|
||||
#endif
|
||||
icg_dir << LIBCLANG_MAJOR << "." << LIBCLANG_MINOR ;
|
||||
#ifdef LIBCLANG_PATCHLEVEL
|
||||
icg_dir << "." << LIBCLANG_PATCHLEVEL ;
|
||||
#endif
|
||||
icg_dir << "/include" ;
|
||||
char * resolved_path = realpath(icg_dir.str().c_str(), NULL ) ;
|
||||
@ -80,11 +78,7 @@ void HeaderSearchDirs::AddCompilerBuiltInSearchDirs () {
|
||||
//std::cout << "dir = " << dir << std::endl ;
|
||||
if ( resolved_path != NULL ) {
|
||||
//std::cout << "gcc resolved_path = " << resolved_path << std::endl ;
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
hso.AddPath(resolved_path , clang::frontend::System, IsFramework, IsSysRootRelative);
|
||||
#else
|
||||
hso.AddPath(resolved_path , clang::frontend::System, IsUserSupplied, IsFramework, IsSysRootRelative);
|
||||
#endif
|
||||
free(resolved_path) ;
|
||||
}
|
||||
} else if ( !strncmp( line, "#include <...>", 14 )) {
|
||||
@ -107,11 +101,7 @@ void HeaderSearchDirs::AddUserSearchDirs ( std::vector<std::string> & include_di
|
||||
char * resolved_path = almostRealPath(include_dirs[ii].c_str()) ;
|
||||
if ( resolved_path != NULL ) {
|
||||
//std::cout << "adding resolved_path = " << resolved_path << std::endl ;
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
hso.AddPath(resolved_path , clang::frontend::Angled, false, true);
|
||||
#else
|
||||
hso.AddPath(resolved_path , clang::frontend::Angled, true, false, true);
|
||||
#endif
|
||||
// Add the path as a system path as well for those included files that are erroneously in <>
|
||||
}
|
||||
}
|
||||
@ -124,11 +114,7 @@ void HeaderSearchDirs::AddTrickSearchDirs () {
|
||||
if ( trick_home != NULL ) {
|
||||
std::string temp_dir = std::string(trick_home) + "/trick_source" ;
|
||||
char * resolved_path = almostRealPath(temp_dir.c_str() ) ;
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
hso.AddPath(resolved_path , clang::frontend::Quoted, false, true);
|
||||
#else
|
||||
hso.AddPath(resolved_path , clang::frontend::Quoted, true, false, true);
|
||||
#endif
|
||||
trick_source_dir = std::string(resolved_path) ;
|
||||
free(resolved_path) ;
|
||||
}
|
||||
|
@ -7,11 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "clang/Lex/HeaderSearch.h"
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
#include "clang/Lex/HeaderSearchOptions.h"
|
||||
#else
|
||||
#include "clang/Frontend/HeaderSearchOptions.h"
|
||||
#endif
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
|
||||
/**
|
||||
|
@ -62,15 +62,6 @@ Most of the main program is pieced together from examples on the web. We are doi
|
||||
*/
|
||||
int main( int argc , char * argv[] ) {
|
||||
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 5)
|
||||
clang::TargetOptions to;
|
||||
#elif (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
clang::TargetOptions * to = new clang::TargetOptions() ;
|
||||
#else
|
||||
clang::TargetOptions to;
|
||||
#endif
|
||||
clang::CompilerInstance ci;
|
||||
|
||||
/* Gather all of the command line arguments into lists of include directories, defines, and input files.
|
||||
All other arguments will be ignored. */
|
||||
llvm::cl::SetVersionPrinter(ICG_version) ;
|
||||
@ -90,67 +81,54 @@ int main( int argc , char * argv[] ) {
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
ci.createDiagnostics();
|
||||
#else
|
||||
ci.createDiagnostics(0,NULL);
|
||||
#endif
|
||||
clang::DiagnosticOptions & diago = ci.getDiagnosticOpts() ;
|
||||
diago.ShowColors = 1 ;
|
||||
ci.getDiagnostics().setIgnoreAllWarnings(true) ;
|
||||
#if ( GCC_MAJOR == 4 ) && ( GCC_MINOR <= 2 )
|
||||
ci.getDiagnostics().setSuppressAllDiagnostics() ;
|
||||
#endif
|
||||
|
||||
// Set all of the defaults to c++
|
||||
clang::CompilerInstance ci;
|
||||
#if (LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR < 9)
|
||||
clang::CompilerInvocation::setLangDefaults(ci.getLangOpts() , clang::IK_CXX) ;
|
||||
#endif
|
||||
ci.createDiagnostics();
|
||||
ci.getDiagnosticOpts().ShowColors = 1 ;
|
||||
ci.getDiagnostics().setIgnoreAllWarnings(true) ;
|
||||
ci.getLangOpts().CXXExceptions = true ;
|
||||
|
||||
// Activate C++11 parsing
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
ci.getLangOpts().Bool = true ;
|
||||
ci.getLangOpts().WChar = true ;
|
||||
ci.getLangOpts().CPlusPlus = true ;
|
||||
ci.getLangOpts().CPlusPlus11 = true ;
|
||||
#else
|
||||
ci.getLangOpts().CPlusPlus0x = true ;
|
||||
#endif
|
||||
|
||||
// Set the default target architecture
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 5)
|
||||
to.Triple = llvm::sys::getDefaultTargetTriple();
|
||||
#elif (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
to->Triple = llvm::sys::getDefaultTargetTriple();
|
||||
#else
|
||||
to.Triple = llvm::sys::getDefaultTargetTriple();
|
||||
#endif
|
||||
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 5)
|
||||
std::shared_ptr<clang::TargetOptions> shared_to = std::make_shared<clang::TargetOptions>(to) ;
|
||||
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), shared_to);
|
||||
#else
|
||||
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), to);
|
||||
#endif
|
||||
ci.setTarget(pti);
|
||||
ci.getLangOpts().CXXOperatorNames = true ;
|
||||
|
||||
// Create all of the necessary managers.
|
||||
ci.createFileManager();
|
||||
ci.createSourceManager(ci.getFileManager());
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 5)
|
||||
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
||||
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 * to = new clang::TargetOptions() ;
|
||||
to->Triple = llvm::sys::getDefaultTargetTriple();
|
||||
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), to);
|
||||
ci.setTarget(pti);
|
||||
ci.createPreprocessor();
|
||||
#endif
|
||||
|
||||
clang::HeaderSearch & hs = ci.getPreprocessor().getHeaderSearchInfo() ;
|
||||
clang::HeaderSearchOptions & hso = ci.getHeaderSearchOpts() ;
|
||||
clang::Preprocessor & pp = ci.getPreprocessor() ;
|
||||
// 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& pp = ci.getPreprocessor();
|
||||
|
||||
// Add all of the include directories to the preprocessor
|
||||
HeaderSearchDirs hsd(hs , hso , pp, sim_services_flag) ;
|
||||
HeaderSearchDirs hsd(ci.getPreprocessor().getHeaderSearchInfo(), ci.getHeaderSearchOpts(), pp, sim_services_flag) ;
|
||||
hsd.addSearchDirs ( include_dirs ) ;
|
||||
|
||||
// Tell the preprocessor to use its default predefines
|
||||
clang::PreprocessorOptions & ppo = ci.getPreprocessorOpts() ;
|
||||
ppo.UsePredefines = true;
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 8)
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 8))
|
||||
pp.getBuiltinInfo().initializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
|
||||
#else
|
||||
pp.getBuiltinInfo().InitializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
|
||||
@ -160,12 +138,7 @@ int main( int argc , char * argv[] ) {
|
||||
|
||||
// Add our comment saver as a comment handler in the preprocessor
|
||||
CommentSaver cs(ci.getSourceManager()) ;
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 3)
|
||||
pp.addCommentHandler(&cs) ;
|
||||
#else
|
||||
pp.AddCommentHandler(&cs) ;
|
||||
#endif
|
||||
|
||||
|
||||
PrintAttributes pa( attr_version, hsd, cs, ci, force, sim_services_flag) ;
|
||||
|
||||
@ -174,9 +147,8 @@ int main( int argc , char * argv[] ) {
|
||||
|
||||
// Tell the compiler to use our ICGASTconsumer
|
||||
ICGASTConsumer *astConsumer = new ICGASTConsumer(ci, hsd, cs, pa);
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 6)
|
||||
std::unique_ptr<clang::ASTConsumer> unique_ast(astConsumer) ;
|
||||
ci.setASTConsumer(std::move(unique_ast));
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 6))
|
||||
ci.setASTConsumer(std::move(std::unique_ptr<clang::ASTConsumer>(astConsumer)));
|
||||
#else
|
||||
ci.setASTConsumer(astConsumer);
|
||||
#endif
|
||||
@ -195,7 +167,7 @@ int main( int argc , char * argv[] ) {
|
||||
|
||||
// Open up the input file and parse it.
|
||||
const clang::FileEntry *pFile = ci.getFileManager().getFile(input_file_full_path);
|
||||
#if (__clang_major__ == 3) && (__clang_minor__ >= 5)
|
||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
||||
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(pFile, clang::SourceLocation(), clang::SrcMgr::C_User));
|
||||
#else
|
||||
ci.getSourceManager().createMainFileID(pFile);
|
||||
|
@ -2,20 +2,18 @@
|
||||
# The config_${HOST_TYPE}.mk file provides LLVM_HOME
|
||||
include ${TRICK_HOME}/makefiles/Makefile.common
|
||||
|
||||
CC := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --bindir)/clang
|
||||
CXX := $(shell $(LLVM_HOME)/bin/$(LLVM_CONFIG) --bindir)/clang++
|
||||
CXXFLAGS := -g -I$(shell $(LLVM_HOME)/bin/llvm-config --includedir) -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti
|
||||
|
||||
CLANG_MINOR_GTEQ5 := $(shell expr `$(LLVM_HOME)/bin/llvm-config --version | cut -f2 -d. ` \>= 5 )
|
||||
CLANG_MAJOR := $(shell $(LLVM_HOME)/bin/llvm-config --version | cut -f1 -d.)
|
||||
CLANG_MINOR := $(shell $(LLVM_HOME)/bin/llvm-config --version | cut -f2 -d.)
|
||||
CLANG_PATCHLEVEL := $(shell $(LLVM_HOME)/bin/llvm-config --version | cut -f3 -d.)
|
||||
# check to see if version is greater than 3.5
|
||||
CLANG_MINOR_GTEQ5 := $(shell [ $(CLANG_MAJOR) -gt 3 -o \( $(CLANG_MAJOR) -eq 3 -a $(CLANG_MINOR) -ge 5 \) ] && echo 1)
|
||||
|
||||
LLVMLDFLAGS := $(shell $(LLVM_HOME)/bin/llvm-config --ldflags)
|
||||
|
||||
OBJ_DIR := object_$(TRICK_HOST_CPU)
|
||||
|
||||
ifeq ($(IS_CC_CLANG), 0)
|
||||
CXXFLAGS += -DGCC_MAJOR=$(GCC_MAJOR) -DGCC_MINOR=$(GCC_MINOR)
|
||||
endif
|
||||
|
||||
ICG := ICG_$(shell uname -s)_$(shell uname -m)
|
||||
|
||||
SOURCES = $(wildcard *.cpp)
|
||||
@ -38,30 +36,34 @@ CLANGLIBS = \
|
||||
-lclangLex \
|
||||
-lclangBasic \
|
||||
|
||||
CXXFLAGS += -DLIBCLANG_MAJOR=$(CLANG_MAJOR) -DLIBCLANG_MINOR=$(CLANG_MINOR)
|
||||
ifneq ($(CLANG_PATCHLEVEL),)
|
||||
CXXFLAGS += -DLIBCLANG_PATCHLEVEL=$(CLANG_PATCHLEVEL)
|
||||
endif
|
||||
|
||||
ifeq ($(TRICK_HOST_TYPE),Linux)
|
||||
CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --libs)
|
||||
ifeq ($(CLANG_MINOR_GTEQ5),1)
|
||||
CXXFLAGS += -std=c++11
|
||||
# Fedora 21 adds -ledit as a system lib, but it isn't installed, or required.
|
||||
CLANGLIBS += $(filter-out -ledit,$(shell $(LLVM_HOME)/bin/llvm-config --system-libs))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(TRICK_HOST_TYPE),Darwin)
|
||||
CXXFLAGS += -std=c++11
|
||||
CLANGLIBS += -lLLVMOption -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMSupport $(shell $(LLVM_HOME)/bin/llvm-config --system-libs)
|
||||
CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --libs)
|
||||
CLANGLIBS += $(shell $(LLVM_HOME)/bin/llvm-config --system-libs)
|
||||
CLANGLIBS += -lc++abi
|
||||
endif
|
||||
|
||||
all: $(ICG)
|
||||
|
||||
$(ICG): $(OBJECTS) $(UNITS_CONV_OBJ)
|
||||
$(CXX) -o $@ $(OBJECTS) $(UNITS_CONV_OBJ) $(LLVMLDFLAGS) $(CLANGLIBS)
|
||||
$(CXX) -o $@ $(OBJECTS) $(UNITS_CONV_OBJ) $(CLANGLIBS) $(LLVMLDFLAGS)
|
||||
|
||||
# Only FieldDescription.cpp includes the units conversion header.
|
||||
$(OBJ_DIR)/FieldDescription.o : CXXFLAGS += $(UNITS_CONV_INCLUDE)
|
||||
$(OBJ_DIR)/HeaderSearchDirs.o : CXXFLAGS += -DLLVM_HOME=\"${LLVM_HOME}\"
|
||||
$(OBJ_DIR)/main.o : CXXFLAGS += $(UNITS_CONV_INCLUDE)
|
||||
$(OBJ_DIR)/main.o : CXXFLAGS += $(UNITS_CONV_INCLUDE) -DTRICK_VERSION=\"${TRICK_VERSION}\"
|
||||
|
||||
$(OBJECTS): $(OBJ_DIR)/%.o : %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
Loading…
x
Reference in New Issue
Block a user