[LLVMdev] could you give me some advice ?
lizhuo
aqex at bsv.com.cn
Sun Mar 26 17:05:41 PST 2006
for example , I have a LLVM bc file generated from c program like this
...
char E1$str[3] = "E1";
char* E1$entry = (char*)E1$str;
struct { char* name_list[16]; } table = { E1$entry, E2$entry, ... };
...
now I need load the bc file , get all names ("E1","E2"...) , then print and save it.
of course, i only know the global variable table name . I can get E1$entry from table ,
I want to get the string pointed by E1$entry .
Now is there a simple solution to get the string object ?
thanks.
>On Sat, 25 Mar 2006, lizhuo wrote:
>> ; define ConstantArray
>> "E1$str" = internal constant [3 x sbyte] c"E1\00"
>>
>> ; use getPtrPtrFromArrayPtr to define SByte* from ConstantArray
>> "E1$entry" = internal constant sbyte* getelementptr ([3 x sbyte]* "E1$str", uint 0, uint 0)
>> ...
>>
>> when i want to get std::string object from this declaration in another program
>>
>> Module* m = loadModule("XXX.bc");
>> Constant* c = findValue(m,"E1$entry");
>> GlobalVariable* gv = cast<GlobalVariable>(c->getOperand(0));
>> ConstantArray* ca = cast<ConstantArray>(gv->getOperand(0));
>> std::string str = ca->getAsString();
>>
>> now str = "E1"
>> these code looks a little ugly , could you tell me better solution ?
>> In another word , I want to know the reverse operation of ConstantExpr::getPtrPtrFromArrayPtr .
>
>I'm not sure I understand. You have a pointer to "E1$entry" and you want
>the string it points to? I assume this is what your findValue
>function does?
>
>-Chris
More information about the llvm-dev
mailing list