in ICG: Add FileSkipped preprocessor callback to FindTrickICG (#1125)

* #608 add implementation of FileSkipped callback to FindTrickICG to add include chains for headers that have already been preprocessed

* #608 add test SIM for FindTrickICG offsets SIM_test_icg_file_skipped
This commit is contained in:
Scott Fennell 2021-04-19 19:34:17 -05:00 committed by GitHub
parent 6356a87b9f
commit 9589c1062c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 143 additions and 0 deletions

View File

@ -0,0 +1,2 @@
trick.stop(3.0);

View File

@ -0,0 +1,34 @@
/************************TRICK HEADER*************************
PURPOSE: (Test that ICG generates the correct offsets for compat15 headers even
When they are skipped by header guard optimization. This is implemented in
ICG's FindTrickICG class)
LIBRARY DEPENDENCIES:
*************************************************************/
#include "sim_objects/default_trick_sys.sm"
##include "Bar.hh"
##include "Baz.hh"
class TestFileSkippedSimObject : public Trick::SimObject {
public:
Bar bar;
Baz baz;
TestFileSkippedSimObject() {
("initialization") trick_ret = bar.test_bar_member_o_correct_offset();
("initialization") trick_ret = baz.test_baz_member_m_correct_offset();
("default_data") trick_ret = bar.test_bar_member_o_correct_offset();
("default_data") trick_ret = baz.test_baz_member_m_correct_offset();
(0.25, "scheduled") trick_ret = bar.test_bar_member_o_correct_offset();
(0.25, "scheduled") trick_ret = baz.test_baz_member_m_correct_offset();
("shutdown") trick_ret = bar.test_bar_member_o_correct_offset();
("shutdown") trick_ret = baz.test_baz_member_m_correct_offset();
}
};
TestFileSkippedSimObject testfsSimObject;

View File

@ -0,0 +1,4 @@
TRICK_CFLAGS += -I./models
TRICK_CXXFLAGS += -I./models
TRICK_ICGFLAGS = "--print-TRICK-ICG=0"

View File

@ -0,0 +1,22 @@
// @trick_parse{everything}
#include "Foo.hh"
#include "trick/memorymanager_c_intf.h"
class Bar {
public:
Foo foo;
int o;
Bar():o(777){}
int test_bar_member_o_correct_offset() {
char ref_name[] = "testfsSimObject.bar.o";
REF2* ref = ref_attributes(ref_name);
if(*((int*)ref->address) == o) {
return 0;
}
else {
return 1;
}
}
};

View File

@ -0,0 +1,22 @@
// @trick_parse{everything}
#include "Foo.hh"
#include "trick/memorymanager_c_intf.h"
class Baz {
public:
Foo foo;
int m;
Baz(): m(42) {}
int test_baz_member_m_correct_offset() {
char ref_name[] = "testfsSimObject.baz.m";
REF2* ref = ref_attributes(ref_name);
if(*((int*)ref->address) == m) {
return 0;
}
else {
return 1;
}
}
};

View File

@ -0,0 +1,15 @@
// @trick_parse{everything}
#ifndef FOO_HH
#define FOO_HH
class Foo {
public:
#ifndef TRICK_ICG
int i;
int j;
int k;
Foo() : i(1), j(2), k(3) {}
#endif
};
#endif

View File

@ -26,6 +26,7 @@ SIMS_TO_COMPILE_AND_RUN = \
SIM_stls \ SIM_stls \
SIM_test_dp \ SIM_test_dp \
SIM_test_dr \ SIM_test_dr \
SIM_test_icg_file_skipped \
SIM_test_io \ SIM_test_io \
SIM_test_ip \ SIM_test_ip \
SIM_test_sched \ SIM_test_sched \

View File

@ -35,6 +35,38 @@ void FindTrickICG::FileChanged(clang::SourceLocation Loc, FileChangeReason Reaso
} }
} }
#if (LIBCLANG_MAJOR < 10) // TODO delete when RHEL 7 no longer supported
void FindTrickICG::FileSkipped(const clang::FileEntry &SkippedFile,
const clang::Token &FilenameTok,
clang::SrcMgr::CharacteristicKind FileType) {
std::string file_name = SkippedFile.getName() ;
#else
void FindTrickICG::FileSkipped(const clang::FileEntryRef & SkippedFile, const clang::Token & FilenameTok,
clang::SrcMgr::CharacteristicKind FileType) {
/* Files that have header guards are only preprocessed once because of an optimization.
We still need to add its include chain to compat15 if TRICK_ICG was found when it was
originally preprocessed */
std::string file_name = SkippedFile.getName().str() ;
#endif
std::string file_path;
{
char* path_cstr = almostRealPath(file_name.c_str());
if(path_cstr != NULL) {
file_path = std::string(path_cstr);
free(path_cstr);
}
}
// Check if skipped header is in Compat15
if(hsd.isPathInCompat15(file_path)) {
// for each header in the stack, mark them as being exposed to TRICK_ICG
for (std::string& file : included_files) {
hsd.addTrickICGFoundFile(file);
}
}
}
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) #if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) void FindTrickICG::If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue)
#else #else

View File

@ -20,6 +20,17 @@ class FindTrickICG : public clang::PPCallbacks {
clang::SrcMgr::CharacteristicKind FileType, clang::SrcMgr::CharacteristicKind FileType,
clang::FileID PrevFID = clang::FileID()) ; clang::FileID PrevFID = clang::FileID()) ;
#if (LIBCLANG_MAJOR < 10) // TODO delete when RHEL 7 no longer supported
virtual void FileSkipped(const clang::FileEntry &SkippedFile,
const clang::Token &FilenameTok,
clang::SrcMgr::CharacteristicKind FileType) ;
#else
// called when a header file is skipped because of a header guard optimization.
virtual void FileSkipped(const clang::FileEntryRef & SkippedFile,
const clang::Token & FilenameTok,
clang::SrcMgr::CharacteristicKind FileType) ;
#endif
// callbacks called when the preprocessor directives of types are processed. // callbacks called when the preprocessor directives of types are processed.
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5)) #if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) ; virtual void If(clang::SourceLocation Loc, clang::SourceRange ConditionRange, clang::PPCallbacks::ConditionValueKind ConditionValue) ;