From: uz Date: Fri, 12 Nov 2010 18:01:31 +0000 (+0000) Subject: Define the __XX_START__ symbol for a memory area earlier, so it may be used in X-Git-Tag: V2.13.3~603 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=de14990fbb66506c6357da55fc57a57194dbe756;p=cc65 Define the __XX_START__ symbol for a memory area earlier, so it may be used in the expression for the size of the same area. git-svn-id: svn://svn.cc65.org/cc65/trunk@4852 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/config.c b/src/ld65/config.c index 623264358..a67a3127e 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -1764,13 +1764,32 @@ unsigned CfgProcess (void) /* Remember if this is a relocatable memory area */ M->Relocatable = RelocatableBinFmt (M->F->Format); - /* Resolve the start address expression */ + /* Resolve the start address expression, remember the start address + * and mark the memory area as placed. + */ if (!IsConstExpr (M->StartExpr)) { CfgError (&M->Pos, "Start address of memory area `%s' is not constant", GetString (M->Name)); } - M->Start = GetExprVal (M->StartExpr); + Addr = M->Start = GetExprVal (M->StartExpr); + M->Flags |= MF_PLACED; + + /* If requested, define the symbol for the start of the memory area. + * Doing it here means that the expression for the size of the area + * may reference this symbol. + */ + if (M->Flags & MF_DEFINE) { + Export* E; + StrBuf Buf = STATIC_STRBUF_INITIALIZER; + + /* Define the start of the memory area */ + SB_Printf (&Buf, "__%s_START__", GetString (M->Name)); + E = CreateMemoryExport (GetStrBufId (&Buf), M, 0); + E->Pos = M->Pos; + + SB_Done (&Buf); + } /* Resolve the size expression */ if (!IsConstExpr (M->SizeExpr)) { @@ -1780,12 +1799,6 @@ unsigned CfgProcess (void) } M->Size = GetExprVal (M->SizeExpr); - /* Mark the memory area as placed */ - M->Flags |= MF_PLACED; - - /* Get the start address of this memory area */ - Addr = M->Start; - /* Walk through the segments in this memory area */ for (J = 0; J < CollCount (&M->SegList); ++J) { @@ -1886,11 +1899,6 @@ unsigned CfgProcess (void) Export* E; StrBuf Buf = STATIC_STRBUF_INITIALIZER; - /* Define the start of the memory area */ - SB_Printf (&Buf, "__%s_START__", GetString (M->Name)); - E = CreateMemoryExport (GetStrBufId (&Buf), M, 0); - E->Pos = M->Pos; - /* Define the size of the memory area */ SB_Printf (&Buf, "__%s_SIZE__", GetString (M->Name)); E = CreateConstExport (GetStrBufId (&Buf), M->Size);