[cfe-dev] How to implement a custom (meta-) CallingConv ?
Nat!
nat at mulle-kybernetik.com
Wed May 27 12:58:51 PDT 2015
With the inlining problem basically solved, here's my second question.
What I would like to achieve is to create my own CallingConvention, or something to that effect. I would want to keep the native calling convention (ABI) intact, but reorganize the parameters and also the return value into a struct.
Here's a simplified example, which I hope makes this clearer:
---
struct bar
{
double a;
int b;
};
struct bar foo( void *p, char *c, double a);
---
would be effectively turned into
---
struct foo_args
{
char *c;
double a;
};
struct foo_rval // pedantic ;)
{
struct bar rval;
};
struct foo_args_rval
{
struct foo_rval rval;
struct foo_args args;
};
void foo( void *p, struct foo_args_rval *params)
---
I think I can achieve that if I hack the AST for the caller and callee, but it's a bit daunting. I would have to rewrite all AST accesses to parameters to params->args for instance.
I would prefer to create something like a custom CallingConvention, where I think I can just keep the AST intact.
In the code I saw
enum CallingConv {
CC_C, // __attribute__((cdecl))
CC_X86StdCall, // __attribute__((stdcall))
...
CC_IntelOclBicc // __attribute__((intel_ocl_bicc))
};
Assuming I have no problems adding a CallingConv enum and writing the necessary code, it seems I would need to pick one of the other calling conventions to base my code on. For example if I pick cdecl I would lose the passing by register. If I pick something else it might not be available on all platforms.
Any thoughts on this ?
Ciao
Nat!
---------------------------------------------------------
Ingenieure sind die Kamele, auf denen die Kaufleute
reiten. -- Unbekannt
More information about the cfe-dev
mailing list