commit 4333ea0b966442c213a1e3fbd4dead03dc5c916b
parent db29d4a0a248c29cdb05a31e1cbe15157d73d1aa
Author: Kyle Milz <kyle@windows.krwm.net>
Date: Sun, 1 Jan 2017 21:34:18 -0800
src: add new function compile_instrumented
Diffstat:
3 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/src/inst_frontend.cc b/src/inst_frontend.cc
@@ -363,6 +363,22 @@ InstFrontend::restore_original_src()
}
}
+void
+InstFrontend::compile_instrumented()
+{
+ int ret;
+
+ ret = fork_compiler();
+ m_log << "Rewritten source compile " << (ret ? "failed" : "successful")
+ << std::endl;
+
+ restore_original_src();
+
+ if (ret)
+ // Rewritten compile failed. Run again without modified src.
+ exec_compiler();
+}
+
//
// Execute the compiler by calling execvp(3) on the m_args vector.
//
@@ -409,9 +425,6 @@ InstFrontend::fork_compiler()
if (WIFEXITED(status))
exit = WEXITSTATUS(status);
- m_log << "Rewritten source compile " << (exit ? "failed" : "successful")
- << std::endl;
-
// Return the exit code of the native compiler.
return exit;
}
diff --git a/src/inst_frontend.h b/src/inst_frontend.h
@@ -10,14 +10,16 @@ public:
void process_cmdline();
void instrument();
- int fork_compiler();
- void exec_compiler();
- void restore_original_src();
+ void compile_instrumented();
private:
+ void log_identity();
void clean_PATH();
void save_if_srcfile(char *);
void if_link_add_runtime(bool, bool);
+ int fork_compiler();
+ void exec_compiler();
+ void restore_original_src();
std::vector<char *> m_args;
InstrumentLogger m_log;
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -55,12 +55,7 @@ main(int argc, char *argv[])
main.process_cmdline();
main.instrument();
+ main.compile_instrumented();
- ret = main.fork_compiler();
- main.restore_original_src();
-
- if (ret)
- // Rewritten compile failed. Run again without modified src.
- main.exec_compiler();
return 0;
}