29
29
#include < llvm/IR/Value.h>
30
30
#include < llvm/Support/Casting.h>
31
31
32
+ #include < fmt/format.h>
33
+
32
34
#include < iostream>
33
35
#include < limits>
34
36
#include < memory>
35
37
#include < set>
36
38
#include < type_traits>
39
+
37
40
namespace kllvm {
38
41
39
42
static std::string LAYOUTITEM_STRUCT = " layoutitem" ;
@@ -104,22 +107,19 @@ getFailPattern(DecisionCase const &_case, bool isInt) {
104
107
+ std::to_string (bitwidth) + " \" )" );
105
108
}
106
109
} else {
107
- std::ostringstream symbol;
108
- _case.getConstructor ()->print (symbol);
109
- std::ostringstream returnSort;
110
- _case.getConstructor ()->getSort ()->print (returnSort);
111
- std::string result = symbol.str () + " (" ;
110
+ auto result = fmt::format (" {}(" , ast_to_string (*_case.getConstructor ()));
111
+
112
112
std::string conn = " " ;
113
113
for (int i = 0 ; i < _case.getConstructor ()->getArguments ().size (); i++) {
114
- result += conn;
115
- result += " Var'Unds'" ;
116
- std::ostringstream argSort;
117
- _case.getConstructor ()->getArguments ()[i]->print (argSort);
118
- result += " :" + argSort.str ();
114
+ result += fmt::format (
115
+ " {}Var'Unds':{}" , conn,
116
+ ast_to_string (*_case.getConstructor ()->getArguments ()[i]));
119
117
conn = " ," ;
120
118
}
121
119
result += " )" ;
122
- return std::make_pair (returnSort.str (), result);
120
+
121
+ auto return_sort = ast_to_string (*_case.getConstructor ()->getSort ());
122
+ return std::make_pair (return_sort, result);
123
123
}
124
124
}
125
125
@@ -732,18 +732,15 @@ void makeEvalOrAnywhereFunction(
732
732
auto returnSort = dynamic_cast <KORECompositeSort *>(function->getSort ().get ())
733
733
->getCategory (definition);
734
734
auto returnType = getParamType (returnSort, module );
735
- std::ostringstream Out;
736
- function->getSort ()->print (Out);
737
- auto debugReturnType = getDebugType (returnSort, Out.str ());
735
+ auto debugReturnType
736
+ = getDebugType (returnSort, ast_to_string (*function->getSort ()));
738
737
std::vector<llvm::Type *> args;
739
738
std::vector<llvm::Metadata *> debugArgs;
740
739
std::vector<ValueType> cats;
741
740
for (auto &sort : function->getArguments ()) {
742
741
auto cat = dynamic_cast <KORECompositeSort *>(sort.get ())
743
742
->getCategory (definition);
744
- std::ostringstream Out;
745
- sort->print (Out);
746
- debugArgs.push_back (getDebugType (cat, Out.str ()));
743
+ debugArgs.push_back (getDebugType (cat, ast_to_string (*sort)));
747
744
switch (cat.cat ) {
748
745
case SortCategory::Map:
749
746
case SortCategory::RangeMap:
@@ -760,9 +757,7 @@ void makeEvalOrAnywhereFunction(
760
757
}
761
758
llvm::FunctionType *funcType
762
759
= llvm::FunctionType::get (returnType, args, false );
763
- std::ostringstream Out2;
764
- function->print (Out2, 0 , false );
765
- std::string name = " eval_" + Out2.str ();
760
+ std::string name = fmt::format (" eval_{}" , ast_to_string (*function, 0 , false ));
766
761
llvm::Function *matchFunc = getOrInsertFunction (module , name, funcType);
767
762
KORESymbolDeclaration *symbolDecl
768
763
= definition->getSymbolDeclarations ().at (function->getName ());
@@ -791,9 +786,9 @@ void makeEvalOrAnywhereFunction(
791
786
++val, ++i) {
792
787
val->setName (" _" + std::to_string (i + 1 ));
793
788
codegen.store (std::make_pair (val->getName ().str (), val->getType ()), val);
794
- std::ostringstream Out;
795
- function-> getArguments () [i]-> print (Out);
796
- initDebugParam (matchFunc, i, val-> getName (). str (), cats [i], Out. str ( ));
789
+ initDebugParam (
790
+ matchFunc, i, val-> getName (). str (), cats [i],
791
+ ast_to_string (*function-> getArguments () [i]));
797
792
}
798
793
addStuck (stuck, module , function, codegen, definition);
799
794
@@ -804,9 +799,7 @@ void abortWhenStuck(
804
799
llvm::BasicBlock *CurrentBlock, llvm::Module *Module, KORESymbol *symbol,
805
800
Decision &codegen, KOREDefinition *d) {
806
801
auto &Ctx = Module->getContext ();
807
- std::ostringstream Out;
808
- symbol->print (Out);
809
- symbol = d->getAllSymbols ().at (Out.str ());
802
+ symbol = d->getAllSymbols ().at (ast_to_string (*symbol));
810
803
auto BlockType = getBlockType (Module, d, symbol);
811
804
llvm::Value *Ptr;
812
805
auto BlockPtr = llvm::PointerType::getUnqual (
@@ -1276,9 +1269,7 @@ void makeStepFunction(
1276
1269
auto argSort
1277
1270
= dynamic_cast <KORECompositeSort *>(res.pattern ->getSort ().get ());
1278
1271
auto cat = argSort->getCategory (definition);
1279
- std::ostringstream Out;
1280
- argSort->print (Out);
1281
- debugTypes.push_back (getDebugType (cat, Out.str ()));
1272
+ debugTypes.push_back (getDebugType (cat, ast_to_string (*argSort)));
1282
1273
switch (cat.cat ) {
1283
1274
case SortCategory::Map:
1284
1275
case SortCategory::RangeMap:
@@ -1334,9 +1325,8 @@ void makeStepFunction(
1334
1325
auto cat = dynamic_cast <KORECompositeSort *>(sort.get ())
1335
1326
->getCategory (definition);
1336
1327
types.push_back (cat);
1337
- std::ostringstream Out;
1338
- sort->print (Out);
1339
- initDebugParam (matchFunc, i, " _" + std::to_string (i + 1 ), cat, Out.str ());
1328
+ initDebugParam (
1329
+ matchFunc, i, " _" + std::to_string (i + 1 ), cat, ast_to_string (*sort));
1340
1330
}
1341
1331
auto header = stepFunctionHeader (
1342
1332
axiom->getOrdinal (), module , definition, block, stuck, args, types);
0 commit comments