[LLVMdev] Getting A Type By Name

Chris Lattner sabre at nondot.org
Wed Dec 31 01:01:01 PST 2003

On Tue, 30 Dec 2003, Reid Spencer wrote:

> What's the RightWay(tm) to get a named type? I want to use the Module's
> symbol table as a repository for named types. But, it doesn't have a way
> to get the type out unless you already know what it is (i.e. the
> addTypeName() method). Similarly the SymbolTable class's lookup() method
> requires a type as well. The Type class also didn't have anything
> obvious.

Yup, currently you have to directly access the Module's symbol table.
Types have class 'Type::TypeTy', so you would do something like this:

Type *Module::getNamedType(const std::string &name) {
  SymbolTable &SymTab = getSymbolTable();
  return cast_or_null<Type>(SymTab.lookup(Type::TypeTy, name));

> which returns the type if found or null if not found.
> This is too simple to not be implemented so I figured I'm looking in the
> wrong places.

Heh, well it's so simple, it's not yet implemented :).  I'll add this



More information about the llvm-dev mailing list