rghelper.pas 2.6 KB

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