Skip to content

Commit c61613d

Browse files
RobertorosmaninhoBaltolirv-jenkins
authored
Exporting kore_symbol in hook_events and exposing symbol entry point in kore_parser (#1064)
This PR introduces the new version of the LLVM Backend Proof Hints: Version 10. The major update is in the `llvm_hook_event`, which will have a new field: `kore_symbol`. The new format of hook accepted and produced is: ``` symbol_name ::= string hook ::= WORD(0xAA) name symbol_name location arg* WORD(0xBB) kore_term ``` It also exposes the `symbol` entry point in the `kore_parser`. This modification will help the Math Proof Team from Pi2 to parse the `llvm_hook_event->kore_symbol` and `llvm_function_event` using the same method. --------- Co-authored-by: Bruce Collie <[email protected]> Co-authored-by: rv-jenkins <[email protected]>
1 parent dbbb8d0 commit c61613d

File tree

96 files changed

+16194
-16154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+16194
-16154
lines changed

bindings/python/ast.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,12 @@ void bind_parser(py::module_ &mod) {
373373
"pattern",
374374
[](kore_parser &parser) { return std::shared_ptr(parser.pattern()); })
375375
.def("sort", [](kore_parser &parser) { return parser.sort(); })
376-
.def("definition", [](kore_parser &parser) {
377-
return std::shared_ptr(parser.definition());
378-
});
376+
.def(
377+
"definition",
378+
[](kore_parser &parser) {
379+
return std::shared_ptr(parser.definition());
380+
})
381+
.def("symbol", &kore_parser::symbol);
379382
}
380383

