itx86int.pas 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit contains the i386 AT&T instruction tables
  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 itx86int;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cgbase;
  22. function masm_regnum_search(const s:string):Tregister;
  23. function masm_regname(r:Tregister):string;
  24. implementation
  25. uses
  26. cutils,verbose,
  27. cpubase;
  28. const
  29. {$ifdef x86_64}
  30. int_regname_table : array[tregisterindex] of string[7] = (
  31. {$i r8664int.inc}
  32. );
  33. int_regname_index : array[tregisterindex] of tregisterindex = (
  34. {$i r8664iri.inc}
  35. );
  36. {$else x86_64}
  37. int_regname_table : array[tregisterindex] of string[7] = (
  38. {$i r386int.inc}
  39. );
  40. int_regname_index : array[tregisterindex] of tregisterindex = (
  41. {$i r386iri.inc}
  42. );
  43. {$endif x86_64}
  44. function findreg_by_intname(const s:string):byte;
  45. var
  46. i,p : tregisterindex;
  47. begin
  48. {Binary search.}
  49. p:=0;
  50. i:=regnumber_count_bsstart;
  51. repeat
  52. if (p+i<=high(tregisterindex)) and (int_regname_table[int_regname_index[p+i]]<=s) then
  53. p:=p+i;
  54. i:=i shr 1;
  55. until i=0;
  56. if int_regname_table[int_regname_index[p]]=s then
  57. findreg_by_intname:=int_regname_index[p]
  58. else
  59. findreg_by_intname:=0;
  60. end;
  61. function masm_regnum_search(const s:string):Tregister;
  62. begin
  63. result:=regnumber_table[findreg_by_intname(s)];
  64. end;
  65. function masm_regname(r:Tregister):string;
  66. var
  67. p : tregisterindex;
  68. begin
  69. p:=findreg_by_number(r);
  70. if p<>0 then
  71. result:=int_regname_table[p]
  72. else
  73. result:=generic_regname(r);
  74. end;
  75. end.