Merge test branch into master (#1047)

* #1041 filter -W workaround for ICG linking to LLVM 10 libclang-cpp.so (#1044)

* 1043 drg checkpoint memory leak (#1045)

* #1043 drg fix drg checkpoint memory leak

* 947 sie generation rework (#1046)

generate  S_sie.resource at during build instead of runtime
This commit is contained in:
Scott Fennell 2020-09-01 15:55:19 -05:00 committed by GitHub
parent 3b89cbfdb2
commit f825dc00fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 260 additions and 13 deletions

1
.gitignore vendored
View File

@ -32,3 +32,4 @@ trick_source/web/HttpServer/mongoose.c
trick_source/web/HttpServer/mongoose.h
trick_source/web/HttpServer/obj/
trick-offline
*sim_services_classes.resource

View File

@ -41,10 +41,12 @@ namespace Trick {
void enum_attr_map_print_xml() ;
void top_level_objects_print_xml() ;
void sie_print_json() ;
void sie_append_runtime_objs() ;
private:
void top_level_objects_print(std::ofstream & sie_out) ;
void runtime_objects_print(std::fstream & sie_out) ;
void top_level_objects_json(std::ofstream & sie_out) ;
// These are singleton maps holding all attributes known to the sim

View File

@ -309,7 +309,7 @@ all: S_sie.resource
S_sie.resource: \$(S_MAIN)
\t\$(PRINT_SIE)
\t\$(call ECHO_AND_LOG,./\$(S_MAIN) sie)\n" ;
\t\$(call ECHO_AND_LOG,\${TRICK_HOME}/\$(LIBEXEC)/trick/sie_concat)" ;
# write out the override files we have read in
open MAKEFILEOVER, ">build/Makefile_overrides" or die "Could not open build/Makefile_overrides" ;

View File

@ -17,7 +17,7 @@ sub s_source($) {
# Generate S_source.c
open S_SOURCE, ">build/S_source.cpp" or die "Couldn't open build/S_source.cpp!\n";
open S_SOURCE_H, ">S_source.hh" or die "Couldn't open S_source.hh!\n";
open CLASSES_RESOURCE, ">build/classes.resource" or die "Couldn't open classes.resource!";
# Get Trick version
my ($version, $thread) = get_trick_version() ;
@ -211,13 +211,20 @@ PURPOSE:
print S_SOURCE " " x 4 , "if ( (ai = get_alloc_info_at(&$inst)) != NULL ) {\n" ;
print S_SOURCE " " x 8 , "ai->alloced_in_memory_init = 1 ;\n" ;
print S_SOURCE " " x 4 , "}\n" ;
print CLASSES_RESOURCE " \<top_level_object\n name=\"$inst\"\n type=\"$temp_type\"\n alloc_memory_init=\"1\"\>\n \</top_level_object\>\n\n";
}
print S_SOURCE " " x 4 , "// Add Integration Loop Sim Object(s) JMP\n" ;
foreach my $integ_loop ( sort sim_integ_by_name @{$$sim_ref{integ_loop}} ) {
print S_SOURCE " " x 4 , "exec_add_sim_object(&$$integ_loop{name} , \"$$integ_loop{name}\") ;\n" ;
print S_SOURCE " " x 4 , "TMM_declare_ext_var(&$$integ_loop{name}, TRICK_STRUCTURED,\"IntegLoopSimObject\", 0, \"$$integ_loop{name}\", 0, NULL) ;\n" ;
print S_SOURCE " " x 4 , "if ( (ai = get_alloc_info_at(&$$integ_loop{name})) != NULL ) {\n" ;
print S_SOURCE " " x 8 , "ai->alloced_in_memory_init = 1 ;\n" ;
print S_SOURCE " " x 4 , "}\n" ;
print CLASSES_RESOURCE " \<top_level_object\n name=\"$$integ_loop{name}\"\n type=\"IntegLoopSimObject\"\n alloc_memory_init=\"1\"\>\n \</top_level_object\>\n\n";
}
close CLASSES_RESOURCE ;
print S_SOURCE "\n" ;
print S_SOURCE $$sim_ref{create_connections} ;

24
libexec/trick/sie_concat Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/perl
package sie_concat;
open(my $S_sie_resource, ">", "./S_sie.resource")
or die "cannot open S_sie.resource $!";
print $S_sie_resource "<?xml version=\"1.0\"?>\n\n<sie>\n\n";
open(my $classes_resource, "<", "build/classes.resource")
or die "cannot open build/classes.resource";
while(my $line = <$classes_resource>) {
print $S_sie_resource $line;
}
close($classes_resource);
open(my $sim_services_resource, "<", "$ENV{TRICK_HOME}/trick_source/sim_services/include/sim_services_classes.resource")
or die "cannot open trick/trick_source/sim_services/include/sim_services_classes.resource";
while(my $line = <$sim_services_resource>) {
print $S_sie_resource $line;
}
close($sim_services_resource);
print $S_sie_resource "<!--\nRuntime Allocations\nDo not edit this comment or file content past this point\n-->\n";
print $S_sie_resource "</sie>";
close($S_sie_resource);

View File

@ -237,7 +237,7 @@ class SieSimObject : public Trick::SimObject {
Trick::Sie sie ;
SieSimObject() {
{TRK} P0 ("default_data") sie.process_sim_args() ;
{TRK} ("initialization") sie.sie_append_runtime_objs() ;
}
}

View File

@ -10,6 +10,12 @@ void EnumValues::addEnum( std::string in_name , long long in_val ) {
enum_values.push_back(new_enum) ;
}
void EnumValues::addFullyQualifiedEnum( std::string in_name , long long in_val ) {
std::pair< std::string , long long > new_enum(in_name, in_val) ;
fully_qualified_enum_values.push_back(new_enum) ;
}
void EnumValues::setHasDefinition( bool in ) {
has_definition = in ;
}

View File

@ -31,6 +31,7 @@ class EnumValues : public ConstructValues {
EnumValues() ;
void addEnum(std::string in_name , long long in_val) ;
void addFullyQualifiedEnum(std::string in_name , long long in_val) ;
void setHasDefinition( bool in ) ;
bool getHasDefinition() ;
@ -39,6 +40,10 @@ class EnumValues : public ConstructValues {
return enum_values;
}
const std::vector<NameValuePair>& getFullyQualifiedPairs() {
return fully_qualified_enum_values;
}
friend std::ostream & operator << (std::ostream & os , EnumValues & ev ) ;
private:
@ -46,6 +51,10 @@ class EnumValues : public ConstructValues {
/** List of enums and their values */
std::vector< NameValuePair > enum_values ;
/** List of fully qualified enums and their values
This is used to generate the S_sie.resource file. */
std::vector< NameValuePair > fully_qualified_enum_values ;
bool has_definition ;
} ;

View File

@ -70,6 +70,7 @@ bool EnumVisitor::VisitEnumType(clang::EnumType *et) {
bool EnumVisitor::VisitEnumConstantDecl(clang::EnumConstantDecl *ecd) {
//std::cout << ecd->getName().str() << " = " << ecd->getInitVal().getSExtValue() << std::endl ;
eval.addEnum(ecd->getName().str() , ecd->getInitVal().getSExtValue()) ;
eval.addFullyQualifiedEnum(ecd->getQualifiedNameAsString(), ecd->getInitVal().getSExtValue());
return true ;
}

View File

@ -15,10 +15,12 @@
#include "PrintAttributes.hh"
#include "PrintFileContentsBase.hh"
#include "PrintFileContents10.hh"
#include "FieldDescription.hh"
#include "HeaderSearchDirs.hh"
#include "CommentSaver.hh"
#include "ClassValues.hh"
#include "EnumValues.hh"
#include "Utilities.hh"
PrintAttributes::PrintAttributes(int in_attr_version , HeaderSearchDirs & in_hsd ,
CommentSaver & in_cs , clang::CompilerInstance & in_ci, bool in_force , bool in_sim_services_flag ,
@ -235,6 +237,7 @@ void PrintAttributes::printClass( ClassValues * cv ) {
if (openIOFile(fileName)) {
printer->printClass(outfile, cv);
outfile.close();
printSieClass(cv);
}
if (!isHeaderExcluded(fileName, false)) {
@ -261,6 +264,7 @@ void PrintAttributes::printEnum(EnumValues* ev) {
if (openIOFile(fileName)) {
printer->printEnum(outfile, ev) ;
outfile.close() ;
printSieEnum(&enumValues) ;
}
if (!isHeaderExcluded(fileName, false)) {
@ -268,6 +272,60 @@ void PrintAttributes::printEnum(EnumValues* ev) {
}
}
void PrintAttributes::printSieClass( ClassValues * cv ) {
std::string xmlFileName;
if(sim_services_flag) {
xmlFileName = std::string(getenv("TRICK_HOME")) + "/trick_source/sim_services/include/sim_services_classes.resource";
} else {
xmlFileName = "build/classes.resource";
}
std::ofstream ostream(xmlFileName, std::ofstream::app);
ostream << " <class name=\"" << sanitize(cv->getFullyQualifiedMangledTypeName("__")) << "\">\n";
for (FieldDescription* fdes : printer->getPrintableFields(*cv)) {
std::string type = fdes->getFullyQualifiedMangledTypeName("__");
std::replace(type.begin(), type.end(), ':', '_');
ostream << " <member\n"
<< " name=\"" << fdes->getName() << "\"\n"
<< " type=\"" << replace_special_chars(type) << "\"\n"
<< " io_attributes=\"" << fdes->getIO() << "\"\n"
<< " units=\"";
if(fdes->isDashDashUnits()) {
ostream << "--\"" ;
} else {
ostream << fdes->getUnits() << "\"" ;
}
std::string description = fdes->getDescription();
if(!description.empty()) {
ostream << "\n description=\"" << replace_special_chars(description) << "\"";
}
ostream << ">\n" ;
for(int i = 0; i < fdes->getNumDims(); i++) {
ostream
<< " <dimension>" << (fdes->getArrayDim(i) != -1 ? fdes->getArrayDim(i) : 0) << "</dimension>\n";
}
ostream << " </member>\n";
}
ostream << " </class>\n" << std::endl;
ostream.close();
}
void PrintAttributes::printSieEnum( EnumValues * ev ) {
std::string xmlFileName;
if(sim_services_flag) {
xmlFileName = std::string(getenv("TRICK_HOME")) + "/trick_source/sim_services/include/sim_services_classes.resource";
} else {
xmlFileName = "build/classes.resource";
}
std::ofstream ostream(xmlFileName, std::ofstream::app);
ostream << " <enumeration name=\"" << sanitize(ev->getFullyQualifiedTypeName("__")) << "\">\n";
for(EnumValues::NameValuePair nvp : ev->getFullyQualifiedPairs()) {
ostream << " <pair label =\"" << nvp.first << "\" value=\"" << nvp.second << "\"/>\n";
}
ostream << " </enumeration>\n" << std::endl;
ostream.close();
}
void PrintAttributes::createMapFiles() {
struct stat buf ;
std::string class_map_function_name ;

View File

@ -58,6 +58,12 @@ class PrintAttributes {
/** Prints an enum to the io_src file */
virtual void printEnum( EnumValues * in_enum) ;
/** Prints a class to the XML resource file */
void printSieClass( ClassValues * cv ) ;
/** Prints an enum to the XML resource file */
void printSieEnum( EnumValues * ev ) ;
bool isHeaderExcluded(const std::string& header, bool exclude_ext_libs = true);
void markHeaderAsVisited(const std::string& header);

View File

@ -42,6 +42,9 @@ class PrintFileContentsBase {
virtual void printEnumMap(std::ostream & ostream, EnumValues * ev) ;
virtual void printEnumMapFooter(std::ostream & ostream) ;
/* gets a vector of fields that can be printed */
std::vector<FieldDescription*> getPrintableFields(ClassValues& classValues, unsigned int ioMask = 0xFFFFFFF);
protected:
/** Prints the io_src_allocate function */
virtual void print_units_map(std::ostream & ostream, ClassValues * cv) ;
@ -55,9 +58,6 @@ class PrintFileContentsBase {
/* internal function determines if a particular field is printable */
bool isPrintable(ClassValues * c , FieldDescription *fdes , unsigned int ioMask = 0xFFFFFFF) ;
/* gets a vector of fields that can be printed */
std::vector<FieldDescription*> getPrintableFields(ClassValues& classValues, unsigned int ioMask = 0xFFFFFFF);
} ;
#endif

View File

@ -14,6 +14,40 @@ std::string sanitize(const std::string& text) {
return result ;
}
// Replace special chars for xml output
std::string & replace_special_chars( std::string & str) {
// escape &
size_t index = 0;
while (index != std::string::npos) {
index = str.find("&" , index) ;
if ( index != std::string::npos ) {
str.replace(index, 1, "&amp;") ;
index += 5;
}
}
// escape "
index = 0;
while (index != std::string::npos) {
index = str.find("\\\"" , index) ;
if ( index != std::string::npos ) {
str.replace(index, 2, "&quot;") ;
}
}
// escape <
index = 0;
while (index != std::string::npos) {
index = str.find("<" , index) ;
if ( index != std::string::npos ) {
str.replace(index, 1, "&lt;") ;
}
}
return str;
}
// removes leading and trailing whitespace from a string
std::string trim(const std::string& str, const std::string& whitespace ) {
size_t strBegin = str.find_first_not_of(whitespace);

View File

@ -14,7 +14,7 @@ enum Color {
SKIP = 95
};
std::string sanitize(const std::string&);
std::string sanitize(const std::string&) ;
std::string trim( const std::string& str, const std::string& whitespace = " \t\n\r" ) ;
bool isInUserCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ;
bool isInUserOrTrickCode( clang::CompilerInstance & ci , clang::SourceLocation sl , HeaderSearchDirs & hsd ) ;
@ -27,5 +27,6 @@ std::string bold(const std::string& text);
std::string underline(const std::string& text);
std::string underline(const std::string& text, unsigned length);
std::string quote(const std::string& text);
std::string & replace_special_chars( std::string & str);
#endif

View File

@ -50,6 +50,7 @@ llvm::cl::opt<llvm::cl::boolOrDefault> print_trick_icg("print-TRICK-ICG", llvm::
llvm::cl::alias compat15_alias ("compat15" , llvm::cl::desc("Alias for -c") , llvm::cl::aliasopt(global_compat15)) ;
llvm::cl::opt<bool> m32("m32", llvm::cl::desc("Generate io code for use with 32bit mode"), llvm::cl::init(false), llvm::cl::ZeroOrMore) ;
/**
Most of the main program is pieced together from examples on the web. We are doing the following:
@ -73,8 +74,18 @@ int main(int argc, char * argv[]) {
/**
* Gather all of the command line arguments into lists of include directories, defines, and input files.
* All other arguments will be ignored.
*
* Filter out -W because of LLVM cl option that has been enabled and cannot be disabled in LLVM 10 when linking libclang-cpp.so.
* TODO: Troubleshoot or contact LLVM for a fix.
*/
llvm::cl::ParseCommandLineOptions(argc, argv);
std::vector<const char *> filtered_args;
for ( unsigned int ii = 0; ii < argc ; ii++ ) {
if( strncmp(argv[ii], "-W", 2) ) {
filtered_args.push_back(argv[ii]);
}
}
llvm::cl::ParseCommandLineOptions(filtered_args.size(), filtered_args.data());
if (input_file_names.empty()) {
std::cerr << "No header file specified" << std::endl;

View File

@ -450,10 +450,35 @@ int Trick::DataRecordGroup::checkpoint() {
}
void Trick::DataRecordGroup::clear_checkpoint_vars() {
if ( variable_names ) TMM_delete_var_a(variable_names) ;
if ( variable_alias ) TMM_delete_var_a(variable_alias) ;
if ( change_variable_names ) TMM_delete_var_a(change_variable_names) ;
if ( change_variable_alias ) TMM_delete_var_a(change_variable_alias) ;
if ( variable_names ) {
for(int jj = 0; jj < num_variable_names; jj++) {
TMM_delete_var_a(variable_names[jj]);
}
TMM_delete_var_a(variable_names) ;
}
if ( variable_alias ) {
for(int jj = 0; jj < num_variable_names; jj++) {
TMM_delete_var_a(variable_alias[jj]);
}
TMM_delete_var_a(variable_alias) ;
}
if ( change_variable_names ) {
for(int jj = 0; jj < num_change_variable_names; jj++) {
TMM_delete_var_a(change_variable_names[jj]);
}
TMM_delete_var_a(change_variable_names) ;
}
if ( change_variable_alias ) {
for(int jj = 0; jj < num_change_variable_names; jj++) {
TMM_delete_var_a(change_variable_alias[jj]);
}
TMM_delete_var_a(change_variable_alias) ;
}
variable_names = NULL ;
variable_alias = NULL ;
change_variable_names = NULL ;

View File

@ -3,6 +3,7 @@
#include <algorithm>
#include <fstream>
#include <string.h>
#include <cstring>
#include "trick/Sie.hh"
#include "trick/SimObject.hh"
@ -74,6 +75,32 @@ void Trick::Sie::top_level_objects_print(std::ofstream & sie_out) {
}
}
void Trick::Sie::runtime_objects_print(std::fstream & sie_out) {
Trick::VARIABLE_MAP_ITER vit ;
int jj ;
for ( vit = trick_MM->variable_map_begin() ; vit != trick_MM->variable_map_end() ; vit++ ) {
ALLOC_INFO * alloc_info = (*vit).second ;
if ( alloc_info != NULL && alloc_info->alloced_in_memory_init == 0) {
sie_out << " <top_level_object" ;
sie_out << "\n name=\"" << vit->first << "\"" ;
sie_out << "\n type=\"" ;
std::string type = trickTypeCharString(alloc_info->type, alloc_info->user_type_name );
std::replace(type.begin(), type.end(), ':', '_');
sie_out << type << "\"\n" ;
sie_out << " alloc_memory_init=\"" << alloc_info->alloced_in_memory_init << "\"";
sie_out << ">\n" ;
if ( alloc_info->num_index > 0 ) {
for (jj = 0; jj < alloc_info->num_index; jj++) {
sie_out << " <dimension>" << alloc_info->index[jj] << "</dimension>\n" ;
}
}
sie_out << " </top_level_object>\n\n" ;
}
}
}
void Trick::Sie::top_level_objects_json(std::ofstream & sie_out) {
Trick::VARIABLE_MAP_ITER vit ;
int jj ;
@ -123,6 +150,36 @@ void Trick::Sie::sie_print_xml() {
sie_out.close() ;
}
void Trick::Sie::sie_append_runtime_objs() {
std::fstream sie_out ;
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie.resource" ;
sie_out.open(file_name.c_str(), std::fstream::in | std::fstream::out) ;
sie_out.seekg(-1, sie_out.end);
const char * comment = "<!--\nRuntime Allocations\nDo not edit this comment or file content past this point\n-->\n";
const int commentLength = 86;
char buff[commentLength + 1] = {0};
char last = '\0';
int pos;
while(memcmp(comment, buff, commentLength) != 0) {
while(last != '!' || sie_out.peek() != '<') {
if(sie_out.bad() || sie_out.fail() || sie_out.eof()) {
std::cerr << "Error: S_sie.resource is corrupted or outdated. Cannot add runtime/dynamic allocations. Please rerun trick-CP" << std::endl;
exit(2);
}
last = sie_out.peek();
sie_out.seekg(-1, std::ios::cur);
pos = sie_out.tellg();
}
sie_out.get(buff, commentLength + 1, '\0');
sie_out.seekg(pos - 1);
}
sie_out.seekg(pos - 1);
sie_out.seekp((int)sie_out.tellg() + commentLength + 1);
runtime_objects_print(sie_out);
sie_out << "</sie>\n";
sie_out.close();
}
void Trick::Sie::sie_print_json() {
std::ofstream sie_out ;
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie.json" ;

View File

@ -459,7 +459,7 @@ int Trick::VariableServerThread::send_file(std::string file_name) {
}
int Trick::VariableServerThread::send_sie_resource() {
sie_print_xml() ;
//sie_print_xml() ;
return transmit_file(std::string(command_line_args_get_default_dir()) + "/S_sie.resource") ;
}

View File

@ -1,3 +1,8 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../../share/trick/makefiles/Makefile.common
include ${TRICK_HOME}/share/trick/makefiles/Makefile.tricklib
-include Makefile_deps
resource_clean:
$(RM) -f sim_services_classes.resource
real_clean: resource_clean