How to change calling convention.

From within HandleTopLevelDecl, I’m trying to modify a function’s calling convention if it is not explicitly given. getType() returns a const though. Any suggestions how to modify the underlying type?

Also, what would be the best way to call a method on the Lexer from BackendConsumer::HandleTopLevelDecl?

Thanks,

Todd

From within HandleTopLevelDecl, I’m trying to modify a function’s calling
convention if it is not explicitly given. getType() returns a const
though. Any suggestions how to modify the underlying type?

Types are immutable, but FunctionDecl's do have a setType method.

Also, what would be the best way to call a method on the Lexer from
BackendConsumer::HandleTopLevelDecl?

What are you trying to do?

-Eli

I tried creating a copy of the type using the copy constructor of FunctionType but that just gave me a bunch of compile errors about the Type constructor being private. Then I wanted to change the calling convention of that copied type and call setType. I'm currently trying to construct a new FunctionType using get methods on the previous type to fill in the parts that remain constant. The problem at the moment is that isVariadic() seems to be private but I presume that function types cannot be Variadic so I'll just pass false there and then try setType.

What I'm trying to do is add pragmas that control the default calling convention. If there is a way to do this all within the Lexer rather than changing it afterwards I'm all ears.

Todd

I tried creating a copy of the type using the copy constructor of FunctionType but that just gave me a bunch of compile errors about the Type constructor being private.

There are methods to build new types on ASTContext.

Then I wanted to change the calling convention of that copied type and call setType. I'm currently trying to construct a new FunctionType using get methods on the previous type to fill in the parts that remain constant. The problem at the moment is that isVariadic() seems to be private but I presume that function types cannot be Variadic so I'll just pass false there and then try setType.

There are two kinds of FunctionType: FunctionProtoType and
FunctionNoProtoType. They need to be handled slightly differently.

What I'm trying to do is add pragmas that control the default calling convention. If there is a way to do this all within the Lexer rather than changing it afterwards I'm all ears.

There are some existing pragmas that are a bit similar; look in
lib/Parse/ParsePragma.cpp.

-Eli