2
0

itcpugas.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 itcpugas;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cgbase,cpubase;
  22. type
  23. TAttSuffix = (AttSufNONE,AttSufINT,AttSufFPU,AttSufFPUint);
  24. const
  25. {$ifdef x86_64}
  26. {x86att.inc contains the name for each x86-64 mnemonic}
  27. gas_op2str:op2strtable={$i x8664att.inc}
  28. gas_needsuffix:array[tasmop] of TAttSuffix={$i x8664ats.inc}
  29. {$else x86_64}
  30. {x86att.inc contains the name for each i386 mnemonic}
  31. gas_op2str:op2strtable={$i i386att.inc}
  32. gas_needsuffix:array[tasmop] of TAttSuffix={$i i386atts.inc}
  33. {$endif x86_64}
  34. {$ifdef x86_64}
  35. gas_opsize2str : array[topsize] of string[2] = ('',
  36. 'b','w','l','q','bw','bl','wl','bq','wq','lq',
  37. 's','l','q',
  38. 's','l','t','v','x',
  39. 'd',
  40. '','','',
  41. 't',
  42. ''
  43. );
  44. {$else x86_64}
  45. gas_opsize2str : array[topsize] of string[2] = ('',
  46. 'b','w','l','q','bw','bl','wl',
  47. 's','l','q',
  48. 's','l','t','v','',
  49. 'd',
  50. '','','',
  51. 't',
  52. ''
  53. );
  54. {$endif x86_64}
  55. function gas_regnum_search(const s:string):Tregister;
  56. function gas_regname(r:Tregister):string;
  57. implementation
  58. uses
  59. cutils,verbose;
  60. const
  61. {$ifdef x86_64}
  62. att_regname_table : array[tregisterindex] of string[7] = (
  63. {r8664att.inc contains the AT&T name of each register.}
  64. {$i r8664att.inc}
  65. );
  66. att_regname_index : array[tregisterindex] of tregisterindex = (
  67. {r8664ari.inc contains an index which sorts att_regname_table by
  68. ATT name.}
  69. {$i r8664ari.inc}
  70. );
  71. {$else x86_64}
  72. att_regname_table : array[tregisterindex] of string[7] = (
  73. {r386att.inc contains the AT&T name of each register.}
  74. {$i r386att.inc}
  75. );
  76. att_regname_index : array[tregisterindex] of tregisterindex = (
  77. {r386ari.inc contains an index which sorts att_regname_table by
  78. ATT name.}
  79. {$i r386ari.inc}
  80. );
  81. {$endif x86_64}
  82. function findreg_by_attname(const s:string):byte;
  83. var
  84. i,p : tregisterindex;
  85. begin
  86. {Binary search.}
  87. p:=0;
  88. i:=regnumber_count_bsstart;
  89. repeat
  90. if (p+i<=high(tregisterindex)) and (att_regname_table[att_regname_index[p+i]]<=s) then
  91. p:=p+i;
  92. i:=i shr 1;
  93. until i=0;
  94. if att_regname_table[att_regname_index[p]]=s then
  95. findreg_by_attname:=att_regname_index[p]
  96. else
  97. findreg_by_attname:=0;
  98. end;
  99. function gas_regnum_search(const s:string):Tregister;
  100. begin
  101. result:=regnumber_table[findreg_by_attname(s)];
  102. end;
  103. function gas_regname(r:Tregister):string;
  104. var
  105. p : tregisterindex;
  106. begin
  107. p:=findreg_by_number(r);
  108. if p<>0 then
  109. result:=att_regname_table[p]
  110. else
  111. result:='%'+generic_regname(r);
  112. end;
  113. end.