-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibdmccapi.cpp
More file actions
162 lines (147 loc) · 8.21 KB
/
libdmccapi.cpp
File metadata and controls
162 lines (147 loc) · 8.21 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* DMC - DMC Model Checker is a modular, multi-core model checker
* Copyright © 2021 Freark van der Berg
*
* This file is part of DMC.
*
* DMC is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* DMC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DMC. If not, see <https://www.gnu.org/licenses/>.
*/
#include <dmc/modelcheckers/interface.h>
#include <dmc/dmcapi.h>
extern "C" StateID dmc_insert(void* ctx_, StateSlot* data, uint32_t length, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
llmc::storage::StorageInterface::StateID r;
// printf("dmc_insert(%p, %p, %u, %u)\n", ctx_, data, length, isRoot); fflush(stdout);
if(isRoot) {
r = ctx->mc->newState(ctx, 0, length, (llmc::storage::StorageInterface::StateSlot*) data).getState();
// r = ctx->mc->newTransition(ctx, stateID, (llmc::storage::StorageInterface::StateSlot*) data, length, TransitionInfoUnExpanded::None());
} else {
r = ctx->mc->newSubState(ctx, length, data);
}
assert(r.getData() && "0 is not a valid chunk ID");
return r.getData();
}
extern "C" StateID dmc_insertB(void* ctx_, StateSlot* data, uint32_t lengthInBytes, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
llmc::storage::StorageInterface::StateID r;
// printf("dmc_insertB(%p, %p, %u, %u)\n", ctx_, data, length, isRoot); fflush(stdout);
size_t len_remainder = (lengthInBytes & (sizeof(llmc::storage::StorageInterface::StateSlot) - 1));
size_t length = lengthInBytes / sizeof(llmc::storage::StorageInterface::StateSlot);
if(len_remainder == 0) {
if(isRoot) {
r = ctx->mc->newState(ctx, 0, length, (llmc::storage::StorageInterface::StateSlot*) data).getState();
} else {
r = ctx->mc->newSubState(ctx, length, data);
}
} else {
StateSlot tempSlots[length+1];
tempSlots[length] = 0;
memcpy(tempSlots, data, lengthInBytes);
if(isRoot) {
r = ctx->mc->newState(ctx, 0, length, tempSlots).getState();
} else {
r = ctx->mc->newSubState(ctx, length, tempSlots);
}
}
assert(r.getData() && "0 is not a valid chunk ID");
return r.getData();
}
extern "C" StateID dmc_transition(void* ctx_, StateID stateID, StateSlot* data, uint32_t length, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
llmc::storage::StorageInterface::StateID r;
// printf("dmc_transition(%p, %zu, %p, %u, %u)\n", ctx_, stateID, data, length, isRoot); fflush(stdout);
if(isRoot) {
r = ctx->mc->newTransition(ctx, stateID, (llmc::storage::StorageInterface::StateSlot*) data, length, TransitionInfoUnExpanded::None());
} else {
r = ctx->mc->newSubState(ctx, length, data);
}
assert(r.getData() && "0 is not a valid chunk ID");
return r.getData();
}
extern "C" StateID dmc_delta(void* ctx_, StateID stateID, uint32_t offset, StateSlot* data, uint32_t length, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
llmc::storage::StorageInterface::StateID r;
// printf("dmc_delta(%p, %zx, %u, %p, %u, %u)\n", ctx_, stateID, offset, data, length, isRoot); fflush(stdout);
if(isRoot) {
r = ctx->mc->newTransition(ctx, offset, length, (llmc::storage::StorageInterface::StateSlot*) data, TransitionInfoUnExpanded::None());
} else {
r = ctx->mc->newSubState(ctx, stateID, offset, length, (llmc::storage::StorageInterface::StateSlot*) data);
}
assert(r.getData() && "0 is not a valid chunk ID");
return r.getData();
}
extern "C" StateID dmc_deltaB(void* ctx_, StateID stateID, uint32_t offsetInBytes, StateSlot* data, uint32_t lengthInBytes, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
llmc::storage::StorageInterface::StateID r;
// printf("dmc_deltaB(%p, %zx, %u, %p, %u, %u)\n", ctx_, stateID, offset, data, length, isRoot); fflush(stdout);
size_t offset_remainder = (offsetInBytes & (sizeof(llmc::storage::StorageInterface::StateSlot) - 1));
size_t len_remainder = (lengthInBytes & (sizeof(llmc::storage::StorageInterface::StateSlot) - 1));
size_t offset = offsetInBytes / sizeof(llmc::storage::StorageInterface::StateSlot);
if(offset_remainder == 0 && len_remainder == 0) {
size_t length = lengthInBytes / sizeof(llmc::storage::StorageInterface::StateSlot);
if(isRoot) {
r = ctx->mc->newTransition( ctx
, offset
, length
, (llmc::storage::StorageInterface::StateSlot*) data
, TransitionInfoUnExpanded::None()
);
} else {
r = ctx->mc->newSubState( ctx
, stateID
, offset
, length
, (llmc::storage::StorageInterface::StateSlot*) data
);
}
} else {
size_t nrSlots = (offset_remainder + lengthInBytes + (sizeof(llmc::storage::StorageInterface::StateSlot) - 1)) / (sizeof(llmc::storage::StorageInterface::StateSlot));
StateSlot tempSlots[nrSlots];
ctx->mc->getStatePartial(ctx, stateID, offset, tempSlots, nrSlots, isRoot);
memcpy(((char*)tempSlots) + offset_remainder, data, lengthInBytes);
if(isRoot) {
r = ctx->mc->newTransition(ctx, offset, nrSlots, tempSlots, TransitionInfoUnExpanded::None());
} else {
r = ctx->mc->newSubState(ctx, stateID, offset, nrSlots, tempSlots);
}
}
assert(r.getData() && "0 is not a valid chunk ID");
return r.getData();
}
extern "C" uint64_t dmc_get(void* ctx_, StateID stateID, StateSlot* data, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
// printf("dmc_get(%p, %zx, %p, %u)\n", ctx_, stateID, data, isRoot); fflush(stdout);
return ctx->mc->getState(ctx, stateID, data, isRoot);
}
extern "C" uint64_t dmc_getpart(void* ctx_, StateID stateID, uint32_t offset, StateSlot* data, uint32_t length, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
// printf("dmc_getpart(%p, %zx, %u, %p, %u, %u)\n", ctx_, stateID, offset, data, length, isRoot); fflush(stdout);
return ctx->mc->getStatePartial(ctx, stateID, offset, data, length, isRoot);
}
extern "C" uint64_t dmc_getpartB(void* ctx_, StateID stateID, uint32_t offsetInBytes, StateSlot* data, uint32_t lengthInBytes, uint32_t isRoot) {
auto ctx = reinterpret_cast<VContext<llmc::storage::StorageInterface>*>(ctx_);
// printf("dmc_getpart(%p, %zx, %u, %p, %u, %u)\n", ctx_, stateID, offset, data, length, isRoot); fflush(stdout);
size_t offset_remainder = (offsetInBytes & (sizeof(llmc::storage::StorageInterface::StateSlot) - 1));
size_t len_remainder = (lengthInBytes & (sizeof(llmc::storage::StorageInterface::StateSlot) - 1));
size_t offset = offsetInBytes / sizeof(llmc::storage::StorageInterface::StateSlot);
if(offset_remainder == 0 && len_remainder == 0) {
size_t length = lengthInBytes / sizeof(llmc::storage::StorageInterface::StateSlot);
return ctx->mc->getStatePartial(ctx, stateID, offset, data, length, isRoot);
} else {
size_t nrSlots = (offset_remainder + lengthInBytes + (sizeof(llmc::storage::StorageInterface::StateSlot) - 1)) / (sizeof(llmc::storage::StorageInterface::StateSlot));
StateSlot tempSlots[nrSlots];
auto r = ctx->mc->getStatePartial(ctx, stateID, offset, tempSlots, nrSlots, isRoot);
memcpy(data, ((char*)tempSlots) + offset_remainder, lengthInBytes);
return r;
}
}