[LLVMdev] Structure declaration with IR builder

Garba,Peter Peter.Garba at safenet-inc.com
Thu Jan 31 01:14:41 PST 2013


Hi,

that's what I'm doing ...

//Init the struct type
  llvm::StructType *structReg = llvm::StructType::create(TargetModule->getContext(),vMember, "struct.Foo");
  structRegPtr = llvm::PointerType::get(structReg, 0);

//Create a llvm function
    llvm::FunctionType* ty = llvm::FunctionType::get(llvm::Type::getInt32Ty(TargetModule->getContext()),structRegPtr,false);
    llvm::Constant *c = TargetModule->getOrInsertFunction(BB.getBlockName(),ty);
    fTest = llvm::cast<llvm::Function>(c);
    fTest ->setCallingConv(llvm::CallingConv::C);

//Access the struct members
llvm:Value *ArgValuePtr = builder->CreateStructGEP(fTest ->arg_begin(),0,"ptrMember1");
llvm::Valuie *StructValue = builder->CreateLoad(ArgValuePtr,false,"member1");

Cheers,
Peter

Peter Garba - Software Engineer - +49 (0)89 894221 190 - Peter.Garba at safenet-inc.com


-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Manuele Conti
Sent: Donnerstag, 31. Januar 2013 08:49
To: llvmdev at cs.uiuc.edu
Subject: [LLVMdev] Structure declaration with IR builder

Hi All,
I tryed to create a global structured derived declaration in my compiler by:
StructType *st = StructType(getGlobalContext(),  elements, false);

In dump module i didn't find any code needed to declare a new user data type.

Is there a instruction to add this class into current module?


Cheers,
Manuele
_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

________________________________________________

SFNT Germany GmbH
Registered office: Gabriele-Muenter-Str. 1
D-82110 Germering, Germany
Managing director (Gesch?ftsf?hrer): Gary Clark
Company Registration number: Amtsgericht Muenchen HRB 171025
________________________________________________
The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.






More information about the llvm-dev mailing list