ltl2tgba.cc 3.53 KB
Newer Older
1
2
3
4
5
#include <iostream>
#include <cassert>
#include "ltlvisit/destroy.hh"
#include "ltlast/allnodes.hh"
#include "ltlparse/public.hh"
6
#include "tgbaalgos/ltl2tgba.hh"
7
#include "tgba/bddprint.hh"
8
#include "tgbaalgos/dotty.hh"
9
#include "tgbaalgos/lbtt.hh"
10
#include "tgba/tgbatba.hh"
11
12
13
14

void
syntax(char* prog)
{
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
15
  std::cerr << "Usage: "<< prog << " [OPTIONS...] formula" << std::endl
Alexandre Duret-Lutz's avatar
spacing  
Alexandre Duret-Lutz committed
16
	    << std::endl
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
17
	    << "Options:" << std::endl
18
	    << "  -a   display the accepting_conditions BDD, not the reachability graph"
19
	    << std::endl
20
	    << "  -A   same as -a, but as a set" << std::endl
21
	    << "  -d   turn on traces during parsing" << std::endl
22
	    << "  -D   degeneralize the automaton" << std::endl
23
	    << "  -r   display the relation BDD, not the reachability graph"
24
	    << std::endl
25
	    << "  -R   same as -r, but as a set" << std::endl
26
	    << "  -t   display reachable states in LBTT's format" << std::endl
Alexandre Duret-Lutz's avatar
spacing  
Alexandre Duret-Lutz committed
27
	    << "  -v   display the BDD variables used by the automaton"
28
	    << std::endl;
29
30
31
32
33
34
35
36
  exit(2);
}

int
main(int argc, char** argv)
{
  int exit_code = 0;

37
  bool debug_opt = false;
38
  bool degeneralize_opt = false;
39
  int output = 0;
40
  int formula_index = 0;
41

42
  for (;;)
43
    {
44
      if (argc < formula_index + 2)
45
	syntax(argv[0]);
46
47
48

      ++formula_index;

49
50
51
52
53
54
55
56
57
      if (!strcmp(argv[formula_index], "-a"))
	{
	  output = 2;
	}
      else if (!strcmp(argv[formula_index], "-A"))
	{
	  output = 4;
	}
      else if (!strcmp(argv[formula_index], "-d"))
58
59
60
	{
	  debug_opt = true;
	}
61
62
63
64
      else if (!strcmp(argv[formula_index], "-D"))
	{
	  degeneralize_opt = true;
	}
65
66
      else if (!strcmp(argv[formula_index], "-r"))
	{
67
68
69
70
71
	  output = 1;
	}
      else if (!strcmp(argv[formula_index], "-R"))
	{
	  output = 3;
72
	}
73
74
75
76
      else if (!strcmp(argv[formula_index], "-t"))
	{
	  output = 6;
	}
77
78
79
80
      else if (!strcmp(argv[formula_index], "-v"))
	{
	  output = 5;
	}
81
82
83
84
      else
	{
	  break;
	}
85
86
87
88
89
    }

  spot::ltl::environment& env(spot::ltl::default_environment::instance());
  spot::ltl::parse_error_list pel;
  spot::ltl::formula* f = spot::ltl::parse(argv[formula_index],
90
					   pel, env, debug_opt);
91
92
93
94

  exit_code =
    spot::ltl::format_parse_errors(std::cerr, argv[formula_index], pel);

95
  spot::bdd_dict* dict = new spot::bdd_dict();
96
97
  if (f)
    {
98
99
      spot::tgba_bdd_concrete* concrete = spot::ltl_to_tgba(f, dict);
      spot::tgba* a = concrete;
100
      spot::ltl::destroy(f);
101
102
103
104
105

      spot::tgba* degeneralized = 0;
      if (degeneralize_opt)
	a = degeneralized = new spot::tgba_tba_proxy(a);

106
107
108
109
110
111
      switch (output)
	{
	case 0:
	  spot::dotty_reachable(std::cout, a);
	  break;
	case 1:
112
113
	  spot::bdd_print_dot(std::cout, concrete->get_dict(),
			      concrete->get_core_data().relation);
114
115
	  break;
	case 2:
116
117
	  spot::bdd_print_dot(std::cout, concrete->get_dict(),
			      concrete->get_core_data().accepting_conditions);
118
119
	  break;
	case 3:
120
121
	  spot::bdd_print_set(std::cout, concrete->get_dict(),
			      concrete->get_core_data().relation);
122
123
	  break;
	case 4:
124
125
	  spot::bdd_print_set(std::cout, concrete->get_dict(),
			      concrete->get_core_data().accepting_conditions);
126
	  break;
127
	case 5:
128
	  a->get_dict()->dump(std::cout);
129
	  break;
130
131
132
	case 6:
	  spot::lbtt_reachable(std::cout, a);
	  break;
133
134
135
	default:
	  assert(!"unknown output option");
	}
136
137
138
139
140

      if (degeneralize_opt)
	delete degeneralized;

      delete concrete;
141
142
143
144
145
146
147
148
149
150
    }
  else
    {
      exit_code = 1;
    }

  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);
151
  delete dict;
152
153
  return exit_code;
}