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 /*****************************************************************************/
164 /* Functions for parsing instructions */
165 /*****************************************************************************/
169 static const char* SkipSpace (const char* S)
170 /* Skip white space and return an updated pointer */
172 while (IsSpace (*S)) {
180 static const char* ReadToken (const char* L, const char* Term,
181 char* Buf, unsigned BufSize)
182 /* Read the next token into Buf, return the updated line pointer. The
183 * token is terminated by one of the characters given in term.
186 /* Read/copy the token */
188 unsigned ParenCount = 0;
189 while (*L && (ParenCount > 0 || strchr (Term, *L) == 0)) {
195 } else if (*L == '(') {
201 /* Terminate the buffer contents */
204 /* Return the updated line pointer */
210 static CodeEntry* ParseInsn (CodeSeg* S, LineInfo* LI, const char* L)
211 /* Parse an instruction nnd generate a code entry from it. If the line contains
212 * errors, output an error message and return NULL.
213 * For simplicity, we don't accept the broad range of input a "real" assembler
214 * does. The instruction and the argument are expected to be separated by
215 * white space, for example.
220 am_t AM = 0; /* Initialize to keep gcc silent */
227 L = ReadToken (L, " \t", Mnemo, sizeof (Mnemo));
229 /* Try to find the opcode description for the mnemonic */
230 OPC = FindOP65 (Mnemo);
232 /* If we didn't find the opcode, print an error and bail out */
234 Error ("ASM code error: %s is not a valid mnemonic", Mnemo);
238 /* Skip separator white space */
241 /* Get the addressing mode */
252 StrCopy (Arg, sizeof (Arg), L+1);
258 L = ReadToken (L+1, ",)", Arg, sizeof (Arg));
260 /* Check for errors */
262 Error ("ASM code error: syntax error");
266 /* Check the different indirect modes */
268 /* Expect zp x indirect */
270 if (toupper (*L) != 'X') {
271 Error ("ASM code error: `X' expected");
276 Error ("ASM code error: `)' expected");
281 Error ("ASM code error: syntax error");
285 } else if (*L == ')') {
286 /* zp indirect or zp indirect, y */
290 if (toupper (*L) != 'Y') {
291 Error ("ASM code error: `Y' expected");
296 Error ("ASM code error: syntax error");
300 } else if (*L == '\0') {
303 Error ("ASM code error: syntax error");
319 /* Absolute, maybe indexed */
320 L = ReadToken (L, ",", Arg, sizeof (Arg));
322 /* Absolute, zeropage or branch */
323 if ((OPC->Info & OF_BRA) != 0) {
326 } else if (IsZPName (Arg, 0)) {
331 } else if (*L == ',') {
335 Error ("ASM code error: syntax error");
341 if (IsZPName (Arg, 0)) {
346 } else if (Reg == 'Y') {
349 Error ("ASM code error: syntax error");
353 Error ("ASM code error: syntax error");
362 /* If the instruction is a branch, check for the label and generate it
363 * if it does not exist. Ignore anything but local labels here.
366 if (AM == AM65_BRA && Arg[0] == 'L') {
368 /* Generate the hash over the label, then search for the label */
369 unsigned Hash = HashStr (Arg) % CS_LABEL_HASH_SIZE;
370 Label = CS_FindLabel (S, Arg, Hash);
372 /* If we don't have the label, it's a forward ref - create it */
374 /* Generate a new label */
375 Label = CS_NewCodeLabel (S, Arg, Hash);
379 /* We do now have the addressing mode in AM. Allocate a new CodeEntry
380 * structure and initialize it.
382 E = NewCodeEntry (OPC->OPC, AM, Arg, Label, LI);
384 /* Return the new code entry */
390 /*****************************************************************************/
392 /*****************************************************************************/
396 CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
397 /* Create a new code segment, initialize and return it */
402 /* Allocate memory */
403 CodeSeg* S = xmalloc (sizeof (CodeSeg));
405 /* Initialize the fields */
406 S->SegName = xstrdup (SegName);
408 InitCollection (&S->Entries);
409 InitCollection (&S->Labels);
410 for (I = 0; I < sizeof(S->LabelHash) / sizeof(S->LabelHash[0]); ++I) {
414 /* If we have a function given, get the return type of the function.
415 * Assume ANY return type besides void will use the A and X registers.
417 RetType = GetFuncReturn (Func->Type);
418 if (S->Func && !IsTypeVoid (RetType)) {
419 if (SizeOf (RetType) == SizeOf (type_long)) {
420 S->ExitRegs = REG_EAX;
422 S->ExitRegs = REG_AX;
425 S->ExitRegs = REG_NONE;
428 /* Return the new struct */
434 void CS_AddEntry (CodeSeg* S, struct CodeEntry* E)
435 /* Add an entry to the given code segment */
437 /* Transfer the labels if we have any */
438 CS_MoveLabelsToEntry (S, E);
440 /* Add the entry to the list of code entries in this segment */
441 CollAppend (&S->Entries, E);
446 void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap)
447 /* Add a line to the given code segment */
453 /* Format the line */
455 xvsprintf (Buf, sizeof (Buf), Format, ap);
457 /* Skip whitespace */
460 /* Check which type of instruction we have */
461 E = 0; /* Assume no insn created */
465 /* Empty line, just ignore it */
469 /* Comment or hint, ignore it for now */
473 /* Control instruction */
474 ReadToken (L, " \t", Token, sizeof (Token));
475 Error ("ASM code error: Pseudo instruction `%s' not supported", Token);
479 E = ParseInsn (S, LI, L);
483 /* If we have a code entry, transfer the labels and insert it */
491 void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, ...)
492 /* Add a line to the given code segment */
495 va_start (ap, Format);
496 CS_AddVLine (S, LI, Format, ap);
502 void CS_InsertEntry (CodeSeg* S, struct CodeEntry* E, unsigned Index)
503 /* Insert the code entry at the index given. Following code entries will be
504 * moved to slots with higher indices.
507 /* Insert the entry into the collection */
508 CollInsert (&S->Entries, E, Index);
513 void CS_DelEntry (CodeSeg* S, unsigned Index)
514 /* Delete an entry from the code segment. This includes moving any associated
515 * labels, removing references to labels and even removing the referenced labels
516 * if the reference count drops to zero.
519 /* Get the code entry for the given index */
520 CodeEntry* E = CS_GetEntry (S, Index);
522 /* If the entry has a labels, we have to move this label to the next insn.
523 * If there is no next insn, move the label into the code segement label
524 * pool. The operation is further complicated by the fact that the next
525 * insn may already have a label. In that case change all reference to
526 * this label and delete the label instead of moving it.
528 unsigned Count = CE_GetLabelCount (E);
531 /* The instruction has labels attached. Check if there is a next
534 if (Index == CS_GetEntryCount (S)-1) {
536 /* No next instruction, move to the codeseg label pool */
537 CS_MoveLabelsToPool (S, E);
541 /* There is a next insn, get it */
542 CodeEntry* N = CS_GetEntry (S, Index+1);
544 /* Move labels to the next entry */
545 CS_MoveLabels (S, E, N);
550 /* If this insn references a label, remove the reference. And, if the
551 * the reference count for this label drops to zero, remove this label.
554 /* Remove the reference */
555 CS_RemoveLabelRef (S, E);
558 /* Delete the pointer to the insn */
559 CollDelete (&S->Entries, Index);
561 /* Delete the instruction itself */
567 void CS_DelEntries (CodeSeg* S, unsigned Start, unsigned Count)
568 /* Delete a range of code entries. This includes removing references to labels,
569 * labels attached to the entries and so on.
572 /* Start deleting the entries from the rear, because this involves less
576 CS_DelEntry (S, Start + Count);
582 void CS_MoveEntries (CodeSeg* S, unsigned Start, unsigned Count, unsigned NewPos)
583 /* Move a range of entries from one position to another. Start is the index
584 * of the first entry to move, Count is the number of entries and NewPos is
585 * the index of the target entry. The entry with the index Start will later
586 * have the index NewPos. All entries with indices NewPos and above are
587 * moved to higher indices. If the code block is moved to the end of the
588 * current code, and if pending labels exist, these labels will get attached
589 * to the first instruction of the moved block (the first one after the
593 /* If NewPos is at the end of the code segment, move any labels from the
594 * label pool to the first instruction of the moved range.
596 if (NewPos == CS_GetEntryCount (S)) {
597 CS_MoveLabelsToEntry (S, CS_GetEntry (S, Start));
600 /* Move the code block to the destination */
601 CollMoveMultiple (&S->Entries, Start, Count, NewPos);
606 struct CodeEntry* CS_GetPrevEntry (CodeSeg* S, unsigned Index)
607 /* Get the code entry preceeding the one with the index Index. If there is no
608 * preceeding code entry, return NULL.
612 /* This is the first entry */
615 /* Previous entry available */
616 return CollAtUnchecked (&S->Entries, Index-1);
622 struct CodeEntry* CS_GetNextEntry (CodeSeg* S, unsigned Index)
623 /* Get the code entry following the one with the index Index. If there is no
624 * following code entry, return NULL.
627 if (Index >= CollCount (&S->Entries)-1) {
628 /* This is the last entry */
631 /* Code entries left */
632 return CollAtUnchecked (&S->Entries, Index+1);
638 int CS_GetEntries (CodeSeg* S, struct CodeEntry** List,
639 unsigned Start, unsigned Count)
640 /* Get Count code entries into List starting at index start. Return true if
641 * we got the lines, return false if not enough lines were available.
644 /* Check if enough entries are available */
645 if (Start + Count > CollCount (&S->Entries)) {
649 /* Copy the entries */
651 *List++ = CollAtUnchecked (&S->Entries, Start++);
654 /* We have the entries */
660 unsigned CS_GetEntryIndex (CodeSeg* S, struct CodeEntry* E)
661 /* Return the index of a code entry */
663 int Index = CollIndex (&S->Entries, E);
670 CodeLabel* CS_AddLabel (CodeSeg* S, const char* Name)
671 /* Add a code label for the next instruction to follow */
673 /* Calculate the hash from the name */
674 unsigned Hash = HashStr (Name) % CS_LABEL_HASH_SIZE;
676 /* Try to find the code label if it does already exist */
677 CodeLabel* L = CS_FindLabel (S, Name, Hash);
679 /* Did we find it? */
681 /* We found it - be sure it does not already have an owner */
682 CHECK (L->Owner == 0);
684 /* Not found - create a new one */
685 L = CS_NewCodeLabel (S, Name, Hash);
688 /* Safety. This call is quite costly, but safety is better */
689 if (CollIndex (&S->Labels, L) >= 0) {
690 Internal ("AddCodeLabel: Label `%s' already defined", Name);
693 /* We do now have a valid label. Remember it for later */
694 CollAppend (&S->Labels, L);
696 /* Return the label */
702 CodeLabel* CS_GenLabel (CodeSeg* S, struct CodeEntry* E)
703 /* If the code entry E does already have a label, return it. Otherwise
704 * create a new label, attach it to E and return it.
709 if (CE_HasLabel (E)) {
711 /* Get the label from this entry */
712 L = CE_GetLabel (E, 0);
717 const char* Name = LocalLabelName (GetLocalLabel ());
719 /* Generate the hash over the name */
720 unsigned Hash = HashStr (Name) % CS_LABEL_HASH_SIZE;
722 /* Create a new label */
723 L = CS_NewCodeLabel (S, Name, Hash);
725 /* Attach this label to the code entry */
726 CE_AttachLabel (E, L);
730 /* Return the label */
736 void CS_DelLabel (CodeSeg* S, CodeLabel* L)
737 /* Remove references from this label and delete it. */
741 /* First, remove the label from the hash chain */
742 CS_RemoveLabelFromHash (S, L);
744 /* Remove references from insns jumping to this label */
745 Count = CollCount (&L->JumpFrom);
746 for (I = 0; I < Count; ++I) {
747 /* Get the insn referencing this label */
748 CodeEntry* E = CollAt (&L->JumpFrom, I);
749 /* Remove the reference */
752 CollDeleteAll (&L->JumpFrom);
754 /* Remove the reference to the owning instruction if it has one. The
755 * function may be called for a label without an owner when deleting
756 * unfinished parts of the code. This is unfortunate since it allows
757 * errors to slip through.
760 CollDeleteItem (&L->Owner->Labels, L);
763 /* All references removed, delete the label itself */
769 void CS_MergeLabels (CodeSeg* S)
770 /* Merge code labels. That means: For each instruction, remove all labels but
771 * one and adjust references accordingly.
776 /* Walk over all code entries */
777 for (I = 0; I < CS_GetEntryCount (S); ++I) {
782 /* Get a pointer to the next entry */
783 CodeEntry* E = CS_GetEntry (S, I);
785 /* If this entry has zero labels, continue with the next one */
786 unsigned LabelCount = CE_GetLabelCount (E);
787 if (LabelCount == 0) {
791 /* We have at least one label. Use the first one as reference label. */
792 RefLab = CE_GetLabel (E, 0);
794 /* Walk through the remaining labels and change references to these
795 * labels to a reference to the one and only label. Delete the labels
796 * that are no longer used. To increase performance, walk backwards
799 for (J = LabelCount-1; J >= 1; --J) {
801 /* Get the next label */
802 CodeLabel* L = CE_GetLabel (E, J);
804 /* Move all references from this label to the reference label */
805 CL_MoveRefs (L, RefLab);
807 /* Remove the label completely. */
811 /* The reference label is the only remaining label. Check if there
812 * are any references to this label, and delete it if this is not
815 if (CollCount (&RefLab->JumpFrom) == 0) {
816 /* Delete the label */
817 CS_DelLabel (S, RefLab);
824 void CS_MoveLabels (CodeSeg* S, struct CodeEntry* Old, struct CodeEntry* New)
825 /* Move all labels from Old to New. The routine will move the labels itself
826 * if New does not have any labels, and move references if there is at least
827 * a label for new. If references are moved, the old label is deleted
831 /* Get the number of labels to move */
832 unsigned OldLabelCount = CE_GetLabelCount (Old);
834 /* Does the new entry have itself a label? */
835 if (CE_HasLabel (New)) {
837 /* The new entry does already have a label - move references */
838 CodeLabel* NewLabel = CE_GetLabel (New, 0);
839 while (OldLabelCount--) {
841 /* Get the next label */
842 CodeLabel* OldLabel = CE_GetLabel (Old, OldLabelCount);
844 /* Move references */
845 CL_MoveRefs (OldLabel, NewLabel);
847 /* Delete the label */
848 CS_DelLabel (S, OldLabel);
854 /* The new entry does not have a label, just move them */
855 while (OldLabelCount--) {
857 /* Move the label to the new entry */
858 CE_MoveLabel (CE_GetLabel (Old, OldLabelCount), New);
867 void CS_RemoveLabelRef (CodeSeg* S, struct CodeEntry* E)
868 /* Remove the reference between E and the label it jumps to. The reference
869 * will be removed on both sides and E->JumpTo will be 0 after that. If
870 * the reference was the only one for the label, the label will get
874 /* Get a pointer to the label and make sure it exists */
875 CodeLabel* L = E->JumpTo;
878 /* Delete the entry from the label */
879 CollDeleteItem (&L->JumpFrom, E);
881 /* The entry jumps no longer to L */
884 /* If there are no more references, delete the label */
885 if (CollCount (&L->JumpFrom) == 0) {
892 void CS_MoveLabelRef (CodeSeg* S, struct CodeEntry* E, CodeLabel* L)
893 /* Change the reference of E to L instead of the current one. If this
894 * was the only reference to the old label, the old label will get
898 /* Get the old label */
899 CodeLabel* OldLabel = E->JumpTo;
901 /* Be sure that code entry references a label */
902 PRECONDITION (OldLabel != 0);
904 /* Remove the reference to our label */
905 CS_RemoveLabelRef (S, E);
907 /* Use the new label */
913 void CS_DelCodeAfter (CodeSeg* S, unsigned Last)
914 /* Delete all entries including the given one */
916 /* Get the number of entries in this segment */
917 unsigned Count = CS_GetEntryCount (S);
919 /* First pass: Delete all references to labels. If the reference count
920 * for a label drops to zero, delete it.
925 /* Get the next entry */
926 CodeEntry* E = CS_GetEntry (S, C);
928 /* Check if this entry has a label reference */
930 /* If the label is a label in the label pool and this is the last
931 * reference to the label, remove the label from the pool.
933 CodeLabel* L = E->JumpTo;
934 int Index = CollIndex (&S->Labels, L);
935 if (Index >= 0 && CollCount (&L->JumpFrom) == 1) {
936 /* Delete it from the pool */
937 CollDelete (&S->Labels, Index);
940 /* Remove the reference to the label */
941 CS_RemoveLabelRef (S, E);
946 /* Second pass: Delete the instructions. If a label attached to an
947 * instruction still has references, it must be references from outside
948 * the deleted area. Don't delete the label in this case, just make it
949 * ownerless and move it to the label pool.
954 /* Get the next entry */
955 CodeEntry* E = CS_GetEntry (S, C);
957 /* Check if this entry has a label attached */
958 if (CE_HasLabel (E)) {
959 /* Move the labels to the pool and clear the owner pointer */
960 CS_MoveLabelsToPool (S, E);
963 /* Delete the pointer to the entry */
964 CollDelete (&S->Entries, C);
966 /* Delete the entry itself */
973 void CS_Output (const CodeSeg* S, FILE* F)
974 /* Output the code segment data to a file */
979 /* Get the number of entries in this segment */
980 unsigned Count = CS_GetEntryCount (S);
982 /* If the code segment is empty, bail out here */
987 /* Output the segment directive */
988 fprintf (F, ".segment\t\"%s\"\n\n", S->SegName);
990 /* If this is a segment for a function, enter a function */
992 fprintf (F, ".proc\t_%s\n\n", S->Func->Name);
995 /* Output all entries, prepended by the line information if it has changed */
997 for (I = 0; I < Count; ++I) {
998 /* Get the next entry */
999 const CodeEntry* E = CollConstAt (&S->Entries, I);
1000 /* Check if the line info has changed. If so, output the source line
1001 * if the option is enabled and output debug line info if the debug
1002 * option is enabled.
1005 /* Line info has changed, remember the new line info */
1008 /* Add the source line as a comment */
1010 fprintf (F, ";\n; %s\n;\n", LI->Line);
1013 /* Add line debug info */
1015 fprintf (F, "\t.dbg\tline, \"%s\", %u\n",
1016 GetInputName (LI), GetInputLine (LI));
1019 /* Output the code */
1023 /* If debug info is enabled, terminate the last line number information */
1025 fprintf (F, "\t.dbg\tline\n");
1028 /* If this is a segment for a function, leave the function */
1030 fprintf (F, "\n.endproc\n\n");
1036 void CS_FreeRegInfo (CodeSeg* S)
1037 /* Free register infos for all instructions */
1040 for (I = 0; I < CS_GetEntryCount (S); ++I) {
1041 CE_FreeRegInfo (CS_GetEntry(S, I));
1047 void CS_GenRegInfo (CodeSeg* S)
1048 /* Generate register infos for all instructions */
1052 RegContents* CurrentRegs;
1055 /* Be sure to delete all register infos */
1058 /* On entry, the register contents are unknown */
1059 RC_Invalidate (&Regs);
1060 CurrentRegs = &Regs;
1062 /* First pass. Walk over all insns an note just the changes from one
1063 * insn to the next one.
1066 for (I = 0; I < CS_GetEntryCount (S); ++I) {
1070 /* Get the next instruction */
1071 CodeEntry* E = CollAtUnchecked (&S->Entries, I);
1073 /* If the instruction has a label, we need some special handling */
1074 unsigned LabelCount = CE_GetLabelCount (E);
1075 if (LabelCount > 0) {
1077 /* Loop over all entry points that jump here. If these entry
1078 * points already have register info, check if all values are
1079 * known and identical. If all values are identical, and the
1080 * preceeding instruction was not an unconditional branch, check
1081 * if the register value on exit of the preceeding instruction
1082 * is also identical. If all these values are identical, the
1083 * value of a register is known, otherwise it is unknown.
1085 CodeLabel* Label = CE_GetLabel (E, 0);
1088 /* Preceeding insn was an unconditional branch */
1089 CodeEntry* J = CL_GetRef(Label, 0);
1093 RC_Invalidate (&Regs);
1097 Regs = *CurrentRegs;
1101 while (Entry < CL_GetRefCount (Label)) {
1102 /* Get this entry */
1103 CodeEntry* J = CL_GetRef (Label, Entry);
1105 /* No register info for this entry, bail out */
1106 RC_Invalidate (&Regs);
1109 if (J->RI->Out2.RegA != Regs.RegA) {
1112 if (J->RI->Out2.RegX != Regs.RegX) {
1115 if (J->RI->Out2.RegY != Regs.RegY) {
1121 /* Use this register info */
1122 CurrentRegs = &Regs;
1126 /* Generate register info for this instruction */
1127 CE_GenRegInfo (E, CurrentRegs);
1129 /* Remember for the next insn if this insn was an uncondition branch */
1130 WasJump = (E->Info & OF_UBRA) != 0;
1132 /* Output registers for this insn are input for the next */
1133 CurrentRegs = &E->RI->Out;
1135 /* If this insn is a branch on zero flag, we may have more info on
1136 * register contents for one of both flow directions, but only if
1137 * there is a previous instruction.
1139 if ((E->Info & OF_ZBRA) != 0 && (P = CS_GetPrevEntry (S, I)) != 0) {
1141 /* Get the branch condition */
1142 bc_t BC = GetBranchCond (E->OPC);
1144 /* Check the previous instruction */
1156 /* A is zero in one execution flow direction */
1158 E->RI->Out2.RegA = 0;
1160 E->RI->Out.RegA = 0;
1165 /* If this is an immidiate compare, the A register has
1166 * the value of the compare later.
1168 if (CE_KnownImm (P)) {
1170 E->RI->Out2.RegA = (unsigned char)P->Num;
1172 E->RI->Out.RegA = (unsigned char)P->Num;
1178 /* If this is an immidiate compare, the X register has
1179 * the value of the compare later.
1181 if (CE_KnownImm (P)) {
1183 E->RI->Out2.RegX = (unsigned char)P->Num;
1185 E->RI->Out.RegX = (unsigned char)P->Num;
1191 /* If this is an immidiate compare, the Y register has
1192 * the value of the compare later.
1194 if (CE_KnownImm (P)) {
1196 E->RI->Out2.RegY = (unsigned char)P->Num;
1198 E->RI->Out.RegY = (unsigned char)P->Num;
1207 /* X is zero in one execution flow direction */
1209 E->RI->Out2.RegX = 0;
1211 E->RI->Out.RegX = 0;
1219 /* X is zero in one execution flow direction */
1221 E->RI->Out2.RegY = 0;
1223 E->RI->Out.RegY = 0;
1229 /* If the branch is a beq, both A and X are zero at the
1230 * branch target, otherwise they are zero at the next
1234 E->RI->Out2.RegA = E->RI->Out2.RegX = 0;
1236 E->RI->Out.RegA = E->RI->Out.RegX = 0;
1242 /* If the branch is a beq, both A and Y are zero at the
1243 * branch target, otherwise they are zero at the next
1247 E->RI->Out2.RegA = E->RI->Out2.RegY = 0;
1249 E->RI->Out.RegA = E->RI->Out.RegY = 0;