From a5ffa1f0f6ccbf483db1267ed2df69334196a6a2 Mon Sep 17 00:00:00 2001 From: Salvador Abreu Date: Tue, 18 Aug 2015 14:49:21 +0900 Subject: [PATCH] does basic coverage (1 back-end for 1 IR) compiles with PaCCS --- fz/examples/aust-paccs.c | 15 ++++++++++++++- fz/paccs/coverage.pl | 26 ++++++++++++++++++++++++++ fz/paccs/output.pl | 15 ++++++++------- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/fz/examples/aust-paccs.c b/fz/examples/aust-paccs.c index 3fe2890..24de9f5 100644 --- a/fz/examples/aust-paccs.c +++ b/fz/examples/aust-paccs.c @@ -1,8 +1,9 @@ #include "paccs.h" -main() +int main(int argc, char *argv[]) { int i, j; + fd_int t = fd_new(1, 3); fd_int v = fd_new(1, 3); fd_int nsw = fd_new(1, 3); @@ -12,6 +13,17 @@ main() fd_int wa = fd_new(1, 3); int X_INTRODUCED_0[2] = { 1, -1 }; + fd_int va_1[2] = { nsw, v }; fd_poly_ne_k(X_INTRODUCED_0, va_1, 2, 0); + fd_int va_2[2] = { q, nsw }; fd_poly_ne_k(X_INTRODUCED_0, va_2, 2, 0); + fd_int va_3[2] = { sa, v }; fd_poly_ne_k(X_INTRODUCED_0, va_3, 2, 0); + fd_int va_4[2] = { sa, nsw }; fd_poly_ne_k(X_INTRODUCED_0, va_4, 2, 0); + fd_int va_5[2] = { sa, q }; fd_poly_ne_k(X_INTRODUCED_0, va_5, 2, 0); + fd_int va_6[2] = { nt, q }; fd_poly_ne_k(X_INTRODUCED_0, va_6, 2, 0); + fd_int va_7[2] = { nt, sa }; fd_poly_ne_k(X_INTRODUCED_0, va_7, 2, 0); + fd_int va_8[2] = { wa, sa }; fd_poly_ne_k(X_INTRODUCED_0, va_8, 2, 0); + fd_int va_9[2] = { wa, nt }; fd_poly_ne_k(X_INTRODUCED_0, va_9, 2, 0); + + if (fd_solve()) { fd_println(t); fd_println(v); @@ -21,5 +33,6 @@ main() fd_println(nt); fd_println(wa); } + fd_end(); } diff --git a/fz/paccs/coverage.pl b/fz/paccs/coverage.pl index 05d5c1c..2857fd2 100644 --- a/fz/paccs/coverage.pl +++ b/fz/paccs/coverage.pl @@ -2,3 +2,29 @@ % == Code coverage for PaCCS ================================================== +% ++ cv_basic(AST, CODE, ST) - - - - - - - - - - - - - - - - - - - - - - - - - + +cv_basic(int_lin_ne(COEF, VARS, CONST), _ST) --> + int_vector(COEF, CC, NN), + var_vector(VARS, YY), + constant(CONST, KK), + { name(CC, CCN), name(YY, YYN), name(KK, KKN), name(NN, NNN) }, + "fd_poly_ne_k(", CCN, ", ", YYN, ", ", NNN, ", ", KKN, ");\n". + +int_vector(val(CC,array(int,1,NN),_,_), CC, NN) --> []. + +var_vector(lit(VS, array(int(_LB,_UB))), VA) --> % array of FD variables + { length(VS, L), name(L, LN), + uniq_name(va, VA), name(VA, VAN) }, + " fd_int ", VAN, "[", LN, "] = { ", + var_name_list(VS), + " }; ". + +constant(lit(KK,int), KK) --> []. + +var_name_list([]) --> []. +var_name_list([var(CVN,_,_,_)]) --> + { !, name(CVN, CVNN) }, CVNN. +var_name_list([var(CVN,_,_,_)|Vs]) --> + { name(CVN, CVNN) }, CVNN, ", ", + var_name_list(Vs). diff --git a/fz/paccs/output.pl b/fz/paccs/output.pl index 5463f62..5103776 100644 --- a/fz/paccs/output.pl +++ b/fz/paccs/output.pl @@ -9,9 +9,12 @@ cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- cg_emit(PS, VS, CS, G, ST) --> cg_prefix, cg_preds(PS, ST), + "\n", cg_vars(decl, VS, ST), cg_vars(init, VS, ST), + "\n", cg_constrs(CS, ST), + "\n", cg_goal(G, VS, ST), cg_suffix. @@ -40,7 +43,7 @@ cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) --> cg_var(init, var(_,int(_,_),_,_), _ST) --> []. cg_var(decl, val(N,int,lit(INIT,_),_), _) --> - { format_to_codes(S, " const int ~w = ~w;\n", [N, INIT]) }, + { format_to_codes(S, " int ~w = ~w;\n", [N, INIT]) }, S. cg_var(init, val(_,int,_,_), _ST) --> []. @@ -62,7 +65,7 @@ cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !, cg_var(decl, val(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) --> { nonvar(INIT), INIT=[_|_] }, !, { SZ is UB-LB+1, - format_to_codes(S, " const int ~w[~d] = {", [N, SZ]) }, + format_to_codes(S, " int ~w[~d] = {", [N, SZ]) }, S, cg_constant_list(INIT, " "), " };\n". @@ -90,11 +93,9 @@ cg_constrs(CS, ST) --> cg_coverage(CS, CR, ST), cg_constrs(CR, ST). % ++ cg_coverage(CI, CO, ST) [DCG] - - - - - - - - - - - - - - - - - - - - - - % % emit an instruction which partly covers CI, leaving CO untreated -% FIXME: for now this just puts out comments +% FIXME: still need to search for an optimal solution... -cg_coverage([C|CS], CS, _ST) --> - { C=constraint(CE, _A), - format_to_codes(S, "// ~w\n", [CE]) }, S. +cg_coverage([constraint(CE, _A)|CS], CS, ST) --> cv_basic(CE, ST). % -- goal --------------------------------------------------------------------- @@ -118,7 +119,7 @@ cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). cg_prefix --> "#include \"paccs.h\"\n\n", - "main()\n", + "int main(int argc, char *argv[])\n", "{\n", " int i, j;\n". -- libgit2 0.21.2