Commit e88c58ae54c3b1f53d54e1b8196f79a1846ac949
1 parent
5a2822a6
Exists in
master
new back-end-specific organization
Showing
3 changed files
with
110 additions
and
108 deletions
Show diff stats
fz/Makefile
| @@ -6,8 +6,10 @@ OTHER = flatzinc.output | @@ -6,8 +6,10 @@ OTHER = flatzinc.output | ||
| 6 | PLFILES = $(filter-out out-%.pl,$(wildcard *.pl)) | 6 | PLFILES = $(filter-out out-%.pl,$(wildcard *.pl)) |
| 7 | PLOFILES = $(patsubst %.pl,%.o,$(PLFILES)) | 7 | PLOFILES = $(patsubst %.pl,%.o,$(PLFILES)) |
| 8 | 8 | ||
| 9 | -# out-XXX.pl produces fz-XXX, the flatzinc-to-XXX compiler | ||
| 10 | -FZSEM = $(patsubst out-%.pl,fz-%,$(wildcard out-*.pl)) | 9 | +# XXX/output.pl produces fz-XXX, the flatzinc-to-XXX compiler |
| 10 | +FZBACKS = $(patsubst %/output.pl,%,$(wildcard */output.pl)) | ||
| 11 | +FZSEM = $(patsubst %/output.pl,fz-%,$(wildcard */output.pl)) | ||
| 12 | +FZOFILES = $(patsubst %,%/*.o,$(FZBACKS)) | ||
| 11 | 13 | ||
| 12 | # NOTE: we need to pass the `-l' flag to ensure the scanner internal | 14 | # NOTE: we need to pass the `-l' flag to ensure the scanner internal |
| 13 | # variable `yylineno' is available. | 15 | # variable `yylineno' is available. |
| @@ -29,12 +31,12 @@ RM = /bin/rm -f | @@ -29,12 +31,12 @@ RM = /bin/rm -f | ||
| 29 | %.ast:: %.fzn | 31 | %.ast:: %.fzn |
| 30 | fzp < $< > $@ | 32 | fzp < $< > $@ |
| 31 | 33 | ||
| 32 | -all: fzp $(FZSEM) $(PLOFILES) $(patsubst %.pl,%.o,$(wildcard out-*.pl)) | 34 | +all: fzp $(FZSEM) $(PLOFILES) $(FZOFILES) |
| 33 | 35 | ||
| 34 | fzp: $(OBJ) | 36 | fzp: $(OBJ) |
| 35 | $(CC) $(CFLAGS) -o $@ $(OBJ) $(LEXLIB) | 37 | $(CC) $(CFLAGS) -o $@ $(OBJ) $(LEXLIB) |
| 36 | 38 | ||
| 37 | -fz-%: out-%.o $(PLOFILES) | 39 | +fz-%: %/output.o $(PLOFILES) |
| 38 | $(GPLC) -o $@ $+ | 40 | $(GPLC) -o $@ $+ |
| 39 | 41 | ||
| 40 | %.o: %.pl | 42 | %.o: %.pl |
| @@ -47,7 +49,7 @@ lex.yy.c: flatzinc.l | @@ -47,7 +49,7 @@ lex.yy.c: flatzinc.l | ||
| 47 | $(LEX) $(LEXFLAGS) flatzinc.l | 49 | $(LEX) $(LEXFLAGS) flatzinc.l |
| 48 | 50 | ||
| 49 | clean: | 51 | clean: |
| 50 | - $(RM) $(OBJ) $(GENCFILES) $(OTHER) core | 52 | + $(RM) $(OBJ) $(PLOFILES) $(FZOFILES) $(GENCFILES) $(OTHER) core |
| 51 | 53 | ||
| 52 | clobber: clean | 54 | clobber: clean |
| 53 | $(RM) $(EXE_FILE) | 55 | $(RM) $(EXE_FILE) |
fz/out-paccs.pl
| @@ -1,103 +0,0 @@ | @@ -1,103 +0,0 @@ | ||
| 1 | -% == No, Emacs this is -*-Prolog-*- code, not what you thought... ============= | ||
| 2 | - | ||
| 3 | -% == Code generation for PaCCS ================================================ | ||
| 4 | - | ||
| 5 | -cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- | ||
| 6 | - cg_prefix(TEXT, PTXT), | ||
| 7 | - cg_preds(PS, ST, PTXT, VTXT1), | ||
| 8 | - cg_vars(decl, VS, ST, VTXT1, VTXT2), | ||
| 9 | - cg_vars(init, VS, ST, VTXT2, CTXT), | ||
| 10 | - %% cg_constrs(CTXT, GTXT, CS, ST), | ||
| 11 | - %% cg_goal(GTXT, STXT, G, VS, ST), | ||
| 12 | - %% cg_suffix(STXT, []), | ||
| 13 | - cg_suffix(CTXT, []), | ||
| 14 | - format("~s\n", [TEXT]). | ||
| 15 | - | ||
| 16 | -% == DCGs for code generation ================================================= | ||
| 17 | - | ||
| 18 | -% -- predicates --------------------------------------------------------------- | ||
| 19 | - | ||
| 20 | -cg_preds(_PS, _ST) --> []. | ||
| 21 | - | ||
| 22 | -% -- variables ---------------------------------------------------------------- | ||
| 23 | - | ||
| 24 | -cg_vars(OP, [V|Vs], ST) --> cg_var(OP, V, ST), cg_vars(OP, Vs, ST). | ||
| 25 | -cg_vars(_OP, [], _) --> []. | ||
| 26 | - | ||
| 27 | -cg_var(OP, var(N,int,I,A), ST) --> | ||
| 28 | - cg_var(OP, var(N,int(1,999),I,A), ST). % FIXME | ||
| 29 | - | ||
| 30 | -cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) --> | ||
| 31 | - { format_to_codes(S, " fd_int ~w = fd_new(~d, ~d);\n", [N, LB, UB]) }, | ||
| 32 | - S. | ||
| 33 | - | ||
| 34 | -cg_var(init, var(_,int(_,_),_,_), _) --> []. | ||
| 35 | - | ||
| 36 | -% -- array of variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 37 | - | ||
| 38 | -cg_var(decl, var(N,array(_T,LB,UB),[],_), _ST) --> !, | ||
| 39 | - { SZ is UB-LB+1, | ||
| 40 | - format_to_codes(S, " fd_int ~w[~d];\n", [N, SZ]) }, | ||
| 41 | - S. | ||
| 42 | - | ||
| 43 | -cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !, | ||
| 44 | - { SZ is AUB-ALB+1, bound(lb, T, LB), bound(ub, T, UB) }, | ||
| 45 | - { format_to_codes(S1, " for (i=0; i<~d; ++i)\n", [SZ]) }, S1, | ||
| 46 | - { format_to_codes(S2, " ~w[i] = fd_new(~d, ~d);\n", [N, LB, UB]) }, S2. | ||
| 47 | - | ||
| 48 | -% -- array of constants - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 49 | - | ||
| 50 | -cg_var(decl, var(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) --> | ||
| 51 | - { nonvar(INIT), INIT=[_|_] }, !, | ||
| 52 | - { SZ is UB-LB+1, | ||
| 53 | - format_to_codes(S, " int ~w[~d] = {\n", [N, SZ]) }, | ||
| 54 | - S, | ||
| 55 | - cg_constant_list(INIT, " "), | ||
| 56 | - " };\n". | ||
| 57 | - | ||
| 58 | -cg_var(init, var(_N,array(_T,_LB,_UB),lit(INIT,array(_)),_), _ST) --> | ||
| 59 | - { nonvar(INIT), INIT=[_|_] }, !, | ||
| 60 | - []. | ||
| 61 | - | ||
| 62 | - | ||
| 63 | -% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 64 | - | ||
| 65 | -cg_constant_list([], _) --> []. | ||
| 66 | -cg_constant_list([C|Cs], PFX) --> | ||
| 67 | - PFX, cg_constant(C), | ||
| 68 | - cg_constant_list(Cs, ", "). | ||
| 69 | - | ||
| 70 | -cg_constant(lit(N,int)) --> { format_to_codes(S, "~w", [N]) }, S. | ||
| 71 | - | ||
| 72 | -% -- constraints -------------------------------------------------------------- | ||
| 73 | - | ||
| 74 | -cg_constrs([C|Cs], ST) --> cg_constr(C, ST), cg_constrs(Cs, ST). | ||
| 75 | -cg_constrs([], _) --> []. | ||
| 76 | - | ||
| 77 | -cg_constr(_C, _ST) --> []. % FIXME: temporary | ||
| 78 | - | ||
| 79 | -% -- goal --------------------------------------------------------------------- | ||
| 80 | - | ||
| 81 | -cg_goal(satisfy, VS, ST) --> | ||
| 82 | - "\n", | ||
| 83 | - " if (fd_solve()) {\n", | ||
| 84 | - cg_var_print(VS, ST, " "), | ||
| 85 | - " }\n". | ||
| 86 | - | ||
| 87 | -cg_var_print([], _, _) --> []. | ||
| 88 | -cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> | ||
| 89 | - { member(output, A), ! }, | ||
| 90 | - { format_to_codes(S, "~sfd_println(~s);\n", [PFX, N]) }, S, | ||
| 91 | - cg_var_print(Vs, ST, PFX). | ||
| 92 | -cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). | ||
| 93 | - | ||
| 94 | - | ||
| 95 | -% -- prefix and suffix -------------------------------------------------------- | ||
| 96 | - | ||
| 97 | -cg_prefix --> | ||
| 98 | - "{\n", | ||
| 99 | - " int i, j;\n". | ||
| 100 | - | ||
| 101 | -cg_suffix --> | ||
| 102 | - "}\n". | ||
| 103 | - |
| @@ -0,0 +1,103 @@ | @@ -0,0 +1,103 @@ | ||
| 1 | +% == No, Emacs this is -*-Prolog-*- code, not what you thought... ============= | ||
| 2 | + | ||
| 3 | +% == Code generation for PaCCS ================================================ | ||
| 4 | + | ||
| 5 | +cg_emit(fzn(preds(PS), vars(VS), constrs(CS), G), ST) :- | ||
| 6 | + cg_prefix(TEXT, PTXT), | ||
| 7 | + cg_preds(PS, ST, PTXT, VTXT1), | ||
| 8 | + cg_vars(decl, VS, ST, VTXT1, VTXT2), | ||
| 9 | + cg_vars(init, VS, ST, VTXT2, CTXT), | ||
| 10 | + %% cg_constrs(CTXT, GTXT, CS, ST), | ||
| 11 | + %% cg_goal(GTXT, STXT, G, VS, ST), | ||
| 12 | + %% cg_suffix(STXT, []), | ||
| 13 | + cg_suffix(CTXT, []), | ||
| 14 | + format("~s\n", [TEXT]). | ||
| 15 | + | ||
| 16 | +% == DCGs for code generation ================================================= | ||
| 17 | + | ||
| 18 | +% -- predicates --------------------------------------------------------------- | ||
| 19 | + | ||
| 20 | +cg_preds(_PS, _ST) --> []. | ||
| 21 | + | ||
| 22 | +% -- variables ---------------------------------------------------------------- | ||
| 23 | + | ||
| 24 | +cg_vars(OP, [V|Vs], ST) --> cg_var(OP, V, ST), cg_vars(OP, Vs, ST). | ||
| 25 | +cg_vars(_OP, [], _) --> []. | ||
| 26 | + | ||
| 27 | +cg_var(OP, var(N,int,I,A), ST) --> | ||
| 28 | + cg_var(OP, var(N,int(1,999),I,A), ST). % FIXME | ||
| 29 | + | ||
| 30 | +cg_var(decl, var(N,int(LB,UB),_I,_A), _ST) --> | ||
| 31 | + { format_to_codes(S, " fd_int ~w = fd_new(~d, ~d);\n", [N, LB, UB]) }, | ||
| 32 | + S. | ||
| 33 | + | ||
| 34 | +cg_var(init, var(_,int(_,_),_,_), _) --> []. | ||
| 35 | + | ||
| 36 | +% -- array of variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 37 | + | ||
| 38 | +cg_var(decl, var(N,array(_T,LB,UB),[],_), _ST) --> !, | ||
| 39 | + { SZ is UB-LB+1, | ||
| 40 | + format_to_codes(S, " fd_int ~w[~d];\n", [N, SZ]) }, | ||
| 41 | + S. | ||
| 42 | + | ||
| 43 | +cg_var(init, var(N,array(T,ALB,AUB),[],_), _ST) --> !, | ||
| 44 | + { SZ is AUB-ALB+1, bound(lb, T, LB), bound(ub, T, UB) }, | ||
| 45 | + { format_to_codes(S1, " for (i=0; i<~d; ++i)\n", [SZ]) }, S1, | ||
| 46 | + { format_to_codes(S2, " ~w[i] = fd_new(~d, ~d);\n", [N, LB, UB]) }, S2. | ||
| 47 | + | ||
| 48 | +% -- array of constants - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 49 | + | ||
| 50 | +cg_var(decl, var(N,array(_T,LB,UB),lit(INIT,array(_)),_), _ST) --> | ||
| 51 | + { nonvar(INIT), INIT=[_|_] }, !, | ||
| 52 | + { SZ is UB-LB+1, | ||
| 53 | + format_to_codes(S, " int ~w[~d] = {\n", [N, SZ]) }, | ||
| 54 | + S, | ||
| 55 | + cg_constant_list(INIT, " "), | ||
| 56 | + " };\n". | ||
| 57 | + | ||
| 58 | +cg_var(init, var(_N,array(_T,_LB,_UB),lit(INIT,array(_)),_), _ST) --> | ||
| 59 | + { nonvar(INIT), INIT=[_|_] }, !, | ||
| 60 | + []. | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| 64 | + | ||
| 65 | +cg_constant_list([], _) --> []. | ||
| 66 | +cg_constant_list([C|Cs], PFX) --> | ||
| 67 | + PFX, cg_constant(C), | ||
| 68 | + cg_constant_list(Cs, ", "). | ||
| 69 | + | ||
| 70 | +cg_constant(lit(N,int)) --> { format_to_codes(S, "~w", [N]) }, S. | ||
| 71 | + | ||
| 72 | +% -- constraints -------------------------------------------------------------- | ||
| 73 | + | ||
| 74 | +cg_constrs([C|Cs], ST) --> cg_constr(C, ST), cg_constrs(Cs, ST). | ||
| 75 | +cg_constrs([], _) --> []. | ||
| 76 | + | ||
| 77 | +cg_constr(_C, _ST) --> []. % FIXME: temporary | ||
| 78 | + | ||
| 79 | +% -- goal --------------------------------------------------------------------- | ||
| 80 | + | ||
| 81 | +cg_goal(satisfy, VS, ST) --> | ||
| 82 | + "\n", | ||
| 83 | + " if (fd_solve()) {\n", | ||
| 84 | + cg_var_print(VS, ST, " "), | ||
| 85 | + " }\n". | ||
| 86 | + | ||
| 87 | +cg_var_print([], _, _) --> []. | ||
| 88 | +cg_var_print([var(N,_,_,A)|Vs], ST, PFX) --> | ||
| 89 | + { member(output, A), ! }, | ||
| 90 | + { format_to_codes(S, "~sfd_println(~s);\n", [PFX, N]) }, S, | ||
| 91 | + cg_var_print(Vs, ST, PFX). | ||
| 92 | +cg_var_print([_|Vs], ST, PFX) --> cg_var_print(Vs, ST, PFX). | ||
| 93 | + | ||
| 94 | + | ||
| 95 | +% -- prefix and suffix -------------------------------------------------------- | ||
| 96 | + | ||
| 97 | +cg_prefix --> | ||
| 98 | + "{\n", | ||
| 99 | + " int i, j;\n". | ||
| 100 | + | ||
| 101 | +cg_suffix --> | ||
| 102 | + "}\n". | ||
| 103 | + |