Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1186 | savelij | 1 | /* lstmacroexp.c */ |
2 | /*****************************************************************************/ |
||
3 | /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */ |
||
4 | /* */ |
||
5 | /* AS-Portierung */ |
||
6 | /* */ |
||
7 | /* Functions & variables regarding macro expansion in listing */ |
||
8 | /* */ |
||
9 | /*****************************************************************************/ |
||
10 | |||
11 | #include <stdio.h> |
||
12 | #include <string.h> |
||
13 | |||
14 | #include "strutil.h" |
||
15 | #include "strcomp.h" |
||
16 | #include "asmdef.h" |
||
17 | #include "asmpars.h" |
||
18 | #include "lstmacroexp.h" |
||
19 | |||
20 | #define MODIFIER_CLR 0x80 |
||
21 | #define LstMacroExpName "MACEXP" /* expandierte Makros anzeigen */ |
||
22 | |||
23 | static tLstMacroExp LstMacroExp; |
||
24 | |||
25 | /*!------------------------------------------------------------------------ |
||
26 | * \fn SetLstMacroExp(tLstMacroExp NewLstMacroExp) |
||
27 | * \brief Set a new value for the 'effective' value of what is expanded in listing |
||
28 | * \param NewLstMacroExp new value to be set |
||
29 | * ------------------------------------------------------------------------ */ |
||
30 | |||
31 | void SetLstMacroExp(tLstMacroExp NewLstMacroExp) |
||
32 | { |
||
33 | tStrComp TmpComp; |
||
34 | String TmpCompStr; |
||
35 | StrCompMkTemp(&TmpComp, TmpCompStr, sizeof(TmpCompStr)); |
||
36 | |||
37 | LstMacroExp = NewLstMacroExp; |
||
38 | strmaxcpy(TmpCompStr, LstMacroExpName, sizeof(TmpCompStr)); EnterIntSymbol(&TmpComp, NewLstMacroExp, SegNone, True); |
||
39 | if (LstMacroExp == eLstMacroExpAll) |
||
40 | strcpy(ListLine, "ALL"); |
||
41 | else if (LstMacroExp == eLstMacroExpNone) |
||
42 | strcpy(ListLine, "NONE"); |
||
43 | else |
||
44 | { |
||
45 | if (LstMacroExp & eLstMacroExpMacro) |
||
46 | { |
||
47 | strmaxcat(ListLine, *ListLine ? "+" : "=", STRINGSIZE); |
||
48 | strmaxcat(ListLine, "MACRO", STRINGSIZE); |
||
49 | } |
||
50 | if (LstMacroExp & eLstMacroExpIf) |
||
51 | { |
||
52 | strmaxcat(ListLine, *ListLine ? "+" : "=", STRINGSIZE); |
||
53 | strmaxcat(ListLine, "IF", STRINGSIZE); |
||
54 | } |
||
55 | if (LstMacroExp & eLstMacroExpRest) |
||
56 | { |
||
57 | strmaxcat(ListLine, *ListLine ? "+" : "=", STRINGSIZE); |
||
58 | strmaxcat(ListLine, "REST", STRINGSIZE); |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | /*!------------------------------------------------------------------------ |
||
64 | * \fn GetLstMacroExp(void) |
||
65 | * \brief Retrieve value of what is currently 'effectively' expanded in listing |
||
66 | * \return value |
||
67 | * ------------------------------------------------------------------------ */ |
||
68 | |||
69 | tLstMacroExp GetLstMacroExp(void) |
||
70 | { |
||
71 | return LstMacroExp; |
||
72 | } |
||
73 | |||
74 | /*!------------------------------------------------------------------------ |
||
75 | * \fn Inverse(Byte Mod1, Byte Mod2) |
||
76 | * \brief check whether one modifier is the exact inverse of another modifier |
||
77 | * \param Mod1, Mod2 modifiers to be analyzed |
||
78 | * \return True of Mod1 is the exact inverse of Mod2 |
||
79 | * ------------------------------------------------------------------------ */ |
||
80 | |||
81 | static Boolean Inverse(Byte Mod1, Byte Mod2) |
||
82 | { |
||
83 | return (Mod1 ^ Mod2) == MODIFIER_CLR; |
||
84 | } |
||
85 | |||
86 | /*!------------------------------------------------------------------------ |
||
87 | * \fn InitLstMacroExpMod(tLstMacroExpMod *pLstMacroExpMod) |
||
88 | * \brief initialize/clear list of macro expansion modifiers |
||
89 | * \param pLstMacroExpMod list to be initialized |
||
90 | * ------------------------------------------------------------------------ */ |
||
91 | |||
92 | void InitLstMacroExpMod(tLstMacroExpMod *pLstMacroExpMod) |
||
93 | { |
||
94 | pLstMacroExpMod->Count = 0; |
||
95 | } |
||
96 | |||
97 | /*!------------------------------------------------------------------------ |
||
98 | * \fn AddLstMacroExpMod(tLstMacroExpMod *pLstMacroExpMod, Boolean Set, tLstMacroExp Mod) |
||
99 | * \brief extend/modify a list of modifiers |
||
100 | * \param pLstMacroExpMod list to be updated |
||
101 | * \param Set is the modifier a set or clear modifier? |
||
102 | * \param Mod component to be set/cleared |
||
103 | * \return True if modifier could be added, otherwise list is full (should not occur?) |
||
104 | * ------------------------------------------------------------------------ */ |
||
105 | |||
106 | Boolean AddLstMacroExpMod(tLstMacroExpMod *pLstMacroExpMod, Boolean Set, tLstMacroExp Mod) |
||
107 | { |
||
108 | Byte NewModifier = Mod | (Set ? 0 : MODIFIER_CLR); |
||
109 | unsigned z, dest; |
||
110 | |||
111 | /* trim out any inverse modifier that is totally neutralized by the new one */ |
||
112 | |||
113 | for (z = dest = 0; z < pLstMacroExpMod->Count; z++) |
||
114 | if (!Inverse(pLstMacroExpMod->Modifiers[z], NewModifier)) |
||
115 | pLstMacroExpMod->Modifiers[dest++] = pLstMacroExpMod->Modifiers[z]; |
||
116 | pLstMacroExpMod->Count = dest; |
||
117 | |||
118 | /* add the new one */ |
||
119 | |||
120 | if (pLstMacroExpMod->Count >= LSTMACROEXPMOD_MAX) |
||
121 | return False; |
||
122 | else |
||
123 | { |
||
124 | pLstMacroExpMod->Modifiers[pLstMacroExpMod->Count++] = NewModifier; |
||
125 | return True; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | /*!------------------------------------------------------------------------ |
||
130 | * \fn ChkLstMacroExpMod(const tLstMacroExpMod *pLstMacroExpMod) |
||
131 | * \brief check whether a modifier list is contradiction-free |
||
132 | * \param pLstMacroExpMod list to be checked |
||
133 | * \return True if list contains no contradictions |
||
134 | * ------------------------------------------------------------------------ */ |
||
135 | |||
136 | Boolean ChkLstMacroExpMod(const tLstMacroExpMod *pLstMacroExpMod) |
||
137 | { |
||
138 | unsigned z1, z2; |
||
139 | |||
140 | for (z1 = 0; z1 < pLstMacroExpMod->Count; z1++) |
||
141 | for (z2 = z1 + 1; z2 < pLstMacroExpMod->Count; z2++) |
||
142 | if (Inverse(pLstMacroExpMod->Modifiers[z1], pLstMacroExpMod->Modifiers[z2])) |
||
143 | return False; |
||
144 | return True; |
||
145 | } |
||
146 | |||
147 | /*!------------------------------------------------------------------------ |
||
148 | * \fn DumpLstMacroExpMod(const tLstMacroExpMod *pLstMacroExpMod, char *pDest, int DestLen) |
||
149 | * \brief transform modifier list to human-readable form |
||
150 | * \param pLstMacroExpMod list to be transformed |
||
151 | * \param pDest where to write human-readable form |
||
152 | * \param DestLen size of dest buffer |
||
153 | * ------------------------------------------------------------------------ */ |
||
154 | |||
155 | void DumpLstMacroExpMod(const tLstMacroExpMod *pLstMacroExpMod, char *pDest, int DestLen) |
||
156 | { |
||
157 | unsigned z; |
||
158 | |||
159 | for (z = 0; z < pLstMacroExpMod->Count; z++) |
||
160 | { |
||
161 | if (z) |
||
162 | strmaxcat(pDest, ",", DestLen); |
||
163 | strmaxcat(pDest, (pLstMacroExpMod->Modifiers[z] & MODIFIER_CLR) ? "NOEXP" : "EXP", DestLen); |
||
164 | switch (pLstMacroExpMod->Modifiers[z] & ~MODIFIER_CLR) |
||
165 | { |
||
166 | case eLstMacroExpRest: |
||
167 | strmaxcat(pDest, "REST", DestLen); break; |
||
168 | case eLstMacroExpIf: |
||
169 | strmaxcat(pDest, "IF", DestLen); break; |
||
170 | case eLstMacroExpMacro: |
||
171 | strmaxcat(pDest, "MACRO", DestLen); break; |
||
172 | case eLstMacroExpAll: |
||
173 | strmaxcat(pDest, "AND", DestLen); break; |
||
174 | default: |
||
175 | strmaxcat(pDest, "?", DestLen); |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | |||
180 | /*!------------------------------------------------------------------------ |
||
181 | * \fn ApplyLstMacroExpMod(tLstMacroExp Src, const tLstMacroExpMod *pLstMacroExpMod) |
||
182 | * \brief apply a list of modifiers to a listing macro expansion bit field |
||
183 | * \param Src original value of bit field |
||
184 | * \param pLstMacroExpMod list of modifiers |
||
185 | * \return resulting new mask |
||
186 | * ------------------------------------------------------------------------ */ |
||
187 | |||
188 | tLstMacroExp ApplyLstMacroExpMod(tLstMacroExp Src, const tLstMacroExpMod *pLstMacroExpMod) |
||
189 | { |
||
190 | unsigned z; |
||
191 | |||
192 | for (z = 0; z < pLstMacroExpMod->Count; z++) |
||
193 | { |
||
194 | if (pLstMacroExpMod->Modifiers[z] & MODIFIER_CLR) |
||
195 | Src &= ~((tLstMacroExp)pLstMacroExpMod->Modifiers[z] & eLstMacroExpAll); |
||
196 | else |
||
197 | Src |= (tLstMacroExp)pLstMacroExpMod->Modifiers[z]; |
||
198 | } |
||
199 | return Src; |
||
200 | } |