On Tue, Jul 16, 2013 at 6:45 AM, Cheng Wang
<chengwang at multicorewareinc.com> wrote:> Is there any API in LLVM that can represent the field in java. such as the
> instucion "iget vx, vy, field_id"
There's no single instruction or API to do all of that. The closest
equivalent would probably be having a pointer to some object and using
a "getelementptr" instruction followed by a "load". For
example, in:
; class MyType { int a; int b; byte c; }
%MyType = {i32, i32, i8}
; byte foo(MyType obj) { return obj.c; }
; i.e. iget-byte vD, vObj, "c"?
define i8 @foo(%MyType* %obj) {
%c_addr = getelementptr %MyType* %obj, i32 0, i32 2
%c = load i8* %c_addr
ret i8 %c
}
The "2" on getelementptr means calculate the address of field #2 (i.e.
the i8, "c") in the object.
Cheers.
Tim.