@@ -15,11 +15,22 @@ Base.parse(::Type{Module}, data::Vector; ctx::Context) =
1515
1616# # writer
1717
18- Base. write (io:: IOStream , mod:: Module ) =
19- API. LLVMWriteBitcodeToFD (mod, Cint (fd (io)), convert (Bool, false ), convert (Bool, true ))
20-
2118Base. convert (:: Type{MemoryBuffer} , mod:: Module ) = MemoryBuffer (
2219 API. LLVMWriteBitcodeToMemoryBuffer (mod))
2320
24- Base. convert (:: Type{Vector{T}} , mod:: Module ) where {T<: Union{UInt8,Int8} } =
25- convert (Vector{T}, convert (MemoryBuffer, mod))
21+ function Base. convert (:: Type{Vector{T}} , mod:: Module ) where {T<: Union{UInt8,Int8} }
22+ buf = convert (MemoryBuffer, mod)
23+ vec = convert (Vector{T}, buf)
24+ dispose (buf)
25+ return vec
26+ end
27+
28+ function Base. write (io:: IOStream , mod:: Module )
29+ # XXX : can't use the LLVM API because it returns 0, not the number of bytes written
30+ # API.LLVMWriteBitcodeToFD(mod, Cint(fd(io)), convert(Bool, false), convert(Bool, true))
31+ buf = convert (MemoryBuffer, mod)
32+ vec = unsafe_wrap (Array, pointer (buf), length (buf))
33+ nb = write (io, vec)
34+ dispose (buf)
35+ return nb
36+ end
0 commit comments