Skip to content

Commit 6932a41

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 5f84f0c + 84d791a commit 6932a41

File tree

12 files changed

+316
-223
lines changed

12 files changed

+316
-223
lines changed

config/llvm_header.inc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ 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_file_v2(ptr, ptr)
197-
declare void @write_uint64_to_file(ptr, i64)
196+
declare void @serialize_configuration_to_proof_writer(ptr, ptr)
197+
declare void @write_uint64_to_proof_trace(ptr, i64)
198198
199199
@proof_output = external global i1
200-
@output_file = external global ptr
200+
@proof_writer = external global ptr
201201
@depth = thread_local global i64 zeroinitializer
202202
@steps = thread_local global i64 zeroinitializer
203203
@current_interval = thread_local global i64 0
@@ -236,9 +236,9 @@ define ptr @take_steps(i64 %depth, ptr %subject) {
236236
%proof_output = load i1, ptr @proof_output
237237
br i1 %proof_output, label %if, label %merge
238238
if:
239-
%output_file = load ptr, ptr @output_file
240-
call void @write_uint64_to_file(ptr %output_file, i64 18446744073709551615)
241-
call void @serialize_configuration_to_file_v2(ptr %output_file, ptr %subject)
239+
%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)
242242
br label %merge
243243
merge:
244244
store i64 %depth, ptr @depth

include/kllvm/binary/serializer.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,42 @@ 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+
void write_bool(bool b) { write(&b, sizeof(bool)); }
164+
void write_uint32(uint32_t i) { write(&i, sizeof(uint32_t)); }
165+
void write_uint64(uint64_t i) { write(&i, sizeof(uint64_t)); }
166+
};
167+
168+
class proof_trace_file_writer : public proof_trace_writer {
169+
private:
170+
FILE *file_;
171+
172+
public:
173+
proof_trace_file_writer(FILE *file)
174+
: file_(file) { }
175+
void write(void const *ptr, size_t len) override;
176+
void write_string(char const *str, size_t len) override;
177+
void write_string(char const *str) override;
178+
};
179+
144180
} // namespace kllvm
145181

146182
#endif

