compile the emitted C

This commit is contained in:
Josh Holtrop 2018-05-20 16:09:58 -04:00
parent 2dea7d0bac
commit db08091cf4

View File

@ -84,6 +84,25 @@ bool emit_c(Node * node)
return true; 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[]) int main(int argc, char * argv[])
{ {
bool preprocess_successful = preprocess(argv[1]); bool preprocess_successful = preprocess(argv[1]);
@ -92,13 +111,20 @@ int main(int argc, char * argv[])
Node * node = parse(preprocessed_fname); Node * node = parse(preprocessed_fname);
if (node != nullptr) if (node != nullptr)
{ {
emit_c(node); if (emit_c(node))
{
compile();
}
} }
} }
/* Clean up temporary files. */ /* Clean up temporary files. */
if (preprocessed_fname_created) if (preprocessed_fname_created)
{ {
//unlink(preprocessed_fname); unlink(preprocessed_fname);
}
if (c_fname_created)
{
unlink(c_fname);
} }
return 0; return 0;