2929#include < llvm/IR/Value.h>
3030#include < llvm/Support/Casting.h>
3131
32+ #include < fmt/format.h>
33+
3234#include < iostream>
3335#include < limits>
3436#include < memory>
3537#include < set>
3638#include < type_traits>
39+
3740namespace kllvm {
3841
3942static std::string LAYOUTITEM_STRUCT = " layoutitem" ;
@@ -104,22 +107,19 @@ getFailPattern(DecisionCase const &_case, bool isInt) {
104107 + std::to_string (bitwidth) + " \" )" );
105108 }
106109 } 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+
112112 std::string conn = " " ;
113113 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]));
119117 conn = " ," ;
120118 }
121119 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);
123123 }
124124}
125125
@@ -732,18 +732,15 @@ void makeEvalOrAnywhereFunction(
732732 auto returnSort = dynamic_cast <KORECompositeSort *>(function->getSort ().get ())
733733 ->getCategory (definition);
734734 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 ()));
738737 std::vector<llvm::Type *> args;
739738 std::vector<llvm::Metadata *> debugArgs;
740739 std::vector<ValueType> cats;
741740 for (auto &sort : function->getArguments ()) {
742741 auto cat = dynamic_cast <KORECompositeSort *>(sort.get ())
743742 ->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)));
747744 switch (cat.cat ) {
748745 case SortCategory::Map:
749746 case SortCategory::RangeMap:
@@ -760,9 +757,7 @@ void makeEvalOrAnywhereFunction(
760757 }
761758 llvm::FunctionType *funcType
762759 = 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 ));
766761 llvm::Function *matchFunc = getOrInsertFunction (module , name, funcType);
767762 KORESymbolDeclaration *symbolDecl
768763 = definition->getSymbolDeclarations ().at (function->getName ());
@@ -791,9 +786,9 @@ void makeEvalOrAnywhereFunction(
791786 ++val, ++i) {
792787 val->setName (" _" + std::to_string (i + 1 ));
793788 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]));
797792 }
798793 addStuck (stuck, module , function, codegen, definition);
799794
@@ -804,9 +799,7 @@ void abortWhenStuck(
804799 llvm::BasicBlock *CurrentBlock, llvm::Module *Module, KORESymbol *symbol,
805800 Decision &codegen, KOREDefinition *d) {
806801 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));
810803 auto BlockType = getBlockType (Module, d, symbol);
811804 llvm::Value *Ptr;
812805 auto BlockPtr = llvm::PointerType::getUnqual (
@@ -1276,9 +1269,7 @@ void makeStepFunction(
12761269 auto argSort
12771270 = dynamic_cast <KORECompositeSort *>(res.pattern ->getSort ().get ());
12781271 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)));
12821273 switch (cat.cat ) {
12831274 case SortCategory::Map:
12841275 case SortCategory::RangeMap:
@@ -1334,9 +1325,8 @@ void makeStepFunction(
13341325 auto cat = dynamic_cast <KORECompositeSort *>(sort.get ())
13351326 ->getCategory (definition);
13361327 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));
13401330 }
13411331 auto header = stepFunctionHeader (
13421332 axiom->getOrdinal (), module , definition, block, stuck, args, types);
0 commit comments