1 /*****************************************************************************/
5 /* Code segment entry */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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 /*****************************************************************************/
56 /*****************************************************************************/
58 /*****************************************************************************/
63 #define CEF_USERMARK 0x0001U /* Generic mark by user functions */
64 #define CEF_NUMARG 0x0002U /* Insn has numerical argument */
66 /* Code entry structure */
67 typedef struct CodeEntry CodeEntry;
69 opc_t OPC; /* Opcode */
70 am_t AM; /* Adressing mode */
71 char* Arg; /* Argument as string */
72 unsigned long Num; /* Numeric argument */
73 unsigned short Flags; /* Flags */
74 unsigned short Info; /* Additional code info */
75 unsigned short Use; /* Registers used */
76 unsigned short Chg; /* Registers changed/destroyed */
77 unsigned char Size; /* Estimated size */
78 CodeLabel* JumpTo; /* Jump label */
79 Collection Labels; /* Labels for this instruction */
80 LineInfo* LI; /* Source line info for this insn */
81 RegInfo* RI; /* Register info for this insn */
86 /*****************************************************************************/
88 /*****************************************************************************/
92 CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
93 CodeLabel* JumpTo, LineInfo* LI);
94 /* Create a new code entry, initialize and return it */
96 void FreeCodeEntry (CodeEntry* E);
97 /* Free the given code entry */
99 void CE_ReplaceOPC (CodeEntry* E, opc_t OPC);
100 /* Replace the opcode of the instruction. This will also replace related info,
101 * Size, Use and Chg, but it will NOT update any arguments or labels.
104 int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2);
105 /* Check if both code entries are equal */
107 void CE_AttachLabel (CodeEntry* E, CodeLabel* L);
108 /* Attach the label to the entry */
110 #if defined(HAVE_INLINE)
111 INLINE int CE_HasLabel (const CodeEntry* E)
112 /* Check if the given code entry has labels attached */
114 return (CollCount (&E->Labels) > 0);
117 # define CE_HasLabel(E) (CollCount (&(E)->Labels) > 0)
120 #if defined(HAVE_INLINE)
121 INLINE unsigned CE_GetLabelCount (const CodeEntry* E)
122 /* Get the number of labels attached to this entry */
124 return CollCount (&E->Labels);
127 # define CE_GetLabelCount(E) CollCount (&(E)->Labels)
130 #if defined(HAVE_INLINE)
131 INLINE CodeLabel* CE_GetLabel (CodeEntry* E, unsigned Index)
132 /* Get a label from this code entry */
134 return CollAt (&E->Labels, Index);
137 # define CE_GetLabel(E, Index) CollAt (&(E)->Labels, (Index))
140 void CE_MoveLabel (CodeLabel* L, CodeEntry* E);
141 /* Move the code label L from it's former owner to the code entry E. */
143 #if defined(HAVE_INLINE)
144 INLINE int CE_HasMark (const CodeEntry* E)
145 /* Return true if the given code entry has the CEF_USERMARK flag set */
147 return (E->Flags & CEF_USERMARK) != 0;
150 # define CE_HasMark(E) (((E)->Flags & CEF_USERMARK) != 0)
153 #if defined(HAVE_INLINE)
154 INLINE void CE_SetMark (CodeEntry* E)
155 /* Set the CEF_USERMARK flag for the given entry */
157 E->Flags |= CEF_USERMARK;
160 # define CE_SetMark(E) ((E)->Flags |= CEF_USERMARK)
163 #if defined(HAVE_INLINE)
164 INLINE void CE_ResetMark (CodeEntry* E)
165 /* Reset the CEF_USERMARK flag for the given entry */
167 E->Flags &= ~CEF_USERMARK;
170 # define CE_ResetMark(E) ((E)->Flags &= ~CEF_USERMARK)
173 void CE_SetNumArg (CodeEntry* E, long Num);
174 /* Set a new numeric argument for the given code entry that must already
175 * have a numeric argument.
178 int CE_KnownImm (const CodeEntry* E);
179 /* Return true if the argument of E is a known immediate value */
181 #if defined(HAVE_INLINE)
182 INLINE int CE_IsCall (const CodeEntry* E, const char* Name)
183 /* Check if this is a call to the given function */
185 return (E->OPC == OP65_JSR && strcmp (E->Arg, Name) == 0);
188 # define CE_IsCall(E, Name) ((E)->OPC == OP65_JSR && strcmp ((E)->Arg, (Name)) == 0)
191 void CE_FreeRegInfo (CodeEntry* E);
192 /* Free an existing register info struct */
194 void CE_GenRegInfo (CodeEntry* E, RegContents* InputRegs);
195 /* Generate register info for this instruction. If an old info exists, it is
199 void CE_Output (const CodeEntry* E, FILE* F);
200 /* Output the code entry to a file */
204 /* End of codeent.h */