[LLVMdev] Python bindings available.
Gordon Henriksen
gordonhenriksen at mac.com
Sun May 11 08:12:11 PDT 2008
On May 11, 2008, at 07:36, Mahadevan R wrote:
> Hi Gordon,
>
> Thanks for your comments.
>>
No problem.
>> :) Type handles in particular are very important. You can't form a
>> recursive type without using them, so you can't build any sort of
>> data structure.
>
> On it already. BTW, where can I find a good example of how to use it?
To close the loop with C++ syntax, LLVMTypeHandleRef is really a
pointer to a heap-allocated PATypeHolder, which is discussed here:
http://llvm.org/docs/ProgrammersManual.html#BuildRecType
The file test/Bindings/Ocaml/vmcore.ml contains this fragment:
(* RUN: grep -v {RecursiveTy.*RecursiveTy} < %t.ll
*)
let ty = opaque_type () in
let th = handle_to_type ty in
refine_type ty (pointer_type ty);
let ty = type_of_handle th in
insist (define_type_name "RecursiveTy" ty m);
insist (ty == element_type ty)
Which constructs %RecursiveType = type %RecursiveType*.
>> Finally, just as the C++ STL has reverse_iterator, it did prove
>> necessary to have a separate (At_begin parent | After element) type
>> in order to walk the IR backwards.
>
> Well, it's possible to do:
>
> for inst in reversed(block.instructions):
> # do stuff with inst
>
> which will iterate backwards over the instructions of a block.
Certainly. There are advantages to using the "up, prev, next" pointers
embedded within the IR in some circumstances, though. Consider what if
'do stuff with inst' might entail deleting another related
instruction, where that instruction might appear later in
reversed(block.instructions)--dangling pointer, boom! :) On the other
hand, creating a copy as your code presumably does is also sometimes
exactly what's wanted... TMTOWTDI, as they say.
— Gordon
More information about the llvm-dev
mailing list