|
10 | 10 | #include <iostream>
|
11 | 11 |
|
12 | 12 | #include "runtime/header.h" //for macros
|
| 13 | + |
13 | 14 | #include "llvm/IR/BasicBlock.h"
|
14 | 15 | #include "llvm/IR/Constants.h"
|
15 | 16 | #include "llvm/IR/DerivedTypes.h"
|
@@ -117,10 +118,6 @@ declare void @printConfiguration(i8 *, %block *)
|
117 | 118 | }
|
118 | 119 | } // namespace
|
119 | 120 |
|
120 |
| -void writeUInt64( |
121 |
| - llvm::Value *outputFile, llvm::Module *Module, uint64_t value, |
122 |
| - llvm::BasicBlock *Block); |
123 |
| - |
124 | 121 | std::unique_ptr<llvm::Module>
|
125 | 122 | newModule(std::string name, llvm::LLVMContext &Context) {
|
126 | 123 | llvm::SMDiagnostic Err;
|
@@ -318,8 +315,8 @@ llvm::Value *CreateTerm::alloc_arg(
|
318 | 315 | llvm::Value *ret
|
319 | 316 | = createAllocation(p, fmt::format("{}:{}", locationStack, idx)).first;
|
320 | 317 | auto sort = dynamic_cast<KORECompositeSort *>(p->getSort().get());
|
321 |
| - ProofEvent e(Definition, CurrentBlock, Module); |
322 |
| - CurrentBlock = e.hookArg(ret, sort); |
| 318 | + ProofEvent e(Definition, Module); |
| 319 | + CurrentBlock = e.hookArg(ret, sort, CurrentBlock); |
323 | 320 | return ret;
|
324 | 321 | }
|
325 | 322 |
|
@@ -700,49 +697,8 @@ llvm::Value *CreateTerm::createFunctionCall(
|
700 | 697 | }
|
701 | 698 | }
|
702 | 699 |
|
703 |
| - llvm::Function *func = CurrentBlock->getParent(); |
704 |
| - |
705 |
| - auto ProofOutputFlag = Module->getOrInsertGlobal( |
706 |
| - "proof_output", llvm::Type::getInt1Ty(Module->getContext())); |
707 |
| - auto OutputFileName = Module->getOrInsertGlobal( |
708 |
| - "output_file", llvm::Type::getInt8PtrTy(Module->getContext())); |
709 |
| - auto proofOutput = new llvm::LoadInst( |
710 |
| - llvm::Type::getInt1Ty(Module->getContext()), ProofOutputFlag, |
711 |
| - "proof_output", CurrentBlock); |
712 |
| - llvm::BasicBlock *TrueBlock |
713 |
| - = llvm::BasicBlock::Create(Module->getContext(), "if", func); |
714 |
| - auto outputFile = new llvm::LoadInst( |
715 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), OutputFileName, "output", |
716 |
| - TrueBlock); |
717 |
| - auto ir = new llvm::IRBuilder(TrueBlock); |
718 |
| - llvm::BasicBlock *MergeBlock |
719 |
| - = llvm::BasicBlock::Create(Module->getContext(), "tail", func); |
720 |
| - llvm::BranchInst::Create(TrueBlock, MergeBlock, proofOutput, CurrentBlock); |
721 |
| - |
722 |
| - std::ostringstream symbolName; |
723 |
| - pattern->getConstructor()->print(symbolName); |
724 |
| - |
725 |
| - auto symbolString |
726 |
| - = ir->CreateGlobalStringPtr(symbolName.str(), "", 0, Module); |
727 |
| - auto positionString = ir->CreateGlobalStringPtr(locationStack, "", 0, Module); |
728 |
| - writeUInt64(outputFile, Module, 0xdddddddddddddddd, TrueBlock); |
729 |
| - ir->CreateCall( |
730 |
| - getOrInsertFunction( |
731 |
| - Module, "printVariableToFile", |
732 |
| - llvm::Type::getVoidTy(Module->getContext()), |
733 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
734 |
| - llvm::Type::getInt8PtrTy(Module->getContext())), |
735 |
| - {outputFile, symbolString}); |
736 |
| - ir->CreateCall( |
737 |
| - getOrInsertFunction( |
738 |
| - Module, "printVariableToFile", |
739 |
| - llvm::Type::getVoidTy(Module->getContext()), |
740 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
741 |
| - llvm::Type::getInt8PtrTy(Module->getContext())), |
742 |
| - {outputFile, positionString}); |
743 |
| - |
744 |
| - llvm::BranchInst::Create(MergeBlock, TrueBlock); |
745 |
| - CurrentBlock = MergeBlock; |
| 700 | + auto event = ProofEvent(Definition, Module); |
| 701 | + CurrentBlock = event.functionEvent(CurrentBlock, pattern, locationStack); |
746 | 702 |
|
747 | 703 | return createFunctionCall(name, returnCat, args, sret, tailcc, locationStack);
|
748 | 704 | }
|
@@ -932,13 +888,12 @@ CreateTerm::createAllocation(KOREPattern *pattern, std::string locationStack) {
|
932 | 888 | .get());
|
933 | 889 | std::string name = strPattern->getContents();
|
934 | 890 |
|
935 |
| - ProofEvent p1(Definition, CurrentBlock, Module); |
936 |
| - CurrentBlock = p1.hookEvent_pre(name); |
| 891 | + ProofEvent p(Definition, Module); |
| 892 | + CurrentBlock = p.hookEvent_pre(name, CurrentBlock); |
937 | 893 | llvm::Value *val = createHook(
|
938 | 894 | symbolDecl->getAttributes().at("hook").get(), constructor,
|
939 | 895 | locationStack);
|
940 |
| - ProofEvent p2(Definition, CurrentBlock, Module); |
941 |
| - CurrentBlock = p2.hookEvent_post(val, sort); |
| 896 | + CurrentBlock = p.hookEvent_post(val, sort, CurrentBlock); |
942 | 897 |
|
943 | 898 | return std::make_pair(val, true);
|
944 | 899 | } else {
|
@@ -1114,91 +1069,10 @@ bool makeFunction(
|
1114 | 1069 |
|
1115 | 1070 | auto CurrentBlock = creator.getCurrentBlock();
|
1116 | 1071 | if (apply && bigStep) {
|
1117 |
| - auto ProofOutputFlag = Module->getOrInsertGlobal( |
1118 |
| - "proof_output", llvm::Type::getInt1Ty(Module->getContext())); |
1119 |
| - auto OutputFileName = Module->getOrInsertGlobal( |
1120 |
| - "output_file", llvm::Type::getInt8PtrTy(Module->getContext())); |
1121 |
| - auto proofOutput = new llvm::LoadInst( |
1122 |
| - llvm::Type::getInt1Ty(Module->getContext()), ProofOutputFlag, |
1123 |
| - "proof_output", CurrentBlock); |
1124 |
| - llvm::BasicBlock *TrueBlock |
1125 |
| - = llvm::BasicBlock::Create(Module->getContext(), "if", applyRule); |
1126 |
| - auto ir = new llvm::IRBuilder(TrueBlock); |
1127 |
| - llvm::BasicBlock *MergeBlock |
1128 |
| - = llvm::BasicBlock::Create(Module->getContext(), "tail", applyRule); |
1129 |
| - llvm::BranchInst::Create(TrueBlock, MergeBlock, proofOutput, CurrentBlock); |
1130 |
| - auto outputFile = new llvm::LoadInst( |
1131 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), OutputFileName, |
1132 |
| - "output", TrueBlock); |
1133 |
| - writeUInt64(outputFile, Module, axiom->getOrdinal(), TrueBlock); |
1134 |
| - writeUInt64( |
1135 |
| - outputFile, Module, applyRule->arg_end() - applyRule->arg_begin(), |
1136 |
| - TrueBlock); |
1137 |
| - for (auto entry = subst.begin(); entry != subst.end(); ++entry) { |
1138 |
| - auto key = entry->getKey(); |
1139 |
| - auto val = entry->getValue(); |
1140 |
| - auto var = vars[key.str()]; |
1141 |
| - auto sort = dynamic_cast<KORECompositeSort *>(var->getSort().get()); |
1142 |
| - auto cat = sort->getCategory(definition); |
1143 |
| - std::ostringstream Out; |
1144 |
| - sort->print(Out); |
1145 |
| - auto sortptr = ir->CreateGlobalStringPtr(Out.str(), "", 0, Module); |
1146 |
| - auto varname = ir->CreateGlobalStringPtr(key, "", 0, Module); |
1147 |
| - ir->CreateCall( |
1148 |
| - getOrInsertFunction( |
1149 |
| - Module, "printVariableToFile", |
1150 |
| - llvm::Type::getVoidTy(Module->getContext()), |
1151 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1152 |
| - llvm::Type::getInt8PtrTy(Module->getContext())), |
1153 |
| - {outputFile, varname}); |
1154 |
| - if (cat.cat == SortCategory::Symbol |
1155 |
| - || cat.cat == SortCategory::Variable) { |
1156 |
| - ir->CreateCall( |
1157 |
| - getOrInsertFunction( |
1158 |
| - Module, "serializeTermToFile", |
1159 |
| - llvm::Type::getVoidTy(Module->getContext()), |
1160 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1161 |
| - getValueType({SortCategory::Symbol, 0}, Module), |
1162 |
| - llvm::Type::getInt8PtrTy(Module->getContext())), |
1163 |
| - {outputFile, val, sortptr}); |
1164 |
| - } else if (val->getType()->isIntegerTy()) { |
1165 |
| - val = ir->CreateIntToPtr( |
1166 |
| - val, llvm::Type::getInt8PtrTy(Module->getContext())); |
1167 |
| - ir->CreateCall( |
1168 |
| - getOrInsertFunction( |
1169 |
| - Module, "serializeRawTermToFile", |
1170 |
| - llvm::Type::getVoidTy(Module->getContext()), |
1171 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1172 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1173 |
| - llvm::Type::getInt8PtrTy(Module->getContext())), |
1174 |
| - {outputFile, val, sortptr}); |
1175 |
| - } else { |
1176 |
| - val = ir->CreatePointerCast( |
1177 |
| - val, llvm::Type::getInt8PtrTy(Module->getContext())); |
1178 |
| - ir->CreateCall( |
1179 |
| - getOrInsertFunction( |
1180 |
| - Module, "serializeRawTermToFile", |
1181 |
| - llvm::Type::getVoidTy(Module->getContext()), |
1182 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1183 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1184 |
| - llvm::Type::getInt8PtrTy(Module->getContext())), |
1185 |
| - {outputFile, val, sortptr}); |
1186 |
| - } |
1187 |
| - writeUInt64(outputFile, Module, 0xcccccccccccccccc, TrueBlock); |
1188 |
| - } |
1189 |
| - |
1190 |
| - writeUInt64(outputFile, Module, 0xffffffffffffffff, TrueBlock); |
1191 |
| - ir->CreateCall( |
1192 |
| - getOrInsertFunction( |
1193 |
| - Module, "serializeConfigurationToFile", |
1194 |
| - llvm::Type::getVoidTy(Module->getContext()), |
1195 |
| - llvm::Type::getInt8PtrTy(Module->getContext()), |
1196 |
| - getValueType({SortCategory::Symbol, 0}, Module)), |
1197 |
| - {outputFile, retval}); |
1198 |
| - writeUInt64(outputFile, Module, 0xcccccccccccccccc, TrueBlock); |
1199 |
| - |
1200 |
| - llvm::BranchInst::Create(MergeBlock, TrueBlock); |
1201 |
| - CurrentBlock = MergeBlock; |
| 1072 | + auto event = ProofEvent(definition, Module); |
| 1073 | + CurrentBlock = event.rewriteEvent( |
| 1074 | + axiom, retval, applyRule->arg_end() - applyRule->arg_begin(), vars, |
| 1075 | + subst, CurrentBlock); |
1202 | 1076 | }
|
1203 | 1077 |
|
1204 | 1078 | if (bigStep) {
|
|
0 commit comments