[cc65] Temporary zero-page allocation

From: doynax <doynax1gmail.com>
Date: 2013-10-27 09:51:08
As the title states I'm wondering whether anyone on the list may have some
ideas on schemes for dealing with zero-page "register" allocation.

My usual approach is to set up an array of virtual registers for any
function to use, and whenever I need (say) a pointer just to grab a pair of
these. Unfortunately you often need multiple levels of function calls, or
return values from one function to survive another sub-function call and
the like. My vague "scheme" thus far has been to allocate bottom-up in the
leaves and top-down in callers, combined with randomly fiddling with
assignments to solve any conflicts which might crop up.

Naturally this is a major source of particularly nasty bugs so the response
of my naturally lazy self has been to forgo the virtual register file in
any remotely tricky cases and instead fill up the zero-page with permanent
one-off variables for anything and everything.

Anyway, I can't imagine I'm the only one with this particular problem and
the CC65 toolchain seems geared towards managing "large" projects so I
though I'd ask here. Obviously if the linker had supported full-on global
live variable and call-graph tracking it would have been used for local
variable assignments in C, but that doesn't mean that there aren't viable
manual schemes to help out and handle the simple cases.

First of all .asserts can always be used in more-or-less automated ways to
check for conflicts.

Perhaps the simplest and most wasteful allocation scheme would be to set up
unique data segments for every call level and manually allocate the
temporaries from the appropriate depth class into these. For extra credit
symbols defining the depth of the every function may then be used for
asserting that no conflicts with the children exist.

A slightly more efficient scheme would be to somehow start register
allocation from the top of the register file for leaf functions, then let
callers advance the base by the maximum usage of any callee. Essentially
you'd define a symbol with the static stack pointer for every function. I'm
not sure if you could get the linker to compute the maximum or whether that
would have to be resolved at assembly-time.

Finally I suppose I could manually write a bunch of meta-data defining the
use-def chains and call graph, then extract these with a script and perform
the allocation externally.

Any ideas? How do you all deal with this?

Regards,
Johan

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Oct 27 09:51:19 2013

This archive was generated by hypermail 2.1.8 : 2013-10-27 09:51:22 CET