Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1186 | savelij | 1 | /* asmlabel.c */ |
| 2 | /*****************************************************************************/ |
||
| 3 | /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only */ |
||
| 4 | /* */ |
||
| 5 | /* AS Port */ |
||
| 6 | /* */ |
||
| 7 | /* Handle Label on Source Line */ |
||
| 8 | /* */ |
||
| 9 | /*****************************************************************************/ |
||
| 10 | |||
| 11 | /* ------------------------------------------------------------------------ |
||
| 12 | * Includes |
||
| 13 | * ------------------------------------------------------------------------ */ |
||
| 14 | |||
| 15 | #include "stdinc.h" |
||
| 16 | #include <string.h> |
||
| 17 | |||
| 18 | #include "asmdef.h" |
||
| 19 | #include "asmsub.h" |
||
| 20 | #include "asmpars.h" |
||
| 21 | #include "asmstructs.h" |
||
| 22 | #include "strcomp.h" |
||
| 23 | |||
| 24 | #include "asmlabel.h" |
||
| 25 | |||
| 26 | /* ------------------------------------------------------------------------ |
||
| 27 | * Local Variables |
||
| 28 | * ------------------------------------------------------------------------ */ |
||
| 29 | |||
| 30 | static PStructElem pLabelElement; |
||
| 31 | static struct sSymbolEntry *pLabelEntry; |
||
| 32 | static LargeWord LabelValue; |
||
| 33 | |||
| 34 | /* ------------------------------------------------------------------------ |
||
| 35 | * Global Functions |
||
| 36 | * ------------------------------------------------------------------------ */ |
||
| 37 | |||
| 38 | /*!------------------------------------------------------------------------ |
||
| 39 | * \fn LabelReset(void) |
||
| 40 | * \brief reset state about most recent label |
||
| 41 | * ------------------------------------------------------------------------ */ |
||
| 42 | |||
| 43 | void LabelReset(void) |
||
| 44 | { |
||
| 45 | pLabelElement = NULL; |
||
| 46 | pLabelEntry = NULL; |
||
| 47 | LabelValue = (LargeWord)-1; |
||
| 48 | } |
||
| 49 | |||
| 50 | /*!------------------------------------------------------------------------ |
||
| 51 | * \fn LabelPresent(void) |
||
| 52 | * \brief check whether line contains a label |
||
| 53 | * \return True if label is present |
||
| 54 | * ------------------------------------------------------------------------ */ |
||
| 55 | |||
| 56 | Boolean LabelPresent(void) |
||
| 57 | { |
||
| 58 | if (!*LabPart.str.p_str) |
||
| 59 | return False; |
||
| 60 | if (IsDef()) |
||
| 61 | return False; |
||
| 62 | |||
| 63 | switch (*OpPart.str.p_str) |
||
| 64 | { |
||
| 65 | case '=': |
||
| 66 | return !Memo("="); |
||
| 67 | case ':': |
||
| 68 | return !Memo(":="); |
||
| 69 | case '.': |
||
| 70 | return !Memo(".SET") && !Memo(".EQU"); |
||
| 71 | case 'M': |
||
| 72 | return !Memo("MACRO"); |
||
| 73 | case 'F': |
||
| 74 | return !Memo("FUNCTION"); |
||
| 75 | case 'L': |
||
| 76 | return !Memo("LABEL"); |
||
| 77 | case 'S': |
||
| 78 | return !memo_set_pseudo() && (!(Memo("STRUCT") || Memo("STRUC"))); |
||
| 79 | case 'E': |
||
| 80 | if (Memo("EQU") || Memo("ENDSTRUCT") || Memo("ENDS") || Memo("ENDSTRUC") || Memo("ENDUNION")) |
||
| 81 | return False; |
||
| 82 | return !Memo("EVAL"); |
||
| 83 | case 'U': |
||
| 84 | return !Memo("UNION"); |
||
| 85 | default: |
||
| 86 | return True; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | /*!------------------------------------------------------------------------ |
||
| 91 | * \fn LabelHandle(const tStrComp *pName, LargeWord Value, Boolean ForceGlobal) |
||
| 92 | * \brief process new label |
||
| 93 | * \param pName label's name |
||
| 94 | * \param Value label's value |
||
| 95 | * \param ForceGlobal force visibility outside macro body |
||
| 96 | * ------------------------------------------------------------------------ */ |
||
| 97 | |||
| 98 | void LabelHandle(const tStrComp *pName, LargeWord Value, Boolean ForceGlobal) |
||
| 99 | { |
||
| 100 | pLabelElement = NULL; |
||
| 101 | pLabelEntry = NULL; |
||
| 102 | |||
| 103 | /* structure element ? */ |
||
| 104 | |||
| 105 | if (pInnermostNamedStruct) |
||
| 106 | { |
||
| 107 | pLabelElement = CreateStructElem(pName); |
||
| 108 | if (!pLabelElement) |
||
| 109 | return; |
||
| 110 | |||
| 111 | pLabelElement->Offset = Value; |
||
| 112 | if (AddStructElem(pInnermostNamedStruct->StructRec, pLabelElement)) |
||
| 113 | AddStructSymbol(pLabelElement->pElemName, Value); |
||
| 114 | } |
||
| 115 | |||
| 116 | /* normal label */ |
||
| 117 | |||
| 118 | else |
||
| 119 | { |
||
| 120 | if (ForceGlobal) |
||
| 121 | PushLocHandle(-1); |
||
| 122 | if (RelSegs) |
||
| 123 | pLabelEntry = EnterRelSymbol(pName, Value, (as_addrspace_t)ActPC, False); |
||
| 124 | else |
||
| 125 | { |
||
| 126 | pLabelEntry = EnterIntSymbolWithFlags(pName, Value, (as_addrspace_t)ActPC, False, |
||
| 127 | eSymbolFlag_Label | |
||
| 128 | (Value == AfterBSRAddr ? eSymbolFlag_NextLabelAfterBSR : eSymbolFlag_None)); |
||
| 129 | } |
||
| 130 | if (ForceGlobal) |
||
| 131 | PopLocHandle(); |
||
| 132 | } |
||
| 133 | LabelValue = Value; |
||
| 134 | } |
||
| 135 | |||
| 136 | /*!------------------------------------------------------------------------ |
||
| 137 | * \fn LabelModify(LargeWord OldValue, LargeWord NewValue) |
||
| 138 | * \brief change value of current label |
||
| 139 | * \param OldValue current value to check consistency |
||
| 140 | * \param NewValue new value to assign |
||
| 141 | * ------------------------------------------------------------------------ */ |
||
| 142 | |||
| 143 | void LabelModify(LargeWord OldValue, LargeWord NewValue) |
||
| 144 | { |
||
| 145 | if (OldValue == LabelValue) |
||
| 146 | { |
||
| 147 | if (pLabelElement) |
||
| 148 | pLabelElement->Offset = NewValue; |
||
| 149 | if (pLabelEntry) |
||
| 150 | ChangeSymbol(pLabelEntry, NewValue); |
||
| 151 | LabelValue = NewValue; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | /*!------------------------------------------------------------------------ |
||
| 156 | * \fn AsmLabelPassInit(void) |
||
| 157 | * \brief Initializations before passing through sources |
||
| 158 | * ------------------------------------------------------------------------ */ |
||
| 159 | |||
| 160 | void AsmLabelPassInit(void) |
||
| 161 | { |
||
| 162 | LabelReset(); |
||
| 163 | } |
||
| 164 | |||
| 165 | /*!------------------------------------------------------------------------ |
||
| 166 | * \fn asmlabel_init(void) |
||
| 167 | * \brief Initializations once at startup |
||
| 168 | * ------------------------------------------------------------------------ */ |
||
| 169 | |||
| 170 | void asmlabel_init(void) |
||
| 171 | { |
||
| 172 | LabelReset(); |
||
| 173 | } |