1 /*****************************************************************************/
5 /* Code/data fragment routines */
9 /* (C) 1998-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
50 /*****************************************************************************/
52 /*****************************************************************************/
56 static FragCheck* NewFragCheck (unsigned Action)
57 /* Allocate a new FragCheck struct and return it */
60 FragCheck* FC = xmalloc (sizeof (FragCheck));
62 /* Initialize the fields */
66 FC->Message = INVALID_STRING_ID;
68 /* Return the new struct */
74 FragCheck* ReadFragCheck (FILE* F, Fragment* Frag)
75 /* Read a fragment check expression from the given file */
77 /* Get the object file pointer from the fragment */
78 ObjData* O = Frag->Obj;
80 /* Read the action and create a new struct */
81 FragCheck* FC = NewFragCheck (ReadVar (F));
83 /* Determine the remaining data from the action */
88 FC->Expr = ReadExpr (F, O);
89 FC->Message = MakeGlobalStringId (O, ReadVar (F));
93 Internal ("In module `%s', file `%s', line %lu: Invalid fragment "
96 GetSourceFileName (O, Frag->Pos.Name),
97 Frag->Pos.Line, FC->Action);
100 /* Return the new fragment check */
106 Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S)
107 /* Create a new fragment and insert it into the section S */
111 /* Calculate the size of the memory block. LitBuf is only needed if the
112 * fragment contains literal data.
114 unsigned FragSize = sizeof (Fragment) - 1;
115 if (Type == FRAG_LITERAL) {
119 /* Allocate memory */
120 F = xmalloc (FragSize);
122 /* Initialize the data */
127 InitFilePos (&F->Pos);
132 /* Insert the code fragment into the section */
133 if (S->FragRoot == 0) {
137 S->FragLast->Next = F;
141 /* Increment the size of the section by the size of the fragment */
144 /* Increment the size of the segment that contains the section */
145 S->Seg->Size += Size;
147 /* Return the new fragment */