Skip to content

Commit e0be53f

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 5f712a6 + 9418f9d commit e0be53f

File tree

11 files changed

+622
-261
lines changed

11 files changed

+622
-261
lines changed

config/llvm_header.inc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ define i1 @string_equal(ptr %str1, ptr %str2, i64 %len1, i64 %len2) {
193193
194194
declare tailcc ptr @k_step(ptr)
195195
declare tailcc void @step_all(ptr)
196-
declare void @serialize_configuration_to_proof_writer(ptr, ptr)
197-
declare void @write_uint64_to_proof_trace(ptr, i64)
196+
declare void @write_configuration_to_proof_trace(ptr, ptr)
198197
199198
@proof_output = external global i1
200199
@proof_writer = external global ptr
@@ -237,8 +236,7 @@ define ptr @take_steps(i64 %depth, ptr %subject) {
237236
br i1 %proof_output, label %if, label %merge
238237
if:
239238
%proof_writer = load ptr, ptr @proof_writer
240-
call void @write_uint64_to_proof_trace(ptr %proof_writer, i64 18446744073709551615)
241-
call void @serialize_configuration_to_proof_writer(ptr %proof_writer, ptr %subject)
239+
call void @write_configuration_to_proof_trace(ptr %proof_writer, ptr %subject)
242240
br label %merge
243241
merge:
244242
store i64 %depth, ptr @depth

include/kllvm/binary/serializer.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -141,46 +141,6 @@ void serializer::emit(T val) {
141141

142142
void emit_kore_rich_header(std::ostream &os, kore_definition *definition);
143143

144-
class proof_trace_writer {
145-
public:
146-
virtual ~proof_trace_writer() = default;
147-
virtual void write(void const *ptr, size_t len) = 0;
148-
149-
virtual void write_string(char const *str, size_t len) = 0;
150-
151-
// Note: This method will not write a 0 at the end of string.
152-
// The passed string should be 0 terminated.
153-
virtual void write_string(char const *str) = 0;
154-
155-
// Note: this method will write a 0 at the end of the string.
156-
// The passed string should be 0 terminated.
157-
void write_null_terminated_string(char const *str) {
158-
write_string(str);
159-
char n = 0;
160-
write(&n, 1);
161-
}
162-
163-
virtual void write_eof() = 0;
164-
165-
void write_bool(bool b) { write(&b, sizeof(bool)); }
166-
void write_uint32(uint32_t i) { write(&i, sizeof(uint32_t)); }
167-
void write_uint64(uint64_t i) { write(&i, sizeof(uint64_t)); }
168-
};
169-
170-
class proof_trace_file_writer : public proof_trace_writer {
171-
private:
172-
FILE *file_;
173-
174-
public:
175-
proof_trace_file_writer(FILE *file)
176-
: file_(file) { }
177-
178-
void write(void const *ptr, size_t len) override;
179-
void write_string(char const *str, size_t len) override;
180-
void write_string(char const *str) override;
181-
void write_eof() override { }
182-
};
183-
184144
} // namespace kllvm
185145

186146
#endif

include/kllvm/codegen/ProofEvent.h

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,103 @@ class proof_event {
4444
event_prelude(std::string const &label, llvm::BasicBlock *insert_at_end);
4545

4646
/*
47-
* Emit a call that will serialize `term` to the specified `proof_writer` as
48-
* binary KORE. This function can be called on any term, but the sort of that
49-
* term must be known.
47+
* Emit an instruction that has no effect and will be removed by optimization
48+
* passes.
49+
*
50+
* We need this workaround because some callsites will try to use
51+
* llvm::Instruction::insertAfter on the back of the MergeBlock after a proof
52+
* branch is created. If the MergeBlock has no instructions, this has resulted
53+
* in a segfault when printing the IR. Adding an effective no-op prevents this.
54+
*/
55+
llvm::BinaryOperator *emit_no_op(llvm::BasicBlock *insert_at_end);
56+
57+
/*
58+
* Emit instructions to get a pointer to the interpreter's proof_trace_writer;
59+
* the data structure that outputs proof trace data.
5060
*/
51-
llvm::CallInst *emit_serialize_term(
52-
kore_composite_sort &sort, llvm::Value *proof_writer, llvm::Value *term,
61+
llvm::LoadInst *emit_get_proof_trace_writer(llvm::BasicBlock *insert_at_end);
62+
63+
/*
64+
* Get the block header value for the given `sort_name`.
65+
*/
66+
uint64_t get_block_header(std::string const &sort_name);
67+
68+
/*
69+
* Emit a call to the `hook_event_pre` API of the specified `proof_writer`.
70+
*/
71+
llvm::CallInst *emit_write_hook_event_pre(
72+
llvm::Value *proof_writer, std::string const &name,
73+
std::string const &pattern, std::string const &location_stack,
5374
llvm::BasicBlock *insert_at_end);
5475

5576
/*
56-
* Emit a call that will serialize `value` to the specified `proof_writer`.
77+
* Emit a call to the `hook_event_post` API of the specified `proof_writer`.
5778
*/
58-
llvm::CallInst *emit_write_uint64(
59-
llvm::Value *proof_writer, uint64_t value,
79+
llvm::CallInst *emit_write_hook_event_post(
80+
llvm::Value *proof_writer, llvm::Value *val, kore_composite_sort &sort,
6081
llvm::BasicBlock *insert_at_end);
6182

6283
/*
63-
* Emit a call that will serialize a boolean value to the specified
64-
* `proof_writer`.
65-
*/
66-
llvm::CallInst *emit_write_bool(
67-
llvm::Value *proof_writer, llvm::Value *term,
84+
* Emit a call to the `argument` API of the specified `proof_writer`.
85+
*/
86+
llvm::CallInst *emit_write_argument(
87+
llvm::Value *proof_writer, llvm::Value *val, kore_composite_sort &sort,
6888
llvm::BasicBlock *insert_at_end);
6989

7090
/*
71-
* Emit a call that will serialize `str` to the specified `proof_writer`.
91+
* Emit a call to the `rewrite_event_pre` API of the specified `proof_writer`.
7292
*/
73-
llvm::CallInst *emit_write_string(
74-
llvm::Value *proof_writer, std::string const &str,
93+
llvm::CallInst *emit_write_rewrite_event_pre(
94+
llvm::Value *proof_writer, uint64_t ordinal, uint64_t arity,
7595
llvm::BasicBlock *insert_at_end);
7696

7797
/*
78-
* Emit an instruction that has no effect and will be removed by optimization
79-
* passes.
80-
*
81-
* We need this workaround because some callsites will try to use
82-
* llvm::Instruction::insertAfter on the back of the MergeBlock after a proof
83-
* branch is created. If the MergeBlock has no instructions, this has resulted
84-
* in a segfault when printing the IR. Adding an effective no-op prevents this.
98+
* Emit a call to the `variable` API of the specified `proof_writer`.
8599
*/
86-
llvm::BinaryOperator *emit_no_op(llvm::BasicBlock *insert_at_end);
100+
llvm::CallInst *emit_write_variable(
101+
llvm::Value *proof_writer, std::string const &name, llvm::Value *val,
102+
kore_composite_sort &sort, llvm::BasicBlock *insert_at_end);
87103

88104
/*
89-
* Emit instructions to get a pointer to the interpreter's proof_trace_writer;
90-
* the data structure that outputs proof trace data.
105+
* Emit a call to the `rewrite_event_post` API of the specified `proof_writer`.
91106
*/
92-
llvm::LoadInst *emit_get_proof_trace_writer(llvm::BasicBlock *insert_at_end);
107+
llvm::CallInst *emit_write_rewrite_event_post(
108+
llvm::Value *proof_writer, llvm::Value *val, kore_composite_sort &sort,
109+
llvm::BasicBlock *insert_at_end);
110+
111+
/*
112+
* Emit a call to the `function_event_pre` API of the specified `proof_writer`.
113+
*/
114+
llvm::CallInst *emit_write_function_event_pre(
115+
llvm::Value *proof_writer, std::string const &name,
116+
std::string const &location_stack, llvm::BasicBlock *insert_at_end);
117+
118+
/*
119+
* Emit a call to the `function_event_post` API of the specified `proof_writer`.
120+
*/
121+
llvm::CallInst *emit_write_function_event_post(
122+
llvm::Value *proof_writer, llvm::BasicBlock *insert_at_end);
123+
124+
/*
125+
* Emit a call to the `side_condition_event_pre` API of the specified `proof_writer`.
126+
*/
127+
llvm::CallInst *emit_write_side_condition_event_pre(
128+
llvm::Value *proof_writer, uint64_t ordinal, uint64_t arity,
129+
llvm::BasicBlock *insert_at_end);
130+
131+
/*
132+
* Emit a call to the `side_condition_event_post` API of the specified `proof_writer`.
133+
*/
134+
llvm::CallInst *emit_write_side_condition_event_post(
135+
llvm::Value *proof_writer, uint64_t ordinal, llvm::Value *val,
136+
llvm::BasicBlock *insert_at_end);
137+
138+
/*
139+
* Emit a call to the `patteern_matching_failure` API of the specified `proof_writer`.
140+
*/
141+
llvm::CallInst *emit_write_pattern_matching_failure(
142+
llvm::Value *proof_writer, std::string const &function_name,
143+
llvm::BasicBlock *insert_at_end);
93144

94145
public:
95146
[[nodiscard]] llvm::BasicBlock *hook_event_pre(

include/runtime/header.h

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <immer/map.hpp>
2323
#include <immer/set.hpp>
2424
#include <kllvm/ast/AST.h>
25-
#include <kllvm/binary/serializer.h>
2625
#include <runtime/collections/rangemap.h>
2726
#include <unordered_set>
2827

@@ -344,18 +343,38 @@ void serialize_term_to_file(
344343
bool k_item_inj = false);
345344
void serialize_raw_term_to_file(
346345
FILE *file, void *subject, char const *sort, bool use_intern);
346+
void serialize_configuration_to_proof_trace(
347+
FILE *file, block *subject, uint32_t sort);
348+
void serialize_term_to_proof_trace(
349+
FILE *file, void *subject, uint64_t block_header, bool indirect);
347350

348351
// The following functions are called by the generated code and runtime code to
349352
// ouput the proof trace data.
350-
void serialize_configuration_to_proof_trace(
351-
void *proof_writer, block *subject, uint32_t sort);
352-
void serialize_configuration_to_proof_writer(
353-
void *proof_writer, block *subject);
354-
void write_uint64_to_proof_trace(void *proof_writer, uint64_t i);
355-
void write_bool_to_proof_trace(void *proof_writer, bool b);
356-
void write_string_to_proof_trace(void *proof_writer, char const *str);
357-
void serialize_term_to_proof_trace(
358-
void *proof_writer, void *subject, uint64_t, bool);
353+
void write_hook_event_pre_to_proof_trace(
354+
void *proof_writer, char const *name, char const *pattern,
355+
char const *location_stack);
356+
void write_hook_event_post_to_proof_trace(
357+
void *proof_writer, void *hook_result, uint64_t block_header,
358+
bool indirect);
359+
void write_argument_to_proof_trace(
360+
void *proof_writer, void *arg, uint64_t block_header, bool indirect);
361+
void write_rewrite_event_pre_to_proof_trace(
362+
void *proof_writer, uint64_t ordinal, uint64_t arity);
363+
void write_variable_to_proof_trace(
364+
void *proof_writer, char const *name, void *var, uint64_t block_header,
365+
bool indirect);
366+
void write_rewrite_event_post_to_proof_trace(
367+
void *proof_writer, void *config, uint64_t block_header, bool indirect);
368+
void write_function_event_pre_to_proof_trace(
369+
void *proof_writer, char const *name, char const *location_stack);
370+
void write_function_event_post_to_proof_trace(void *proof_writer);
371+
void write_side_condition_event_pre_to_proof_trace(
372+
void *proof_writer, uint64_t ordinal, uint64_t arity);
373+
void write_side_condition_event_post_to_proof_trace(
374+
void *proof_writer, uint64_t ordinal, bool side_cond_result);
375+
void write_pattern_matching_failure_to_proof_trace(
376+
void *proof_writer, char const *function_name);
377+
void write_configuration_to_proof_trace(void *proof_writer, block *config);
359378

360379
// The following functions have to be generated at kompile time
361380
// and linked with the interpreter.
@@ -400,16 +419,16 @@ using visitor = struct {
400419
};
401420

402421
using serialize_to_proof_trace_visitor = struct {
403-
void (*visit_config)(void *, block *, uint32_t, bool);
404-
void (*visit_map)(void *, map *, uint32_t, uint32_t, uint32_t);
405-
void (*visit_list)(void *, list *, uint32_t, uint32_t, uint32_t);
406-
void (*visit_set)(void *, set *, uint32_t, uint32_t, uint32_t);
407-
void (*visit_int)(void *, mpz_t, uint32_t);
408-
void (*visit_float)(void *, floating *, uint32_t);
409-
void (*visit_bool)(void *, bool, uint32_t);
410-
void (*visit_string_buffer)(void *, stringbuffer *, uint32_t);
411-
void (*visit_m_int)(void *, size_t *, size_t, uint32_t);
412-
void (*visit_range_map)(void *, rangemap *, uint32_t, uint32_t, uint32_t);
422+
void (*visit_config)(FILE *, block *, uint32_t, bool);
423+
void (*visit_map)(FILE *, map *, uint32_t, uint32_t, uint32_t);
424+
void (*visit_list)(FILE *, list *, uint32_t, uint32_t, uint32_t);
425+
void (*visit_set)(FILE *, set *, uint32_t, uint32_t, uint32_t);
426+
void (*visit_int)(FILE *, mpz_t, uint32_t);
427+
void (*visit_float)(FILE *, floating *, uint32_t);
428+
void (*visit_bool)(FILE *, bool, uint32_t);
429+
void (*visit_string_buffer)(FILE *, stringbuffer *, uint32_t);
430+
void (*visit_m_int)(FILE *, size_t *, size_t, uint32_t);
431+
void (*visit_range_map)(FILE *, rangemap *, uint32_t, uint32_t, uint32_t);
413432
};
414433

415434
void print_map(
@@ -423,8 +442,7 @@ void print_list(
423442
void visit_children(
424443
block *subject, writer *file, visitor *printer, void *state);
425444
void visit_children_for_serialize_to_proof_trace(
426-
block *subject, void *proof_writer,
427-
serialize_to_proof_trace_visitor *printer);
445+
block *subject, FILE *file, serialize_to_proof_trace_visitor *printer);
428446

429447
stringbuffer *hook_BUFFER_empty(void);
430448
stringbuffer *hook_BUFFER_concat(stringbuffer *buf, string *s);

0 commit comments

Comments
 (0)