diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-05-09 02:56:07 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-06-21 01:15:38 +0200 |
| commit | b25ff71bb198c227b3202ee32a8067cda413bc16 (patch) | |
| tree | 41d665a87d948c10b17a853220cbcdbaeebf3672 /main.c | |
| download | prc-b25ff71bb198c227b3202ee32a8067cda413bc16.tar.gz | |
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -0,0 +1,53 @@ +#include "cgen.h" +#include "lex.h" +#include "parse.h" +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +int main(int argc, char *argv[]) +{ + struct lex l = {0}; + struct ast a = {0}; + struct cgen c = {0}; + FILE *f = stdin; + int opened = 0, ret = EXIT_FAILURE; + + if (argc != 2) + { + fprintf(stderr, "%s: error: missing input file\n", *argv); + goto end; + } + else if (strcmp(argv[1], "-")) + { + if (!(f = fopen(argv[1], "rb"))) + { + fprintf(stderr, "failed to open %s: %s\n", argv[1], + strerror(errno)); + goto end; + } + + opened = 1; + l.loc.f = argv[1]; + } + else + l.loc.f = "stdin"; + + if (lex(&l, f) || parse(&l, &a) || cgen(&a, &c)) + goto end; + + ret = EXIT_SUCCESS; + +end: + if (opened && fclose(f)) + { + perror("fclose(3)"); + ret = EXIT_FAILURE; + } + + cgen_free(&c); + ast_free(&a); + lex_free(&l); + return ret; +} |
