Permalink
Browse files

Add llvm_extra.cpp with supplimentary LLVM functions.

  • Loading branch information...
1 parent 34851f7 commit d8f5c7238d2b2b70956d0f840e84c4534e9d4540 @bacek bacek committed with Reini Urban Apr 25, 2011
Showing with 74 additions and 0 deletions.
  1. +4 −0 config/gen/makefiles/root.in
  2. +70 −0 src/llvm_extra.cpp
@@ -535,6 +535,9 @@ INTERP_O_FILES = \
src/longopt$(O) \
@TEMP_platform_o@ \
+LLVM_O_FILES = \
+ src/llvm_extra$(O)
+
OPS_FILES = @ops@
###############################################################################
@@ -1101,6 +1104,7 @@ O_FILES = \
$(IO_O_FILES) \
$(CLASS_O_FILES) \
$(ENCODING_O_FILES) \
+#IF(has_llvm): $(LLVM_O_FILES) \
$(IMCC_O_FILES)
lib_deps_object : $(O_FILES)
View
@@ -0,0 +1,70 @@
+/*
+Copyright (C) 2011, Parrot Foundation.
+
+=head1 NAME
+
+src/llvm_extra.c - Extra functions to extend LLVM C API.
+
+=head1 DESCRIPTION
+
+*/
+
+#include "parrot/parrot.h"
+
+#include <llvm/Support/raw_ostream.h>
+#include <llvm/Module.h>
+
+#include <llvm-c/Core.h>
+
+/*
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+
+/* Helper method for LLVMDumpXXXToString() methods. */
+template <typename W>
+STRING *do_print(PARROT_INTERP, W obj)
+{
+ std::string s;
+ llvm::raw_string_ostream buf(s);
+ llvm::unwrap(obj)->print(buf);
+ return Parrot_str_from_platform_cstring(interp, s.c_str());
+}
+
+PARROT_EXPORT
+STRING *Parrot_LLVMDumpModuleToString(PARROT_INTERP, LLVMModuleRef module)
+{
+ // 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);
+ return Parrot_str_from_platform_cstring(interp, s.c_str());
+}
+
+PARROT_EXPORT
+STRING *Parrot_LLVMDumpTypeToString(PARROT_INTERP, LLVMTypeRef type)
+{
+ return do_print(interp, type);
+}
+
+PARROT_EXPORT
+STRING *Parrot_LLVMDumpValueToString(PARROT_INTERP, LLVMValueRef value)
+{
+ return do_print(interp, value);
+}
+
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
+ */

0 comments on commit d8f5c72

Please sign in to comment.