@@ -15,7 +15,6 @@ namespace Llvm.NET
1515{
1616 /// <summary>LLVM MemoryBuffer</summary>
1717 public sealed class MemoryBuffer
18- : IDisposable
1918 {
2019 /// <summary>Initializes a new instance of the <see cref="MemoryBuffer"/> class from a file</summary>
2120 /// <param name="path">Path of the file to load</param>
@@ -43,16 +42,6 @@ public int Size
4342 }
4443 }
4544
46- /// <inheritdoc/>
47- public void Dispose ( )
48- {
49- if ( BufferHandle == default )
50- {
51- LLVMDisposeMemoryBuffer ( BufferHandle ) ;
52- BufferHandle_ = default ;
53- }
54- }
55-
5645 /// <summary>Gets an array of bytes from the buffer</summary>
5746 /// <returns>Array of bytes copied from the buffer</returns>
5847 public byte [ ] ToArray ( )
@@ -72,6 +61,7 @@ internal MemoryBuffer( LLVMMemoryBufferRef bufferHandle )
7261
7362 internal LLVMMemoryBufferRef BufferHandle => BufferHandle_ ;
7463
64+ // TODO: Consider some form of WriteOnce<T> to enforce semantics and not rely on a coment
7565 // keep as a private field so this is usable as an out parameter in constructor
7666 // do not write to it directly, treat it as readonly.
7767 [ SuppressMessage ( "StyleCop.CSharp.NamingRules"
@@ -80,5 +70,33 @@ internal MemoryBuffer( LLVMMemoryBufferRef bufferHandle )
8070 )
8171 ]
8272 private LLVMMemoryBufferRef BufferHandle_ ;
73+
74+ [ DllImport ( LibraryPath , CallingConvention = CallingConvention . Cdecl , CharSet = CharSet . Ansi , ThrowOnUnmappableChar = true , BestFitMapping = false ) ]
75+ private static extern LLVMStatus LLVMCreateMemoryBufferWithContentsOfFile ( [ MarshalAs ( UnmanagedType . LPStr ) ] string @Path
76+ , out LLVMMemoryBufferRef @OutMemBuf
77+ , [ MarshalAs ( UnmanagedType . CustomMarshaler , MarshalTypeRef = typeof ( StringMarshaler ) , MarshalCookie = "DisposeMessage" ) ] out string @OutMessage
78+ ) ;
79+
80+ [ DllImport ( LibraryPath , CallingConvention = CallingConvention . Cdecl ) ]
81+ private static extern LLVMStatus LLVMCreateMemoryBufferWithSTDIN ( out LLVMMemoryBufferRef @OutMemBuf , out IntPtr @OutMessage ) ;
82+
83+ [ DllImport ( LibraryPath , CallingConvention = CallingConvention . Cdecl , CharSet = CharSet . Ansi , ThrowOnUnmappableChar = true , BestFitMapping = false ) ]
84+ private static extern LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange ( [ MarshalAs ( UnmanagedType . LPStr ) ] string @InputData
85+ , size_t @InputDataLength
86+ , [ MarshalAs ( UnmanagedType . LPStr ) ] string @BufferName
87+ , [ MarshalAs ( UnmanagedType . Bool ) ] bool @RequiresNullTerminator
88+ ) ;
89+
90+ [ DllImport ( LibraryPath , CallingConvention = CallingConvention . Cdecl , CharSet = CharSet . Ansi , ThrowOnUnmappableChar = true , BestFitMapping = false ) ]
91+ private static extern LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy ( [ MarshalAs ( UnmanagedType . LPStr ) ] string @InputData
92+ , size_t @InputDataLength
93+ , [ MarshalAs ( UnmanagedType . LPStr ) ] string @BufferName
94+ ) ;
95+
96+ [ DllImport ( LibraryPath , CallingConvention = CallingConvention . Cdecl ) ]
97+ private static extern IntPtr LLVMGetBufferStart ( LLVMMemoryBufferRef @MemBuf ) ;
98+
99+ [ DllImport ( LibraryPath , CallingConvention = CallingConvention . Cdecl ) ]
100+ private static extern size_t LLVMGetBufferSize ( LLVMMemoryBufferRef @MemBuf ) ;
83101 }
84102}
0 commit comments