about summary refs log tree commit diff homepage
path: root/lib/Core/ExecutionTreeWriter.h
blob: d78ad0b1f2a853e50b800e7a64b2d436147bfb30 (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
//===-- ExecutionTreeWriter.h -----------------------------------*- C++ -*-===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#pragma once

#include <sqlite3.h>

#include <cstdint>
#include <string>

namespace klee {
class AnnotatedExecutionTreeNode;

/// @brief Writes execution tree nodes into an SQLite database
class ExecutionTreeWriter {
  friend class PersistentExecutionTree;

  ::sqlite3 *db{nullptr};
  ::sqlite3_stmt *insertStmt{nullptr};
  ::sqlite3_stmt *transactionBeginStmt{nullptr};
  ::sqlite3_stmt *transactionCommitStmt{nullptr};
  std::uint32_t batch{0};
  bool flushed{true};

  /// Writes nodes in batches
  void batchCommit(bool force = false);

public:
  explicit ExecutionTreeWriter(const std::string &dbPath);
  ~ExecutionTreeWriter();
  ExecutionTreeWriter(const ExecutionTreeWriter &other) = delete;
  ExecutionTreeWriter(ExecutionTreeWriter &&other) noexcept = delete;
  ExecutionTreeWriter &operator=(const ExecutionTreeWriter &other) = delete;
  ExecutionTreeWriter &operator=(ExecutionTreeWriter &&other) noexcept = delete;

  /// Write new node into database
  void write(const AnnotatedExecutionTreeNode &node);
};

} // namespace klee