Skip to content

Commit 2b9c79f

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 9b362e5 + db7ebd0 commit 2b9c79f

File tree

20 files changed

+9218
-70
lines changed

20 files changed

+9218
-70
lines changed

include/kllvm/codegen/ProofEvent.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class proof_event {
8383
*/
8484
llvm::LoadInst *emit_get_proof_chunk_size(llvm::BasicBlock *insert_at_end);
8585

86+
/*
87+
* Check if a value of the given `sort` corresponds to an llvm scalar and
88+
* return the size in bits of that scalar. Returns 0 if the given `sort` does
89+
* not correspond to an llvm scalar.
90+
*/
91+
uint64_t get_llvm_scalar_bits(kore_composite_sort &sort);
92+
8693
/*
8794
* Get the block header value for the given `sort_name`.
8895
*/

include/runtime/header.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void serialize_raw_term_to_file(
346346
void serialize_configuration_to_proof_trace(
347347
FILE *file, block *subject, uint32_t sort);
348348
void serialize_term_to_proof_trace(
349-
FILE *file, void *subject, uint64_t block_header, bool indirect);
349+
FILE *file, void *subject, uint64_t block_header, uint64_t bits);
350350

351351
// The following functions are called by the generated code and runtime code to
352352
// ouput the proof trace data.
@@ -355,16 +355,16 @@ void write_hook_event_pre_to_proof_trace(
355355
char const *location_stack);
356356
void write_hook_event_post_to_proof_trace(
357357
void *proof_writer, void *hook_result, uint64_t block_header,
358-
bool indirect);
358+
uint64_t bits);
359359
void write_argument_to_proof_trace(
360-
void *proof_writer, void *arg, uint64_t block_header, bool indirect);
360+
void *proof_writer, void *arg, uint64_t block_header, uint64_t bits);
361361
void write_rewrite_event_pre_to_proof_trace(
362362
void *proof_writer, uint64_t ordinal, uint64_t arity);
363363
void write_variable_to_proof_trace(
364364
void *proof_writer, char const *name, void *var, uint64_t block_header,
365-
bool indirect);
365+
uint64_t bits);
366366
void write_rewrite_event_post_to_proof_trace(
367-
void *proof_writer, void *config, uint64_t block_header, bool indirect);
367+
void *proof_writer, void *config, uint64_t block_header, uint64_t bits);
368368
void write_function_event_pre_to_proof_trace(
369369
void *proof_writer, char const *name, char const *location_stack);
370370
void write_function_event_post_to_proof_trace(void *proof_writer);

include/runtime/proof_trace_writer.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class proof_trace_writer {
1515
char const *name, char const *pattern, char const *location_stack)
1616
= 0;
1717
virtual void
18-
hook_event_post(void *hook_result, uint64_t block_header, bool indirect)
18+
hook_event_post(void *hook_result, uint64_t block_header, uint64_t bits)
1919
= 0;
20-
virtual void argument(void *arg, uint64_t block_header, bool indirect) = 0;
20+
virtual void argument(void *arg, uint64_t block_header, uint64_t bits) = 0;
2121
virtual void rewrite_event_pre(uint64_t ordinal, uint64_t arity) = 0;
2222
virtual void
23-
variable(char const *name, void *var, uint64_t block_header, bool indirect)
23+
variable(char const *name, void *var, uint64_t block_header, uint64_t bits)
2424
= 0;
2525
virtual void
26-
rewrite_event_post(void *config, uint64_t block_header, bool indirect)
26+
rewrite_event_post(void *config, uint64_t block_header, uint64_t bits)
2727
= 0;
2828
virtual void function_event_pre(char const *name, char const *location_stack)
2929
= 0;
@@ -106,13 +106,13 @@ class proof_trace_file_writer : public proof_trace_writer {
106106
}
107107

