Skip to content

Commit eaf43b8

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 04b0ba0 + 9d21e4d commit eaf43b8

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed

include/runtime/proof_trace_writer.h

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,195 @@ class proof_trace_file_writer : public proof_trace_writer {
145145
void end_of_trace() override { }
146146
};
147147

148+
class proof_trace_callback_writer : public proof_trace_writer {
149+
private:
150+
struct kore_term_construction {
151+
void *subject;
152+
uint64_t block_header;
153+
bool indirect;
154+
155+
kore_term_construction()
156+
: subject(nullptr)
157+
, block_header(0)
158+
, indirect(false) { }
159+
160+
kore_term_construction(void *subject, uint64_t block_header, bool indirect)
161+
: subject(subject)
162+
, block_header(block_header)
163+
, indirect(indirect) { }
164+
};
165+
166+
struct kore_configuration_construction {
167+
void *subject;
168+
169+
kore_configuration_construction(void *subject)
170+
: subject(subject) { }
171+
};
172+
173+
struct pattern_matching_failure_construction {
174+
char const *function_name;
175+
176+
pattern_matching_failure_construction(char const *function_name)
177+
: function_name(function_name) { }
178+
};
179+
180+
struct side_condition_result_construction {
181+
uint64_t ordinal;
182+
bool result;
183+
184+
side_condition_result_construction(uint64_t ordinal, bool result)
185+
: ordinal(ordinal)
186+
, result(result) { }
187+
};
188+
189+
struct call_event_construction {
190+
char const *hook_name;
191+
char const *symbol_name;
192+
char const *location;
193+
std::vector<kore_term_construction> arguments;
194+
std::optional<kore_term_construction> result;
195+
196+
call_event_construction(
197+
char const *hook_name, char const *symbol_name, char const *location)
198+
: hook_name(hook_name)
199+
, symbol_name(symbol_name)
200+
, location(location) { }
201+
202+
call_event_construction(char const *symbol_name, char const *location)
203+
: hook_name(nullptr)
204+
, symbol_name(symbol_name)
205+
, location(location) { }
206+
};
207+
208+
struct rewrite_event_construction {
209+
using subst_t
210+
= std::vector<std::pair<char const *, kore_term_construction>>;
211+
212+
uint64_t ordinal;
213+
uint64_t arity;
214+
size_t pos;
215+
subst_t substitution;
216+
217+
rewrite_event_construction(uint64_t ordinal, uint64_t arity)
218+
: ordinal(ordinal)
219+
, arity(arity)
220+
, pos(0) {
221+
substitution.resize(arity);
222+
}
223+
};
224+
225+
std::optional<call_event_construction> current_call_event_;
226+
227+
std::optional<rewrite_event_construction> current_rewrite_event_{
228+
std::nullopt};
229+
230+
[[clang::optnone]] void proof_trace_header_callback(uint32_t version) { }
231+
[[clang::optnone]] void
232+
hook_event_callback(call_event_construction const &event) { }
233+
[[clang::optnone]] void
234+
rewrite_event_callback(rewrite_event_construction const &event) { }
235+
[[clang::optnone]] void
236+
configuration_term_event_callback(kore_term_construction const &config) { }
237+
[[clang::optnone]] void
238+
function_event_callback(call_event_construction const &event) { }
239+
[[clang::optnone]] void
240+
side_condition_event_callback(rewrite_event_construction const &event) { }
241+
[[clang::optnone]] void side_condition_result_callback(
242+
side_condition_result_construction const &event) { }
243+
[[clang::optnone]] void pattern_matching_failure_callback(
244+
pattern_matching_failure_construction const &event) { }
245+
[[clang::optnone]] void
246+
configuration_event_callback(kore_configuration_construction const &config) {
247+
}
248+
249+
public:
250+
proof_trace_callback_writer() { }
251+
252+
void proof_trace_header(uint32_t version) override {
253+
proof_trace_header_callback(version);
254+
}
255+
256+
void hook_event_pre(
257+
char const *name, char const *pattern,
258+
char const *location_stack) override {
259+
current_call_event_.reset();
260+
current_call_event_.emplace(name, pattern, location_stack);
261+
}
262+
263+
void hook_event_post(
264+
void *hook_result, uint64_t block_header, bool indirect) override {
265+
current_call_event_->result.emplace(hook_result, block_header, indirect);
266+
hook_event_callback(current_call_event_.value());
267+
}
268+
269+
void argument(void *arg, uint64_t block_header, bool indirect) override {
270+
current_call_event_->arguments.emplace_back(arg, block_header, indirect);
271+
}
272+
273+
void rewrite_event_pre(uint64_t ordinal, uint64_t arity) override {
274+
current_rewrite_event_.reset();
275+
current_rewrite_event_.emplace(ordinal, arity);
276+
if (arity == 0) {
277+
rewrite_event_callback(current_rewrite_event_.value());
278+
}
279+
}
280+
281+
void variable(
282+
char const *name, void *var, uint64_t block_header,
283+
bool indirect) override {
284+
auto &p = current_rewrite_event_->substitution[current_rewrite_event_->pos];
285+
p.first = name;
286+
p.second.subject = var;
287+
p.second.block_header = block_header;
288+
p.second.indirect = indirect;
289+
size_t new_pos = ++current_rewrite_event_->pos;
290+
if (new_pos == current_rewrite_event_->arity) {
291+
rewrite_event_callback(current_rewrite_event_.value());
292+
}
293+
}
294+
295+
void rewrite_event_post(
296+
void *config, uint64_t block_header, bool indirect) override {
297+
kore_term_construction configuration(config, block_header, indirect);
298+
configuration_term_event_callback(configuration);
299+
}
300+
301+
void
302+
function_event_pre(char const *name, char const *location_stack) override {
303+
current_call_event_.reset();
304+
current_call_event_.emplace(name, location_stack);
305+
}
306+
307+
void function_event_post() override {
308+
function_event_callback(current_call_event_.value());
309+
}
310+
311+
void side_condition_event_pre(uint64_t ordinal, uint64_t arity) override {
312+
current_rewrite_event_.reset();
313+
current_rewrite_event_.emplace(ordinal, arity);
314+
if (arity == 0) {
315+
side_condition_event_callback(current_rewrite_event_.value());
316+
}
317+
}
318+
319+
void
320+
side_condition_event_post(uint64_t ordinal, bool side_cond_result) override {
321+
side_condition_result_construction side_condition_result(
322+
ordinal, side_cond_result);
323+
side_condition_result_callback(side_condition_result);
324+
}
325+
326+
void pattern_matching_failure(char const *function_name) override {
327+
pattern_matching_failure_construction pm_failure(function_name);
328+
pattern_matching_failure_callback(pm_failure);
329+
}
330+
331+
void configuration(block *config) override {
332+
kore_configuration_construction configuration(config);
333+
configuration_event_callback(configuration);
334+
}
335+
336+
void end_of_trace() override { }
337+
};
338+
148339
#endif // RUNTIME_PROOF_TRACE_WRITER_H

0 commit comments

Comments
 (0)