aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Writer/BitWriter.cpp
diff options
context:
space:
mode:
authorGordon Henriksen <gordonhenriksen@mac.com>2007-09-18 03:18:57 +0000
committerGordon Henriksen <gordonhenriksen@mac.com>2007-09-18 03:18:57 +0000
commit76a0374b252c24bf2b2f571b252a3822698c1c33 (patch)
treed682609002df0e24516fc0ab297ea8f307bfc287 /llvm/lib/Bitcode/Writer/BitWriter.cpp
parent64e72c034ac31b50f16572ced9ce34bf3d1122e1 (diff)
downloadllvm-76a0374b252c24bf2b2f571b252a3822698c1c33.zip
llvm-76a0374b252c24bf2b2f571b252a3822698c1c33.tar.gz
llvm-76a0374b252c24bf2b2f571b252a3822698c1c33.tar.bz2
C bindings for libLLVMCore.a and libLLVMBitWriter.a.
- The naming prefix is LLVM. - All types are represented using opaque references. - Functions are not named LLVM{Type}{Method}; the names became unreadable goop. Instead, they are named LLVM{ImperativeSentence}. - Where an attribute only appears once in the class hierarchy (e.g., linkage only applies to values; parameter types only apply to function types), the class is omitted from identifiers for brevity. Tastes like methods. - Strings are C strings or string/length tuples on a case-by-case basis. - APIs which give the caller ownership of an object are not mapped (removeFromParent, certain constructor overloads). This keeps keep memory management as simple as possible. For each library with bindings: llvm-c/<LIB>.h - Declares the bindings. lib/<LIB>/<LIB>.cpp - Implements the bindings. So just link with the library of your choice and use the C header instead of the C++ one. llvm-svn: 42077
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitWriter.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitWriter.cpp b/llvm/lib/Bitcode/Writer/BitWriter.cpp
new file mode 100644
index 0000000..7b90586
--- /dev/null
+++ b/llvm/lib/Bitcode/Writer/BitWriter.cpp
@@ -0,0 +1,51 @@
+//===-- BitWriter.cpp -----------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm-c/BitWriter.h"
+#include "llvm/CHelpers.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include <fstream>
+
+using namespace llvm;
+
+
+/*===-- Operations on modules ---------------------------------------------===*/
+
+int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
+ std::ofstream OS(Path);
+
+ if (!OS.fail())
+ WriteBitcodeToFile(unwrap(M), OS);
+
+ if (OS.fail())
+ return -1;
+
+ return 0;
+}
+
+#ifdef __GNUC__
+#include <ext/stdio_filebuf.h>
+
+// FIXME: Control this with configure? Provide some portable abstraction in
+// libSystem? As is, the user will just get a linker error if they use this on
+// non-GCC. Some C++ stdlibs even have ofstream::ofstream(int fd).
+int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
+ __gnu_cxx::stdio_filebuf<char> Buffer(FileHandle, std::ios_base::out);
+ std::ostream OS(&Buffer);
+
+ if (!OS.fail())
+ WriteBitcodeToFile(unwrap(M), OS);
+
+ if (OS.fail())
+ return -1;
+
+ return 0;
+}
+
+#endif