eltl2tgba.cc 4.1 KB
Newer Older
1
2
// Copyright (C) 2008, 2009 Laboratoire de Recherche et Developpement
// de l'Epita (LRDE)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//
// This file is part of Spot, a model checking library.
//
// Spot 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.
//
// Spot 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 Spot; see the file COPYING.  If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.

#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
26
#include "ltlparse/public.hh"
27
28
29
#include "eltlparse/public.hh"
#include "tgbaalgos/eltl2tgba_lacim.hh"
#include "tgbaalgos/dotty.hh"
30
#include "tgbaalgos/lbtt.hh"
31
#include "tgbaalgos/save.hh"
32
#include "ltlvisit/tostring.hh"
33
#include "ltlast/allnodes.hh"
34
35
36
37

void
syntax(char* prog)
{
38
39
40
41
  std::cerr << "Usage: " << prog << " [OPTIONS...]  formula [file]" << std::endl
	    << "       " << prog << " -F  [OPTIONS...] file [file]" << std::endl
	    << "       " << prog << " -L  [OPTIONS...] file [file]" << std::endl
	    << "       " << prog << " -LW [OPTIONS...] file [file]" << std::endl
42
43
44
	    << std::endl
	    << "Options:" << std::endl
	    << "  -F    read the formula from the file (extended input format)"
45
46
	    << std::endl
	    << "  -L    read the formula from an LBTT-compatible file"
47
48
49
	    << std::endl
	    << "  -LW   read the formula from an LBTT-compatible file"
	    << " (with no reduction)"
50
51
52
53
54
55
56
57
58
59
60
61
62
	    << std::endl;
}

std::string
ltl_defs()
{
  std::string s = "\
X=(0 1 true	   \
   1 2 $0	   \
   accept 2)	   \
U=(0 0 $0	   \
   0 1 $1	   \
   accept 1)	   \
63
64
65
G=(0 0 $0)	   \
F=U(true, $0)	   \
R=!U(!$0, !$1)";
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  return s;
}

int
main(int argc, char** argv)
{
  if (argc < 2)
  {
    syntax(argv[0]);
    return 1;
  }

  spot::eltl::parse_error_list p;
  spot::ltl::environment& env(spot::ltl::default_environment::instance());
  spot::ltl::formula* f = 0;
  int formula_index = 0;
82
  int reduce = 1;
83
84
85
86
87
88

  if (strcmp(argv[1], "-F") == 0)
  {
    f = spot::eltl::parse_file(argv[2], p, env, false);
    formula_index = 2;
  }
89
  if (strcmp(argv[1], "-L") == 0 || strcmp(argv[1], "-LW") == 0)
90
  {
91
    reduce = strcmp(argv[1], "-LW") == 0 ? 0 : 1;
92
93
94
95
96
97
98
99
100
    std::string input;
    std::ifstream ifs(argv[2]);
    std::getline(ifs, input, '\0');

    spot::ltl::parse_error_list p_;
    f = spot::ltl::parse(input, p_, env, false);
    input = ltl_defs();
    input += "%";
    input += spot::ltl::to_string(f, true);
101
    f->destroy();
102
103
104
105
106

    f = spot::eltl::parse_string(input, p, env, false);
    formula_index = 2;
  }
  if (formula_index == 0)
107
108
109
  {
    std::stringstream oss;
    oss << ltl_defs() << "%" << argv[1];
110
    f = spot::eltl::parse_string(oss.str(), p, env, false);
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    formula_index = 1;
  }

  if (spot::eltl::format_parse_errors(std::cerr, p))
  {
    if (f != 0)
      std::cout << f->dump() << std::endl;
    return 1;
  }

  assert(f != 0);
  std::cerr << f->dump() << std::endl;

  spot::bdd_dict* dict = new spot::bdd_dict();
  spot::tgba_bdd_concrete* concrete = spot::eltl_to_tgba_lacim(f, dict);
126
127
  if (reduce == 1)
    concrete->delete_unaccepting_scc();
128

129
  if (strcmp(argv[1], "-L") == 0 || strcmp(argv[1], "-LW") == 0)
130
131
    spot::lbtt_reachable(std::cout, concrete);
  else
132
  {
133
134
135
136
137
138
139
    spot::dotty_reachable(std::cout, concrete);
    if (formula_index + 1 < argc)
    {
      std::ofstream ofs(argv[formula_index + 1]);
      spot::tgba_save_reachable(ofs, concrete);
      ofs.close();
    }
140
141
  }

142
  f->destroy();
143
  delete concrete;
144
145
146
147
148
149

  assert(spot::ltl::atomic_prop::instance_count() == 0);
  assert(spot::ltl::unop::instance_count() == 0);
  assert(spot::ltl::binop::instance_count() == 0);
  assert(spot::ltl::multop::instance_count() == 0);
  assert(spot::ltl::automatop::instance_count() == 0);
150
151
  delete dict;
}