safra.cc 4.14 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2015, 2016 Laboratoire de Recherche et Développement
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// de l'Epita (LRDE).
//
// 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 3 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 this program.  If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
21
#include <cstring>
22

23
24
25
26
27
28
29
#include "spot/tl/parse.hh" // spot::parse_infix_psl
#include "spot/tl/formula.hh" // spot::formula
#include "spot/parseaut/public.hh"
#include "spot/twa/twagraph.hh"
#include "spot/twaalgos/degen.hh"
#include "spot/twaalgos/dot.hh" // print_dot
#include "spot/twaalgos/hoa.hh" // print_hoa
30
#include "spot/twaalgos/determinize.hh"
31
#include "spot/twaalgos/translate.hh"
32
33


34
int help();
35
36
37
38
39
40
41
int help()
{
  std::cerr << "safra [OPTIONS]\n";
  std::cerr << "\t-f ltl_formula\tinput string is an ltl formulae\n";
  std::cerr << "\t--hoa file.hoa\tinput file has hoa format\n";
  std::cerr << "\t-p\tpretty print states\n";
  std::cerr << "\t-H\toutput hoa format\n";
42
  std::cerr << "\t-b\treduce result using bisimulation\n";
43
  std::cerr << "\t--scc_opt\tUse an SCC-based Safra\n";
44
45
46
  std::cerr << "\t--bisim_opt\tUse Simulation info to reduce macro-states "
               "size\n";
  std::cerr << "\t--stutter\tStutter-invarience optimisation\n";
47
48
49
  return 1;
}

50
51
int main(int argc, char* argv[])
{
52
  bool scc_opt = false;
53
  bool use_bisim = false;
54
  bool sim = false;
55
56
57
58
59
  bool in_hoa = false;
  bool in_ltl = false;
  bool out_dot = true;
  bool out_hoa = false;
  bool pretty_print = false;
60
  bool complete = false;
61
  bool use_stutter = false;
62
63

  char* input = nullptr;
64
  if (argc <= 2)
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    return help();
  for (int i = 1; i < argc; ++i)
    {
      if (!strncmp(argv[i], "--hoa", 5))
        {
          in_hoa = true;
          if (i + 1 >= argc)
            return help();
          input = argv[++i];
        }
      else if (!strncmp(argv[i], "-f", 2))
        {
          in_ltl = true;
          if (i + 1 >= argc)
            return help();
          input = argv[++i];
        }
      else if (!strncmp(argv[i], "-H", 2))
        {
          out_dot = false;
          out_hoa = true;
        }
      else if (!strncmp(argv[i], "-p", 2))
        pretty_print = true;
89
90
      else if (!strncmp(argv[i], "-b", 2))
        sim = true;
91
92
      else if (!strncmp(argv[i], "-c", 2))
        complete = true;
93
94
      else if (!strncmp(argv[i], "--scc_opt", 9))
        scc_opt = true;
95
96
      else if (!strncmp(argv[i], "--bisim_opt", 10))
        use_bisim = true;
97
98
      else if (!strncmp(argv[i], "--stutter", 9))
        use_stutter = true;
99
      else
100
101
102
103
        {
          std::cerr << "Warning: " << argv[i] << " not used\n";
          return 1;
        }
104
105
106
107
108
    }

  if (!input)
    help();

109
  auto dict = spot::make_bdd_dict();
110
  spot::twa_graph_ptr res;
111
  if (in_ltl)
112
    {
113
114
115
      spot::parse_error_list pel;
      spot::formula f = spot::parse_infix_psl(input, pel);
      if (spot::format_parse_errors(std::cerr, input, pel))
116
        return 2;
117
118
119
      spot::translator trans(dict);
      trans.set_pref(spot::postprocessor::Deterministic);
      auto tmp = trans.run(f);
120
      res = spot::tgba_determinisation(tmp, sim, pretty_print, scc_opt,
121
                                       use_bisim, complete, use_stutter);
122
    }
123
  else if (in_hoa)
124
    {
125
126
      auto aut = spot::parse_aut(input, dict);
      if (aut->format_errors(std::cerr))
127
        return 2;
128
      res = tgba_determinisation(aut->aut, sim, pretty_print, scc_opt,
129
                                 use_bisim, complete, use_stutter);
130
    }
131
  res->merge_edges();
132

133
  if (out_hoa)
134
    {
135
      spot::print_hoa(std::cout, res, "t");
136
137
      std::cout << std::endl;
    }
138
  else if (out_dot)
139
    spot::print_dot(std::cout, res);
140
141
  else
    assert(false);
142
}