2000-11-02 22:11:25 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* fragment.c */
|
|
|
|
|
/* */
|
|
|
|
|
/* Code/data fragment routines */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2003-05-25 17:57:50 +00:00
|
|
|
|
/* (C) 1998-2003 Ullrich von Bassewitz */
|
|
|
|
|
/* R<>merstrasse 52 */
|
|
|
|
|
/* D-70794 Filderstadt */
|
2001-05-23 19:03:40 +00:00
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-11-02 22:11:25 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
|
/* */
|
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
|
/* distribution. */
|
|
|
|
|
/* */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2000-11-20 21:56:48 +00:00
|
|
|
|
|
2000-11-02 22:11:25 +00:00
|
|
|
|
|
|
|
|
|
/* common */
|
2003-06-03 22:19:46 +00:00
|
|
|
|
#include "segdefs.h"
|
2000-11-02 22:11:25 +00:00
|
|
|
|
#include "xmalloc.h"
|
|
|
|
|
|
|
|
|
|
/* ld65 */
|
|
|
|
|
#include "segments.h"
|
|
|
|
|
#include "fragment.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Code */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-03 22:19:46 +00:00
|
|
|
|
Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S)
|
2000-11-02 22:11:25 +00:00
|
|
|
|
/* Create a new fragment and insert it into the section S */
|
|
|
|
|
{
|
2003-06-03 22:19:46 +00:00
|
|
|
|
Fragment* F;
|
|
|
|
|
|
|
|
|
|
/* Calculate the size of the memory block. LitBuf is only needed if the
|
|
|
|
|
* fragment contains literal data.
|
|
|
|
|
*/
|
|
|
|
|
unsigned FragSize = sizeof (Fragment) - 1;
|
|
|
|
|
if (Type == FRAG_LITERAL) {
|
|
|
|
|
FragSize += Size;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-02 22:11:25 +00:00
|
|
|
|
/* Allocate memory */
|
2003-06-03 22:19:46 +00:00
|
|
|
|
F = xmalloc (FragSize);
|
2000-11-02 22:11:25 +00:00
|
|
|
|
|
|
|
|
|
/* Initialize the data */
|
2003-05-25 17:57:50 +00:00
|
|
|
|
F->Next = 0;
|
|
|
|
|
F->Obj = 0;
|
|
|
|
|
F->Size = Size;
|
|
|
|
|
F->Expr = 0;
|
2000-11-20 21:56:48 +00:00
|
|
|
|
InitFilePos (&F->Pos);
|
2003-05-25 17:57:50 +00:00
|
|
|
|
F->LI = 0;
|
2003-06-03 22:19:46 +00:00
|
|
|
|
F->Check = 0;
|
2003-05-25 17:57:50 +00:00
|
|
|
|
F->Type = Type;
|
2000-11-02 22:11:25 +00:00
|
|
|
|
|
2000-11-20 21:56:48 +00:00
|
|
|
|
/* Insert the code fragment into the section */
|
2000-11-02 22:11:25 +00:00
|
|
|
|
if (S->FragRoot == 0) {
|
|
|
|
|
/* First fragment */
|
|
|
|
|
S->FragRoot = F;
|
|
|
|
|
} else {
|
|
|
|
|
S->FragLast->Next = F;
|
|
|
|
|
}
|
|
|
|
|
S->FragLast = F;
|
2000-11-20 21:56:48 +00:00
|
|
|
|
|
|
|
|
|
/* Increment the size of the section by the size of the fragment */
|
2000-11-02 22:11:25 +00:00
|
|
|
|
S->Size += Size;
|
|
|
|
|
|
2000-11-20 21:56:48 +00:00
|
|
|
|
/* Increment the size of the segment that contains the section */
|
|
|
|
|
S->Seg->Size += Size;
|
|
|
|
|
|
2000-11-02 22:11:25 +00:00
|
|
|
|
/* Return the new fragment */
|
|
|
|
|
return F;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|