From 412a1300f9c7b9aacd5aef1d565cdee3eabbf1d8 Mon Sep 17 00:00:00 2001 From: cuz Date: Tue, 17 May 2005 12:42:34 +0000 Subject: [PATCH] Fixed a bug git-svn-id: svn://svn.cc65.org/cc65/trunk@3513 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codeent.c | 2 +- src/cc65/codeinfo.c | 49 ++++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/cc65/codeent.c b/src/cc65/codeent.c index 5f2b3f1ee..3c2f03b32 100644 --- a/src/cc65/codeent.c +++ b/src/cc65/codeent.c @@ -144,7 +144,7 @@ static void SetUseChgInfo (CodeEntry* E, const OPCDesc* D) * lookup the information about this function and use it. The jump itself * does not change any registers, so we don't need to use the data from D. */ - if ((E->Info & (OF_BRA | OF_CALL)) != 0 && E->JumpTo == 0) { + if ((E->Info & (OF_UBRA | OF_CALL)) != 0 && E->JumpTo == 0) { /* A subroutine call or jump to external symbol (function exit) */ GetFuncInfo (E->Arg, &E->Use, &E->Chg); } else { diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index 254b4e07d..712dd1ea6 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -416,7 +416,7 @@ static unsigned GetRegInfo2 (CodeSeg* S, /* Evaluate the used registers */ R = E->Use; if (E->OPC == OP65_RTS || - ((E->Info & OF_BRA) != 0 && E->JumpTo == 0)) { + ((E->Info & OF_UBRA) != 0 && E->JumpTo == 0)) { /* This instruction will leave the function */ R |= S->ExitRegs; } @@ -472,30 +472,37 @@ static unsigned GetRegInfo2 (CodeSeg* S, */ } else if ((E->Info & OF_CBRA) != 0) { - if (E->JumpTo) { + /* Recursively determine register usage at the branch target */ + unsigned U1; + unsigned U2; - /* Recursively determine register usage at the branch target */ - unsigned U1; - unsigned U2; + if (E->JumpTo) { + /* Jump to internal label */ U1 = GetRegInfo2 (S, E->JumpTo->Owner, -1, Visited, Used, Unused, Wanted); - if (U1 == REG_ALL) { - /* All registers used, no need for second call */ - return REG_AXY; - } - if (Index < 0) { - Index = CS_GetEntryIndex (S, E); - } - if ((E = CS_GetEntry (S, ++Index)) == 0) { - Internal ("GetRegInfo2: No next entry!"); - } - U2 = GetRegInfo2 (S, E, Index, Visited, Used, Unused, Wanted); - return U1 | U2; /* Used in any of the branches */ - } else { - /* Jump to global symbol */ - break; - } + } else { + + /* Jump to external label. This will effectively exit the + * function, so we use the exitregs information here. + */ + U1 = S->ExitRegs; + + } + + /* Get the next entry */ + if (Index < 0) { + Index = CS_GetEntryIndex (S, E); + } + if ((E = CS_GetEntry (S, ++Index)) == 0) { + Internal ("GetRegInfo2: No next entry!"); + } + + /* Follow flow if branch not taken */ + U2 = GetRegInfo2 (S, E, Index, Visited, Used, Unused, Wanted); + + /* Registers are used if they're use in any of the branches */ + return U1 | U2; } else { -- 2.39.5