381384
void bind_proof_trace(py::module_ &m) {
@@ -421,6 +424,7 @@ void bind_proof_trace(py::module_ &m) {
421424
py::class_<llvm_hook_event, std::shared_ptr<llvm_hook_event>>(
422425
proof_trace, "llvm_hook_event", step_event)
423426
.def_property_readonly("name", &llvm_hook_event::get_name)
427+
.def_property_readonly("symbol_name", &llvm_hook_event::get_symbol_name)
424428
.def_property_readonly(
425429
"relative_position", &llvm_hook_event::get_relative_position)
426430
.def_property_readonly("args", &llvm_hook_event::get_arguments)

docs/proof-trace.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ name ::= string
4848
location ::= string
4949
function ::= WORD(0xDD) name location arg* WORD(0x11) // the arg list is ommited in normal mode
5050
51-
hook ::= WORD(0xAA) name location arg* WORD(0xBB) kore_term
51+
symbol_name ::= string
52+
hook ::= WORD(0xAA) name symbol_name location arg* WORD(0xBB) kore_term
5253
5354
ordinal ::= uint64
5455
arity ::= uint64

include/kllvm/binary/ProofTraceParser.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,27 @@ class llvm_function_event : public llvm_step_event {
159159
class llvm_hook_event : public llvm_step_event {
160160
private:
161161
std::string name_;
162+
std::string symbol_name_;
162163
std::string relative_position_;
163164
std::vector<llvm_event> arguments_;
164165
sptr<kore_pattern> kore_pattern_;
165166
uint64_t pattern_length_{0U};
166167

167-
llvm_hook_event(std::string name, std::string relative_position);
168+
llvm_hook_event(
169+
std::string name, std::string symbol_name, std::string relative_position);
168170

169171
public:
170-
static sptr<llvm_hook_event>
171-
create(std::string const &name, std::string const &relative_position) {
172-
return sptr<llvm_hook_event>(new llvm_hook_event(name, relative_position));
172+
static sptr<llvm_hook_event> create(
173+
std::string const &name, std::string const &symbol_name,
174+
std::string const &relative_position) {
175+
return sptr<llvm_hook_event>(
176+
new llvm_hook_event(name, symbol_name, relative_position));
173177
}
174178

175179
[[nodiscard]] std::string const &get_name() const { return name_; }
180+
[[nodiscard]] std::string const &get_symbol_name() const {
181+
return symbol_name_;
182+
}
176183
[[nodiscard]] std::string const &get_relative_position() const {
177184
return relative_position_;
178185
}
@@ -260,7 +267,7 @@ class llvm_rewrite_trace {
260267

261268
class proof_trace_parser {
262269
public:
263-
static constexpr uint32_t expected_version = 9U;
270+
static constexpr uint32_t expected_version = 10U;
264271

265272
private:
266273
bool verbose_;
@@ -415,12 +422,17 @@ class proof_trace_parser {
415422
return nullptr;
416423
}
417424

425+
std::string symbol_name;
426+
if (!parse_name(ptr, end, symbol_name)) {
427+
return nullptr;
428+
}
429+
418430
std::string location;
419431
if (!parse_location(ptr, end, location)) {
420432
return nullptr;
421433
}
422434

423-
auto event = llvm_hook_event::create(name, location);
435+
auto event = llvm_hook_event::create(name, symbol_name, location);
424436

425437
while (std::distance(ptr, end) < 8U
426438
|| peek_word(ptr) != hook_result_sentinel) {

include/kllvm/codegen/ProofEvent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class proof_event {
9292

9393
public:
9494
[[nodiscard]] llvm::BasicBlock *hook_event_pre(
95-
std::string const &name, llvm::BasicBlock *current_block,
96-
std::string const &location_stack);
95+
std::string const &name, kore_composite_pattern *pattern,
96+
llvm::BasicBlock *current_block, std::string const &location_stack);
9797

9898
[[nodiscard]] llvm::BasicBlock *hook_event_post(
9999
llvm::Value *val, kore_composite_sort *sort,

include/kllvm/parser/KOREParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class kore_parser {
2323
ptr<kore_definition> definition();
2424
sptr<kore_pattern> pattern();
2525
sptr<kore_sort> sort();
26+
ptr<kore_symbol> symbol();
2627
std::vector<ptr<kore_declaration>> declarations();
2728

2829
std::pair<std::string, std::vector<sptr<kore_sort>>> symbol_sort_list();

lib/binary/ProofTraceParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ void llvm_function_event::add_argument(llvm_event const &argument) {
2020
}
2121

2222
llvm_hook_event::llvm_hook_event(
23-
std::string name, std::string relative_position)
23+
std::string name, std::string symbol_name, std::string relative_position)
2424
: name_(std::move(name))
25+
, symbol_name_(std::move(symbol_name))
2526
, relative_position_(std::move(relative_position))
2627
, kore_pattern_(nullptr) { }
2728

@@ -81,7 +82,8 @@ void llvm_function_event::print(
8182
void llvm_hook_event::print(
8283
std::ostream &out, bool expand_terms, unsigned ind) const {
8384
std::string indent(ind * indent_size, ' ');
84-
out << fmt::format("{}hook: {} ({})\n", indent, name_, relative_position_);
85+
out << fmt::format(
86+
"{}hook: {} {} ({})\n", indent, name_, symbol_name_, relative_position_);
8587
for (auto const &arg : arguments_) {
8688
arg.print(out, expand_terms, true, ind + 1U);
8789
}

lib/codegen/CreateTerm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ std::pair<llvm::Value *, bool> create_term::create_allocation(
938938
std::string name = str_pattern->get_contents();
939939

940940
proof_event p(definition_, module_);
941-
current_block_ = p.hook_event_pre(name, current_block_, location_stack);
941+
current_block_ = p.hook_event_pre(
942+
name, constructor, current_block_, location_stack);
942943
llvm::Value *val = create_hook(
943944
symbol_decl->attributes().get(attribute_set::key::Hook).get(),
944945
constructor, location_stack);

lib/codegen/ProofEvent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ proof_event::event_prelude(
166166
*/
167167

168168
llvm::BasicBlock *proof_event::hook_event_pre(
169-
std::string const &name, llvm::BasicBlock *current_block,
170-
std::string const &location_stack) {
169+
std::string const &name, kore_composite_pattern *pattern,
170+
llvm::BasicBlock *current_block, std::string const &location_stack) {
171171
if (!proof_hint_instrumentation) {
172172
return current_block;
173173
}
@@ -177,6 +177,8 @@ llvm::BasicBlock *proof_event::hook_event_pre(
177177

178178
emit_write_uint64(outputFile, detail::word(0xAA), true_block);
179179
emit_write_string(outputFile, name, true_block);
180+
emit_write_string(
181+
outputFile, ast_to_string(*pattern->get_constructor()), true_block);
180182
emit_write_string(outputFile, location_stack, true_block);
181183

182184
llvm::BranchInst::Create(merge_block, true_block);

lib/parser/KOREParser.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,7 @@ sptr<kore_pattern> kore_parser::application_pattern(std::string const &name) {
343343
consume(token::LeftBrace);
344344
consume(token::RightBrace);
345345
consume(token::LeftParen);
346-
std::string symbol = consume(token::Id);
347-
consume(token::LeftBrace);
348-
auto pat = kore_composite_pattern::create(symbol);
349-
sorts(pat->get_constructor());
350-
pat->get_constructor()->init_pattern_arguments();
351-
consume(token::RightBrace);
346+
auto sym = symbol();
352347
consume(token::LeftParen);
353348
std::vector<sptr<kore_pattern>> pats;
354349
patterns(pats);
@@ -358,7 +353,7 @@ sptr<kore_pattern> kore_parser::application_pattern(std::string const &name) {
358353
sptr<kore_pattern> accum = pats[0];
359354
for (auto i = 1U; i < pats.size(); i++) {
360355
sptr<kore_composite_pattern> new_accum
361-
= kore_composite_pattern::create(pat->get_constructor());
356+
= kore_composite_pattern::create(sym.get());
362357
new_accum->add_argument(accum);
363358
new_accum->add_argument(pats[i]);
364359
accum = new_accum;
@@ -368,7 +363,7 @@ sptr<kore_pattern> kore_parser::application_pattern(std::string const &name) {
368363
sptr<kore_pattern> accum = pats[pats.size() - 1];
369364
for (int i = pats.size() - 2; i >= 0; i--) {
370365
sptr<kore_composite_pattern> new_accum
371-
= kore_composite_pattern::create(pat->get_constructor());
366+
= kore_composite_pattern::create(sym.get());
372367
new_accum->add_argument(pats[i]);
373368
new_accum->add_argument(accum);
374369
accum = new_accum;
@@ -402,6 +397,16 @@ sptr<kore_pattern> kore_parser::application_pattern(std::string const &name) {
402397
return result;
403398
}
404399

400+
ptr<kore_symbol> kore_parser::symbol() {
401+
std::string symbol = consume(token::Id);
402+
consume(token::LeftBrace);
403+
auto pat = kore_composite_pattern::create(symbol);
404+
sorts(pat->get_constructor());
405+
pat->get_constructor()->init_pattern_arguments();
406+
consume(token::RightBrace);
407+
return std::make_unique<kore_symbol>(*pat->get_constructor());
408+
}
409+
405410
ptr<kore_composite_pattern>
406411
kore_parser::application_pattern_internal(std::string const &name) {
407412
consume(token::LeftBrace);

runtime/util/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ block *construct_raw_term(void *subject, char const *sort, bool raw_value) {
3535
}
3636

3737
void print_proof_hint_header(FILE *file) {
38-
uint32_t version = 9;
38+
uint32_t version = 10;
3939
fmt::print(file, "HINT");
4040
fwrite(&version, sizeof(version), 1, file);
4141
}

0 commit comments

Comments
 (0)