From c52a6bedb06d83adca8e5a89ec23d77967ae4cce Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 11 Jan 2020 20:12:20 +0000 Subject: Rename compiler to sinc --- Makefile | 18 ++-- common.mak | 6 +- examples/nq/Makefile | 2 +- graphviz_codegen.c | 2 +- graphviz_codegen.h | 2 +- lex.l | 2 +- llvm_codegen.c | 2 +- llvm_codegen.h | 2 +- parse.y | 2 +- sinc.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++ sinc.h | 31 +++++++ sinter.c | 243 --------------------------------------------------- sinter.h | 31 ------- sinter_codegen.c | 2 +- sinter_codegen.h | 2 +- 15 files changed, 295 insertions(+), 295 deletions(-) create mode 100644 sinc.c create mode 100644 sinc.h delete mode 100644 sinter.c delete mode 100644 sinter.h diff --git a/Makefile b/Makefile index e25ffd0..86068b0 100644 --- a/Makefile +++ b/Makefile @@ -22,26 +22,26 @@ LDLIBS += $(shell llvm-config --libs $(LLVM_MODULES) --system-libs) default: all -all: sinter +all: sinc install: all $(INSTALL) -d $(PREFIX)/bin/ - $(INSTALL) sinter $(PREFIX)/bin/ + $(INSTALL) sinc $(PREFIX)/bin/ uninstall: - $(RM) $(PREFIX)/bin/sinter + $(RM) $(PREFIX)/bin/sinc -sinter.o: sinter.h parse.h debug.h error.h scope.h llvm_codegen.h \ +sinc.o: sinc.h parse.h debug.h error.h scope.h llvm_codegen.h \ graphviz_codegen.h -llvm_codegen.o: llvm_codegen.h sinter.h scope.h debug.h parse.h error.h +llvm_codegen.o: llvm_codegen.h sinc.h scope.h debug.h parse.h error.h sinter_codegen.o: sinter_codegen.h parse.h graphviz_codegen.o: graphviz_codegen.h parse.h error.h -parse.o: sinter.h -lex.o: sinter.h parse.h +parse.o: sinc.h +lex.o: sinc.h parse.h scope.o: scope.h error.h debug.h common.o: debug.h -sinter: sinter.o parse.o lex.o scope.o llvm_codegen.o sinter_codegen.o \ +sinc: sinc.o parse.o lex.o scope.o llvm_codegen.o sinter_codegen.o \ graphviz_codegen.o $(LINK.cc) $(OUTPUT_OPTION) $^ $(LDLIBS) @@ -61,4 +61,4 @@ lex.o: lex.c $(YACC) -o $@ $< clean: - $(RM) sinter *.tab.* *.o lex.c parse.c parse.h + $(RM) sinc *.tab.* *.o lex.c parse.c parse.h diff --git a/common.mak b/common.mak index 5b49f55..e9b8059 100644 --- a/common.mak +++ b/common.mak @@ -1,8 +1,8 @@ -LLC ?= clang -SINC ?= sinter +LLC ?= llc +SINC ?= sinc %.o: %.ll - $(LLC) -c $(LLCFLAGS) -o $@ $< + $(LLC) -filetype obj $(LLCFLAGS) -o $@ $< %.ll: %.sin $(SINC) -l $(SINCFLAGS) -o $@ $< diff --git a/examples/nq/Makefile b/examples/nq/Makefile index 719acc2..3939123 100644 --- a/examples/nq/Makefile +++ b/examples/nq/Makefile @@ -7,7 +7,7 @@ CFLAGS = $(DEBUG) -Werror -Wpedantic -Wall -I$(HOME)/usr/include LDFLAGS = $(DEBUG) -L$(HOME)/usr/lib LDLIBS = -lgc -LLCFLAGS = $(DEBUG) -Werror -Wpedantic -Wall +LLCFLAGS = -O0 SINCFLAGS = -u never -w 32 TRGT = nqueens diff --git a/graphviz_codegen.c b/graphviz_codegen.c index 4e94483..bbb29a1 100644 --- a/graphviz_codegen.c +++ b/graphviz_codegen.c @@ -2,7 +2,7 @@ #include #include "graphviz_codegen.h" -#include "sinter.h" +#include "sinc.h" #include "parse.h" #include "error.h" diff --git a/graphviz_codegen.h b/graphviz_codegen.h index 6fae8d5..72a9698 100644 --- a/graphviz_codegen.h +++ b/graphviz_codegen.h @@ -1,7 +1,7 @@ #ifndef GRAPHVIZ_CODEGEN_H #define GRAPHVIZ_CODEGEN_H -#include "sinter.h" +#include "sinc.h" void graphviz_codegen_prologue(); void graphviz_codegen(sexpr *ast); diff --git a/lex.l b/lex.l index 5319430..5546bad 100644 --- a/lex.l +++ b/lex.l @@ -8,7 +8,7 @@ #include #include "sexpr.h" -#include "sinter.h" +#include "sinc.h" #include "parse.h" void yyerror(const char *s, ...); diff --git a/llvm_codegen.c b/llvm_codegen.c index 1e6ce93..2789345 100644 --- a/llvm_codegen.c +++ b/llvm_codegen.c @@ -12,7 +12,7 @@ #include #include "llvm_codegen.h" -#include "sinter.h" +#include "sinc.h" #include "scope.h" #include "debug.h" #include "parse.h" diff --git a/llvm_codegen.h b/llvm_codegen.h index 70d116d..5e30b18 100644 --- a/llvm_codegen.h +++ b/llvm_codegen.h @@ -1,7 +1,7 @@ #ifndef LLVM_CODEGEN_H #define LLVM_CODEGEN_H -#include "sinter.h" +#include "sinc.h" typedef enum { ALWAYS_BOX, diff --git a/parse.y b/parse.y index 20233fa..97c113c 100644 --- a/parse.y +++ b/parse.y @@ -7,7 +7,7 @@ #include #include "sexpr.h" -#include "sinter.h" +#include "sinc.h" extern int yylineno; int yylex(void); diff --git a/sinc.c b/sinc.c new file mode 100644 index 0000000..cc0117c --- /dev/null +++ b/sinc.c @@ -0,0 +1,243 @@ +#include +#include +#include +#include +#include + +#include "sinc.h" +#include "sexpr.h" +#include "llvm_codegen.h" +#include "sinter_codegen.h" +#include "graphviz_codegen.h" +#include "parse.h" +#include "debug.h" +#include "error.h" + +typedef unsigned int uint; + +static char *input_filename; +static char *output_filename; +static format_t format; + +extern FILE *yyin; +int yyparse(void); + +int verbose; + +sexpr *new_sexpr(int type, contents val, lloc_t lloc) { + /* FIXME: unchecked memory allocation! */ + sexpr *ret = malloc(sizeof (*ret)); + ret->type = type; + ret->contents = val; + ret->lloc = lloc; + return ret; +} + +sexpr *new_int(int num, lloc_t lloc) { + contents c; + c.i = num; + return new_sexpr(INT, c, lloc); +} + +sexpr *new_str(char *str, lloc_t lloc) { + contents c; + c.s = str; + return new_sexpr(STRING, c, lloc); +} + +sexpr *new_float(double num, lloc_t lloc) { + contents c; + c.f = num; + return new_sexpr(FLOAT, c, lloc); +} + +sexpr *new_id(char *id, lloc_t lloc) { + contents c; + c.s = id; + return new_sexpr(ID, c, lloc); +} + +sexpr *new_node(sexpr *l, sexpr *r, lloc_t lloc) { + contents c; + c.n.l = l; + c.n.r = r; + return new_sexpr(BRANCH, c, lloc); +} + +void prologue(boxing_rule_t br, uint dbw) { + + switch (format) { + + case LLVM_INTERMEDIATE: + case BITCODE: + case INTERPRET: + llvm_codegen_prologue(input_filename, br, dbw); + break; + + case GRAPHVIZ: + graphviz_codegen_prologue(); + break; + + case SINTER: + sinter_codegen_prologue(); + break; + + } +} + +void handle(sexpr *se) { + + switch (format) { + + case LLVM_INTERMEDIATE: + case BITCODE: + case INTERPRET: + llvm_codegen(se); + break; + + case GRAPHVIZ: + graphviz_codegen(se); + break; + + case SINTER: + sinter_codegen(se); + break; + + } +} + +void epilogue(char *output_filename, format_t format) { + + switch (format) { + + case LLVM_INTERMEDIATE: + case BITCODE: + case INTERPRET: + llvm_codegen_epilogue(output_filename, format); + break; + + case GRAPHVIZ: + graphviz_codegen_epilogue(output_filename); + break; + + case SINTER: + sinter_codegen_epilogue(output_filename); + break; + + } +} + +int main(int argc, char **argv) { + int c; + + output_filename = 0; + format = LLVM_INTERMEDIATE; + + boxing_rule_t boxing_rules = ALWAYS_BOX; + uint default_bit_width = 0; + verbose = 0; + + debug("\n"); + + while ((c = getopt(argc, argv, "bghilo:qsu:vw:")) != -1) { + switch (c) { + case 'b': + format = BITCODE; + break; + + case 'g': + format = GRAPHVIZ; + break; + + case 'h': + printf( +"usage: %s [options] \n" +"-b Specify bitcode-format output\n" +"-c Compile mode\n" +"-g Output a Graphviz .dot file\n" +"-h Print this help message\n" +"-i Interpret mode\n" +"-l Specify human-readable output\n" +"-o Specify output filename\n" +"-q Quiet (default)\n" +"-s Output S-expression description\n" +"-u Set the boxing rule: always, never, or smart\n" +"-v Verbose\n" +"-w Specify default width of integers in bits\n", + argv[0]); + exit(0); + + case 'i': + format = INTERPRET; + break; + + case 'l': + format = LLVM_INTERMEDIATE; + break; + + case 'o': + output_filename = strdup(optarg); + break; + + case 'q': + verbose = 0; + break; + + case 's': + format = SINTER; + break; + + case 'u': + if (!strcmp(optarg, "always")) { + boxing_rules = ALWAYS_BOX; + + } else if (!strcmp(optarg, "never")) { + boxing_rules = NEVER_BOX; + + } else if (!strcmp(optarg, "smart")) { + boxing_rules = SMART_BOX; + + } else { + error(INVALID_ARGUMENTS, + "%s is not a valid option for -u\n", optarg); + + } + break; + + case 'v': + verbose = 1; + break; + + case 'w': + default_bit_width = atoi(optarg); + break; + + case '?': + switch (optopt) { + case 'o': + error(INVALID_ARGUMENTS, + "-%c option requires an argument", optopt); + break; + + default: + error(INVALID_ARGUMENTS, "unknown option %c", optopt); + } + break; + + default: + error(INVALID_ARGUMENTS, "error parsing arguments"); + } + } + + if (argc - optind > 1) { + error(INVALID_ARGUMENTS, "too many arguments"); + } else if (argc - optind == 1) { + input_filename = argv[argc - 1]; + yyin = fopen(input_filename, "r"); + } + + prologue(boxing_rules, default_bit_width); + yyparse(); + epilogue(output_filename, format); + return 0; +} diff --git a/sinc.h b/sinc.h new file mode 100644 index 0000000..0288887 --- /dev/null +++ b/sinc.h @@ -0,0 +1,31 @@ +#ifndef SINTER_H +#define SINTER_H + +#include + +#include "sexpr.h" +#include "parse.h" + +typedef enum { + BITCODE, + LLVM_INTERMEDIATE, + INTERPRET, + GRAPHVIZ, + SINTER +} format_t; + +typedef struct node node; +typedef union contents contents; + +sexpr *new_int(int num, lloc_t lloc); +sexpr *new_float(double num, lloc_t lloc); +sexpr *new_id(char *id, lloc_t lloc); +sexpr *new_node(sexpr *l, sexpr *r, lloc_t lloc); +sexpr *new_str(char *str, lloc_t lloc); + +void print_sexpr(sexpr *se); +void fprint_sexpr(FILE *f, sexpr *se); + +void handle(sexpr *se); + +#endif /* SINTER_H */ diff --git a/sinter.c b/sinter.c deleted file mode 100644 index 1792bf1..0000000 --- a/sinter.c +++ /dev/null @@ -1,243 +0,0 @@ -#include -#include -#include -#include -#include - -#include "sinter.h" -#include "sexpr.h" -#include "llvm_codegen.h" -#include "sinter_codegen.h" -#include "graphviz_codegen.h" -#include "parse.h" -#include "debug.h" -#include "error.h" - -typedef unsigned int uint; - -static char *input_filename; -static char *output_filename; -static format_t format; - -extern FILE *yyin; -int yyparse(void); - -int verbose; - -sexpr *new_sexpr(int type, contents val, lloc_t lloc) { - /* FIXME: unchecked memory allocation! */ - sexpr *ret = malloc(sizeof (*ret)); - ret->type = type; - ret->contents = val; - ret->lloc = lloc; - return ret; -} - -sexpr *new_int(int num, lloc_t lloc) { - contents c; - c.i = num; - return new_sexpr(INT, c, lloc); -} - -sexpr *new_str(char *str, lloc_t lloc) { - contents c; - c.s = str; - return new_sexpr(STRING, c, lloc); -} - -sexpr *new_float(double num, lloc_t lloc) { - contents c; - c.f = num; - return new_sexpr(FLOAT, c, lloc); -} - -sexpr *new_id(char *id, lloc_t lloc) { - contents c; - c.s = id; - return new_sexpr(ID, c, lloc); -} - -sexpr *new_node(sexpr *l, sexpr *r, lloc_t lloc) { - contents c; - c.n.l = l; - c.n.r = r; - return new_sexpr(BRANCH, c, lloc); -} - -void prologue(boxing_rule_t br, uint dbw) { - - switch (format) { - - case LLVM_INTERMEDIATE: - case BITCODE: - case INTERPRET: - llvm_codegen_prologue(input_filename, br, dbw); - break; - - case GRAPHVIZ: - graphviz_codegen_prologue(); - break; - - case SINTER: - sinter_codegen_prologue(); - break; - - } -} - -void handle(sexpr *se) { - - switch (format) { - - case LLVM_INTERMEDIATE: - case BITCODE: - case INTERPRET: - llvm_codegen(se); - break; - - case GRAPHVIZ: - graphviz_codegen(se); - break; - - case SINTER: - sinter_codegen(se); - break; - - } -} - -void epilogue(char *output_filename, format_t format) { - - switch (format) { - - case LLVM_INTERMEDIATE: - case BITCODE: - case INTERPRET: - llvm_codegen_epilogue(output_filename, format); - break; - - case GRAPHVIZ: - graphviz_codegen_epilogue(output_filename); - break; - - case SINTER: - sinter_codegen_epilogue(output_filename); - break; - - } -} - -int main(int argc, char **argv) { - int c; - - output_filename = 0; - format = LLVM_INTERMEDIATE; - - boxing_rule_t boxing_rules = ALWAYS_BOX; - uint default_bit_width = 0; - verbose = 0; - - debug("\n"); - - while ((c = getopt(argc, argv, "bghilo:qsu:vw:")) != -1) { - switch (c) { - case 'b': - format = BITCODE; - break; - - case 'g': - format = GRAPHVIZ; - break; - - case 'h': - printf( -"usage: %s [options] \n" -"-b Specify bitcode-format output\n" -"-c Compile mode\n" -"-g Output a Graphviz .dot file\n" -"-h Print this help message\n" -"-i Interpret mode\n" -"-l Specify human-readable output\n" -"-o Specify output filename\n" -"-q Quiet (default)\n" -"-s Output S-expression description\n" -"-u Set the boxing rule: always, never, or smart\n" -"-v Verbose\n" -"-w Specify default width of integers in bits\n", - argv[0]); - exit(0); - - case 'i': - format = INTERPRET; - break; - - case 'l': - format = LLVM_INTERMEDIATE; - break; - - case 'o': - output_filename = strdup(optarg); - break; - - case 'q': - verbose = 0; - break; - - case 's': - format = SINTER; - break; - - case 'u': - if (!strcmp(optarg, "always")) { - boxing_rules = ALWAYS_BOX; - - } else if (!strcmp(optarg, "never")) { - boxing_rules = NEVER_BOX; - - } else if (!strcmp(optarg, "smart")) { - boxing_rules = SMART_BOX; - - } else { - error(INVALID_ARGUMENTS, - "%s is not a valid option for -u\n", optarg); - - } - break; - - case 'v': - verbose = 1; - break; - - case 'w': - default_bit_width = atoi(optarg); - break; - - case '?': - switch (optopt) { - case 'o': - error(INVALID_ARGUMENTS, - "-%c option requires an argument", optopt); - break; - - default: - error(INVALID_ARGUMENTS, "unknown option %c", optopt); - } - break; - - default: - error(INVALID_ARGUMENTS, "error parsing arguments"); - } - } - - if (argc - optind > 1) { - error(INVALID_ARGUMENTS, "too many arguments"); - } else if (argc - optind == 1) { - input_filename = argv[argc - 1]; - yyin = fopen(input_filename, "r"); - } - - prologue(boxing_rules, default_bit_width); - yyparse(); - epilogue(output_filename, format); - return 0; -} diff --git a/sinter.h b/sinter.h deleted file mode 100644 index 0288887..0000000 --- a/sinter.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef SINTER_H -#define SINTER_H - -#include - -#include "sexpr.h" -#include "parse.h" - -typedef enum { - BITCODE, - LLVM_INTERMEDIATE, - INTERPRET, - GRAPHVIZ, - SINTER -} format_t; - -typedef struct node node; -typedef union contents contents; - -sexpr *new_int(int num, lloc_t lloc); -sexpr *new_float(double num, lloc_t lloc); -sexpr *new_id(char *id, lloc_t lloc); -sexpr *new_node(sexpr *l, sexpr *r, lloc_t lloc); -sexpr *new_str(char *str, lloc_t lloc); - -void print_sexpr(sexpr *se); -void fprint_sexpr(FILE *f, sexpr *se); - -void handle(sexpr *se); - -#endif /* SINTER_H */ diff --git a/sinter_codegen.c b/sinter_codegen.c index 56930df..b4a15a3 100644 --- a/sinter_codegen.c +++ b/sinter_codegen.c @@ -2,7 +2,7 @@ #include #include "sinter_codegen.h" -#include "sinter.h" +#include "sinc.h" #include "parse.h" #include "error.h" diff --git a/sinter_codegen.h b/sinter_codegen.h index e0a0737..98d579f 100644 --- a/sinter_codegen.h +++ b/sinter_codegen.h @@ -1,7 +1,7 @@ #ifndef SINTER_CODEGEN_H #define SINTER_CODEGEN_H -#include "sinter.h" +#include "sinc.h" void sinter_codegen_prologue(); void sinter_codegen(sexpr *ast); -- cgit v1.2.1