[LLVMdev] Building a new struct type, etc

Chris Lattner sabre at nondot.org
Tue Jan 28 14:05:01 PST 2003

> I was just wondering if someone would be willing to tell me the best way
> to make a new structure type in LLVM and get it inserted as a valid type
> into a particular Module instance?

I know you've already figured out a solution, but here's an answer for
others who may be wondering the same:

> I've done the following:
>         vector<const Type*> types;
>         types.push_back(Type::UIntTy);
>         types.push_back(Type::UIntTy);
>         structType = StructType::get(types);
> But can't seem to find any member functions in Module that allow me to
> introduce this as a new type...

Modules don't need to do anything special to use types: types are global
things which do not belong to a particular module.  If you want to insert
a name into a particular module for a type (creating a '%foo = type {
uint,uint}' declaration in the llvm assembly), use the Module::addTypeName

> Furthermore, how would I create a (preferably static) global instance of
> the above structure type, together with a static initializer for it?

Do something like this:

#include "Support/VectorExtras.h"
static const Type *Ty = StructType::get(make_vector(Type::UIntTy,
                                                    Type::UIntTy, 0));



More information about the llvm-dev mailing list