From d7b386227a193565bc942f0f6186d9a5c286aa4c Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Tue, 21 Jul 2015 08:52:00 -0500 Subject: [PATCH] Split CP up into components that can be called individually Fixed some library dependency bugs. JEOD test sims compile now. refs #86 --- libexec/trick/make_makefile_swig | 2 +- libexec/trick/pm/get_lib_deps.pm | 14 ++++---- libexec/trick/pm/s_source.pm | 4 +-- share/trick/makefiles/Makefile.sim | 7 ++-- .../Interface_Code_Gen/PrintAttributes.cpp | 36 +++++++++++++++++++ .../Interface_Code_Gen/PrintAttributes.hh | 6 ++++ 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index 4bbaa9f5..56860b99 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -300,7 +300,7 @@ OBJECTS += \$(SWIG_MODULE_OBJECTS) open TOPFILE , ">build/top.i" or return ; print TOPFILE "\%module top\n\n" ; print TOPFILE "\%{\n#include \"../S_source.hh\"\n\n" ; - print TOPFILE map { "extern $_" } @instances ; + print TOPFILE @instances ; print TOPFILE "\n\%}\n\n" ; print TOPFILE "\%import \"build$wd/S_source.i\"\n\n" ; print TOPFILE @instances ; diff --git a/libexec/trick/pm/get_lib_deps.pm b/libexec/trick/pm/get_lib_deps.pm index e23c7c69..8b0ea416 100644 --- a/libexec/trick/pm/get_lib_deps.pm +++ b/libexec/trick/pm/get_lib_deps.pm @@ -15,7 +15,7 @@ sub get_lib_deps ($$) { my (@lib_list) ; my (@inc_paths) ; - ($lib_deps) = $contents =~ /LIBRARY[ _]DEPENDENC(?:Y|IES):[^(]*(.*?)\)([A-Z _\t\n\r]+:|[ \t\n\r]*$)/si ; + ($lib_deps) = $contents =~ /LIBRARY[ _]DEPENDENC(?:Y|IES):[^(]*(.*?)\)([A-Z _\t\n\r]+:|\s*\*)/si ; @lib_list = split /\)[ \t\n\r\*]*\(/ , $lib_deps ; @inc_paths = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS @@ -59,18 +59,20 @@ sub get_lib_deps ($$) { } } else { $l =~ s/o$// ; + my ($rel_dir) = dirname($l) ; + my ($base) = basename($l) ; foreach my $inc ( $file_path_dir , @inc_paths) { foreach my $ext ( "cpp" , "cc" , "c" , "c++" , "cxx" , "C" ) { - if ( -e "$inc/$l$ext" ) { + if ( -e "$inc/$rel_dir/$base$ext" ) { #print "found $inc/$l$ext\n" ; - my $f = abs_path(dirname("$inc/$l$ext")) . "/" . basename("$inc/$l$ext") ; + my $f = abs_path("$inc/$rel_dir") . "/$base$ext" ; push @resolved_files, $f ; $found = 1 ; last ; } - elsif ( -e "$inc/src/$l$ext" ) { + elsif ( -e "$inc/$rel_dir/src/$base$ext" ) { #print "found $inc/src/$l$ext\n" ; - my $f = abs_path(dirname("$inc/src/$l$ext")) . "/" . basename("$inc/src/$l$ext") ; + my $f = abs_path("$inc/$rel_dir/src") . "/$base$ext" ; push @resolved_files, $f ; $found = 1 ; last ; @@ -81,7 +83,7 @@ sub get_lib_deps ($$) { } if ( $found == 0 ) { - print STDERR "@ARGV[0]: Warning: Could not find dependency $l\n" ; + print STDERR "Warning: Could not find dependency $l\n" ; } } return @resolved_files ; diff --git a/libexec/trick/pm/s_source.pm b/libexec/trick/pm/s_source.pm index 982c2f7d..59c2d940 100644 --- a/libexec/trick/pm/s_source.pm +++ b/libexec/trick/pm/s_source.pm @@ -319,9 +319,9 @@ PURPOSE: open S_INSTANCE, ">build/S_instances" or die "Couldn't open build/S_instances!\n"; - print S_INSTANCE $$sim_ref{instance_declarations} ; + print S_INSTANCE $$sim_ref{extern_instance_declarations} ; foreach my $integ_loop ( @{$$sim_ref{integ_loop}} ) { - print S_INSTANCE "IntegLoopSimObject $$integ_loop{name} ;\n" ; + print S_INSTANCE "extern IntegLoopSimObject $$integ_loop{name} ;\n" ; } close S_INSTANCE ; } diff --git a/share/trick/makefiles/Makefile.sim b/share/trick/makefiles/Makefile.sim index 6fac3c4d..1337e1be 100644 --- a/share/trick/makefiles/Makefile.sim +++ b/share/trick/makefiles/Makefile.sim @@ -85,11 +85,8 @@ convert_swig: $(ECHO_CMD)${TRICK_HOME}/$(LIBEXEC)/trick/convert_swig ${TRICK_CONVERT_SWIG_FLAGS} @ touch $(CURDIR)/build/convert_swig_last_run -S_define_exp: - $(TRICK_CC) -E -C -xc++ ${TRICK_SFLAGS} S_define > $@ - # Pass these options -sie: +sie S_define_exp: @if [ -f build/Makefile_src ] ; then $(MAKE) --no-print-directory -f build/Makefile_src $@ ; else echo "No build/Makefile_src found" ; fi help: @@ -121,7 +118,7 @@ apocalypse: clean # Dependencies for the above rules generated by configuration_process, ICG, make_makefile and make_makefile_swig --include S_overrides.mk +#-include S_overrides.mk -include build/S_define.deps -include build/Makefile_ICG -include build/Makefile_convert_swig diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp index ef00e2ce..d5bb2447 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.cpp @@ -357,6 +357,36 @@ void PrintAttributes::closeMapFiles() { } } +void PrintAttributes::addEmptyFiles() { + // Make a list of the empty files we processed. + // This list is written to the ICG_processed file and used by other processors. + clang::SourceManager::fileinfo_iterator fi ; + for ( fi = ci.getSourceManager().fileinfo_begin() ; fi != ci.getSourceManager().fileinfo_end() ; fi++ ) { + const clang::FileEntry * fe = (*fi).first ; + std::string header_file_name = fe->getName() ; + if ( visited_files.find(header_file_name) == visited_files.end() ) { + visited_files.insert(header_file_name) ; + // several tests require the real path of the header file. + char * rp = almostRealPath(header_file_name.c_str()) ; + if ( rp != NULL ) { + // Only include user directories (not system dirs like /usr/include) + if ( hsd.isPathInUserDir(rp) ) { + // Don't process files in excluded directories + if ( hsd.isPathInICGExclude(rp) == false ) { + // Only include files that do not have ICG: (No) + // hasICGNo uses original header name, not the real path + if ( ! cs.hasICGNo(header_file_name) ) { + std::string io_file_name = createIOFileName(std::string(rp)) ; + empty_header_files.insert(rp) ; + } + } + } + free(rp) ; + } + } + } +} + //TODO: Move this into PrintFileContents10. void PrintAttributes::printIOMakefile() { std::ofstream makefile_io_src ; @@ -447,6 +477,12 @@ void PrintAttributes::printIOMakefile() { link_io_objs << (*mit).second.substr(0,found) << ".o" << std::endl ; ICG_processed << (*mit).first << std::endl ; } + // Create the list of empty (of classes/enums) header files to be written to ICG_processed. + addEmptyFiles() ; + std::set< std::string >::iterator sit ; + for ( sit = empty_header_files.begin() ; sit != empty_header_files.end() ; sit++ ) { + ICG_processed << (*sit) << std::endl ; + } makefile_ICG << std::endl << std::endl ; makefile_ICG.close() ; link_io_objs << "build/class_map.o" << std::endl ; diff --git a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh index 12bcf452..9a00fbb7 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh +++ b/trick_source/codegen/Interface_Code_Gen/PrintAttributes.hh @@ -98,6 +98,9 @@ class PrintAttributes { bool isIOFileOutOfDate(std::string header_file_name, std::string io_file_name ) ; bool doesIODirectoryExist(std::string io_file_name ) ; + /** Adds empty header files to list of processed files. */ + void addEmptyFiles() ; + /** Determines the io_file_name based on the given header file name @param header_file_name = full path to header file @return string of full path to io_src file name. @@ -110,6 +113,9 @@ class PrintAttributes { /** map of all io_files we processed */ std::map< std::string , std::string > all_io_files ; + /** map of all io_files we processed */ + std::set< std::string > empty_header_files ; + /** map of open files to the out of date io_src file */ std::map< std::string , std::string > out_of_date_io_files ;