itcpugas.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. {$else x86_64}
  44. gas_opsize2str : array[topsize] of string[2] = ('',
  45. 'b','w','l','q','bw','bl','wl',
  46. 's','l','q',
  47. 's','l','t','v','',
  48. 'd',
  49. '','','',
  50. 't'
  51. );
  52. {$endif x86_64}
  53. function gas_regnum_search(const s:string):Tregister;
  54. function gas_regname(r:Tregister):string;
  55. implementation
  56. uses
  57. cutils,verbose;
  58. const
  59. {$ifdef x86_64}
  60. att_regname_table : array[tregisterindex] of string[7] = (
  61. {r8664att.inc contains the AT&T name of each register.}
  62. {$i r8664att.inc}
  63. );
  64. att_regname_index : array[tregisterindex] of tregisterindex = (
  65. {r8664ari.inc contains an index which sorts att_regname_table by
  66. ATT name.}
  67. {$i r8664ari.inc}
  68. );
  69. {$else x86_64}
  70. att_regname_table : array[tregisterindex] of string[7] = (
  71. {r386att.inc contains the AT&T name of each register.}
  72. {$i r386att.inc}
  73. );
  74. att_regname_index : array[tregisterindex] of tregisterindex = (
  75. {r386ari.inc contains an index which sorts att_regname_table by
  76. ATT name.}
  77. {$i r386ari.inc}
  78. );
  79. {$endif x86_64}
  80. function findreg_by_attname(const s:string):byte;
  81. var
  82. i,p : tregisterindex;
  83. begin
  84. {Binary search.}
  85. p:=0;
  86. i:=regnumber_count_bsstart;
  87. repeat
  88. if (p+i<=high(tregisterindex)) and (att_regname_table[att_regname_index[p+i]]<=s) then
  89. p:=p+i;
  90. i:=i shr 1;
  91. until i=0;
  92. if att_regname_table[att_regname_index[p]]=s then
  93. findreg_by_attname:=att_regname_index[p]
  94. else
  95. findreg_by_attname:=0;
  96. end;
  97. function gas_regnum_search(const s:string):Tregister;
  98. begin
  99. result:=regnumber_table[findreg_by_attname(s)];
  100. end;
  101. function gas_regname(r:Tregister):string;
  102. var
  103. p : tregisterindex;
  104. begin
  105. p:=findreg_by_number(r);
  106. if p<>0 then
  107. result:=att_regname_table[p]
  108. else
  109. result:='%'+generic_regname(r);
  110. end;
  111. end.