This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Getting a static const char * assembled in place?

Hi, I'm tinkering with some experiments in type introspection, and part of that's generating a 'name' member for types, methods, members, etc.

The code I've written (ends up in cc1plus, called from cp/pt.c:instantiate_class_template), generates the VAR_DECL for a static const char * member named 'name.' However, any reference to it ends up generating assembly that refers to it as an external entity (which won't be found). I'd like it to just assemble to a locally-defined string. Here's an example to clarify:

For code:
struct foo {
 static const char * const s = "foobar";
        char *f;

int main() {
int printf(const char *, ...) throw ();
return printf("%s-%s", foo::s, std::type_description<foo>::name);

It currently generates:

        .align 2
        .ascii "%s-%s\0"
        .align 2
        .ascii "foobar\0"
        .align 2
        .globl _main
        lis r3,ha16(__ZNSt16type_descriptionI3fooE4nameE)
        lis r2,ha16(LC0)
        lwz r5,lo16(__ZNSt16type_descriptionI3fooE4nameE)(r3)
        la r3,lo16(LC0)(r2)
        lis r2,ha16(LC1)
        la r4,lo16(LC1)(r2)
        b __Z6printfPKcz

I'd like type_description<foo>::name to generate similar asm to foo::s. My extension generates a VAR_DECL for type_description<foo>, but it apparently isn't right, despite it looking quite similar to the VAR_DECL for foo::s. I've got the initial value in as well. Yeah, I had to force cp/decl.c:check_static_variable_definition to always return 0 to get this to work, but it'll be normal when I'm finished (I just needed foo::s to compile).

So, finally, my question: where's the decision made how to refer to the strings (inline like foo::s or externally like type_description<foo>::name) in the generated asm? I just need an idea where to look for how the trees are interpreted.

-- Government is not reason, it is not eloquence, it is force; like fire, a troublesome servant and a fearful master. Never for a moment should it be left to irresponsible action.
- George Washington

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]