Closed nektro closed 4 years ago
additionally, pr.Type() == t == true
Hi, ir.Param
is not a constant, this is expected. The reason is the value of a parameter cannot be detected before runtime. What you need is alloca an instance for the structure type, ref: https://llir.github.io/document/user-guide/types/#structure
I don't need to instantiate the type and I'm okay with it being a value.Value
but what I'm trying to do is access the fields of the struct.
using block.NewGetElementPtr
worked, thanks for the docs pointer!
hmmm, I can't seem to get past this though
llvm-as-10: out.ll:11:30: error: explicit pointee type doesn't match operand's pointee type
%3 = getelementptr inbounds [15 x i8], { [15 x i8], i32 }* %1, i32 0
^
Because the operand's type mismatched, it should be getelementptr inbounds { [15 x i8], i32 }, { [15 x i8], i32 }*
.
func NewGetElementPtr(elemType types.Type, src value.Value, indices ...value.Value) *InstGetElementPtr
ahhh, didn't realized that elemType
is the type of src
. thought for a while it was the output type.
@mewmew any suggestion about this signature? elemType seems quite wrong.
@mewmew any suggestion about this signature? elemType seems quite wrong.
The intention is to mirror that of the official LLVM IR semantics for the getelementptr
instruction. So the first argument to NewGetElementPtr
is the same as the first argument to the getelementptr instruction.
Perhaps the name elemType
is confusion? Any thoughts about what name would be better suited?
Well, getelementptr
always take a pointer or vector, can seem as Ptr<T>
or Vec<T>
, say T
is elemType make sense IMO.
however, this produces an error:
cannot use pr (type *ir.Param) as type constant.Constant in argument to constant.NewStruct: *ir.Param does not implement constant.Constant (missing IsConstant method)
is this a bug, or is there another intended way to cast a
Param
to a custom type?