File tree Expand file tree Collapse file tree 2 files changed +30
-8
lines changed Expand file tree Collapse file tree 2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 1+ extern crate llvm_sys;
2+ extern crate llvm;
3+ use llvm:: * ;
4+ use llvm:: Attribute :: * ;
5+ fn main ( ) {
6+ let ctx = Context :: new ( ) ;
7+ let module = Module :: new ( "simple" , & ctx) ;
8+ type N = f64 ;
9+ type T = extern "C" fn ( N ) -> N ;
10+ let func = module. add_function (
11+ "thr" , Type :: get :: < T > ( & ctx) ) ;
12+ func. add_attributes ( & [ NoUnwind , ReadNone ] ) ;
13+ let entry = func. append ( "entry" ) ;
14+ let builder = Builder :: new ( & ctx) ;
15+ fn n ( x : N ) -> N { x }
16+ let three_r = n ( 3 as N ) . compile ( & ctx) ;
17+ builder. position_at_end ( entry) ;
18+ builder. build_ret ( three_r) ;
19+ module. verify ( ) . unwrap ( ) ;
20+
21+ let ee = llvm:: JitEngine :: new (
22+ & module, llvm:: JitOptions { opt_level : 0 } ) . unwrap ( ) ;
23+ println ! ( "{:?}" , module) ;
24+ ee. with_function ( func, |thr : T | {
25+ for i in 0 ..3 {
26+ println ! ( "thr {} = {}" , i, thr( 0 as N ) )
27+ }
28+ } ) ;
29+ }
Original file line number Diff line number Diff line change @@ -238,13 +238,6 @@ impl Function {
238238 pub fn get_entry ( & self ) -> Option < & BasicBlock > {
239239 unsafe { mem:: transmute ( core:: LLVMGetEntryBasicBlock ( self . into ( ) ) ) }
240240 }
241- /// Returns the name of this function.
242- pub fn get_name ( & self ) -> & str {
243- unsafe {
244- let c_name = core:: LLVMGetValueName ( self . into ( ) ) ;
245- util:: to_str ( c_name as * mut i8 )
246- }
247- }
248241 /// Returns the function signature representing this function's signature.
249242 pub fn get_signature ( & self ) -> & FunctionType {
250243 unsafe {
@@ -338,7 +331,7 @@ pub enum Attribute {
338331 NoRedZone = 0b1000000000000000000 ,
339332 /// Disable implicit float instructions.
340333 NoImplicitFloat = 0b10000000000000000000 ,
341- /// Naked function.
334+ /// Only allows native assembly code in the function.
342335 Naked = 0b100000000000000000000 ,
343336 /// The source language has marked this function as inline.
344337 InlineHint = 0b1000000000000000000000 ,
You can’t perform that action at this time.
0 commit comments