#include "all.h" #include "str.h" #include #include #include #include #include int main(void) { str input = {0}; str_append_fread(&input, stdin); // Run the lexer to get tokens (honestly useless considering the simplicity of // BF) lexer_t lexer = lex_init(&input); lex_run(&lexer); // Run the parser and turn tokens into an AST representation parser_t p = parser_init(&lexer); ast_node_t *ast = parse_program(&p); str c_code = gen_code(ast); // Run gcc int fd[2]; pipe(fd); if (fork() == 0) { dup2(fd[0], STDIN_FILENO); close(fd[0]); close(fd[1]); char *argv[] = {"gcc", "-Os", "-flto", "-fuse-linker-plugin", "-DNDEBUG", "-fomit-frame-pointer", "-nostdlib", "-nostartfiles", "-no-pie", "-fno-stack-protector", "-o", "/proc/self/fd/1", "-x", "c", "-", NULL}; execvp("gcc", argv); perror("execvp"); _exit(1); } // Cleanup close(fd[0]); write(fd[1], c_code.data, strlen(c_code.data)); close(fd[1]); wait(NULL); ast_free(ast); free_str(&input); return 0; }