Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use template specialization for dumping modules. Also rename 'do_prin…

…t' to 'dump_to_string'
  • Loading branch information...
commit 67c4b8bed429aaa681abb6f752d4e16d2f8fc17b 1 parent 48694c4
@bacek bacek authored
Showing with 13 additions and 10 deletions.
  1. +13 −10 src/llvm_extra.cpp
View
23 src/llvm_extra.cpp
@@ -28,8 +28,8 @@ src/llvm_extra.c - Extra functions to extend LLVM C API.
/* Helper method for LLVMDumpXXXToString() methods. */
-template <typename W>
-STRING *do_print(PARROT_INTERP, W obj)
+template <typename Type>
+STRING *dump_to_string(PARROT_INTERP, Type obj)
{
std::string s;
llvm::raw_string_ostream buf(s);
@@ -37,28 +37,31 @@ STRING *do_print(PARROT_INTERP, W obj)
return Parrot_str_from_platform_cstring(interp, s.c_str());
}
-PARROT_EXPORT
-STRING *Parrot_LLVMDumpModuleToString(PARROT_INTERP, LLVMModuleRef module)
+template <>
+STRING *dump_to_string(PARROT_INTERP, LLVMModuleRef obj)
{
- // Unfortunatelly Module.print requires additional
- // llvm::AssemblyAnnotationWriter* without defaulting it to NULL.
- // return do_print(interp, module);
std::string s;
llvm::raw_string_ostream buf(s);
- llvm::unwrap(module)->print(buf, NULL);
+ llvm::unwrap(obj)->print(buf, NULL);
return Parrot_str_from_platform_cstring(interp, s.c_str());
}
PARROT_EXPORT
+STRING *Parrot_LLVMDumpModuleToString(PARROT_INTERP, LLVMModuleRef module)
+{
+ return dump_to_string(interp, module);
+}
+
+PARROT_EXPORT
STRING *Parrot_LLVMDumpTypeToString(PARROT_INTERP, LLVMTypeRef type)
{
- return do_print(interp, type);
+ return dump_to_string(interp, type);
}
PARROT_EXPORT
STRING *Parrot_LLVMDumpValueToString(PARROT_INTERP, LLVMValueRef value)
{
- return do_print(interp, value);
+ return dump_to_string(interp, value);
}
Please sign in to comment.
Something went wrong with that request. Please try again.