1 /*****************************************************************************/
5 /* Code segment structure */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
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 /*****************************************************************************/
59 /*****************************************************************************/
60 /* Helper functions */
61 /*****************************************************************************/
65 static void CS_MoveLabelsToEntry (CodeSeg* S, CodeEntry* E)
66 /* Move all labels from the label pool to the given entry and remove them
70 /* Transfer the labels if we have any */
72 unsigned LabelCount = CollCount (&S->Labels);
73 for (I = 0; I < LabelCount; ++I) {
76 CodeLabel* L = CollAt (&S->Labels, I);
78 /* Attach it to the entry */
79 CE_AttachLabel (E, L);
82 /* Delete the transfered labels */
83 CollDeleteAll (&S->Labels);
88 static void CS_MoveLabelsToPool (CodeSeg* S, CodeEntry* E)
89 /* Move the labels of the code entry E to the label pool of the code segment */
91 unsigned LabelCount = CE_GetLabelCount (E);
92 while (LabelCount--) {
93 CodeLabel* L = CE_GetLabel (E, LabelCount);
95 CollAppend (&S->Labels, L);
97 CollDeleteAll (&E->Labels);
102 static CodeLabel* CS_FindLabel (CodeSeg* S, const char* Name, unsigned Hash)
103 /* Find the label with the given name. Return the label or NULL if not found */
105 /* Get the first hash chain entry */
106 CodeLabel* L = S->LabelHash[Hash];
108 /* Search the list */
110 if (strcmp (Name, L->Name) == 0) {
121 static CodeLabel* CS_NewCodeLabel (CodeSeg* S, const char* Name, unsigned Hash)
122 /* Create a new label and insert it into the label hash table */
124 /* Create a new label */
125 CodeLabel* L = NewCodeLabel (Name, Hash);
127 /* Enter the label into the hash table */
128 L->Next = S->LabelHash[L->Hash];
129 S->LabelHash[L->Hash] = L;
131 /* Return the new label */
137 static void CS_RemoveLabelFromHash (CodeSeg* S, CodeLabel* L)
138 /* Remove the given code label from the hash list */
140 /* Get the first entry in the hash chain */
141 CodeLabel* List = S->LabelHash[L->Hash];
144 /* First, remove the label from the hash chain */
146 /* First entry in hash chain */
147 S->LabelHash[L->Hash] = L->Next;
149 /* Must search through the chain */
150 while (List->Next != L) {
151 /* If we've reached the end of the chain, something is *really* wrong */
152 CHECK (List->Next != 0);
156 /* The next entry is the one, we have been searching for */
157 List->Next = L->Next;
163 static CodeLabel* CS_AddLabelInternal (CodeSeg* S, const char* Name, int UserCode)
164 /* Add a code label for the next instruction to follow */
166 /* Calculate the hash from the name */
167 unsigned Hash = HashStr (Name) % CS_LABEL_HASH_SIZE;
169 /* Try to find the code label if it does already exist */
170 CodeLabel* L = CS_FindLabel (S, Name, Hash);
172 /* Did we find it? */
174 /* We found it - be sure it does not already have an owner */
177 Error ("ASM label `%s' is already defined", Name);
179 Internal ("CS_AddLabelInternal: Label `%s' already defined", Name);
183 /* Not found - create a new one */
184 L = CS_NewCodeLabel (S, Name, Hash);
187 /* Safety. This call is quite costly, but safety is better */
188 if (CollIndex (&S->Labels, L) >= 0) {
190 Error ("ASM label `%s' is already defined", Name);
192 Internal ("CS_AddLabelInternal: Label `%s' already defined", Name);
196 /* We do now have a valid label. Remember it for later */
197 CollAppend (&S->Labels, L);
199 /* Return the label */
205 /*****************************************************************************/
206 /* Functions for parsing instructions */
207 /*****************************************************************************/
211 static const char* SkipSpace (const char* S)
212 /* Skip white space and return an updated pointer */
214 while (IsSpace (*S)) {
222 static const char* ReadToken (const char* L, const char* Term,
223 char* Buf, unsigned BufSize)
224 /* Read the next token into Buf, return the updated line pointer. The
225 * token is terminated by one of the characters given in term.
228 /* Read/copy the token */
230 unsigned ParenCount = 0;
231 while (*L && (ParenCount > 0 || strchr (Term, *L) == 0)) {
237 } else if (*L == '(') {
243 /* Terminate the buffer contents */
246 /* Return the updated line pointer */
252 static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
253 /* Parse an instruction nnd generate a code entry from it. If the line contains
254 * errors, output an error message and return NULL.
255 * For simplicity, we don't accept the broad range of input a "real" assembler
256 * does. The instruction and the argument are expected to be separated by
257 * white space, for example.
262 am_t AM = 0; /* Initialize to keep gcc silent */
268 /* Read the first token and skip white space after it */
269 L = SkipSpace (ReadToken (L, " \t:", Mnemo, sizeof (Mnemo)));
271 /* Check if we have a label */
274 /* Skip the colon and following white space */
278 CS_AddLabelInternal (S, Mnemo, 1);
280 /* If we have reached end of line, bail out, otherwise a mnemonic
287 L = SkipSpace (ReadToken (L, " \t", Mnemo, sizeof (Mnemo)));
290 /* Try to find the opcode description for the mnemonic */
291 OPC = FindOP65 (Mnemo);
293 /* If we didn't find the opcode, print an error and bail out */
295 Error ("ASM code error: %s is not a valid mnemonic", Mnemo);
299 /* Get the addressing mode */
310 StrCopy (Arg, sizeof (Arg), L+1);
316 L = ReadToken (L+1, ",)", Arg, sizeof (Arg));
318 /* Check for errors */
320 Error ("ASM code error: syntax error");
324 /* Check the different indirect modes */
326 /* Expect zp x indirect */
328 if (toupper (*L) != 'X') {
329 Error ("ASM code error: `X' expected");
334 Error ("ASM code error: `)' expected");
339 Error ("ASM code error: syntax error");
343 } else if (*L == ')') {
344 /* zp indirect or zp indirect, y */
348 if (toupper (*L) != 'Y') {
349 Error ("ASM code error: `Y' expected");
354 Error ("ASM code error: syntax error");
358 } else if (*L == '\0') {
361 Error ("ASM code error: syntax error");
377 /* Absolute, maybe indexed */
378 L = ReadToken (L, ",", Arg, sizeof (Arg));
380 /* Absolute, zeropage or branch */
381 if ((OPC->Info & OF_BRA) != 0) {
384 } else if (GetZPInfo(Arg) != 0) {
389 } else if (*L == ',') {
393 Error ("ASM code error: syntax error");
399 if (GetZPInfo(Arg) != 0) {
404 } else if (Reg == 'Y') {
407 Error ("ASM code error: syntax error");
411 Error ("ASM code error: syntax error");
420 /* If the instruction is a branch, check for the label and generate it
421 * if it does not exist. Ignore anything but local labels here.
424 if (AM == AM65_BRA && Arg[0] == 'L') {
426 /* Generate the hash over the label, then search for the label */
427 unsigned Hash = HashStr (Arg) % CS_LABEL_HASH_SIZE;
428 Label = CS_FindLabel (S, Arg, Hash);
430 /* If we don't have the label, it's a forward ref - create it */
432 /* Generate a new label */
433 Label = CS_NewCodeLabel (S, Arg, Hash);
437 /* We do now have the addressing mode in AM. Allocate a new CodeEntry
438 * structure and initialize it.
440 E = NewCodeEntry (OPC->OPC, AM, Arg, Label, LI);
442 /* Return the new code entry */
448 /*****************************************************************************/
450 /*****************************************************************************/
454 CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
455 /* Create a new code segment, initialize and return it */
460 /* Allocate memory */
461 CodeSeg* S = xmalloc (sizeof (CodeSeg));
463 /* Initialize the fields */
464 S->SegName = xstrdup (SegName);
466 InitCollection (&S->Entries);
467 InitCollection (&S->Labels);
468 for (I = 0; I < sizeof(S->LabelHash) / sizeof(S->LabelHash[0]); ++I) {
472 /* If we have a function given, get the return type of the function.
473 * Assume ANY return type besides void will use the A and X registers.
475 if (S->Func && !IsTypeVoid ((RetType = GetFuncReturn (Func->Type)))) {
476 if (SizeOf (RetType) == SizeOf (type_long)) {
477 S->ExitRegs = REG_EAX;
479 S->ExitRegs = REG_AX;
482 S->ExitRegs = REG_NONE;
485 /* Return the new struct */
491 void CS_AddEntry (CodeSeg* S, struct CodeEntry* E)
492 /* Add an entry to the given code segment */
494 /* Transfer the labels if we have any */
495 CS_MoveLabelsToEntry (S, E);
497 /* Add the entry to the list of code entries in this segment */
498 CollAppend (&S->Entries, E);
503 void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
504 /* Add a line to the given code segment */
510 /* Format the line */
512 xvsprintf (Buf, sizeof (Buf), Format, ap);
514 /* Skip whitespace */
517 /* Check which type of instruction we have */
518 E = 0; /* Assume no insn created */
522 /* Empty line, just ignore it */
526 /* Comment or hint, ignore it for now */
530 /* Control instruction */
531 ReadToken (L, " \t", Token, sizeof (Token));
532 Error ("ASM code error: Pseudo instruction `%s' not supported", Token);
536 E = ParseInsn (S, LI, L);
540 /* If we have a code entry, transfer the labels and insert it */
548 void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, ...)
549 /* Add a line to the given code segment */
552 va_start (ap, Format);
553 CS_AddVLine (S, LI, Format, ap);
559 void CS_InsertEntry (CodeSeg* S, struct CodeEntry* E, unsigned Index)
560 /* Insert the code entry at the index given. Following code entries will be
561 * moved to slots with higher indices.
564 /* Insert the entry into the collection */
565 CollInsert (&S->Entries, E, Index);
570 void CS_DelEntry (CodeSeg* S, unsigned Index)
571 /* Delete an entry from the code segment. This includes moving any associated
572 * labels, removing references to labels and even removing the referenced labels
573 * if the reference count drops to zero.
576 /* Get the code entry for the given index */
577 CodeEntry* E = CS_GetEntry (S, Index);
579 /* If the entry has a labels, we have to move this label to the next insn.
580 * If there is no next insn, move the label into the code segement label
581 * pool. The operation is further complicated by the fact that the next
582 * insn may already have a label. In that case change all reference to
583 * this label and delete the label instead of moving it.
585 unsigned Count = CE_GetLabelCount (E);
588 /* The instruction has labels attached. Check if there is a next
591 if (Index == CS_GetEntryCount (S)-1) {
593 /* No next instruction, move to the codeseg label pool */
594 CS_MoveLabelsToPool (S, E);
598 /* There is a next insn, get it */
599 CodeEntry* N = CS_GetEntry (S, Index+1);
601 /* Move labels to the next entry */
602 CS_MoveLabels (S, E, N);
607 /* If this insn references a label, remove the reference. And, if the
608 * the reference count for this label drops to zero, remove this label.
611 /* Remove the reference */
612 CS_RemoveLabelRef (S, E);
615 /* Delete the pointer to the insn */
616 CollDelete (&S->Entries, Index);
618 /* Delete the instruction itself */
624 void CS_DelEntries (CodeSeg* S, unsigned Start, unsigned Count)
625 /* Delete a range of code entries. This includes removing references to labels,
626 * labels attached to the entries and so on.
629 /* Start deleting the entries from the rear, because this involves less
633 CS_DelEntry (S, Start + Count);
639 void CS_MoveEntries (CodeSeg* S, unsigned Start, unsigned Count, unsigned NewPos)
640 /* Move a range of entries from one position to another. Start is the index
641 * of the first entry to move, Count is the number of entries and NewPos is
642 * the index of the target entry. The entry with the index Start will later
643 * have the index NewPos. All entries with indices NewPos and above are
644 * moved to higher indices. If the code block is moved to the end of the
645 * current code, and if pending labels exist, these labels will get attached
646 * to the first instruction of the moved block (the first one after the
650 /* If NewPos is at the end of the code segment, move any labels from the
651 * label pool to the first instruction of the moved range.
653 if (NewPos == CS_GetEntryCount (S)) {
654 CS_MoveLabelsToEntry (S, CS_GetEntry (S, Start));
657 /* Move the code block to the destination */
658 CollMoveMultiple (&S->Entries, Start, Count, NewPos);
663 struct CodeEntry* CS_GetPrevEntry (CodeSeg* S, unsigned Index)
664 /* Get the code entry preceeding the one with the index Index. If there is no
665 * preceeding code entry, return NULL.
669 /* This is the first entry */
672 /* Previous entry available */
673 return CollAtUnchecked (&S->Entries, Index-1);
679 struct CodeEntry* CS_GetNextEntry (CodeSeg* S, unsigned Index)
680 /* Get the code entry following the one with the index Index. If there is no
681 * following code entry, return NULL.
684 if (Index >= CollCount (&S->Entries)-1) {
685 /* This is the last entry */
688 /* Code entries left */
689 return CollAtUnchecked (&S->Entries, Index+1);
695 int CS_GetEntries (CodeSeg* S, struct CodeEntry** List,
696 unsigned Start, unsigned Count)
697 /* Get Count code entries into List starting at index start. Return true if
698 * we got the lines, return false if not enough lines were available.
701 /* Check if enough entries are available */
702 if (Start + Count > CollCount (&S->Entries)) {
706 /* Copy the entries */
708 *List++ = CollAtUnchecked (&S->Entries, Start++);
711 /* We have the entries */
717 unsigned CS_GetEntryIndex (CodeSeg* S, struct CodeEntry* E)
718 /* Return the index of a code entry */
720 int Index = CollIndex (&S->Entries, E);
727 CodeLabel* CS_AddLabel (CodeSeg* S, const char* Name)
728 /* Add a code label for the next instruction to follow */
730 return CS_AddLabelInternal (S, Name, 0);
735 CodeLabel* CS_GenLabel (CodeSeg* S, struct CodeEntry* E)
736 /* If the code entry E does already have a label, return it. Otherwise
737 * create a new label, attach it to E and return it.
742 if (CE_HasLabel (E)) {
744 /* Get the label from this entry */
745 L = CE_GetLabel (E, 0);
750 const char* Name = LocalLabelName (GetLocalLabel ());
752 /* Generate the hash over the name */
753 unsigned Hash = HashStr (Name) % CS_LABEL_HASH_SIZE;
755 /* Create a new label */
756 L = CS_NewCodeLabel (S, Name, Hash);
758 /* Attach this label to the code entry */
759 CE_AttachLabel (E, L);
763 /* Return the label */
769 void CS_DelLabel (CodeSeg* S, CodeLabel* L)
770 /* Remove references from this label and delete it. */
774 /* First, remove the label from the hash chain */
775 CS_RemoveLabelFromHash (S, L);
777 /* Remove references from insns jumping to this label */
778 Count = CollCount (&L->JumpFrom);
779 for (I = 0; I < Count; ++I) {
780 /* Get the insn referencing this label */
781 CodeEntry* E = CollAt (&L->JumpFrom, I);
782 /* Remove the reference */
785 CollDeleteAll (&L->JumpFrom);
787 /* Remove the reference to the owning instruction if it has one. The
788 * function may be called for a label without an owner when deleting
789 * unfinished parts of the code. This is unfortunate since it allows
790 * errors to slip through.
793 CollDeleteItem (&L->Owner->Labels, L);
796 /* All references removed, delete the label itself */
802 void CS_MergeLabels (CodeSeg* S)
803 /* Merge code labels. That means: For each instruction, remove all labels but
804 * one and adjust references accordingly.
809 /* Walk over all code entries */
810 for (I = 0; I < CS_GetEntryCount (S); ++I) {
815 /* Get a pointer to the next entry */
816 CodeEntry* E = CS_GetEntry (S, I);
818 /* If this entry has zero labels, continue with the next one */
819 unsigned LabelCount = CE_GetLabelCount (E);
820 if (LabelCount == 0) {
824 /* We have at least one label. Use the first one as reference label. */
825 RefLab = CE_GetLabel (E, 0);
827 /* Walk through the remaining labels and change references to these
828 * labels to a reference to the one and only label. Delete the labels
829 * that are no longer used. To increase performance, walk backwards
832 for (J = LabelCount-1; J >= 1; --J) {
834 /* Get the next label */
835 CodeLabel* L = CE_GetLabel (E, J);
837 /* Move all references from this label to the reference label */
838 CL_MoveRefs (L, RefLab);
840 /* Remove the label completely. */
844 /* The reference label is the only remaining label. Check if there
845 * are any references to this label, and delete it if this is not
848 if (CollCount (&RefLab->JumpFrom) == 0) {
849 /* Delete the label */
850 CS_DelLabel (S, RefLab);
857 void CS_MoveLabels (CodeSeg* S, struct CodeEntry* Old, struct CodeEntry* New)
858 /* Move all labels from Old to New. The routine will move the labels itself
859 * if New does not have any labels, and move references if there is at least
860 * a label for new. If references are moved, the old label is deleted
864 /* Get the number of labels to move */
865 unsigned OldLabelCount = CE_GetLabelCount (Old);
867 /* Does the new entry have itself a label? */
868 if (CE_HasLabel (New)) {
870 /* The new entry does already have a label - move references */
871 CodeLabel* NewLabel = CE_GetLabel (New, 0);
872 while (OldLabelCount--) {
874 /* Get the next label */
875 CodeLabel* OldLabel = CE_GetLabel (Old, OldLabelCount);
877 /* Move references */
878 CL_MoveRefs (OldLabel, NewLabel);
880 /* Delete the label */
881 CS_DelLabel (S, OldLabel);
887 /* The new entry does not have a label, just move them */
888 while (OldLabelCount--) {
890 /* Move the label to the new entry */
891 CE_MoveLabel (CE_GetLabel (Old, OldLabelCount), New);
900 void CS_RemoveLabelRef (CodeSeg* S, struct CodeEntry* E)
901 /* Remove the reference between E and the label it jumps to. The reference
902 * will be removed on both sides and E->JumpTo will be 0 after that. If
903 * the reference was the only one for the label, the label will get
907 /* Get a pointer to the label and make sure it exists */
908 CodeLabel* L = E->JumpTo;
911 /* Delete the entry from the label */
912 CollDeleteItem (&L->JumpFrom, E);
914 /* The entry jumps no longer to L */
917 /* If there are no more references, delete the label */
918 if (CollCount (&L->JumpFrom) == 0) {
925 void CS_MoveLabelRef (CodeSeg* S, struct CodeEntry* E, CodeLabel* L)
926 /* Change the reference of E to L instead of the current one. If this
927 * was the only reference to the old label, the old label will get
931 /* Get the old label */
932 CodeLabel* OldLabel = E->JumpTo;
934 /* Be sure that code entry references a label */
935 PRECONDITION (OldLabel != 0);
937 /* Remove the reference to our label */
938 CS_RemoveLabelRef (S, E);
940 /* Use the new label */
946 void CS_DelCodeAfter (CodeSeg* S, unsigned Last)
947 /* Delete all entries including the given one */
949 /* Get the number of entries in this segment */
950 unsigned Count = CS_GetEntryCount (S);
952 /* First pass: Delete all references to labels. If the reference count
953 * for a label drops to zero, delete it.
958 /* Get the next entry */
959 CodeEntry* E = CS_GetEntry (S, C);
961 /* Check if this entry has a label reference */
963 /* If the label is a label in the label pool and this is the last
964 * reference to the label, remove the label from the pool.
966 CodeLabel* L = E->JumpTo;
967 int Index = CollIndex (&S->Labels, L);
968 if (Index >= 0 && CollCount (&L->JumpFrom) == 1) {
969 /* Delete it from the pool */
970 CollDelete (&S->Labels, Index);
973 /* Remove the reference to the label */
974 CS_RemoveLabelRef (S, E);
979 /* Second pass: Delete the instructions. If a label attached to an
980 * instruction still has references, it must be references from outside
981 * the deleted area. Don't delete the label in this case, just make it
982 * ownerless and move it to the label pool.
987 /* Get the next entry */
988 CodeEntry* E = CS_GetEntry (S, C);
990 /* Check if this entry has a label attached */
991 if (CE_HasLabel (E)) {
992 /* Move the labels to the pool and clear the owner pointer */
993 CS_MoveLabelsToPool (S, E);
996 /* Delete the pointer to the entry */
997 CollDelete (&S->Entries, C);
999 /* Delete the entry itself */
1006 void CS_Output (const CodeSeg* S, FILE* F)
1007 /* Output the code segment data to a file */
1012 /* Get the number of entries in this segment */
1013 unsigned Count = CS_GetEntryCount (S);
1015 /* If the code segment is empty, bail out here */
1020 /* Output the segment directive */
1021 fprintf (F, ".segment\t\"%s\"\n\n", S->SegName);
1023 /* If this is a segment for a function, enter a function */
1025 fprintf (F, ".proc\t_%s\n\n", S->Func->Name);
1028 /* Output all entries, prepended by the line information if it has changed */
1030 for (I = 0; I < Count; ++I) {
1031 /* Get the next entry */
1032 const CodeEntry* E = CollConstAt (&S->Entries, I);
1033 /* Check if the line info has changed. If so, output the source line
1034 * if the option is enabled and output debug line info if the debug
1035 * option is enabled.
1038 /* Line info has changed, remember the new line info */
1041 /* Add the source line as a comment */
1043 fprintf (F, ";\n; %s\n;\n", LI->Line);
1046 /* Add line debug info */
1048 fprintf (F, "\t.dbg\tline, \"%s\", %u\n",
1049 GetInputName (LI), GetInputLine (LI));
1052 /* Output the code */
1056 /* If debug info is enabled, terminate the last line number information */
1058 fprintf (F, "\t.dbg\tline\n");
1061 /* If this is a segment for a function, leave the function */
1063 fprintf (F, "\n.endproc\n\n");
1069 void CS_FreeRegInfo (CodeSeg* S)
1070 /* Free register infos for all instructions */
1073 for (I = 0; I < CS_GetEntryCount (S); ++I) {
1074 CE_FreeRegInfo (CS_GetEntry(S, I));
1080 void CS_GenRegInfo (CodeSeg* S)
1081 /* Generate register infos for all instructions */
1084 RegContents Regs; /* Initial register contents */
1085 RegContents* CurrentRegs; /* Current register contents */
1086 int WasJump; /* True if last insn was a jump */
1088 /* Be sure to delete all register infos */
1091 /* On entry, the register contents are unknown */
1092 RC_Invalidate (&Regs);
1093 CurrentRegs = &Regs;
1095 /* First pass. Walk over all insns and note just the changes from one
1096 * insn to the next one.
1099 for (I = 0; I < CS_GetEntryCount (S); ++I) {
1103 /* Get the next instruction */
1104 CodeEntry* E = CollAtUnchecked (&S->Entries, I);
1106 /* If the instruction has a label, we need some special handling */
1107 unsigned LabelCount = CE_GetLabelCount (E);
1108 if (LabelCount > 0) {
1110 /* Loop over all entry points that jump here. If these entry
1111 * points already have register info, check if all values are
1112 * known and identical. If all values are identical, and the
1113 * preceeding instruction was not an unconditional branch, check
1114 * if the register value on exit of the preceeding instruction
1115 * is also identical. If all these values are identical, the
1116 * value of a register is known, otherwise it is unknown.
1118 CodeLabel* Label = CE_GetLabel (E, 0);
1121 /* Preceeding insn was an unconditional branch */
1122 CodeEntry* J = CL_GetRef(Label, 0);
1126 RC_Invalidate (&Regs);
1130 Regs = *CurrentRegs;
1134 while (Entry < CL_GetRefCount (Label)) {
1135 /* Get this entry */
1136 CodeEntry* J = CL_GetRef (Label, Entry);
1138 /* No register info for this entry, bail out */
1139 RC_Invalidate (&Regs);
1142 if (J->RI->Out2.RegA != Regs.RegA) {
1145 if (J->RI->Out2.RegX != Regs.RegX) {
1148 if (J->RI->Out2.RegY != Regs.RegY) {
1151 if (J->RI->Out2.SRegLo != Regs.SRegLo) {
1154 if (J->RI->Out2.SRegHi != Regs.SRegHi) {
1160 /* Use this register info */
1161 CurrentRegs = &Regs;
1165 /* Generate register info for this instruction */
1166 CE_GenRegInfo (E, CurrentRegs);
1168 /* Remember for the next insn if this insn was an uncondition branch */
1169 WasJump = (E->Info & OF_UBRA) != 0;
1171 /* Output registers for this insn are input for the next */
1172 CurrentRegs = &E->RI->Out;
1174 /* If this insn is a branch on zero flag, we may have more info on
1175 * register contents for one of both flow directions, but only if
1176 * there is a previous instruction.
1178 if ((E->Info & OF_ZBRA) != 0 && (P = CS_GetPrevEntry (S, I)) != 0) {
1180 /* Get the branch condition */
1181 bc_t BC = GetBranchCond (E->OPC);
1183 /* Check the previous instruction */
1195 /* A is zero in one execution flow direction */
1197 E->RI->Out2.RegA = 0;
1199 E->RI->Out.RegA = 0;
1204 /* If this is an immidiate compare, the A register has
1205 * the value of the compare later.
1207 if (CE_KnownImm (P)) {
1209 E->RI->Out2.RegA = (unsigned char)P->Num;
1211 E->RI->Out.RegA = (unsigned char)P->Num;
1217 /* If this is an immidiate compare, the X register has
1218 * the value of the compare later.
1220 if (CE_KnownImm (P)) {
1222 E->RI->Out2.RegX = (unsigned char)P->Num;
1224 E->RI->Out.RegX = (unsigned char)P->Num;
1230 /* If this is an immidiate compare, the Y register has
1231 * the value of the compare later.
1233 if (CE_KnownImm (P)) {
1235 E->RI->Out2.RegY = (unsigned char)P->Num;
1237 E->RI->Out.RegY = (unsigned char)P->Num;
1246 /* X is zero in one execution flow direction */
1248 E->RI->Out2.RegX = 0;
1250 E->RI->Out.RegX = 0;
1258 /* X is zero in one execution flow direction */
1260 E->RI->Out2.RegY = 0;
1262 E->RI->Out.RegY = 0;
1268 /* If the branch is a beq, both A and X are zero at the
1269 * branch target, otherwise they are zero at the next
1273 E->RI->Out2.RegA = E->RI->Out2.RegX = 0;
1275 E->RI->Out.RegA = E->RI->Out.RegX = 0;
1281 /* If the branch is a beq, both A and Y are zero at the
1282 * branch target, otherwise they are zero at the next
1286 E->RI->Out2.RegA = E->RI->Out2.RegY = 0;
1288 E->RI->Out.RegA = E->RI->Out.RegY = 0;