gen/
.clang-format
570 B
.gitignore
30 B
.gitsigners
112 B
LICENSE
1.1 KiB
Makefile
911 B
README
1.8 KiB
ast.c
5.0 KiB
ast.h
15.1 KiB
desugar.c
23.1 KiB
desugar.h
286 B
gen.c
108.5 KiB
gen.h
4.9 KiB
io.c
1.1 KiB
io.h
444 B
limits.h
1.3 KiB
module.c
10.0 KiB
module.h
2.2 KiB
options.c
1.4 KiB
options.h
472 B
parser.c
68.3 KiB
parser.h
942 B
radiance.c
3.7 KiB
ralloc.c
2.0 KiB
ralloc.h
1.1 KiB
resolver.c
109.7 KiB
resolver.h
5.6 KiB
riscv.c
12.0 KiB
riscv.h
12.0 KiB
scanner.c
10.2 KiB
scanner.h
3.2 KiB
strings.c
2.6 KiB
strings.h
407 B
symtab.c
5.7 KiB
symtab.h
4.6 KiB
types.h
1.0 KiB
util.h
1.5 KiB
options.c
raw
| 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | #include "io.h" |
| 6 | #include "options.h" |
| 7 | #include "types.h" |
| 8 | |
| 9 | /* Create a new options struct. */ |
| 10 | struct options options(int argc, char *argv[]) { |
| 11 | return (struct options){ |
| 12 | .inputs = { 0 }, |
| 13 | .ninputs = 0, |
| 14 | .modules = { 0 }, |
| 15 | .nmodules = 0, |
| 16 | .argv = argv, |
| 17 | .argc = argc, |
| 18 | .output = NULL, |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | /* Parse the command line options. */ |
| 23 | int options_parse(struct options *o) { |
| 24 | for (int i = 1; i < o->argc; i++) { |
| 25 | if (o->argv[i][0] != '-') { |
| 26 | o->inputs[o->ninputs++] = o->argv[i]; |
| 27 | continue; |
| 28 | } |
| 29 | char *arg = &o->argv[i][1]; |
| 30 | |
| 31 | if (!strcmp(arg, "o")) { |
| 32 | if (++i >= o->argc) |
| 33 | bail("`-o` requires an output path"); |
| 34 | o->output = o->argv[i]; |
| 35 | } else if (!strcmp(arg, "mod")) { |
| 36 | if (++i >= o->argc) |
| 37 | bail("`-mod` requires a module path"); |
| 38 | o->modules[o->nmodules++] = o->argv[i]; |
| 39 | } else if (!strcmp(arg, "pkg") || !strcmp(arg, "entry")) { |
| 40 | /* Ignored; consumed by the self-hosted compiler only. */ |
| 41 | i++; |
| 42 | } else if (!strcmp(arg, "test") || !strcmp(arg, "dump")) { |
| 43 | /* Ignored; consumed by the self-hosted compiler only. */ |
| 44 | } else { |
| 45 | bail("unknown option `-%s`", arg); |
| 46 | } |
| 47 | } |
| 48 | return 0; |
| 49 | } |