108108
void hook_event_post(
109-
void *hook_result, uint64_t block_header, bool indirect) override {
109+
void *hook_result, uint64_t block_header, uint64_t bits) override {
110110
write_uint64(kllvm::hook_result_sentinel);
111-
serialize_term_to_proof_trace(file_, hook_result, block_header, indirect);
111+
serialize_term_to_proof_trace(file_, hook_result, block_header, bits);
112112
}
113113

114-
void argument(void *arg, uint64_t block_header, bool indirect) override {
115-
serialize_term_to_proof_trace(file_, arg, block_header, indirect);
114+
void argument(void *arg, uint64_t block_header, uint64_t bits) override {
115+
serialize_term_to_proof_trace(file_, arg, block_header, bits);
116116
}
117117

118118
void rewrite_event_pre(uint64_t ordinal, uint64_t arity) override {
@@ -123,15 +123,15 @@ class proof_trace_file_writer : public proof_trace_writer {
123123

124124
void variable(
125125
char const *name, void *var, uint64_t block_header,
126-
bool indirect) override {
126+
uint64_t bits) override {
127127
write_null_terminated_string(name);
128-
serialize_term_to_proof_trace(file_, var, block_header, indirect);
128+
serialize_term_to_proof_trace(file_, var, block_header, bits);
129129
}
130130

131131
void rewrite_event_post(
132-
void *config, uint64_t block_header, bool indirect) override {
132+
void *config, uint64_t block_header, uint64_t bits) override {
133133
write_uint64(kllvm::config_sentinel);
134-
serialize_term_to_proof_trace(file_, config, block_header, indirect);
134+
serialize_term_to_proof_trace(file_, config, block_header, bits);
135135
}
136136

137137
void
@@ -191,17 +191,17 @@ class proof_trace_callback_writer : public proof_trace_writer {
191191
struct kore_term_construction {
192192
void *subject;
193193
uint64_t block_header;
194-
bool indirect;
194+
uint64_t bits;
195195

196196
kore_term_construction()
197197
: subject(nullptr)
198198
, block_header(0)
199-
, indirect(false) { }
199+
, bits(0) { }
200200

201-
kore_term_construction(void *subject, uint64_t block_header, bool indirect)
201+
kore_term_construction(void *subject, uint64_t block_header, uint64_t bits)
202202
: subject(subject)
203203
, block_header(block_header)
204-
, indirect(indirect) { }
204+
, bits(bits) { }
205205
};
206206

207207
struct kore_configuration_construction {
@@ -301,13 +301,13 @@ class proof_trace_callback_writer : public proof_trace_writer {
301301
}
302302

303303
void hook_event_post(
304-
void *hook_result, uint64_t block_header, bool indirect) override {
305-
current_call_event_->result.emplace(hook_result, block_header, indirect);
304+
void *hook_result, uint64_t block_header, uint64_t bits) override {
305+
current_call_event_->result.emplace(hook_result, block_header, bits);
306306
hook_event_callback(current_call_event_.value());
307307
}
308308

309-
void argument(void *arg, uint64_t block_header, bool indirect) override {
310-
current_call_event_->arguments.emplace_back(arg, block_header, indirect);
309+
void argument(void *arg, uint64_t block_header, uint64_t bits) override {
310+
current_call_event_->arguments.emplace_back(arg, block_header, bits);
311311
}
312312

313313
void rewrite_event_pre(uint64_t ordinal, uint64_t arity) override {
@@ -320,21 +320,21 @@ class proof_trace_callback_writer : public proof_trace_writer {
320320

321321
void variable(
322322
char const *name, void *var, uint64_t block_header,
323-
bool indirect) override {
323+
uint64_t bits) override {
324324
auto &p = current_rewrite_event_->substitution[current_rewrite_event_->pos];
325325
p.first = name;
326326
p.second.subject = var;
327327
p.second.block_header = block_header;
328-
p.second.indirect = indirect;
328+
p.second.bits = bits;
329329
size_t new_pos = ++current_rewrite_event_->pos;
330330
if (new_pos == current_rewrite_event_->arity) {
331331
rewrite_event_callback(current_rewrite_event_.value());
332332
}
333333
}
334334

335335
void rewrite_event_post(
336-
void *config, uint64_t block_header, bool indirect) override {
337-
kore_term_construction configuration(config, block_header, indirect);
336+
void *config, uint64_t block_header, uint64_t bits) override {
337+
kore_term_construction configuration(config, block_header, bits);
338338
configuration_term_event_callback(configuration);
339339
}
340340

lib/ast/definition.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <kllvm/ast/AST.h>
22

33
#include <iostream>
4+
#include <stack>
45
#include <string>
56
#include <unordered_set>
67

@@ -285,12 +286,40 @@ void kore_definition::preprocess() {
285286
for (auto *symbol : entry.second) {
286287
if (symbol->is_concrete()) {
287288
for (auto const &sort : symbol->get_arguments()) {
289+
// We use a work list to ensure that parametric sorts get ordinals
290+
// that are greater than the ordinals of any of their parameters.
291+
// This invariant is usefull for serialization purposes, and given
292+
// that all parametric sorts are statically known, it is sound to
293+
// assign ordinals to them in such a topological order.
294+
std::stack<std::pair<kore_composite_sort *, bool>> worklist;
288295
auto *ctr = dynamic_cast<kore_composite_sort *>(sort.get());
289-
if (!sorts.contains(*ctr)) {
290-
sorts.emplace(*ctr, next_sort++);
291-
all_sorts_.push_back(ctr);
296+
worklist.push(std::make_pair(ctr, false));
297+
298+
while (!worklist.empty()) {
299+
auto *sort_to_process = worklist.top().first;
300+
bool params_processed = worklist.top().second;
301+
worklist.pop();
302+
303+
if (!sorts.contains(*sort_to_process)) {
304+
if (!params_processed) {
305+
// Defer processing this sort until its parameter sorts have
306+
// been processed.
307+
worklist.push(std::make_pair(sort_to_process, true));
308+
for (auto const &param_sort :
309+
sort_to_process->get_arguments()) {
310+
auto *param_ctr
311+
= dynamic_cast<kore_composite_sort *>(param_sort.get());
312+
worklist.push(std::make_pair(param_ctr, false));
313+
}
314+
continue;
315+
}
316+
317+
sorts.emplace(*sort_to_process, next_sort++);
318+
all_sorts_.push_back(sort_to_process);
319+
}
320+
321+
sort_to_process->set_ordinal(sorts[*sort_to_process]);
292322
}
293-
ctr->set_ordinal(sorts[*ctr]);
294323
}
295324
if (!instantiations.contains(*symbol)) {
296325
instantiations.emplace(*symbol, next_symbol++);

lib/binary/serializer.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,18 @@ void emit_kore_rich_header(std::ostream &os, kore_definition *definition) {
179179
for (uint32_t i = 0; i < num_sorts; i++) {
180180
uint32_t idx = i + num_tags;
181181
os.write(reinterpret_cast<char const *>(&idx), 4);
182-
if (!definition->get_all_sorts()[i]->get_arguments().empty()) {
183-
throw std::runtime_error(
184-
"cannot yet serialize sorts with sort parameters");
182+
auto const &sort = definition->get_all_sorts().at(i);
183+
uint8_t num_sort_params = sort->get_arguments().size();
184+
os.write(reinterpret_cast<char const *>(&num_sort_params), 1);
185+
for (uint8_t j = 0; j < num_sort_params; j++) {
186+
auto *param_sort
187+
= dynamic_cast<kore_composite_sort *>(sort->get_arguments()[j].get());
188+
uint32_t param_ordinal = param_sort->get_ordinal();
189+
if (param_ordinal >= i) {
190+
throw std::runtime_error("found sort ordinal not in topological order");
191+
}
192+
os.write(reinterpret_cast<char const *>(&param_ordinal), 4);
185193
}
186-
os.put('\000');
187194
}
188195

189196
for (uint32_t i = 0; i < num_tags; i++) {

0 commit comments

Comments
 (0)