diff --git a/src/main.cc b/src/main.cc index fd61f64..eff5ec3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -84,6 +84,25 @@ bool emit_c(Node * node) return true; } +bool compile() +{ + pid_t pid = fork(); + if (pid < 0) + { + perror("fork"); + return false; + } + else if (pid == 0) + { + execlp("gcc", "gcc", "-x", "c", "-c", c_fname, "-o", "out.o", NULL); + } + else + { + waitpid(pid, NULL, 0); + } + return true; +} + int main(int argc, char * argv[]) { bool preprocess_successful = preprocess(argv[1]); @@ -92,13 +111,20 @@ int main(int argc, char * argv[]) Node * node = parse(preprocessed_fname); if (node != nullptr) { - emit_c(node); + if (emit_c(node)) + { + compile(); + } } } /* Clean up temporary files. */ if (preprocessed_fname_created) { - //unlink(preprocessed_fname); + unlink(preprocessed_fname); + } + if (c_fname_created) + { + unlink(c_fname); } return 0;