10#define DEBUG_TYPE "TreeStreamWriter"
13#include "klee/Support/Debug.h"
21#include "llvm/Support/raw_ostream.h"
28TreeStreamWriter::TreeStreamWriter(
const std::string &_path)
32 output(new std::ofstream(path.c_str(),
33 std::ios::out | std::ios::binary)),
58 output->write(
reinterpret_cast<const char*
>(&os.
id), 4);
59 unsigned tag =
id | (1<<31);
60 output->write(
reinterpret_cast<const char*
>(&tag), 4);
76 output->write(
reinterpret_cast<const char*
>(&os.
id), 4);
77 output->write(
reinterpret_cast<const char*
>(&size), 4);
84 output->write(
reinterpret_cast<const char*
>(&
lastID), 4);
97 std::vector<unsigned char> &out) {
98 assert(streamID>0 && streamID<
ids);
101 std::ifstream is(
path.c_str(),
102 std::ios::in | std::ios::binary);
104 KLEE_DEBUG(llvm::errs() <<
"finding chain for: " << streamID <<
"\n");
106 std::map<unsigned,unsigned> parents;
107 std::vector<unsigned> roots;
112 is.read(
reinterpret_cast<char*
>(&
id), 4);
113 is.read(
reinterpret_cast<char*
>(&tag), 4);
115 unsigned child = tag ^ (1<<31);
117 if (child==streamID) {
118 roots.push_back(child);
121 std::map<unsigned, unsigned>::iterator it = parents.find(
id);
122 assert(it!=parents.end());
127 parents.insert(std::make_pair(child,
id));
131 while (size--) is.get();
135 llvm::errs() <<
"roots: ";
136 for (
size_t i = 0, e = roots.size(); i < e; ++i) {
137 llvm::errs() << roots[i] <<
" ";
139 llvm::errs() <<
"\n";
141 is.seekg(0, std::ios::beg);
145 is.read(
reinterpret_cast<char*
>(&
id), 4);
146 is.read(
reinterpret_cast<char*
>(&tag), 4);
147 if (!is.good())
break;
149 unsigned child = tag ^ (1<<31);
150 if (
id==roots.back() && roots.size()>1 && child==roots[roots.size()-2])
154 if (
id==roots.back()) {
155 while (size--) out.push_back(is.get());
157 while (size--) is.get();
190 write(s.c_str(), s.size());
TreeStreamWriter * writer
void write(const char *buffer, unsigned size)
TreeOStream & operator<<(const std::string &s)
void write(TreeOStream &os, const char *s, unsigned size)
void readStream(TreeStreamID id, std::vector< unsigned char > &out)
static const unsigned bufferSize