rgbase.pas 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Helper routines for register allocator
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit rgbase;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cpuBase,cgBase;
  22. type
  23. TRegNameTable = array[tregisterindex] of string[14];
  24. TRegisterIndexTable = array[tregisterindex] of tregisterindex;
  25. function findreg_by_number_table(r:Tregister;const regnumber_index:TRegisterIndexTable):tregisterindex;
  26. function findreg_by_name_table(const s:string;const regname_table:TRegNameTable;const regname_index:TRegisterIndexTable):byte;
  27. implementation
  28. function findreg_by_name_table(const s:string;const regname_table:TRegNameTable;const regname_index:TRegisterIndexTable):byte;
  29. var
  30. i,p,q : tregisterindex;
  31. begin
  32. p:=Low(tregisterindex);
  33. q:=high(tregisterindex);
  34. repeat
  35. i:=(p+q) shr 1;
  36. if s>regname_table[regname_index[i]] then
  37. p:=i+1
  38. else
  39. q:=i;
  40. until p=q;
  41. if regname_table[regname_index[p]]=s then
  42. result:=regname_index[p]
  43. else
  44. result:=0;
  45. end;
  46. function findreg_by_number_table(r:Tregister;const regnumber_index:TRegisterIndexTable):tregisterindex;
  47. var
  48. i,p,q : longint;
  49. begin
  50. p:=Low(tregisterindex);
  51. q:=high(tregisterindex);
  52. repeat
  53. i:=(p+q) shr 1;
  54. if r>regnumber_table[regnumber_index[i]] then
  55. p:=i+1
  56. else
  57. q:=i;
  58. until p=q;
  59. if regnumber_table[regnumber_index[p]]=r then
  60. result:=regnumber_index[p]
  61. else
  62. result:=0;
  63. end;
  64. end.