mirror of
https://github.com/nasa/trick.git
synced 2025-02-21 09:31:49 +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:
parent
e66fc2bbd5
commit
ba75f6ff37
@ -56,7 +56,7 @@ bool CXXRecordVisitor::TraverseDecl(clang::Decl *d) {
|
|||||||
clang::RecordDecl * rd = crd->getDefinition() ;
|
clang::RecordDecl * rd = crd->getDefinition() ;
|
||||||
if ( rd != NULL ) {
|
if ( rd != NULL ) {
|
||||||
if ( rd->getAccess() == clang::AS_public ) {
|
if ( rd->getAccess() == clang::AS_public ) {
|
||||||
if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) {
|
if ( isInUserCode(ci , crd->getSourceRange().getEnd(), hsd) ) {
|
||||||
CXXRecordVisitor embedded_cvis(ci , cs, hsd , pa, true) ;
|
CXXRecordVisitor embedded_cvis(ci , cs, hsd , pa, true) ;
|
||||||
embedded_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ;
|
embedded_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ;
|
||||||
pa.printClass(embedded_cvis.get_class_data()) ;
|
pa.printClass(embedded_cvis.get_class_data()) ;
|
||||||
@ -149,7 +149,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return false to stop processing if this header file is excluded by one of many reasons.
|
// Return false to stop processing if this header file is excluded by one of many reasons.
|
||||||
std::string header_file_name = getFileName(ci , rec->getRBraceLoc(), hsd) ;
|
std::string header_file_name = getFileName(ci , rec->getSourceRange().getEnd(), hsd) ;
|
||||||
char * rp = almostRealPath(header_file_name.c_str()) ;
|
char * rp = almostRealPath(header_file_name.c_str()) ;
|
||||||
if ( rp == NULL ||
|
if ( rp == NULL ||
|
||||||
!hsd.isPathInUserDir(rp) ||
|
!hsd.isPathInUserDir(rp) ||
|
||||||
@ -200,13 +200,13 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
clang::RecordDecl * rd = rt->getDecl() ;
|
clang::RecordDecl * rd = rt->getDecl() ;
|
||||||
//std::cout << " [34m" << cval.getName() << " inherits from " << rd->getNameAsString() << "[00m" << std::endl ;
|
//std::cout << " [34m" << cval.getName() << " inherits from " << rd->getNameAsString() << "[00m" << std::endl ;
|
||||||
//rd->dump() ; std::cout << std::endl ;
|
//rd->dump() ; std::cout << std::endl ;
|
||||||
if ( isInUserOrTrickCode(ci , rd->getRBraceLoc(), hsd) ) {
|
if ( isInUserOrTrickCode(ci , rd->getSourceRange().getEnd(), hsd) ) {
|
||||||
const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec);
|
const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec);
|
||||||
unsigned int inherit_class_offset ;
|
unsigned int inherit_class_offset ;
|
||||||
|
|
||||||
inherit_class_offset = record_layout.getBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ;
|
inherit_class_offset = record_layout.getBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ;
|
||||||
//std::cout << " [34minherit_class_offset = " << inherit_class_offset << "[00m" << std::endl ;
|
//std::cout << " [34minherit_class_offset = " << inherit_class_offset << "[00m" << std::endl ;
|
||||||
//std::cout << " [34m" << getFileName(ci , rd->getRBraceLoc(), hsd) << "[00m" << std::endl ;
|
//std::cout << " [34m" << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "[00m" << std::endl ;
|
||||||
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
||||||
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
||||||
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(),
|
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(),
|
||||||
@ -248,7 +248,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
//std::cout << " [34m" << cval.getName() << " virtually inherits from "
|
//std::cout << " [34m" << cval.getName() << " virtually inherits from "
|
||||||
// << rd->getNameAsString() << "[00m" << std::endl ;
|
// << rd->getNameAsString() << "[00m" << std::endl ;
|
||||||
//rd->dump() ; std::cout << std::endl ;
|
//rd->dump() ; std::cout << std::endl ;
|
||||||
if ( isInUserOrTrickCode(ci , rd->getRBraceLoc(), hsd) ) {
|
if ( isInUserOrTrickCode(ci , rd->getSourceRange().getEnd(), hsd) ) {
|
||||||
const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec);
|
const clang::ASTRecordLayout &record_layout = rec->getASTContext().getASTRecordLayout(rec);
|
||||||
unsigned int inherit_class_offset ;
|
unsigned int inherit_class_offset ;
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ bool CXXRecordVisitor::VisitCXXRecordDecl( clang::CXXRecordDecl *rec ) {
|
|||||||
inherit_class_offset = record_layout.getVBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ;
|
inherit_class_offset = record_layout.getVBaseClassOffset(llvm::cast<clang::CXXRecordDecl>(rd)).getQuantity() ;
|
||||||
|
|
||||||
//std::cout << " [34minherit_class_offset = " << inherit_class_offset << "[00m" << std::endl ;
|
//std::cout << " [34minherit_class_offset = " << inherit_class_offset << "[00m" << std::endl ;
|
||||||
//std::cout << " [34m" << getFileName(ci , rd->getRBraceLoc(), hsd) << "[00m" << std::endl ;
|
//std::cout << " [34m" << getFileName(ci , rd->getSourceRange().getEnd(), hsd) << "[00m" << std::endl ;
|
||||||
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
CXXRecordVisitor inherit_cvis(ci , cs, hsd , pa, false) ;
|
||||||
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
inherit_cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(rd)) ;
|
||||||
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(), inherit_class_offset, true) ;
|
cval.addInheritedFieldDescriptions(inherit_cvis.get_class_data()->getFieldDescription(), inherit_class_offset, true) ;
|
||||||
|
@ -26,7 +26,7 @@ bool EnumVisitor::VisitType(clang::Type *t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) {
|
bool EnumVisitor::VisitEnumDecl(clang::EnumDecl *ed) {
|
||||||
eval.setFileName(getFileName(ci , ed->getRBraceLoc(), hsd)) ;
|
eval.setFileName(getFileName(ci , ed->getSourceRange().getEnd(), hsd)) ;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,6 +300,7 @@ void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassVa
|
|||||||
ostream << " typedef " << cv->getName() << " " << cv->getMangledTypeName() << " ;\n\n" ;
|
ostream << " typedef " << cv->getName() << " " << cv->getMangledTypeName() << " ;\n\n" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
if ( !global_compat15 and !cv->isCompat15()) {
|
if ( !global_compat15 and !cv->isCompat15()) {
|
||||||
ostream << " if ( sizeof(" ;
|
ostream << " if ( sizeof(" ;
|
||||||
printNamespaces( ostream, cv , "::" ) ;
|
printNamespaces( ostream, cv , "::" ) ;
|
||||||
@ -314,6 +315,7 @@ void PrintFileContents10::print_init_attr_func( std::ostream & ostream , ClassVa
|
|||||||
ostream << cv->getName() << ") - " << cv->getSize() << ") , \"" << cv->getFileName() << "\")) ;\n" ;
|
ostream << cv->getName() << ") - " << cv->getSize() << ") , \"" << cv->getFileName() << "\")) ;\n" ;
|
||||||
ostream << " }\n" ;
|
ostream << " }\n" ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned int ii = 0 ;
|
unsigned int ii = 0 ;
|
||||||
for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
|
for ( fit = cv->field_begin() ; fit != cv->field_end() ; fit++ ) {
|
||||||
|
@ -46,29 +46,33 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
|
|||||||
In this case the CXXRecordDecl file name will not match the current file name, and is
|
In this case the CXXRecordDecl file name will not match the current file name, and is
|
||||||
in fact empty */
|
in fact empty */
|
||||||
clang::RecordDecl * rd = crd->getDefinition() ;
|
clang::RecordDecl * rd = crd->getDefinition() ;
|
||||||
if ( rd != NULL and ! getFileName(ci , crd->getRBraceLoc(), hsd).empty() ) {
|
if ( rd != NULL ) {
|
||||||
//crd->dump() ; std::cout << std::endl ;
|
std::string rd_file = getFileName(ci , rd->getSourceRange().getEnd(), hsd) ;
|
||||||
if ( isInUserCode(ci , crd->getRBraceLoc(), hsd) ) {
|
std::string crd_file = getFileName(ci , crd->getSourceRange().getEnd(), hsd) ;
|
||||||
CXXRecordVisitor cvis(ci , cs, hsd , pa, true) ;
|
if (!crd_file.empty() and !crd_file.compare(rd_file)) {
|
||||||
|
//crd->dump() ; std::cout << std::endl ;
|
||||||
|
if ( isInUserCode(ci , crd->getSourceRange().getEnd(), hsd) ) {
|
||||||
|
CXXRecordVisitor cvis(ci , cs, hsd , pa, true) ;
|
||||||
|
|
||||||
cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ;
|
cvis.TraverseCXXRecordDecl(static_cast<clang::CXXRecordDecl *>(d)) ;
|
||||||
pa.printClass(cvis.get_class_data()) ;
|
pa.printClass(cvis.get_class_data()) ;
|
||||||
|
|
||||||
/* Check to see if the struct/class is forward declared in the same file.
|
/* Check to see if the struct/class is forward declared in the same file.
|
||||||
If it is, then remove the notation that it is forward declared. This
|
If it is, then remove the notation that it is forward declared. This
|
||||||
is to allow C structs to be forward declared and typedeffed and io_src
|
is to allow C structs to be forward declared and typedeffed and io_src
|
||||||
code will be generated for both the original structure name and typedeffed
|
code will be generated for both the original structure name and typedeffed
|
||||||
name.
|
name.
|
||||||
|
|
||||||
struct Astruct ;
|
struct Astruct ;
|
||||||
typedef struct Astruct {} Bstruct ;
|
typedef struct Astruct {} Bstruct ;
|
||||||
*/
|
*/
|
||||||
std::set< std::string >::iterator it ;
|
std::set< std::string >::iterator it ;
|
||||||
std::string file_name = getFileName(ci , d->getLocEnd(), hsd) ;
|
std::string file_name = getFileName(ci , d->getLocEnd(), hsd) ;
|
||||||
std::string source_type = cvis.get_class_data()->getName() ;
|
std::string source_type = cvis.get_class_data()->getName() ;
|
||||||
it = fwd_declared_classes[file_name].find(source_type) ;
|
it = fwd_declared_classes[file_name].find(source_type) ;
|
||||||
if ( it != fwd_declared_classes[file_name].end() ) {
|
if ( it != fwd_declared_classes[file_name].end() ) {
|
||||||
fwd_declared_classes[file_name].erase(it) ;
|
fwd_declared_classes[file_name].erase(it) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -81,7 +85,7 @@ bool TranslationUnitVisitor::TraverseDecl(clang::Decl *d) {
|
|||||||
break ;
|
break ;
|
||||||
case clang::Decl::Enum : {
|
case clang::Decl::Enum : {
|
||||||
clang::EnumDecl * ed = static_cast<clang::EnumDecl *>(d) ;
|
clang::EnumDecl * ed = static_cast<clang::EnumDecl *>(d) ;
|
||||||
if ( isInUserCode(ci , ed->getRBraceLoc(), hsd) ) {
|
if ( isInUserCode(ci , ed->getSourceRange().getEnd(), hsd) ) {
|
||||||
EnumVisitor evis(ci, hsd) ;
|
EnumVisitor evis(ci, hsd) ;
|
||||||
evis.TraverseDecl(ed) ;
|
evis.TraverseDecl(ed) ;
|
||||||
//if ( evis.get_enum_data() != NULL ) {
|
//if ( evis.get_enum_data() != NULL ) {
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
#include "PrintAttributesFactory.hh"
|
#include "PrintAttributesFactory.hh"
|
||||||
#include "Utilities.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> 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::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> 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> 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<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<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<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"));
|
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> 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> 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::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:
|
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;
|
std::cerr << "No header file specified" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
clang::CompilerInstance ci ;
|
||||||
|
#if (LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR < 9)
|
||||||
|
clang::CompilerInvocation::setLangDefaults(ci.getLangOpts() , clang::IK_CXX) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
clang::CompilerInstance compilerInstance;
|
ci.createDiagnostics();
|
||||||
compilerInstance.createDiagnostics();
|
ci.getDiagnosticOpts().ShowColors = 1 ;
|
||||||
compilerInstance.getDiagnosticOpts().ShowColors = 1;
|
ci.getDiagnostics().setIgnoreAllWarnings(true) ;
|
||||||
compilerInstance.getDiagnostics().setIgnoreAllWarnings(true);
|
ci.getLangOpts().CXXExceptions = true ;
|
||||||
|
|
||||||
// Set all of the defaults to c++
|
|
||||||
clang::CompilerInvocation::setLangDefaults(compilerInstance.getLangOpts(), clang::IK_CXX);
|
|
||||||
compilerInstance.getLangOpts().CXXExceptions = true;
|
|
||||||
|
|
||||||
// Activate C++11 parsing
|
// 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
|
// Set the default target architecture
|
||||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
||||||
clang::TargetOptions targetOptions;
|
clang::TargetOptions to;
|
||||||
targetOptions.Triple = llvm::sys::getDefaultTargetTriple();
|
to.Triple = llvm::sys::getDefaultTargetTriple();
|
||||||
compilerInstance.setTarget(clang::TargetInfo::CreateTargetInfo(compilerInstance.getDiagnostics(), std::make_shared<clang::TargetOptions>(targetOptions)));
|
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
|
#else
|
||||||
clang::TargetOptions* targetOptions = new clang::TargetOptions();
|
clang::TargetOptions * to = new clang::TargetOptions() ;
|
||||||
targetOptions->Triple = llvm::sys::getDefaultTargetTriple();
|
to->Triple = llvm::sys::getDefaultTargetTriple();
|
||||||
compilerInstance.setTarget(clang::TargetInfo::CreateTargetInfo(compilerInstance.getDiagnostics(), targetOptions));
|
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), to);
|
||||||
|
ci.setTarget(pti);
|
||||||
|
ci.createPreprocessor();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create all of the necessary managers
|
// Set all of the defaults to c++
|
||||||
compilerInstance.createFileManager();
|
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 9))
|
||||||
compilerInstance.createSourceManager(compilerInstance.getFileManager());
|
llvm::Triple trip (to.Triple) ;
|
||||||
|
clang::CompilerInvocation::setLangDefaults(ci.getLangOpts(), clang::IK_CXX, trip, ppo) ;
|
||||||
// Create the preprocessor
|
// setting the language defaults clears the c++11 flag.
|
||||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
ci.getLangOpts().CPlusPlus11 = true ;
|
||||||
compilerInstance.createPreprocessor(clang::TU_Complete);
|
|
||||||
#else
|
|
||||||
compilerInstance.createPreprocessor();
|
|
||||||
#endif
|
#endif
|
||||||
clang::Preprocessor& preprocessor = compilerInstance.getPreprocessor();
|
clang::Preprocessor& pp = ci.getPreprocessor();
|
||||||
|
|
||||||
// Add all of the include directories to the preprocessor
|
// Add all of the include directories to the preprocessor
|
||||||
HeaderSearchDirs headerSearchDirs(compilerInstance.getPreprocessor().getHeaderSearchInfo(), compilerInstance.getHeaderSearchOpts(), preprocessor, sim_services_flag);
|
HeaderSearchDirs hsd(ci.getPreprocessor().getHeaderSearchInfo(), ci.getHeaderSearchOpts(), pp, sim_services_flag);
|
||||||
headerSearchDirs.addSearchDirs(include_dirs);
|
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))
|
#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
|
#else
|
||||||
preprocessor.getBuiltinInfo().InitializeBuiltins(preprocessor.getIdentifierTable(), preprocessor.getLangOpts());
|
pp.getBuiltinInfo().InitializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
|
||||||
#endif
|
#endif
|
||||||
// Add all of the #define from the command line to the default predefines
|
// 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
|
// Add our comment saver as a comment handler in the preprocessor
|
||||||
CommentSaver commentSaver(compilerInstance, headerSearchDirs);
|
CommentSaver cs(ci, hsd);
|
||||||
preprocessor.addCommentHandler(&commentSaver);
|
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
|
// Create new class and enum map files
|
||||||
if (create_map) {
|
if (create_map) {
|
||||||
@ -134,14 +146,14 @@ int main(int argc, char * argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tell the compiler to use our ICGASTconsumer
|
// 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))
|
#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
|
#else
|
||||||
compilerInstance.setASTConsumer(astConsumer);
|
ci.setASTConsumer(astConsumer);
|
||||||
#endif
|
#endif
|
||||||
compilerInstance.createASTContext();
|
ci.createASTContext();
|
||||||
compilerInstance.createSema(clang::TU_Prefix, NULL);
|
ci.createSema(clang::TU_Prefix, NULL);
|
||||||
|
|
||||||
// Get the full path of the file to be read
|
// Get the full path of the file to be read
|
||||||
char buffer[input_file_names[0].size()];
|
char buffer[input_file_names[0].size()];
|
||||||
@ -158,16 +170,16 @@ int main(int argc, char * argv[]) {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
// Open up the input file and parse it
|
// 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);
|
free(inputFilePath);
|
||||||
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
|
#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
|
#else
|
||||||
compilerInstance.getSourceManager().createMainFileID(fileEntry);
|
ci.getSourceManager().createMainFileID(fileEntry);
|
||||||
#endif
|
#endif
|
||||||
compilerInstance.getDiagnosticClient().BeginSourceFile(compilerInstance.getLangOpts(), &compilerInstance.getPreprocessor());
|
ci.getDiagnosticClient().BeginSourceFile(ci.getLangOpts(), &ci.getPreprocessor());
|
||||||
clang::ParseAST(compilerInstance.getSema());
|
clang::ParseAST(ci.getSema());
|
||||||
compilerInstance.getDiagnosticClient().EndSourceFile();
|
ci.getDiagnosticClient().EndSourceFile();
|
||||||
|
|
||||||
if (!sim_services_flag) {
|
if (!sim_services_flag) {
|
||||||
printAttributes.printIOMakefile();
|
printAttributes.printIOMakefile();
|
||||||
|
@ -48,7 +48,8 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(TRICK_HOST_TYPE),Darwin)
|
ifeq ($(TRICK_HOST_TYPE),Darwin)
|
||||||
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
|
CLANGLIBS += -lc++abi
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user