ltl2tgba.cc 3.07 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
11
12
13

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

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

35
  bool debug_opt = false;
36
  int output = 0;
37
  int formula_index = 0;
38

39
  for (;;)
40
    {
41
      if (argc < formula_index + 2)
42
	syntax(argv[0]);
43
44
45

      ++formula_index;

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

  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],
83
					   pel, env, debug_opt);
84
85
86
87

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

88
  spot::bdd_dict* dict = new spot::bdd_dict();
89
90
  if (f)
    {
91
      spot::tgba_bdd_concrete* a = spot::ltl_to_tgba(f, dict);
92
      spot::ltl::destroy(f);
93
94
95
96
97
98
      switch (output)
	{
	case 0:
	  spot::dotty_reachable(std::cout, a);
	  break;
	case 1:
99
100
	  spot::bdd_print_dot(std::cout, a->get_dict(),
			      a->get_core_data().relation);
101
102
	  break;
	case 2:
103
104
	  spot::bdd_print_dot(std::cout, a->get_dict(),
			      a->get_core_data().accepting_conditions);
105
106
	  break;
	case 3:
107
108
	  spot::bdd_print_set(std::cout, a->get_dict(),
			      a->get_core_data().relation);
109
110
	  break;
	case 4:
111
112
	  spot::bdd_print_set(std::cout, a->get_dict(),
			      a->get_core_data().accepting_conditions);
113
	  break;
114
	case 5:
115
	  a->get_dict()->dump(std::cout);
116
	  break;
117
118
119
	case 6:
	  spot::lbtt_reachable(std::cout, a);
	  break;
120
121
122
	default:
	  assert(!"unknown output option");
	}
123
      delete a;
124
125
126
127
128
129
130
131
132
133
    }
  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);
134
  delete dict;
135
136
  return exit_code;
}