harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 516a961cdf2e2ac3351685cfdf3af6400b36b68c
parent 34ada58581c1a9aba9fa84f3d3010a4246a167fe
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 30 Dec 2020 11:27:31 -0500

Rig runtime up into build system

Gated behind --enable-rt because it does not currently build.

Diffstat:
MMakefile | 4+++-
Mconfig.sh | 10+++++++++-
Mconfigure | 19+++++++++++++++++++
Minclude/lex.h | 2+-
Art/Makefile | 14++++++++++++++
Mrt/assert.ha | 2+-
Art/configure | 6++++++
Msrc/lex.c | 4++--
Msrc/main.c | 4++--
9 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -8,7 +8,9 @@ harec: $(harec_objects) @printf 'CCLD\t$@\n' @$(CC) $(LDFLAGS) -o $@ $(harec_objects) $(LIBS) -.SUFFIXES: .c .o .scd .1 .5 +include rt/Makefile + +.SUFFIXES: .c .o .ha .s .scd .1 .5 .c.o: @printf 'CC\t$@\n' diff --git a/config.sh b/config.sh @@ -32,6 +32,9 @@ do --sysconfdir=*) SYSCONFDIR=${arg#*=} ;; + *) + option "$arg" + ;; esac done @@ -48,6 +51,10 @@ genrules() { ext="${file#*.}" file="${file%.*}" deps= + if [ $ext = "ha" ] + then + deps=" harec" + fi printf '%s.o: %s.%s%s\n' "$file" "$file" "$ext" "$deps" done printf '%s_objects=\\\n' "$target" @@ -190,9 +197,10 @@ run_configure() { ) printf "Populating build dir... " + populate "$srcdir/doc" populate "$srcdir/include" + populate "$srcdir/rt" populate "$srcdir/src" - populate "$srcdir/doc" ln -sf "$srcdir"/Makefile ./ echo done } diff --git a/configure b/configure @@ -2,6 +2,20 @@ srcdir=${SRCDIR:-$(dirname "$0")} eval ". $srcdir/config.sh" +enable_rt=0 + +option() { + case $1 in + enable-rt) + enable_rt=1 + ;; + *) + printf 'Unknown option %s\n' "$arg" >&2 + exit 1 + ;; + esac +} + harec() { genrules harec \ src/check.c \ @@ -25,4 +39,9 @@ harec() { all="harec" +if [ $enable_rt -eq 1 ] +then + subdir rt +fi + run_configure diff --git a/include/lex.h b/include/lex.h @@ -157,7 +157,7 @@ struct lexer { struct location loc; }; -void lex_init(struct lexer *lexer, FILE *f); +void lex_init(struct lexer *lexer, FILE *f, const char *filename); void lex_finish(struct lexer *lexer); enum lexical_token lex(struct lexer *lexer, struct token *out); void unlex(struct lexer *lexer, struct token *in); diff --git a/rt/Makefile b/rt/Makefile @@ -0,0 +1,14 @@ +libhart_srcs=\ + rt/assert.ha \ + rt/malloc.ha \ + rt/memcmp.ha \ + rt/memcpy.ha \ + rt/memset.ha + +libhart.a: $(libhart_srcs) + @printf 'HAREC\t$@\n' + @./harec -N rt -o $@.ssa $(libhart_srcs) + @qbe -o $@.s $@.ssa + @$(AS) -o $@.o $@.s + @$(AR) -csr $@ $@.o + @rm $@.o $@.s $@.ssa diff --git a/rt/assert.ha b/rt/assert.ha @@ -1,4 +1,4 @@ -export fn abort @noreturn void = kill(getpid(), SIGABRT); +export @noreturn fn abort() void = kill(getpid(), SIGABRT); export @symbol("sys.assert") fn assert_(cond: bool, msg: str) void = { if (!cond) { diff --git a/rt/configure b/rt/configure @@ -0,0 +1,6 @@ +#!/bin/sh +all="$all rt" + +rt() { + echo "rt: libhart.a" +} diff --git a/src/lex.c b/src/lex.c @@ -122,7 +122,7 @@ static const char *tokens[] = { }; void -lex_init(struct lexer *lexer, FILE *f) +lex_init(struct lexer *lexer, FILE *f, const char *filename) { memset(lexer, 0, sizeof(*lexer)); lexer->in = f; @@ -131,7 +131,7 @@ lex_init(struct lexer *lexer, FILE *f) lexer->un.token = T_ERROR; lexer->loc.lineno = 1; lexer->loc.colno = 0; - lexer->loc.path = "stdin"; // TODO: non-stdin paths + lexer->loc.path = filename; lexer->c[0] = UINT32_MAX; lexer->c[1] = UINT32_MAX; } diff --git a/src/main.c b/src/main.c @@ -70,7 +70,7 @@ main(int argc, char *argv[]) case 'N': unit.ns = xcalloc(1, sizeof(struct identifier)); FILE *in = fmemopen(optarg, strlen(optarg), "r"); - lex_init(&lexer, in); + lex_init(&lexer, in, "-N"); parse_identifier(&lexer, unit.ns); lex_finish(&lexer); break; @@ -106,7 +106,7 @@ main(int argc, char *argv[]) return 1; } - lex_init(&lexer, in); + lex_init(&lexer, in, path); if (stage == STAGE_LEX) { struct token tok; while (lex(&lexer, &tok) != T_EOF);