geon wrote:
So, if file A depends on File B and C, and File B and C both depend on file D, What file should include what?
After a bit of experimentation, the approach I finally settled on was to use the include directive only in the top-level file for the application, and directly include dependencies before the things that depend upon them. In other words:
Code:
include "D"
include "B"
include "C"
include "A"
In some cases the "dependecies" are not actually other files, but just things that need to be defined for a particular platform. For example, my 6800 monitor in `pmon.a68` needs to have `pmon_ramlo`, `pmon_org` and various other things set before the assembler starts assembling it, so I do all that in the top-level file for the particular platform (in my case, currently a simulated machine run in Python and a National/Panasonic JR-200) and then `include "src/mc68/pmon.a68"`.
In either case, I try to ensure that if I forget something some reasonably clear error message is produced. For the pmon thing above, I use
AS's `pushv` and `popv` directives (which save and restore symbol values) on them as a no-op that will fail if they're not defined:
Code:
; Abort assembly with a clear message if an essential definition is missing.
set ______,
pushv , pmon_ramlo, rdlinebuf, rdlinebuf_end, pmon_org
popv , ______, ______, ______, ______
(That first `set` just ensures that the symbol `______` is defined so that I can restore the values to it, which merely makes for a bit less text for the programmer to read and interpret, and makes it slightly more clear that this is a no-op.)
As well as avoiding the risk of a file being included multiple times, I find that having a top-level file that mentions
every other file used in the assembly makes it easier to understand the program as a whole and do optimization on it because I'm never getting stuff dragged in that I might not notice. That's not necessarily an approach I'd be taking with higher-level languages on larger systems, but if I'm writing anything substantial in assembler, I'm almost certainly quite concerned about program size and speed.