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 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
61 #define CEF_USERMARK 0x0001U /* Generic mark by user functions */
62 #define CEF_NUMARG 0x0002U /* Insn has numerical argument */
64 /* Code entry structure */
65 typedef struct CodeEntry CodeEntry;
67 opc_t OPC; /* Opcode */
68 am_t AM; /* Adressing mode */
69 char* Arg; /* Argument as string */
70 unsigned long Num; /* Numeric argument */
71 unsigned short Flags; /* Flags */
72 unsigned char Size; /* Estimated size */
73 unsigned char Info; /* Additional code info */
74 unsigned char Use; /* Registers used */
75 unsigned char Chg; /* Registers changed/destroyed */
76 CodeLabel* JumpTo; /* Jump label */
77 Collection Labels; /* Labels for this instruction */
78 LineInfo* LI; /* Source line info for this insn */
83 /*****************************************************************************/
85 /*****************************************************************************/
89 CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
90 CodeLabel* JumpTo, LineInfo* LI);
91 /* Create a new code entry, initialize and return it */
93 void FreeCodeEntry (CodeEntry* E);
94 /* Free the given code entry */
96 void ReplaceOPC (CodeEntry* E, opc_t OPC);
97 /* Replace the opcode of the instruction. This will also replace related info,
98 * Size, Use and Chg, but it will NOT update any arguments or labels.
101 int CodeEntriesAreEqual (const CodeEntry* E1, const CodeEntry* E2);
102 /* Check if both code entries are equal */
104 void AttachCodeLabel (CodeEntry* E, CodeLabel* L);
105 /* Attach the label to the entry */
107 #if defined(HAVE_INLINE)
108 INLINE int CodeEntryHasLabel (const CodeEntry* E)
109 /* Check if the given code entry has labels attached */
111 return (CollCount (&E->Labels) > 0);
114 # define CodeEntryHasLabel(E) (CollCount (&(E)->Labels) > 0)
117 #if defined(HAVE_INLINE)
118 INLINE unsigned GetCodeLabelCount (const CodeEntry* E)
119 /* Get the number of labels attached to this entry */
121 return CollCount (&E->Labels);
124 # define GetCodeLabelCount(E) CollCount (&(E)->Labels)
127 #if defined(HAVE_INLINE)
128 INLINE CodeLabel* GetCodeLabel (CodeEntry* E, unsigned Index)
129 /* Get a label from this code entry */
131 return CollAt (&E->Labels, Index);
134 # define GetCodeLabel(E, Index) CollAt (&(E)->Labels, (Index))
137 void MoveCodeLabel (CodeLabel* L, CodeEntry* E);
138 /* Move the code label L from it's former owner to the code entry E. */
140 #if defined(HAVE_INLINE)
141 INLINE int CodeEntryHasMark (const CodeEntry* E)
142 /* Return true if the given code entry has the CEF_USERMARK flag set */
144 return (E->Flags & CEF_USERMARK) != 0;
147 # define CodeEntryHasMark(E) (((E)->Flags & CEF_USERMARK) != 0)
150 #if defined(HAVE_INLINE)
151 INLINE void CodeEntrySetMark (CodeEntry* E)
152 /* Set the CEF_USERMARK flag for the given entry */
154 E->Flags |= CEF_USERMARK;
157 # define CodeEntrySetMark(E) ((E)->Flags |= CEF_USERMARK)
160 #if defined(HAVE_INLINE)
161 INLINE void CodeEntryResetMark (CodeEntry* E)
162 /* Reset the CEF_USERMARK flag for the given entry */
164 E->Flags &= ~CEF_USERMARK;
167 # define CodeEntryResetMark(E) ((E)->Flags &= ~CEF_USERMARK)
170 void CodeEntrySetArg (CodeEntry* E, const char* Arg);
171 /* Set a new argument for the given code entry. An old string is deleted. */
173 void OutputCodeEntry (const CodeEntry* E, FILE* F);
174 /* Output the code entry to a file */
178 /* End of codeent.h */