Hi,
I was wondering if it was possible to create a Dummy Type by subclassing LLVM
Type.
I do not want to create a new type or even do much with this dummy type , all I
need
is a placeholder type until I generate IR.
I want to use this approach as most of my AST is already configured to
accept a Type* and not a DummyType* ( which is my own class )
I explored this a bit and did manage to create one.
========== DummyType class ========
class DummyType : public llvm::Type
{
private:
std::string typeIdentifier;
public:
DummyType(const std::string& typeIdentifier,TypeID
tyId):typeIdentifier(typeIdentifier),Type(TheContext,tyId)
{
}
std::string getTypeIdentifierString() const
{
return this->typeIdentifier ;
}
};
===========================================
Now ,
Type* ty = new DummyType() works.
However , I wish to use "dynamic_cast<>" at runtime but I'm
unable to do so.
example - DummyType* dum_type = dynamic_cast<DummyType>(ty) ; // where ty
is a Type*
I get the following error -
error: 'llvm::Type' is not polymorphic
Is there some way around this ( without suggesting a change to my entire AST ) ?
Any help will be appreciated.
Thanks,
Malhar
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20170609/84c71614/attachment.html>
On 9 June 2017 at 12:03, Jajoo, Malhar via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Is there some way around this ( without suggesting a change to my entire AST ) ?LLVM has its own lightweight dynamic casting infrastructure which the Type hierarchy already makes use of. You have to implement a "classof" function in your DummyType definition. That means you'll need a new type ID. Appropriating an unused one is slightly dodgy, but probably OK in practice if you're careful. After that you'd write "dyn_cast" instead of "dynamic_cast", since that's what the LLVM version is called. Cheers. Tim.
This [1] might worth reading, Malhar. [1] http://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html 2017-06-10 4:12 GMT+08:00 Tim Northover via llvm-dev < llvm-dev at lists.llvm.org>:> On 9 June 2017 at 12:03, Jajoo, Malhar via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > Is there some way around this ( without suggesting a change to my entire > AST ) ? > > LLVM has its own lightweight dynamic casting infrastructure which the > Type hierarchy already makes use of. > > You have to implement a "classof" function in your DummyType > definition. That means you'll need a new type ID. Appropriating an > unused one is slightly dodgy, but probably OK in practice if you're > careful. > > After that you'd write "dyn_cast" instead of "dynamic_cast", since > that's what the LLVM version is called. > > Cheers. > > Tim. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170610/8f5386ab/attachment.html>