2010-11-03 23:53:14 +01:00
|
|
|
/***** ltl2ba : main.c *****/
|
|
|
|
|
|
|
|
/* Written by Denis Oddoux, LIAFA, France */
|
|
|
|
/* Copyright (c) 2001 Denis Oddoux */
|
|
|
|
/* Modified by Paul Gastin, LSV, France */
|
|
|
|
/* Copyright (c) 2007 Paul Gastin */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify */
|
|
|
|
/* it under the terms of the GNU General Public License as published by */
|
|
|
|
/* the Free Software Foundation; either version 2 of the License, or */
|
|
|
|
/* (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program is distributed in the hope that it will be useful, */
|
|
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
|
|
/* GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License */
|
|
|
|
/* along with this program; if not, write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
|
|
|
|
/* */
|
|
|
|
/* Based on the translation algorithm by Gastin and Oddoux, */
|
|
|
|
/* presented at the 13th International Conference on Computer Aided */
|
|
|
|
/* Verification, CAV 2001, Paris, France. */
|
|
|
|
/* Proceedings - LNCS 2102, pp. 53-65 */
|
|
|
|
/* */
|
|
|
|
/* Send bug-reports and/or questions to Paul Gastin */
|
|
|
|
/* http://www.lsv.ens-cachan.fr/~gastin */
|
|
|
|
/* */
|
|
|
|
/* Some of the code in this file was taken from the Spin software */
|
|
|
|
/* Written by Gerard J. Holzmann, Bell Laboratories, U.S.A. */
|
|
|
|
|
2010-11-28 21:46:18 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2010-11-03 23:53:14 +01:00
|
|
|
|
2010-11-28 21:46:18 +01:00
|
|
|
#include "ltl2ba.h"
|
2010-11-03 23:53:14 +01:00
|
|
|
|
|
|
|
static char **ltl_file = (char **)0;
|
|
|
|
static char **add_ltl = (char **)0;
|
|
|
|
|
|
|
|
static void tl_endstats(void);
|
2010-11-28 21:46:18 +01:00
|
|
|
static const char *outfile;
|
2010-11-03 23:53:14 +01:00
|
|
|
|
|
|
|
void
|
2010-11-28 21:46:18 +01:00
|
|
|
cleanup()
|
2010-11-03 23:53:14 +01:00
|
|
|
{
|
2010-11-28 21:46:18 +01:00
|
|
|
if (outfile != NULL) {
|
|
|
|
unlink (outfile);
|
|
|
|
}
|
2010-11-03 23:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
2010-11-28 21:46:18 +01:00
|
|
|
cpyfile(const char *src, const char *tgt)
|
2010-11-03 23:53:14 +01:00
|
|
|
{ FILE *inp, *out;
|
2010-11-28 22:10:47 +01:00
|
|
|
char buf[4096];
|
2010-11-03 23:53:14 +01:00
|
|
|
|
|
|
|
inp = fopen(src, "r");
|
|
|
|
out = fopen(tgt, "w");
|
|
|
|
if (!inp || !out)
|
|
|
|
{ printf("ltl2ba: cannot cp %s to %s\n", src, tgt);
|
|
|
|
alldone(1);
|
|
|
|
}
|
2010-11-28 22:10:47 +01:00
|
|
|
while (fgets(buf, sizeof buf, inp))
|
|
|
|
fputs(buf, out);
|
2010-11-03 23:53:14 +01:00
|
|
|
fclose(inp);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
printf("usage: ltl2ba [-flag] -f formula\n");
|
|
|
|
printf(" or -F file\n");
|
|
|
|
printf(" -f \"formula\"\ttranslate LTL ");
|
|
|
|
printf("into never claim\n");
|
|
|
|
printf(" -F file\tlike -f, but with the LTL ");
|
|
|
|
printf("formula stored in a 1-line file\n");
|
|
|
|
printf(" -d\t\tdisplay automata (D)escription at each step\n");
|
|
|
|
printf(" -s\t\tcomputing time and automata sizes (S)tatistics\n");
|
|
|
|
printf(" -l\t\tdisable (L)ogic formula simplification\n");
|
|
|
|
printf(" -p\t\tdisable a-(P)osteriori simplification\n");
|
|
|
|
printf(" -o\t\tdisable (O)n-the-fly simplification\n");
|
|
|
|
printf(" -c\t\tdisable strongly (C)onnected components simplification\n");
|
|
|
|
printf(" -a\t\tdisable trick in (A)ccepting conditions\n");
|
|
|
|
|
|
|
|
alldone(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
tl_main(int argc, char *argv[])
|
|
|
|
{ int i;
|
2010-11-28 21:46:18 +01:00
|
|
|
int hasuform = 0;
|
2010-11-03 23:53:14 +01:00
|
|
|
while (argc > 1 && argv[1][0] == '-')
|
|
|
|
{ switch (argv[1][1]) {
|
|
|
|
case 'f': argc--; argv++;
|
|
|
|
for (i = 0; i < argv[1][i]; i++)
|
|
|
|
{ if (argv[1][i] == '\t'
|
|
|
|
|| argv[1][i] == '\"'
|
|
|
|
|| argv[1][i] == '\n')
|
|
|
|
argv[1][i] = ' ';
|
|
|
|
}
|
2010-11-28 21:46:18 +01:00
|
|
|
hasuform = set_uform(argv[1]);
|
2010-11-03 23:53:14 +01:00
|
|
|
break;
|
|
|
|
default : usage();
|
|
|
|
}
|
|
|
|
argc--; argv++;
|
|
|
|
}
|
|
|
|
if (hasuform == 0) usage();
|
|
|
|
tl_parse();
|
2010-11-29 15:34:21 +01:00
|
|
|
print_spin_buchi();
|
2010-11-03 23:53:14 +01:00
|
|
|
if (tl_stats) tl_endstats();
|
|
|
|
return tl_errs;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
2010-11-28 21:46:18 +01:00
|
|
|
{ ltl2ba_init();
|
|
|
|
tl_out = stdout;
|
|
|
|
atexit(cleanup);
|
2010-11-03 23:53:14 +01:00
|
|
|
while (argc > 1 && argv[1][0] == '-')
|
|
|
|
{ switch (argv[1][1]) {
|
|
|
|
case 'F': ltl_file = (char **) (argv+2);
|
|
|
|
argc--; argv++; break;
|
|
|
|
case 'f': add_ltl = (char **) argv;
|
|
|
|
argc--; argv++; break;
|
|
|
|
case 'a': tl_fjtofj = 0; break;
|
|
|
|
case 'c': tl_simp_scc = 0; break;
|
|
|
|
case 'o': tl_simp_fly = 0; break;
|
|
|
|
case 'p': tl_simp_diff = 0; break;
|
|
|
|
case 'l': tl_simp_log = 0; break;
|
|
|
|
case 'd': tl_verbose = 1; break;
|
|
|
|
case 's': tl_stats = 1; break;
|
|
|
|
default : usage(); break;
|
|
|
|
}
|
|
|
|
argc--, argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ltl_file && !add_ltl) usage();
|
|
|
|
|
|
|
|
if (ltl_file)
|
|
|
|
{ char formula[4096];
|
|
|
|
add_ltl = ltl_file-2; add_ltl[1][1] = 'f';
|
|
|
|
if (!(tl_out = fopen(*ltl_file, "r")))
|
|
|
|
{ printf("ltl2ba: cannot open %s\n", *ltl_file);
|
|
|
|
alldone(1);
|
|
|
|
}
|
|
|
|
fgets(formula, 4096, tl_out);
|
|
|
|
fclose(tl_out);
|
|
|
|
tl_out = stdout;
|
|
|
|
*ltl_file = (char *) formula;
|
|
|
|
}
|
|
|
|
if (argc > 1)
|
2010-11-28 21:46:18 +01:00
|
|
|
{ outfile = "_tmp2_";
|
|
|
|
tl_out = cpyfile(argv[1], outfile);
|
2010-11-03 23:53:14 +01:00
|
|
|
tl_main(2, add_ltl);
|
|
|
|
fclose(tl_out);
|
2010-11-28 21:46:18 +01:00
|
|
|
if (rename(outfile, argv[1]) != 0) {
|
|
|
|
perror("rename");
|
|
|
|
alldone(1);
|
|
|
|
}
|
|
|
|
outfile = NULL;
|
2010-11-03 23:53:14 +01:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (argc > 0)
|
|
|
|
exit(tl_main(2, add_ltl));
|
|
|
|
usage();
|
|
|
|
}
|
2010-11-28 21:46:18 +01:00
|
|
|
exit (EXIT_SUCCESS);
|
2010-11-03 23:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tl_endstats(void)
|
2010-11-28 21:46:18 +01:00
|
|
|
{ printf("\ntotal memory used: %9ld\n", All_Mem);
|
2010-11-03 23:53:14 +01:00
|
|
|
/*cache_stats();*/
|
|
|
|
a_stats();
|
|
|
|
}
|