Commit a5ffa1f0f6ccbf483db1267ed2df69334196a6a2

Authored by Salvador Abreu
1 parent 3a811a46
Exists in master

does basic coverage (1 back-end for 1 IR)

compiles with PaCCS
fz/examples/aust-paccs.c
1 #include "paccs.h" 1 #include "paccs.h"
2 2
3 -main() 3 +int main(int argc, char *argv[])
4 { 4 {
5 int i, j; 5 int i, j;
  6 +
6 fd_int t = fd_new(1, 3); 7 fd_int t = fd_new(1, 3);
7 fd_int v = fd_new(1, 3); 8 fd_int v = fd_new(1, 3);
8 fd_int nsw = fd_new(1, 3); 9 fd_int nsw = fd_new(1, 3);
@@ -12,6 +13,17 @@ main() @@ -12,6 +13,17 @@ main()
12 fd_int wa = fd_new(1, 3); 13 fd_int wa = fd_new(1, 3);
13 int X_INTRODUCED_0[2] = { 1, -1 }; 14 int X_INTRODUCED_0[2] = { 1, -1 };
14 15
  16 + fd_int va_1[2] = { nsw, v }; fd_poly_ne_k(X_INTRODUCED_0, va_1, 2, 0);
  17 + fd_int va_2[2] = { q, nsw }; fd_poly_ne_k(X_INTRODUCED_0, va_2, 2, 0);
  18 + fd_int va_3[2] = { sa, v }; fd_poly_ne_k(X_INTRODUCED_0, va_3, 2, 0);
  19 + fd_int va_4[2] = { sa, nsw }; fd_poly_ne_k(X_INTRODUCED_0, va_4, 2, 0);
  20 + fd_int va_5[2] = { sa, q }; fd_poly_ne_k(X_INTRODUCED_0, va_5, 2, 0);
  21 + fd_int va_6[2] = { nt, q }; fd_poly_ne_k(X_INTRODUCED_0, va_6, 2, 0);
  22 + fd_int va_7[2] = { nt, sa }; fd_poly_ne_k(X_INTRODUCED_0, va_7, 2, 0);
  23 + fd_int va_8[2] = { wa, sa }; fd_poly_ne_k(X_INTRODUCED_0, va_8, 2, 0);
  24 + fd_int va_9[2] = { wa, nt }; fd_poly_ne_k(X_INTRODUCED_0, va_9, 2, 0);
  25 +
  26 +
15 if (fd_solve()) { 27 if (fd_solve()) {
16 fd_println(t); 28 fd_println(t);
17 fd_println(v); 29 fd_println(v);
@@ -21,5 +33,6 @@ main() @@ -21,5 +33,6 @@ main()
21 fd_println(nt); 33 fd_println(nt);
22 fd_println(wa); 34 fd_println(wa);
23 } 35 }
  36 + fd_end();
24 } 37 }
25 38
fz/paccs/coverage.pl
@@ -2,3 +2,29 @@ @@ -2,3 +2,29 @@
2 2
3 % == Code coverage for PaCCS ================================================== 3 % == Code coverage for PaCCS ==================================================
4 4
  5 +% ++ cv_basic(AST, CODE, ST) - - - - - - - - - - - - - - - - - - - - - - - - -
  6 +
  7 +cv_basic(int_lin_ne(COEF, VARS, CONST), _ST) -->
  8 + int_vector(COEF, CC, NN),
  9 + var_vector(VARS, YY),
  10 + constant(CONST, KK),
  11 + { name(CC, CCN), name(YY, YYN), name(KK, KKN), name(NN, NNN) },
  12 + "fd_poly_ne_k(", CCN, ", ", YYN, ", ", NNN, ", ", KKN, ");\n".
  13 +
  14 +int_vector(val(CC,array(int,1,NN),_,_), CC, NN) --> [].
  15 +
  16 +var_vector(lit(VS, array(int(_LB,_UB))), VA) --> % array of FD variables
  17 + { length(VS, L), name(L, LN),
  18 + uniq_name(va, VA), name(VA, VAN) },
  19 + " fd_int ", VAN, "[", LN, "] = { ",
  20 + var_name_list(VS),
  21 + " }; ".
  22 +
  23 +constant(lit(KK,int), KK) --> [].
  24 +
  25 +var_name_list([]) --> [].
  26 +var_name_list([var(CVN,_,_,_)]) -->
  27 + { !, name(CVN, CVNN) }, CVNN.
  28 +var_name_list([var(CVN,_,_,_)|Vs]) -->
  29 + { name(CVN, CVNN) }, CVNN, ", ",
  30 + var_name_list(Vs).