include/kllvm/codegen/ProofEvent.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,41 @@ class proof_event {
3737
* proof output and continuation, then loading the output filename from its
3838
* global.
3939
*
40-
* Returns a triple [proof enabled, merge, output_file]; see `proofBranch` and
41-
* `emitGetOutputFileName`.
40+
* Returns a triple [proof enabled, merge, proof_writer]; see `proofBranch`
41+
* and `emitGetOutputFileName`.
4242
*/
4343
std::tuple<llvm::BasicBlock *, llvm::BasicBlock *, llvm::Value *>
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 `outputFile` as
47+
* Emit a call that will serialize `term` to the specified `proof_writer` as
4848
* binary KORE. This function can be called on any term, but the sort of that
4949
* term must be known.
5050
*/
5151
llvm::CallInst *emit_serialize_term(
52-
kore_composite_sort &sort, llvm::Value *output_file, llvm::Value *term,
52+
kore_composite_sort &sort, llvm::Value *proof_writer, llvm::Value *term,
5353
llvm::BasicBlock *insert_at_end);
5454

5555
/*
56-
* Emit a call that will serialize `value` to the specified `outputFile`.
56+
* Emit a call that will serialize `value` to the specified `proof_writer`.
5757
*/
5858
llvm::CallInst *emit_write_uint64(
59-
llvm::Value *output_file, uint64_t value,
59+
llvm::Value *proof_writer, uint64_t value,
6060
llvm::BasicBlock *insert_at_end);
6161

6262
/*
63-
* Emit a call that will serialize a boolean value to the specified `output_file`.
63+
* Emit a call that will serialize a boolean value to the specified
64+
* `proof_writer`.
6465
*/
65-
llvm::CallInst *emit_bool_term(
66-
llvm::Value *output_file, llvm::Value *term,
66+
llvm::CallInst *emit_write_bool(
67+
llvm::Value *proof_writer, llvm::Value *term,
6768
llvm::BasicBlock *insert_at_end);
6869

6970
/*
70-
* Emit a call that will serialize `str` to the specified `outputFile`.
71+
* Emit a call that will serialize `str` to the specified `proof_writer`.
7172
*/
7273
llvm::CallInst *emit_write_string(
73-
llvm::Value *output_file, std::string const &str,
74+
llvm::Value *proof_writer, std::string const &str,
7475
llvm::BasicBlock *insert_at_end);
7576

7677
/*
@@ -85,10 +86,10 @@ class proof_event {
8586
llvm::BinaryOperator *emit_no_op(llvm::BasicBlock *insert_at_end);
8687

8788
/*
88-
* Emit instructions to load the path of the interpreter's current output
89-
* file; used here for binary proof trace data.
89+
* Emit instructions to get a pointer to the interpreter's proof_trace_writer;
90+
* the data structure that outputs proof trace data.
9091
*/
91-
llvm::LoadInst *emit_get_output_file_name(llvm::BasicBlock *insert_at_end);
92+
llvm::LoadInst *emit_get_proof_trace_writer(llvm::BasicBlock *insert_at_end);
9293

9394
public:
9495
[[nodiscard]] llvm::BasicBlock *hook_event_pre(

include/runtime/header.h

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

@@ -336,19 +337,25 @@ void serialize_configurations(
336337
void serialize_configuration(
337338
block *subject, char const *sort, char **data_out, size_t *size_out,
338339
bool emit_size, bool use_intern);
339-
void serialize_configuration_v2(FILE *file, block *subject, uint32_t sort);
340340
void serialize_configuration_to_file(
341341
FILE *file, block *subject, bool emit_size, bool use_intern);
342-
void serialize_configuration_to_file_v2(FILE *file, block *subject);
343-
void write_uint64_to_file(FILE *file, uint64_t i);
344-
void write_bool_to_file(FILE *file, bool b);
345342
void serialize_term_to_file(
346343
FILE *file, void *subject, char const *sort, bool use_intern,
347344
bool k_item_inj = false);
348-
void serialize_term_to_file_v2(FILE *file, void *subject, uint64_t, bool);
349345
void serialize_raw_term_to_file(
350346
FILE *file, void *subject, char const *sort, bool use_intern);
351-
void print_variable_to_file(FILE *file, char const *varname);
347+
348+
// The following functions are called by the generated code and runtime code to
349+
// 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);
352359

353360
// The following functions have to be generated at kompile time
354361
// and linked with the interpreter.
@@ -368,7 +375,8 @@ bool hook_STRING_eq(SortString, SortString);
368375
char const *get_symbol_name_for_tag(uint32_t tag);
369376
char const *get_return_sort_for_tag(uint32_t tag);
370377
char const **get_argument_sorts_for_tag(uint32_t tag);
371-
uint32_t *get_argument_sorts_for_tag_v2(uint32_t tag);
378+
uint32_t *
379+
get_argument_sorts_for_tag_with_proof_trace_serialization(uint32_t tag);
372380
char const *top_sort(void);
373381

374382
bool symbol_is_instantiation(uint32_t tag);
@@ -391,17 +399,17 @@ using visitor = struct {
391399
writer *, rangemap *, char const *, char const *, char const *, void *);
392400
};
393401

394-
using serialize_visitor = struct {
395-
void (*visit_config)(writer *, block *, uint32_t, bool);
396-
void (*visit_map)(writer *, map *, uint32_t, uint32_t, uint32_t);
397-
void (*visit_list)(writer *, list *, uint32_t, uint32_t, uint32_t);
398-
void (*visit_set)(writer *, set *, uint32_t, uint32_t, uint32_t);
399-
void (*visit_int)(writer *, mpz_t, uint32_t);
400-
void (*visit_float)(writer *, floating *, uint32_t);
401-
void (*visit_bool)(writer *, bool, uint32_t);
402-
void (*visit_string_buffer)(writer *, stringbuffer *, uint32_t);
403-
void (*visit_m_int)(writer *, size_t *, size_t, uint32_t);
404-
void (*visit_range_map)(writer *, rangemap *, uint32_t, uint32_t, uint32_t);
402+
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);
405413
};
406414

407415
void print_map(
@@ -414,8 +422,9 @@ void print_list(
414422
writer *, list *, char const *, char const *, char const *, void *);
415423
void visit_children(
416424
block *subject, writer *file, visitor *printer, void *state);
417-
void visit_children_for_serialize(
418-
block *subject, writer *file, serialize_visitor *printer);
425+
void visit_children_for_serialize_to_proof_trace(
426+
block *subject, void *proof_writer,
427+
serialize_to_proof_trace_visitor *printer);
419428

420429
stringbuffer *hook_BUFFER_empty(void);
421430
stringbuffer *hook_BUFFER_concat(stringbuffer *buf, string *s);

lib/binary/serializer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,16 @@ void emit_kore_rich_header(std::ostream &os, kore_definition *definition) {
210210
}
211211
}
212212

213+
void proof_trace_file_writer::write(void const *ptr, size_t len) {
214+
fwrite(ptr, len, 1, file_);
215+
}
216+
217+
void proof_trace_file_writer::write_string(char const *str, size_t len) {
218+
fwrite(str, 1, len, file_);
219+
}
220+
221+
void proof_trace_file_writer::write_string(char const *str) {
222+
fputs(str, file_);
223+
}
224+
213225
} // namespace kllvm

lib/codegen/EmitConfigParser.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) {
670670

671671
static llvm::StructType *make_packed_visitor_structure_type(
672672
llvm::LLVMContext &ctx, llvm::Module *module, bool is_serialize) {
673-
std::string const name = is_serialize ? "serialize_visitor" : "visitor";
673+
std::string const name
674+
= is_serialize ? "serialize_to_proof_trace_visitor" : "visitor";
674675
static auto types = std::map<llvm::LLVMContext *, llvm::StructType *>{};
675676

676677
auto *ptr_ty = llvm::PointerType::getUnqual(ctx);
@@ -1077,7 +1078,7 @@ static void get_visitor(
10771078
}
10781079

10791080
// NOLINTNEXTLINE(*-cognitive-complexity)
1080-
static void get_serialize_visitor(
1081+
static void get_serialize_to_proof_trace_visitor(
10811082
kore_definition *definition, llvm::Module *module, kore_symbol *symbol,
10821083
llvm::BasicBlock *case_block, std::vector<llvm::Value *> const &callbacks) {
10831084
get_visitor(definition, module, symbol, case_block, callbacks, false);
@@ -1179,11 +1180,11 @@ static void emit_visit_children(kore_definition *def, llvm::Module *mod) {
11791180
emit_traversal("visit_children", def, mod, true, false, get_visitor);
11801181
}
11811182

1182-
static void
1183-
emit_visit_children_for_serialize(kore_definition *def, llvm::Module *mod) {
1183+
static void emit_visit_children_for_serialize_to_proof_trace(
1184+
kore_definition *def, llvm::Module *mod) {
11841185
emit_traversal(
1185-
"visit_children_for_serialize", def, mod, true, true,
1186-
get_serialize_visitor);
1186+
"visit_children_for_serialize_to_proof_trace", def, mod, true, true,
1187+
get_serialize_to_proof_trace_visitor);
11871188
}
11881189

11891190
static void emit_inj_tags(kore_definition *def, llvm::Module *mod) {
@@ -1205,7 +1206,8 @@ static void emit_inj_tags(kore_definition *def, llvm::Module *mod) {
12051206
}
12061207
}
12071208

1208-
static void emit_sort_table_v2(kore_definition *def, llvm::Module *mod) {
1209+
static void emit_sort_table_for_proof_trace_serialization(
1210+
kore_definition *def, llvm::Module *mod) {
12091211
auto getter = [](kore_definition *definition, llvm::Module *module,
12101212
kore_symbol *symbol) -> llvm::Constant * {
12111213
auto &ctx = module->getContext();
@@ -1245,7 +1247,8 @@ static void emit_sort_table_v2(kore_definition *def, llvm::Module *mod) {
12451247
auto *debug_ty = get_pointer_debug_type(get_int_debug_type(), "int *");
12461248

12471249
emit_data_table_for_symbol(
1248-
"get_argument_sorts_for_tag_v2", entry_ty, debug_ty, def, mod, getter);
1250+
"get_argument_sorts_for_tag_with_proof_trace_serialization", entry_ty,
1251+
debug_ty, def, mod, getter);
12491252
}
12501253

12511254
static void emit_sort_table(kore_definition *def, llvm::Module *mod) {
@@ -1373,14 +1376,14 @@ void emit_config_parser_functions(
13731376

13741377
emit_get_symbol_name_for_tag(definition, module);
13751378
emit_visit_children(definition, module);
1376-
emit_visit_children_for_serialize(definition, module);
1379+
emit_visit_children_for_serialize_to_proof_trace(definition, module);
13771380

13781381
emit_layouts(definition, module);
13791382

13801383
emit_inj_tags(definition, module);
13811384

13821385
emit_sort_table(definition, module);
1383-
emit_sort_table_v2(definition, module);
1386+
emit_sort_table_for_proof_trace_serialization(definition, module);
13841387
emit_return_sort_table(definition, module);
13851388
emit_symbol_is_instantiation(definition, module);
13861389
}

0 commit comments

Comments
 (0)