This repository was archived by the owner on Nov 12, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathvalue.cpp
More file actions
86 lines (74 loc) · 2.16 KB
/
Copy pathvalue.cpp
File metadata and controls
86 lines (74 loc) · 2.16 KB
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
#include "value.hpp"
#include "allocations.hpp"
#include "env.hpp"
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <map>
#include <sstream>
using boost::property_tree::ptree;
using boost::property_tree::read_json;
using boost::property_tree::write_json;
const Value::id_type Value::noid = reinterpret_cast<Value::id_type>(nullptr);
void Value::add_depends_on(id_type id) {
dependsOnIdx_.push_back(id);
ptree pt;
pt.put("dep.dst_id", Id());
pt.put("dep.src_id", id);
std::ofstream buf(env::output_path(), std::ofstream::app);
write_json(buf, pt, false);
buf.flush();
}
std::string Value::json() const {
ptree pt;
pt.put("val.id", Id());
pt.put("val.pos", pos_);
pt.put("val.size", size_);
pt.put("val.allocation_id", allocation_id_);
pt.put("val.initialized", is_initialized_);
std::stringstream buf;
write_json(buf, pt, false);
return buf.str();
}
void Value::record_meta_append(const std::string &s) {
ptree pt;
pt.put("meta.append", s);
pt.put("meta.val_id", Id());
std::ofstream buf(env::output_path(), std::ofstream::app);
write_json(buf, pt, false);
buf.flush();
}
void Value::record_meta_set(const std::string &s) {
ptree pt;
pt.put("meta.set", s);
pt.put("meta.val_id", Id());
std::ofstream buf(env::output_path(), std::ofstream::app);
write_json(buf, pt, false);
buf.flush();
}
/*
FIXME - not thread-safe, allications may be modified while calling this function
*/
AddressSpace Value::address_space() const {
return Allocations::instance().at(allocation_id_)->address_space();
}
void Value::set_size(size_t size) {
size_ = size;
std::ofstream buf(env::output_path(), std::ofstream::app);
buf << *this;
buf.flush();
}
// Value &Value::UnknownValue() {
// static Value unknown(0 /*pos*/, 0 /*size*/,
// Allocation::UnknownAllocation().Id());
// unknown.is_unknown_ = true;
// return unknown;
// }
// Value &Value::NoValue() {
// static Value v(0 /*pos*/, 0 /*size*/, Allocation::NoAllocation().Id());
// v.is_not_value_ = true;
// return v;
// }
std::ostream &operator<<(std::ostream &os, const Value &v) {
os << v.json();
return os;
}