about summary refs log tree commit diff homepage
path: root/tools/klee-ptree/main.cpp
blob: 96d2be7553611e7cfe5184cf7aa9c6a3c3f85cad (plain) (blame)
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
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include <cstdlib>
#include <filesystem>
#include <iostream>

#include "Printers.h"

namespace fs = std::filesystem;

void print_usage() {
  std::cout << "Usage: klee-ptree <option> /path[/ptree.db]\n\n"
               "Options:\n"
               "\tbranches     -  print branch statistics in csv format\n"
               "\tdepths       -  print depths statistics in csv format\n"
               "\tinstructions -  print asm line summary in csv format\n"
               "\tterminations -  print termination statistics in csv format\n"
               "\ttree-dot     -  print tree in dot format\n"
               "\ttree-info    -  print tree statistics"
               "\n";
}

int main(int argc, char *argv[]) {
  if (argc != 3) {
    print_usage();
    exit(EXIT_FAILURE);
  }

  // parse options
  void (*action)(const Tree &);
  std::string option(argv[1]);
  if (option == "branches") {
    action = printBranches;
  } else if (option == "instructions") {
    action = printInstructions;
  } else if (option == "depths") {
    action = printDepths;
  } else if (option == "terminations") {
    action = printTerminations;
  } else if (option == "tree-dot") {
    action = printDOT;
  } else if (option == "tree-info") {
    action = printTreeInfo;
  } else {
    print_usage();
    exit(EXIT_FAILURE);
  }

  // create tree
  fs::path path{argv[2]};
  if (fs::is_directory(path))
    path /= "ptree.db";
  if (!fs::exists(path)) {
    std::cerr << "Cannot open " << path << '\n';
    exit(EXIT_FAILURE);
  }
  Tree tree(path);

  // print results
  action(tree);
}