fz/paccs/output.pl
@@ -9,9 +9,12 @@ cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- @@ -9,9 +9,12 @@ cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :-
9 cg_emit(PS, VS, CS, G, ST) --> 9 cg_emit(PS, VS, CS, G, ST) -->
10 cg_prefix, 10 cg_prefix,
11 cg_preds(PS, ST), 11 cg_preds(PS, ST),
  12 + "\n",
12 cg_vars(decl, VS, ST), 13 cg_vars(decl, VS, ST),
13 cg_vars(init, VS, ST), 14 cg_vars(init, VS, ST),
  15 + "\n",
14 cg_constrs(CS, ST), 16 cg_constrs(CS, ST),
  17 + "\n",
15 cg_goal(G, VS, ST), 18 cg_goal(G, VS, ST),
16 cg_suffix. 19 cg_suffix.
17 20
@@ -40,7 +43,7 @@ cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) --> @@ -40,7 +43,7 @@ cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) -->
40 cg_var(init, var(_,int(_,_),_,_), _ST) --> []. 43 cg_var(init, var(_,int(_,_),_,_), _ST) --> [].
41 44
42 cg_var(decl, val(N,int,lit(INIT,_),_), _) --> 45 cg_var(decl, val(N,int,lit(INIT,_),_), _) -->
43 - { format_to_codes(S, " const int ~w = ~w;\n", [N, INIT]) }, 46 + { format_to_codes(S, " int ~w = ~w;\n", [N, INIT]) },
44 S. 47 S.
45 48
46 cg_var(init, val(_,int,_,_), _ST) --> []. 49 cg_var(init, val(_,int,_,_), _ST) --> [].
@@ -62,7 +65,7 @@ cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !, @@ -62,7 +65,7 @@ cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !,
62 cg_var(decl, val(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) --> 65 cg_var(decl, val(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) -->
63 { nonvar(INIT), INIT=[_|_] }, !, 66 { nonvar(INIT), INIT=[_|_] }, !,
64 { SZ is UB-LB+1, 67 { SZ is UB-LB+1,
65 - format_to_codes(S, " const int ~w[~d] = {", [N, SZ]) }, 68 + format_to_codes(S, " int ~w[~d] = {", [N, SZ]) },
66 S, 69 S,
67 cg_constant_list(INIT, " "), 70 cg_constant_list(INIT, " "),
68 " };\n". 71 " };\n".
@@ -90,11 +93,9 @@ cg_constrs(CS, ST) --> cg_coverage(CS, CR, ST), cg_constrs(CR, ST). @@ -90,11 +93,9 @@ cg_constrs(CS, ST) --> cg_coverage(CS, CR, ST), cg_constrs(CR, ST).
90 % ++ cg_coverage(CI, CO, ST) [DCG] - - - - - - - - - - - - - - - - - - - - - - 93 % ++ cg_coverage(CI, CO, ST) [DCG] - - - - - - - - - - - - - - - - - - - - - -
91 % 94 %
92 % emit an instruction which partly covers CI, leaving CO untreated 95 % emit an instruction which partly covers CI, leaving CO untreated
93 -% FIXME: for now this just puts out comments 96 +% FIXME: still need to search for an optimal solution...
94 97
95 -cg_coverage([C|CS], CS, _ST) -->  
96 - { C=constraint(CE, _A),  
97 - format_to_codes(S, "// ~w\n", [CE]) }, S. 98 +cg_coverage([constraint(CE, _A)|CS], CS, ST) --> cv_basic(CE, ST).
98 99
99 100
100 % -- goal --------------------------------------------------------------------- 101 % -- goal ---------------------------------------------------------------------
@@ -118,7 +119,7 @@ cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). @@ -118,7 +119,7 @@ cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX).
118 119
119 cg_prefix --> 120 cg_prefix -->
120 "#include \"paccs.h\"\n\n", 121 "#include \"paccs.h\"\n\n",
121 - "main()\n", 122 + "int main(int argc, char *argv[])\n",
122 "{\n", 123 "{\n",
123 " int i, j;\n". 124 " int i, j;\n".
124 125