This repository was archived by the owner on Jan 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ target_compile_definitions(call-hook++ PUBLIC RUNTIME_HOME="${CMAKE_SOURCE_DIR}/
2222target_compile_definitions (call-hook++ PUBLIC USE_CXX)
2323
2424list (APPEND STRUCT_PARSER_SRCS ${BASE_SRCS} src/pass/pass_struct_parser.cc src/wrapper/wrapper_struct_parser.cc src/utility/struct_parser.cc)
25+ list (APPEND STRUCT_PARSER_SRCS src/utility/location .cc)
2526add_executable (struct-parser ${STRUCT_PARSER_SRCS} src/main/struct_parser.cc)
2627add_executable (struct-parser++ ${STRUCT_PARSER_SRCS} src/main/struct_parser.cc)
2728target_compile_definitions (struct-parser++ PUBLIC USE_CXX)
Original file line number Diff line number Diff line change 55#include " common/logging.h"
66#include " llvm/IR/Instructions.h"
77#include " pass/pass_base.h"
8+ #include " utility/location.h"
89#include " utility/struct_parser.h"
910
1011using namespace llvm ;
@@ -32,6 +33,7 @@ bool PassStructParser::run_on_load_inst(LoadInst& inst) {
3233 bool modified = false ;
3334 auto name = this ->struct_parser ().get_field_name_from_value (inst);
3435 if (name.empty ()) return modified;
36+ logger ().info (" at {}" , get_inst_loc (inst));
3537 logger ().info (" {}: {}" , name, inst);
3638 return modified;
3739}
@@ -40,6 +42,7 @@ bool PassStructParser::run_on_get_element_ptr_inst(GetElementPtrInst& inst) {
4042 bool modified = false ;
4143 auto name = this ->struct_parser ().get_field_name_from_address (inst);
4244 if (name.empty ()) return modified;
45+ logger ().info (" at {}" , get_inst_loc (inst));
4346 logger ().info (" {}: {}" , name, inst);
4447 return modified;
4548}
Original file line number Diff line number Diff line change 1+ #include " location.h"
2+
3+ #include < sstream>
4+ #include < string>
5+
6+ #include " llvm/IR/DebugInfoMetadata.h"
7+ #include " llvm/IR/DebugLoc.h"
8+ #include " llvm/IR/Function.h"
9+ #include " llvm/IR/Instruction.h"
10+ #include " llvm/IR/Module.h"
11+ #include " llvm/Support/raw_ostream.h"
12+
13+ using namespace llvm ;
14+
15+ std::string get_inst_loc (Instruction& inst) {
16+ std::string str;
17+ auto oss = raw_string_ostream (str);
18+ auto debug_loc = inst.getDebugLoc ();
19+ if (debug_loc) {
20+ int line = debug_loc.getLine ();
21+ int col = debug_loc.getCol ();
22+ auto dir = debug_loc->getDirectory ();
23+ auto file = debug_loc->getFilename ();
24+ oss << dir.str () << " /" << file.str () << " :" << line << " :" << col;
25+ } else {
26+ auto mod = inst.getModule ()->getName ();
27+ auto func = inst.getFunction ()->getName ();
28+ auto opcode = inst.getOpcodeName ();
29+ oss << mod.str () << " :" << func.str () << " :" << opcode;
30+ }
31+ return oss.str ();
32+ }
Original file line number Diff line number Diff line change 1+ #ifndef LOCATION_H_
2+ #define LOCATION_H_
3+
4+ #include < string>
5+
6+ #include " llvm/IR/Instruction.h"
7+
8+ std::string get_inst_loc (llvm::Instruction& inst);
9+
10+ #endif // LOCATION_H_
You can’t perform that action at this time.
0 commit comments