From 1a3dc02a18a9050877288a5867e44d9c47a53542 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 11 Jan 2020 02:53:36 +0000 Subject: Added int width specifiers The width of an int can be specified at the site of its creation. For example, the following function returns an int of width 2 bits and value 1: [def two_bit_int [] (2 1)] Ints can still be written the old way; in these cases the compiler looks for a default int bit-width (specified with the -w flag). If a default has not been defined, the compiler throws an error. --- sinter.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'sinter.c') diff --git a/sinter.c b/sinter.c index 0eaeb85..1792bf1 100644 --- a/sinter.c +++ b/sinter.c @@ -19,8 +19,6 @@ static char *input_filename; static char *output_filename; static format_t format; -static boxing_rule_t boxing_rules; - extern FILE *yyin; int yyparse(void); @@ -66,14 +64,14 @@ sexpr *new_node(sexpr *l, sexpr *r, lloc_t lloc) { return new_sexpr(BRANCH, c, lloc); } -void prologue() { +void prologue(boxing_rule_t br, uint dbw) { switch (format) { case LLVM_INTERMEDIATE: case BITCODE: case INTERPRET: - llvm_codegen_prologue(input_filename, boxing_rules); + llvm_codegen_prologue(input_filename, br, dbw); break; case GRAPHVIZ: @@ -135,12 +133,13 @@ int main(int argc, char **argv) { output_filename = 0; format = LLVM_INTERMEDIATE; - boxing_rules = ALWAYS_BOX; + boxing_rule_t boxing_rules = ALWAYS_BOX; + uint default_bit_width = 0; verbose = 0; debug("\n"); - while ((c = getopt(argc, argv, "bghilo:qsu:v")) != -1) { + while ((c = getopt(argc, argv, "bghilo:qsu:vw:")) != -1) { switch (c) { case 'b': format = BITCODE; @@ -163,7 +162,8 @@ int main(int argc, char **argv) { "-q Quiet (default)\n" "-s Output S-expression description\n" "-u Set the boxing rule: always, never, or smart\n" -"-v Verbose\n", +"-v Verbose\n" +"-w Specify default width of integers in bits\n", argv[0]); exit(0); @@ -208,6 +208,10 @@ int main(int argc, char **argv) { verbose = 1; break; + case 'w': + default_bit_width = atoi(optarg); + break; + case '?': switch (optopt) { case 'o': @@ -232,7 +236,7 @@ int main(int argc, char **argv) { yyin = fopen(input_filename, "r"); } - prologue(); + prologue(boxing_rules, default_bit_width); yyparse(); epilogue(output_filename, format); return 0; -- cgit v1.2.1