qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

commit b75cb8388fb9b5f2393443d008bb46c522c5ec9b
parent 1b4943eb1f2a10837f56070bfe604179d0dc10e0
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date:   Mon, 28 Mar 2016 12:53:53 -0400

new layout, put LICENSE in root

Diffstat:
M.gitignore | 5++++-
Rsrc/.tag -> .tag | 0
ALICENSE | 19+++++++++++++++++++
MMakefile | 45+++++++++++++++++++++++++++++++++++++++------
AREADME | 8++++++++
Rsrc/all.h -> all.h | 0
Rsrc/copy.c -> copy.c | 0
Rsrc/emit.c -> emit.c | 0
Rsrc/isel.c -> isel.c | 0
Rsrc/live.c -> live.c | 0
Rsrc/main.c -> main.c | 0
Rsrc/mem.c -> mem.c | 0
Dminic/LICENSE | 21---------------------
Mminic/Makefile | 4+---
Mminic/mcc | 2+-
Rsrc/parse.c -> parse.c | 0
Rsrc/rega.c -> rega.c | 0
Rsrc/spill.c -> spill.c | 0
Dsrc/.gitignore | 5-----
Dsrc/Makefile | 24------------------------
Rsrc/ssa.c -> ssa.c | 0
Dtest/go.sh | 119-------------------------------------------------------------------------------
Mtools/abifuzz.sh | 2+-
Dtools/fptox.c | 18------------------
Mtools/pmov.c | 2+-
Dtools/regress.sh | 17-----------------
Atools/unit.sh | 119+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/util.c -> util.c | 0
28 files changed, 193 insertions(+), 217 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1 +1,4 @@ -papers +obj +config.h +.comfile +*.out diff --git a/src/.tag b/.tag diff --git a/LICENSE b/LICENSE @@ -0,0 +1,19 @@ +© 2015-2016 Quentin Carbonneaux <quentin@c9x.me> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/Makefile b/Makefile @@ -1,8 +1,41 @@ -all clean check: - @make -C src $@ - @make -C minic $@ +BIN = qbe -sync-papers: - unison -auto papers ssh://qcar@h/data/d/ssa-doc +V = @ +OBJDIR = obj -.PHONY: all clean check sync-papers +SRC = main.c util.c parse.c mem.c ssa.c copy.c live.c isel.c spill.c rega.c emit.c +OBJ = $(SRC:%.c=$(OBJDIR)/%.o) + +CFLAGS += -Wall -Wextra -std=c99 -g -pedantic + +$(OBJDIR)/$(BIN): $(OBJ) $(OBJDIR)/timestamp + @echo "ld $@" + $(V)$(CC) $(LDFLAGS) $(OBJ) -o $@ + +$(OBJDIR)/%.o: %.c $(OBJDIR)/timestamp + @echo "cc $<" + $(V)$(CC) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/timestamp: + @mkdir -p $(OBJDIR) + @touch $@ + +$(OBJ): all.h +obj/main.o: config.h + +config.h: + @case `uname` in \ + *Darwin*) echo "#define Defaultasm Gasmacho" ;; \ + *Linux*) echo "#define Defaultasm Gaself" ;; \ + esac > $@ + +clean: + rm -fr $(OBJDIR) + +clean-gen: clean + rm -f config.h + +check: $(OBJDIR)/$(BIN) + tools/unit.sh all + +.PHONY: clean clean-gen check syndoc diff --git a/README b/README @@ -0,0 +1,8 @@ +QBE - Backend Compiler http://c9x.me/compile/ + +doc/ Documentation. +minic/ An example C frontend for QBE. +tools/ Miscelaneous tools (testing). +test/ Unit tests. + +The LICENSE file applies to all files distributed. diff --git a/src/all.h b/all.h diff --git a/src/copy.c b/copy.c diff --git a/src/emit.c b/emit.c diff --git a/src/isel.c b/isel.c diff --git a/src/live.c b/live.c diff --git a/src/main.c b/main.c diff --git a/src/mem.c b/mem.c diff --git a/minic/LICENSE b/minic/LICENSE @@ -1,21 +0,0 @@ -MIT/X Consortium License - -© 2015-2016 Quentin Carbonneaux - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/minic/Makefile b/minic/Makefile @@ -6,9 +6,7 @@ $(BIN): yacc minic.y ./yacc minic.y $(CC) $(CFLAGS) -o $@ y.tab.c -all: $(BIN) -check: clean: rm -f yacc minic y.* -.PHONY: all check clean +.PHONY: clean diff --git a/minic/mcc b/minic/mcc @@ -29,7 +29,7 @@ fi ../minic/minic < $file > /tmp/minic.ssa && -../src/qbe < /tmp/minic.ssa > /tmp/minic.s && +../obj/qbe < /tmp/minic.ssa > /tmp/minic.s && cc $flags /tmp/minic.s if test $? -ne 0 diff --git a/src/parse.c b/parse.c diff --git a/src/rega.c b/rega.c diff --git a/src/spill.c b/spill.c diff --git a/src/.gitignore b/src/.gitignore @@ -1,5 +0,0 @@ -qbe -config.h -.comfile -*.o -*.out diff --git a/src/Makefile b/src/Makefile @@ -1,24 +0,0 @@ -BIN = qbe -OBJ = main.o util.o parse.o mem.o ssa.o copy.o live.o isel.o spill.o rega.o emit.o - -CFLAGS += -Wall -Wextra -std=c99 -g -pedantic - -$(BIN): $(OBJ) - $(CC) $(LDFLAGS) $(OBJ) -o $@ - -$(OBJ): all.h config.h - -config.h: - @case `uname` in \ - *Darwin*) echo "#define Defaultasm Gasmacho" ;; \ - *Linux*) echo "#define Defaultasm Gaself" ;; \ - esac > $@ - - -all: $(BIN) -clean: - rm -f $(BIN) $(OBJ) -check: $(BIN) - ../test/go.sh all - -.PHONY: all clean check syndoc diff --git a/src/ssa.c b/ssa.c diff --git a/test/go.sh b/test/go.sh @@ -1,119 +0,0 @@ -#!/bin/sh - -DIR=`cd $(dirname "$0"); pwd` -QBE=$DIR/../src/qbe - -TMP=/tmp/qbe.zzzz - -DRV=$TMP.c -ASM=$TMP.s -BIN=$TMP.bin -OUT=$TMP.out - -cleanup() { - rm -f $DRV $ASM $BIN $OUT -} - -extract() { - WHAT="$1" - FILE="$2" - - awk " - /^# >>> $WHAT/ { - p = 1 - next - } - /^# <<</ { - if (p) - p = 0 - } - p - " $FILE \ - | sed -e 's/# //' \ - | sed -e 's/#$//' -} - -once() { - T="$1" - - if ! test -f $T - then - echo "invalid test file $T" >&2 - exit 1 - fi - - echo "$(basename $T)..." - - if ! $QBE -o $ASM $T - then - echo "[qbe fail]" - return 1 - fi - - extract driver $T > $DRV - extract output $T > $OUT - - if test -s $DRV - then - LNK="$DRV $ASM" - else - LNK="$ASM" - fi - - if ! cc -g -o $BIN $LNK - then - echo "[cc fail]" - return 1 - fi - - if test -s $OUT - then - $BIN a b c | diff - $OUT - RET=$? - REASON="output" - else - $BIN a b c - RET=$? - REASON="returned $RET" - fi - - if test $RET -ne 0 - then - echo "[$REASON fail]" - return 1 - fi - - printf "\033[1A\033[45C[ok]\n" -} - - -#trap cleanup TERM QUIT - -if test -z "$1" -then - echo "usage: test/go.sh {all, SSAFILE}" 2>&1 - exit 1 -fi - -case $1 in - "all") - F=0 - for T in $DIR/[!_]*.ssa - do - once $T - F=`expr $F + $?` - done - if test $F -ge 1 - then - echo - echo "$F test(s) failed!" - else - echo - echo "All is fine!" - fi - ;; - *) - once $1 - exit $? - ;; -esac diff --git a/tools/abifuzz.sh b/tools/abifuzz.sh @@ -2,7 +2,7 @@ OCAMLC=${OCAMLC:-/usr/bin/ocamlc} DIR=`cd $(dirname "$0"); pwd` -QBE=$DIR/../src/qbe +QBE=$DIR/../obj/qbe failure() { echo "Failure at stage:" $1 >&2 diff --git a/tools/fptox.c b/tools/fptox.c @@ -1,18 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int -main(int ac, char *av[]) -{ - double d; - float f; - - if (ac < 2) { - usage: - fputs("usage: fptox NUMBER\n", stderr); - return 1; - } - f = d = strtod(av[1], 0); - printf("0x%08x 0x%016llx\n", *(unsigned *)&f, *(unsigned long long*)&d); - return 0; -} diff --git a/tools/pmov.c b/tools/pmov.c @@ -13,7 +13,7 @@ static void assert_test(char *, int), fail(void), iexec(int *); -#include "../src/rega.c" +#include "../../rega.c" static void bsinit_(BSet *, uint); diff --git a/tools/regress.sh b/tools/regress.sh @@ -1,17 +0,0 @@ -#!/bin/sh - -for t in ../test/* -do - printf "Test $t ... " - - ./qbe $t >/tmp/out.0 2>&1 - ./qbe.1 $t >/tmp/out.1 2>&1 - - if diff /tmp/out.0 /tmp/out.1 > /dev/null - then - echo "OK" - else - echo "KO" - break - fi -done diff --git a/tools/unit.sh b/tools/unit.sh @@ -0,0 +1,119 @@ +#!/bin/sh + +DIR=`cd $(dirname "$0"); pwd` +QBE=$DIR/../obj/qbe + +TMP=/tmp/qbe.zzzz + +DRV=$TMP.c +ASM=$TMP.s +BIN=$TMP.bin +OUT=$TMP.out + +cleanup() { + rm -f $DRV $ASM $BIN $OUT +} + +extract() { + WHAT="$1" + FILE="$2" + + awk " + /^# >>> $WHAT/ { + p = 1 + next + } + /^# <<</ { + if (p) + p = 0 + } + p + " $FILE \ + | sed -e 's/# //' \ + | sed -e 's/#$//' +} + +once() { + T="$1" + + if ! test -f $T + then + echo "invalid test file $T" >&2 + exit 1 + fi + + echo "$(basename $T)..." + + if ! $QBE -o $ASM $T + then + echo "[qbe fail]" + return 1 + fi + + extract driver $T > $DRV + extract output $T > $OUT + + if test -s $DRV + then + LNK="$DRV $ASM" + else + LNK="$ASM" + fi + + if ! cc -g -o $BIN $LNK + then + echo "[cc fail]" + return 1 + fi + + if test -s $OUT + then + $BIN a b c | diff - $OUT + RET=$? + REASON="output" + else + $BIN a b c + RET=$? + REASON="returned $RET" + fi + + if test $RET -ne 0 + then + echo "[$REASON fail]" + return 1 + fi + + printf "\033[1A\033[45C[ok]\n" +} + + +#trap cleanup TERM QUIT + +if test -z "$1" +then + echo "usage: test/go.sh {all, SSAFILE}" 2>&1 + exit 1 +fi + +case $1 in + "all") + F=0 + for T in $DIR/../test/[!_]*.ssa + do + once $T + F=`expr $F + $?` + done + if test $F -ge 1 + then + echo + echo "$F test(s) failed!" + else + echo + echo "All is fine!" + fi + ;; + *) + once $1 + exit $? + ;; +esac diff --git a/src/util.c b/util.c