I'm going down the route of marking the variable declaration as "named
register" in SemaDecl (ActOnVariableDeclarator) and then adding the
intrinsic at the initialization time.
Since it has no explicit initializer, it ends up in the
TentativeDefinitions array, which gets initialized in
ActOnEndOfTranslationUnit. But that's not what I want, since this
"variable" doesn't exist, per se, but I still need to keep it around
for replacing all reads/writes by an intrinsic.
Also, while parsing statements that contain a reference to this
variable, the diagnostics on the use of the global variable detect an
"undeclared local variable":
named_reg_global.c:4:10: error: reference to local variable
'current_stack_pointer' declared in enclosing context
named_reg_global.c:1:24: note: 'current_stack_pointer' declared here
register unsigned long current_stack_pointer asm("sp");
This looks like I'm not setting the right flags beforehand, so that
ParseStatement recognizes it's not a local variable, or just that I
still haven't found the right place to do the substitution.
ParseStatementOrDeclarationAfterAttributes has a switch with
"identifier" in it, but that doesn't seem a specific enough place to
add this logic. Any pointers?
The changes I made to stop marking the declaration invalid and to mark
it as "named register" is attached. Not that this would be the final
patch, but it's helping me understand the code.
named-regs.patch (3.62 KB)