[LLVMdev] Python bindings available.
Mahadevan R
mdevan.foobar at gmail.com
Sun May 11 04:36:04 PDT 2008
Hi Gordon,
Thanks for your comments.
> > Constant.string(value, dont_null_terminate) -- value is a string
> > Constant.struct(consts, packed) -- a struct, consts is a list of
> > other constants, packed is boolean
>
> I did this in Ocaml initially, but found the boolean constants pretty
> confusing to read in code. I kept asking "What's that random true
> doing there?" Therefore, the bindings expose these as const_string/
> const_stringz and const_struct/const_packed_struct respectively. I
OK, will do.
> :) 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?
> Uninitialized builders are very dangerous (they leak instructions if
> you use them), so you might want to add overloads for new in order to
> avoid boilerplate code.
By 'uninitialized', I guess you're referring to builders that are yet
positioned on a block/instruction? Maybe it makes more sense to
create it 'from' a block, something like:
builder = basic_block_obj.builder()
with it being positioned at the end of the block by default. But then,
your ocaml syntax is much cleaner:
> // At the start or end of a BB:
> Builder.new(At_end bb)
> Builder.new(bb.begin)
>
> // Before or after a given instruction:
> Builder.new(Before instr)
> Builder.new(instr.succ)
so I'll see how this can be done a bit, ah, Pythonically.
> 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.
Thanks & Regards,
-Mahadevan.
More information about the llvm-dev
mailing list