I'm building a PHP compiler with an LLVM back-end. I will use the Zend type zend_string
to represent strings. For this I need an LLVM pointer type called zend_string_ptr
or whatever. How do I create this pointer type with the OCaml LLVM bindings?
For exampel, this PHP code
$a = 'asd';
should correspond to this C code
zend_string *a = zend_string_init("asd", 3, 1);
zend_new_interned_string(a);
To make an LLVM double type in OCaml, you would write
let double_type = double_type llvm_context
And to make a function type which takes 0 arguments and returns a double, you would write
let f_type = function_type double_type [||]
I've checked the OCaml docs here and the C++ docs here, but I'm still not sure how to go about this.
What I want is a function type that takes zend_string_ptr
, int
and int
as arguments and returns zend_string_ptr
.
The generated LLVM bytecode should be something like this
%zend_string = type opaque
declare %zend_string* @zend_string_init(i8, i32, i32)
where i8
is the element pointer to a constant string; and then
%1 = alloca %zend_string_ptr
and so on.
Tips?
Edit: Using named_struct_type
will create an opaque type, which can be inspected using is_opaque
and dump_type
.