summaryrefslogtreecommitdiff
path: root/proofs/lfsc_checker/main.cpp
blob: 1d8ba58095dac75fa4b0b96e2d7ea0724d09319c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "expr.h"
#include "check.h"
#include <signal.h>
#include "sccwriter.h"
#include "libwriter.h"
#include <time.h>

using namespace std;

args a;

static void parse_args(int argc, char **argv, args &a)
{
  char *arg0 = *argv;

  /* skip 0'th argument */
  argv++;
  argc--;

  while (argc) {

    if ((strncmp("-h", *argv, 2) == 0) || 
	(strncmp("--h", *argv, 3) == 0)) {
      cout << "Usage: " << arg0 << " [options] infile1 ...infile_n\n";
      cout << "If no infiles are named on the command line, input is read\n"
	   << "from stdin.  Specifying the infile \"stdin\" will also read\n"
	   << "from stdin.  Options are:\n\n";
      cout << "--show-runs: print debugging information for runs of side condition code\n"; 
      cout << "--compile-scc: compile side condition code\n"; 
      cout << "--compile-scc-debug: compile debug versions of side condition code\n"; 
      cout << "--run-scc: use compiled side condition code\n"; 
      exit(0);
    }	  
    else if(strcmp("--show-runs", *argv) == 0) {
      argc--; argv++;
      a.show_runs = true;
    }
    else if(strcmp("--no-tail-calls", *argv) == 0) {
      // this is just for debugging.
      argc--; argv++;
      a.no_tail_calls = true;
    }
    else if( strcmp("--compile-scc", *argv) == 0 ){
      argc--; argv++;
      a.compile_scc = true;
      a.compile_scc_debug = false;
    }
    else if( strcmp("--compile-scc-debug", *argv) == 0 )
    {
       argc--; argv++;
       a.compile_scc = true;
       a.compile_scc_debug = true;
    }
    else if( strcmp("--compile-lib", *argv) == 0 )
    {
       argc--; argv++;
       a.compile_lib = true;
    }
    else if( strcmp("--run-scc", *argv) == 0 ){
      argc--; argv++;
      a.run_scc = true;
    }
    else if( strcmp("--use-nested-app", *argv) == 0 ){
      argc--; argv++;
      a.use_nested_app = true;    //not implemented yet
    }else {
      a.files.push_back(*argv);
      argc--; argv++;
    }
  }
}

void sighandler(int /* signum */) {
  cerr << "\nInterrupted.  sc is aborting.\n";
  exit(1);
}

int main(int argc, char **argv) {

  a.show_runs = false;
  a.no_tail_calls = false;
  a.compile_scc = false;
  a.run_scc = false;
  a.use_nested_app = false;

  signal(SIGINT, sighandler);

  parse_args(argc, argv, a);

  init();

  check_time = (int)clock();

  if (a.files.size()) {
    sccwriter* scw = NULL;
    libwriter* lw = NULL;
    if( a.compile_scc ){
       scw = new sccwriter( a.compile_scc_debug ? opt_write_call_debug : 0 );
    }
    if( a.compile_lib ){
       lw = new libwriter;
    }
    /* process the files named */
    int i = 0, iend = a.files.size();
    for (; i < iend; i++) {
      const char *filename = a.files[i].c_str();
      check_file(filename, a, scw, lw);
    }
    if( scw ){
      scw->write_file();
      delete scw;
    }
    if( lw ){
#ifdef DEBUG_SYM_NAMES
      lw->write_file();
      delete lw;
#else
      std::cout << "ERROR libwriter: Must compile LFSC with DEBUG_SYM_NAMES flag (see Expr.h)" << std::endl;
#endif
    }
  }
  else 
    check_file("stdin", a);

  //std::cout << "time = " << (int)clock() - t << std::endl;
  //while(1){}

#ifdef DEBUG
  cout << "Clearing globals.\n";
  cout.flush(); 

  cleanup();
  a.files.clear();
#endif

  std::cout << "Proof checked successfully!" << std::endl << std::endl;
  std::cout << "time = " << (int)clock() - check_time << std::endl;
  std::cout << "sym count = " << SymExpr::symmCount << std::endl;
  std::cout << "marked count = " << Expr::markedCount << std::endl;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback