From aa26db13f4daedec371a17ee7f79ecce7f8fb60f Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Wed, 25 Apr 2018 15:26:28 +0200 Subject: MPPA - Added coverage test --- .gitmodules | 3 +++ mppa_k1c/TargetPrinter.ml | 6 +++--- test/mppa/Makefile | 5 +++++ test/mppa/asm_coverage | 1 + test/mppa/coverage.sh | 17 +++++++++++++++++ test/mppa/coverage_helper.py | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 test/mppa/asm_coverage create mode 100644 test/mppa/coverage.sh create mode 100644 test/mppa/coverage_helper.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..955c7fc2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/mppa/asm_coverage"] + path = test/mppa/asm_coverage + url = git@gricad-gitlab.univ-grenoble-alpes.fr:sixcy/asm-scanner.git diff --git a/mppa_k1c/TargetPrinter.ml b/mppa_k1c/TargetPrinter.ml index 6dd2bbad..b3c05f9c 100644 --- a/mppa_k1c/TargetPrinter.ml +++ b/mppa_k1c/TargetPrinter.ml @@ -196,7 +196,7 @@ module Target : TARGET = | Pj_l(s) -> fprintf oc " goto %a\n;;\n" print_label s | Pret -> - fprintf oc " ret\n;;\n" + fprintf oc " ret \n;;\n" | Pget (rd, rs) -> fprintf oc " get %a = %a\n;;\n" ireg rd preg rs | Pset (rd, rs) -> @@ -288,11 +288,11 @@ module Target : TARGET = | Pcompw (it, rd, rs1, rs2) -> fprintf oc " compw.%a %a = %a, %a\n;;\n" icond it ireg rd ireg rs1 ireg rs2 | Pcompiw (it, rd, rs1, imm) -> - fprintf oc " compiw.%a %a = %a, %a\n;;\n" icond it ireg rd ireg rs1 coqint64 imm + fprintf oc " compw.%a %a = %a, %a\n;;\n" icond it ireg rd ireg rs1 coqint64 imm | Pcompd (it, rd, rs1, rs2) -> fprintf oc " compd.%a %a = %a, %a\n;;\n" icond it ireg rd ireg rs1 ireg rs2 | Pcompid (it, rd, rs1, imm) -> - fprintf oc " compid.%a %a = %a, %a\n;;\n" icond it ireg rd ireg rs1 coqint64 imm + fprintf oc " compd.%a %a = %a, %a\n;;\n" icond it ireg rd ireg rs1 coqint64 imm | Pcb (bt, r, lbl) | Pcbu (bt, r, lbl) -> fprintf oc " cb.%a %a?%a\n;;\n" bcond bt ireg r print_label lbl diff --git a/test/mppa/Makefile b/test/mppa/Makefile index b210efaf..87315f6e 100644 --- a/test/mppa/Makefile +++ b/test/mppa/Makefile @@ -36,6 +36,11 @@ FORCE: .PHONY: check: $(TOK) sort mmult +.PHONY: +coverage: $(ASM) + bash coverage.sh $(DIR)/$(ASMDIR) + + .PHONY: sort: FORCE (cd sort && make compc-check) diff --git a/test/mppa/asm_coverage b/test/mppa/asm_coverage new file mode 160000 index 00000000..5bdb081b --- /dev/null +++ b/test/mppa/asm_coverage @@ -0,0 +1 @@ +Subproject commit 5bdb081bc5fd4962315e960af3c539f2ddd24477 diff --git a/test/mppa/coverage.sh b/test/mppa/coverage.sh new file mode 100644 index 00000000..0a057ff9 --- /dev/null +++ b/test/mppa/coverage.sh @@ -0,0 +1,17 @@ +asmdir=$1 +to_cover_raw=/tmp/to_cover_raw +to_cover=/tmp/to_cover +covered_raw=/tmp/covered_raw +covered=/tmp/covered + +sed -n "s/^.*fprintf oc \" \(.*\) .*/\1/p" ../../mppa_k1c/TargetPrinter.ml > $to_cover_raw +sed -n "s/^.*fprintf oc \" \(.*\)\\n.*/\1/p" ../../mppa_k1c/TargetPrinter.ml >> $to_cover_raw +python2.7 coverage_helper.py $to_cover_raw > $to_cover + +rm -f $covered_raw +for asm in $(ls $asmdir/*.s); do + bash asm_coverage/asm-coverage.sh $asm >> $covered_raw +done +python2.7 coverage_helper.py $covered_raw > $covered + +vimdiff $to_cover $covered diff --git a/test/mppa/coverage_helper.py b/test/mppa/coverage_helper.py new file mode 100644 index 00000000..f886264c --- /dev/null +++ b/test/mppa/coverage_helper.py @@ -0,0 +1,35 @@ +import fileinput + +occurs = {} + +for line in fileinput.input(): + line_noc = line.replace('\n', '') + if line_noc not in occurs: + occurs[line_noc] = 0 + occurs[line_noc] += 1 + +# HACK: Removing all the instructions with "%a", replacing them with all their variations +# Also removing all instructions starting with '.' +pruned_occurs = dict(occurs) +for inst in occurs: + if inst[0] == '.': + del pruned_occurs[inst] + if "%a" not in inst: + continue + inst_no_a = inst.replace(".%a", "") + if inst_no_a in ("compw", "compd"): + del pruned_occurs[inst] + for mod in ("ne", "eq", "lt", "gt", "le", "ge", "ltu", "leu", "geu", + "gtu", "all", "any", "nall", "none"): + pruned_occurs[inst_no_a + "." + mod] = 1 + elif inst_no_a in ("cb"): + del pruned_occurs[inst] + for mod in ("wnez", "weqz", "wltz", "wgez", "wlez", "wgtz", "dnez", + "dltz", "dgez", "dlez", "dgtz"): + pruned_occurs[inst_no_a + "." + mod] = 1 + else: + assert False, "Found instruction with %a: " + inst +occurs = pruned_occurs + +for inst in sorted(occurs): + print inst -- cgit