fe.h (1631B)
1 // 2 // Instrument Frontend. 3 // Takes command lines and instruments source code. 4 // 5 #include "log.h" 6 7 #include <chrono> // std::chrono::high_resolution_clock 8 #include <map> // std::map 9 #include <string> // std::string 10 11 class InstFrontend 12 { 13 void save_if_srcfile(char *); 14 void restore_original_src(); 15 16 std::string m_compilers_path; 17 std::string m_lib_path; 18 std::chrono::high_resolution_clock::time_point m_start_time; 19 std::map<std::string, std::string> m_temp_file_map; 20 21 // Implemented by operating system specific classes. 22 virtual void log_os_str() = 0; 23 virtual char dir_sep() = 0; 24 virtual char path_sep() = 0; 25 virtual std::string lib_name() = 0; 26 virtual void set_path(std::string const &) = 0; 27 virtual bool is_link(bool, bool) = 0; 28 virtual void copy_file(std::string const &, std::string const &) = 0; 29 virtual void exec_compiler() = 0; 30 virtual int fork_compiler() = 0; 31 32 protected: 33 std::vector<char *> m_args; 34 bool m_is_citruninst; 35 std::vector<std::string> m_source_files; 36 InstrumentLogger m_log; 37 38 public: 39 InstFrontend(int, char *argv[], bool); 40 virtual ~InstFrontend() = 0; 41 42 void log_identity(); 43 void get_paths(); 44 void clean_PATH(); 45 void process_cmdline(); 46 void instrument(); 47 void compile_instrumented(); 48 }; 49 50 // 51 // Helper class that is a unary predicate suitable for use with std::find_if. 52 // 53 class ends_with 54 { 55 std::string arg; 56 public: 57 ends_with(char *argument) : 58 arg(argument) 59 {} 60 61 bool operator ()(std::string const &suffix) const 62 { 63 if (suffix.length() > arg.length()) 64 return false; 65 66 return std::equal(suffix.rbegin(), suffix.rend(), arg.rbegin()); 67 } 68 };