[llvm-commits] [PATCH] Add the rest of the C and Ocaml bindings to for the tutorial

Gordon Henriksen gordonhenriksen at mac.com
Tue Mar 18 21:20:15 PDT 2008


On Mar 18, 2008, at 16:39, Erick Tryzelaar wrote:

> This is the last of the wrapped method calls in order to get the  
> kaleidoscope tutorials to work. In short, this patch adds some new  
> passes, and allows for the builder to be set at the start of a block.

Erick,

Your type qualifiers aren't quite right for the pass bindings; 'a  
PassManager.t uses the closed type model as we've discussed, so you  
should specify [<PassManager.any] PassManager.t. Please resubmit that  
part.

As for position_at_start, I'd prefer to provide the tools to  
synthesize that. I've committed C bindings for the APIs I think are  
necessary.

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080317/059869.html

I think these prototypes make sense for Ocaml bindings:

val first_instr : llbasicblock -> llvalue option
val last_instr : llbasicblock -> llvalue option
val next_instr : llbasicblock -> llvalue option
val prev_instr : llbasicblock -> llvalue option

(* ... likewise for *_function, *_global, and *_block. *)

(* This is strictly redundant to position_before and position_at_end. *)
val position_builder : llbuilder -> llbasicblock -> llvalue option

I considered using exceptions here, but it's not exceptional for these  
to be blank, and I think raising Not_found is much uglier as a result:

(* first_instr : llbasicblock -> llvalue option *)

let position_at_start bb b =
   position_builder bb (first_instr bb) b

let iter_block bb f =
   let helper i f =
     f i;
     match next_instr i with
     | Some j -> helper j
     | None -> ()
   in helper (first_instr bb) f

or

(* first_instr : llbasicblock -> llvalue
    @raise Not_found if the basic block is empty. *)

let position_at_start bb b =
   try position_before (first_instr bb) b
   with Not_found -> position_at_end bb b

let iter_block bb f =
   let helper i f =
     f i;
     (* avoid masking Not_found from f! *)
     match try Some (next_instr i)
           with Not_found -> None
     with Some j -> helper j
        | None -> ()
   in helper (first_instr bb) f

Of course, this does penalize the case where the user knows that there  
is a link in the list, so I could be convinced to go either way.  
Alternatively, first/last could be exceptional, while next/prev could  
use options. I'm not strongly opinionated on the matter except that I  
don't think there's any cause to bind position_builder if first_instr  
raises.

If you can cook up the ocaml bindings on top of those, that would be  
great. Otherwise, I'll try to get to them sometime this week.

Thanks Erick!

— Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20080319/aa408cfb/attachment.html>


More information about the llvm-commits mailing list