The question about how to refer an element in a pointer array by a dynamic index by IR

5 views
Skip to first unread message

Michael.Kang

unread,
Jul 1, 2010, 3:34:22 AM7/1/10
to Michael Steil, lib...@googlegroups.com
Now I am trying to use libcpu to write a simulator and take LLVM as IR
to dynamic translate machine code,
I encounter some issues when try to write some IR to express writting
a value to the reigster.
The situation is described as the following description.

write_reg is my function for writing "v" to the register indicated by
"index". ptr_gpr is the struct pointer for my general register file.


write_reg(cpu_t *cpu, uint32_t index, Value *v,BasicBlock *bb ){
Value **regs = cpu->ptr_gpr;
}

If index do not need to do any runtime calculation, I can write the
following sentence to fulfil my requirement.

new StoreInst(v, regs[index], bb);

But if I need to do some runtime calculation for index such as
modular. Since my register index is a kind of logic register number, it
will dynamic map to a physical register by register window in runtime.

1. Use IR to calculate index by some
"BinaryOperator::Create(Instruction::Add, a, b, "", bb)" sentences.
2. Use the above index to refer the register in "regs".

Should I use GEP in second step ? And how to use it?

Thanks
MK

--
www.skyeye.org

Reply all
Reply to author
Forward
0 new messages