aasmcpu.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. {
  2. Copyright (c) 1999-2008 by Mazen Neifer and Florian Klaempfl
  3. Contains the assembler object for the Z80
  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 aasmcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,globals,verbose,
  23. aasmbase,aasmtai,aasmdata,aasmsym,
  24. cgbase,cgutils,cpubase,cpuinfo,
  25. ogbase;
  26. const
  27. { "mov reg,reg" source operand number }
  28. O_MOV_SOURCE = 1;
  29. { "mov reg,reg" source operand number }
  30. O_MOV_DEST = 0;
  31. instabentries = {$i z80nop.inc}
  32. maxinfolen = 18;
  33. type
  34. { Operand types }
  35. toperandtype=(
  36. OT_NONE,
  37. OT_IMM3, { 3-bit immediate value (bit number: [0..7]) }
  38. OT_IMM8, { 8-bit immediate value }
  39. OT_IMM16, { 16-bit immediate value }
  40. OT_IMM_VAL0, { the immediate value 0 }
  41. OT_IMM_VAL1, { the immediate value 1 }
  42. OT_IMM_VAL2, { the immediate value 2 }
  43. OT_IMM_RST, { immediate value in [$00,$08,$10,$18,$20,$28,$30,$38] }
  44. OT_IMM_PORT, { 8-bit immediate port number for the IN and OUT instructions }
  45. OT_REG8, { 8-bit register: A/B/C/D/E/H/L }
  46. OT_REG8_A, { register A }
  47. OT_REG8_I, { register I }
  48. OT_REG8_R, { register R }
  49. OT_REG8_C_PORT, { implied parameter of the IN and OUT instructions }
  50. OT_REG16_IX, { register IX }
  51. OT_REG16_IY, { register IY }
  52. OT_REG16_SP, { register SP }
  53. OT_REG16_BC_DE_HL_SP, { 16-bit register pair: BC/DE/HL/SP }
  54. OT_REG16_BC_DE_HL_AF, { 16-bit register pair: BC/DE/HL/AF }
  55. OT_REG16_BC_DE_IX_SP, { 16-bit register pair: BC/DE/IX/SP }
  56. OT_REG16_BC_DE_IY_SP, { 16-bit register pair: BC/DE/IY/SP }
  57. OT_REG16_DE, { 16-bit register pair DE }
  58. OT_REG16_HL, { 16-bit register pair HL }
  59. OT_REG16_AF, { 16-bit register pair AF }
  60. OT_REG16_AF_, { alternate register set, 16-bit register pair AF' }
  61. OT_RELJMP8, { 8-bit relative jump offset }
  62. OT_COND, { condition: NZ/Z/NC/C/PO/PE/P/M }
  63. OT_COND_C, { condition C }
  64. OT_COND_NC, { condition NC }
  65. OT_COND_Z, { condition Z }
  66. OT_COND_NZ, { condition NZ }
  67. OT_REF_ADDR16, { memory contents at address (nn = 16-bit immediate address) }
  68. OT_REF_BC, { memory contents at address in register BC }
  69. OT_REF_DE, { memory contents at address in register DE }
  70. OT_REF_HL, { memory contents at address in register HL }
  71. OT_REF_SP, { memory contents at address in register SP }
  72. OT_REF_IX, { memory contents at address in register IX }
  73. OT_REF_IY, { memory contents at address in register IY }
  74. OT_REF_IX_d, { memory contents at address in register IX+d, d is in [-128..127] }
  75. OT_REF_IY_d); { memory contents at address in register IY+d, d is in [-128..127] }
  76. timmoperandtype = OT_IMM3..OT_IMM_PORT;
  77. tregoperandtype = OT_REG8..OT_REG16_AF_;
  78. treg8operandtype = OT_REG8..OT_REG8_C_PORT;
  79. treg16operandtype = OT_REG16_IX..OT_REG16_AF_;
  80. tcondoperandtype = OT_COND..OT_COND_NZ;
  81. trefoperandtype = OT_REF_ADDR16..OT_REF_IY_d;
  82. trefoperandtypes = set of trefoperandtype;
  83. tinsentry = record
  84. opcode : tasmop;
  85. ops : byte;
  86. optypes : array[0..max_operands-1] of toperandtype;
  87. code : array[0..maxinfolen] of char;
  88. flags : longint;
  89. end;
  90. pinsentry=^tinsentry;
  91. { taicpu }
  92. taicpu = class(tai_cpu_abstract_sym)
  93. private
  94. function Matches(p:PInsEntry):boolean;
  95. public
  96. constructor op_none(op : tasmop);
  97. constructor op_reg(op : tasmop;_op1 : tregister);
  98. constructor op_const(op : tasmop;_op1 : LongInt);
  99. constructor op_ref(op : tasmop;const _op1 : treference);
  100. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  101. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  102. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  103. constructor op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  104. constructor op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  105. constructor op_ref_const(op:tasmop; _op1: treference; _op2: LongInt);
  106. { this is for Jmp instructions }
  107. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  108. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  109. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  110. procedure loadbool(opidx:longint;_b:boolean);
  111. { register allocation }
  112. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  113. { register spilling code }
  114. function spilling_get_operation_type(opnr: longint): topertype;override;
  115. end;
  116. tai_align = class(tai_align_abstract)
  117. { nothing to add }
  118. end;
  119. procedure InitAsm;
  120. procedure DoneAsm;
  121. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  122. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  123. function is_ref_addr16(const ref:treference): Boolean;
  124. function is_ref_bc(const ref:treference): Boolean;
  125. function is_ref_de(const ref:treference): Boolean;
  126. function is_ref_hl(const ref:treference): Boolean;
  127. function is_ref_sp(const ref:treference): Boolean;
  128. function is_ref_ix(const ref:treference): Boolean;
  129. function is_ref_iy(const ref:treference): Boolean;
  130. function is_ref_ix_d(const ref:treference): Boolean;
  131. function is_ref_iy_d(const ref:treference): Boolean;
  132. function is_ref_opertype(const ref:treference;opertype:toperandtype): Boolean;
  133. function is_ref_in_opertypes(const ref:treference;const refopertypes:trefoperandtypes): Boolean;
  134. implementation
  135. {****************************************************************************
  136. Instruction table
  137. *****************************************************************************}
  138. type
  139. TInsTabCache=array[TasmOp] of longint;
  140. PInsTabCache=^TInsTabCache;
  141. const
  142. InsTab:array[0..instabentries-1] of TInsEntry={$i z80tab.inc}
  143. var
  144. InsTabCache : PInsTabCache;
  145. {*****************************************************************************
  146. taicpu Constructors
  147. *****************************************************************************}
  148. procedure taicpu.loadbool(opidx:longint;_b:boolean);
  149. begin
  150. if opidx>=ops then
  151. ops:=opidx+1;
  152. with oper[opidx]^ do
  153. begin
  154. if typ=top_ref then
  155. dispose(ref);
  156. b:=_b;
  157. typ:=top_bool;
  158. end;
  159. end;
  160. function taicpu.Matches(p: PInsEntry): boolean;
  161. function OperandsMatch(const oper: toper; const ot: toperandtype): boolean;
  162. begin
  163. case ot of
  164. OT_IMM3:
  165. result:=(oper.typ=top_const) and (oper.val>=0) and (oper.val<=7);
  166. OT_IMM8:
  167. { todo: lo8, hi8 addresses }
  168. result:=(oper.typ=top_const) and (oper.val>=0) and (oper.val<=255);
  169. OT_IMM16:
  170. { todo: addresses }
  171. result:=(oper.typ=top_const) and (oper.val>=0) and (oper.val<=65535);
  172. OT_IMM_VAL0:
  173. result:=(oper.typ=top_const) and (oper.val=0);
  174. OT_IMM_VAL1:
  175. result:=(oper.typ=top_const) and (oper.val=1);
  176. OT_IMM_VAL2:
  177. result:=(oper.typ=top_const) and (oper.val=2);
  178. OT_IMM_RST:
  179. result:=(oper.typ=top_const) and ((oper.val=$00) or (oper.val=$08) or
  180. (oper.val=$10) or (oper.val=$18) or
  181. (oper.val=$20) or (oper.val=$28) or
  182. (oper.val=$30) or (oper.val=$38));
  183. {todo: OT_IMM_PORT}
  184. OT_REG8:
  185. result:=(oper.typ=top_reg) and ((oper.reg=NR_A) or (oper.reg=NR_B) or
  186. (oper.reg=NR_C) or (oper.reg=NR_D) or
  187. (oper.reg=NR_E) or (oper.reg=NR_H) or
  188. (oper.reg=NR_L));
  189. OT_REG8_A:
  190. result:=(oper.typ=top_reg) and (oper.reg=NR_A);
  191. OT_REG8_I:
  192. result:=(oper.typ=top_reg) and (oper.reg=NR_I);
  193. OT_REG8_R:
  194. result:=(oper.typ=top_reg) and (oper.reg=NR_R);
  195. {todo: OT_REG8_C_PORT}
  196. OT_REG16_IX:
  197. result:=(oper.typ=top_reg) and (oper.reg=NR_IX);
  198. OT_REG16_IY:
  199. result:=(oper.typ=top_reg) and (oper.reg=NR_IY);
  200. OT_REG16_SP:
  201. result:=(oper.typ=top_reg) and (oper.reg=NR_SP);
  202. OT_REG16_BC_DE_HL_SP:
  203. result:=(oper.typ=top_reg) and ((oper.reg=NR_BC) or (oper.reg=NR_DE) or (oper.reg=NR_HL) or (oper.reg=NR_SP));
  204. OT_REG16_BC_DE_HL_AF:
  205. result:=(oper.typ=top_reg) and ((oper.reg=NR_BC) or (oper.reg=NR_DE) or (oper.reg=NR_HL) or (oper.reg=NR_AF));
  206. OT_REG16_BC_DE_IX_SP:
  207. result:=(oper.typ=top_reg) and ((oper.reg=NR_BC) or (oper.reg=NR_DE) or (oper.reg=NR_IX) or (oper.reg=NR_SP));
  208. OT_REG16_BC_DE_IY_SP:
  209. result:=(oper.typ=top_reg) and ((oper.reg=NR_BC) or (oper.reg=NR_DE) or (oper.reg=NR_IY) or (oper.reg=NR_SP));
  210. OT_REG16_DE:
  211. result:=(oper.typ=top_reg) and (oper.reg=NR_DE);
  212. OT_REG16_HL:
  213. result:=(oper.typ=top_reg) and (oper.reg=NR_HL);
  214. OT_REG16_AF:
  215. result:=(oper.typ=top_reg) and (oper.reg=NR_AF);
  216. OT_REG16_AF_:
  217. result:=(oper.typ=top_reg) and (oper.reg=NR_AF_);
  218. {todo: OT_RELJMP8}
  219. OT_REF_ADDR16,
  220. OT_REF_BC,
  221. OT_REF_DE,
  222. OT_REF_HL,
  223. OT_REF_SP,
  224. OT_REF_IX,
  225. OT_REF_IY,
  226. OT_REF_IX_d,
  227. OT_REF_IY_d:
  228. result:=(oper.typ=top_ref) and is_ref_opertype(oper.ref^,ot);
  229. else
  230. internalerror(2020042901);
  231. end;
  232. end;
  233. var
  234. i: Integer;
  235. begin
  236. result:=false;
  237. { Check the opcode }
  238. if p^.opcode<>opcode then
  239. exit;
  240. { The opcode doesn't support conditions, but we have a condition?
  241. That's an invalid instruction, don't match it against anything. }
  242. if (condition<>C_NONE) and not (opcode in cond_instructions) then
  243. exit;
  244. { if our opcode supports a condition, but our operation doesn't have
  245. one, and we're matching it with an instruction entry 'p' that has a
  246. condition, then it doesn't match }
  247. if (opcode in cond_instructions) and (condition=C_None) and
  248. (p^.ops>0) and (p^.optypes[0] in [OT_COND..OT_COND_NZ]) then
  249. exit;
  250. { instruction has a condition? }
  251. if (opcode in cond_instructions) and (condition<>C_None) then
  252. begin
  253. { Check the operand count }
  254. if p^.ops<>(ops+1) then
  255. exit;
  256. { Check the condition }
  257. case p^.optypes[0] of
  258. OT_COND:
  259. { any condition accepted };
  260. OT_COND_C:
  261. if condition<>C_C then
  262. exit;
  263. OT_COND_NC:
  264. if condition<>C_NC then
  265. exit;
  266. OT_COND_Z:
  267. if condition<>C_Z then
  268. exit;
  269. OT_COND_NZ:
  270. if condition<>C_NZ then
  271. exit;
  272. else
  273. { no condition in 'p'? Then it's not a match! }
  274. exit;
  275. end;
  276. { Check the operands }
  277. for i:=1 to p^.ops-1 do
  278. if not OperandsMatch(oper[i-1]^,p^.optypes[i]) then
  279. exit;
  280. end
  281. else
  282. { no condition }
  283. begin
  284. { Check the operand count }
  285. if p^.ops<>ops then
  286. exit;
  287. { Check the operands }
  288. for i:=0 to p^.ops-1 do
  289. if not OperandsMatch(oper[i]^,p^.optypes[i]) then
  290. exit;
  291. end;
  292. result:=true;
  293. end;
  294. constructor taicpu.op_none(op : tasmop);
  295. begin
  296. inherited create(op);
  297. end;
  298. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  299. begin
  300. inherited create(op);
  301. ops:=1;
  302. loadreg(0,_op1);
  303. end;
  304. constructor taicpu.op_ref(op : tasmop;const _op1 : treference);
  305. begin
  306. inherited create(op);
  307. ops:=1;
  308. loadref(0,_op1);
  309. end;
  310. constructor taicpu.op_const(op : tasmop;_op1 : LongInt);
  311. begin
  312. inherited create(op);
  313. ops:=1;
  314. loadconst(0,_op1);
  315. end;
  316. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  317. begin
  318. inherited create(op);
  319. ops:=2;
  320. loadreg(0,_op1);
  321. loadreg(1,_op2);
  322. end;
  323. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: LongInt);
  324. begin
  325. inherited create(op);
  326. ops:=2;
  327. loadreg(0,_op1);
  328. loadconst(1,_op2);
  329. end;
  330. constructor taicpu.op_const_reg(op:tasmop; _op1: LongInt; _op2: tregister);
  331. begin
  332. inherited create(op);
  333. ops:=2;
  334. loadconst(0,_op1);
  335. loadreg(1,_op2);
  336. end;
  337. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  338. begin
  339. inherited create(op);
  340. ops:=2;
  341. loadreg(0,_op1);
  342. loadref(1,_op2);
  343. end;
  344. constructor taicpu.op_ref_reg(op : tasmop;const _op1 : treference;_op2 : tregister);
  345. begin
  346. inherited create(op);
  347. ops:=2;
  348. loadref(0,_op1);
  349. loadreg(1,_op2);
  350. end;
  351. constructor taicpu.op_ref_const(op: tasmop; _op1: treference; _op2: LongInt);
  352. begin
  353. inherited create(op);
  354. ops:=2;
  355. loadref(0,_op1);
  356. loadconst(1,_op2);
  357. end;
  358. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  359. begin
  360. inherited create(op);
  361. is_jmp:=op in jmp_instructions;
  362. condition:=cond;
  363. ops:=1;
  364. loadsymbol(0,_op1,0);
  365. end;
  366. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  367. begin
  368. inherited create(op);
  369. is_jmp:=op in jmp_instructions;
  370. ops:=1;
  371. loadsymbol(0,_op1,0);
  372. end;
  373. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  374. begin
  375. inherited create(op);
  376. ops:=1;
  377. loadsymbol(0,_op1,_op1ofs);
  378. end;
  379. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  380. begin
  381. result:=(
  382. ((opcode in [A_LD]) and (regtype = R_INTREGISTER))
  383. ) and
  384. (ops=2) and
  385. (oper[0]^.typ=top_reg) and
  386. (oper[1]^.typ=top_reg) and
  387. (oper[0]^.reg=oper[1]^.reg);
  388. end;
  389. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  390. begin
  391. result:=operand_read;
  392. case opcode of
  393. A_LD,
  394. A_POP:
  395. if opnr=0 then
  396. result:=operand_write;
  397. A_PUSH,
  398. A_BIT,
  399. A_CP,
  400. A_DJNZ,
  401. A_JR,
  402. A_JP,
  403. A_CALL,
  404. A_RET,
  405. A_RETI,
  406. A_RETN,
  407. A_RST,
  408. A_IM:
  409. ;
  410. A_SET,
  411. A_RES:
  412. if opnr=1 then
  413. result:=operand_readwrite;
  414. A_EX:
  415. result:=operand_readwrite;
  416. else
  417. begin
  418. if opnr=0 then
  419. result:=operand_readwrite;
  420. end;
  421. end;
  422. end;
  423. function spilling_create_load(const ref:treference;r:tregister):Taicpu;
  424. begin
  425. case getregtype(r) of
  426. R_INTREGISTER :
  427. result:=taicpu.op_reg_ref(A_LD,r,ref)
  428. else
  429. internalerror(200401041);
  430. end;
  431. end;
  432. function spilling_create_store(r:tregister; const ref:treference):Taicpu;
  433. begin
  434. case getregtype(r) of
  435. R_INTREGISTER :
  436. result:=taicpu.op_ref_reg(A_LD,ref,r);
  437. else
  438. internalerror(200401041);
  439. end;
  440. end;
  441. function is_ref_addr16(const ref: treference): Boolean;
  442. begin
  443. result:=(ref.base=NR_NO) and (ref.index=NR_NO);
  444. end;
  445. function is_ref_bc(const ref: treference): Boolean;
  446. begin
  447. result:=(((ref.base=NR_BC) and (ref.index=NR_NO)) or
  448. ((ref.base=NR_NO) and (ref.index=NR_BC))) and
  449. (ref.offset=0) and (ref.scalefactor<=1) and
  450. (ref.symbol=nil) and (ref.relsymbol=nil);
  451. end;
  452. function is_ref_de(const ref: treference): Boolean;
  453. begin
  454. result:=(((ref.base=NR_DE) and (ref.index=NR_NO)) or
  455. ((ref.base=NR_NO) and (ref.index=NR_DE))) and
  456. (ref.offset=0) and (ref.scalefactor<=1) and
  457. (ref.symbol=nil) and (ref.relsymbol=nil);
  458. end;
  459. function is_ref_hl(const ref: treference): Boolean;
  460. begin
  461. result:=(((ref.base=NR_HL) and (ref.index=NR_NO)) or
  462. ((ref.base=NR_NO) and (ref.index=NR_HL))) and
  463. (ref.offset=0) and (ref.scalefactor<=1) and
  464. (ref.symbol=nil) and (ref.relsymbol=nil);
  465. end;
  466. function is_ref_sp(const ref: treference): Boolean;
  467. begin
  468. result:=(((ref.base=NR_SP) and (ref.index=NR_NO)) or
  469. ((ref.base=NR_NO) and (ref.index=NR_SP))) and
  470. (ref.offset=0) and (ref.scalefactor<=1) and
  471. (ref.symbol=nil) and (ref.relsymbol=nil);
  472. end;
  473. function is_ref_ix(const ref: treference): Boolean;
  474. begin
  475. result:=(((ref.base=NR_IX) and (ref.index=NR_NO)) or
  476. ((ref.base=NR_NO) and (ref.index=NR_IX))) and
  477. (ref.offset=0) and (ref.scalefactor<=1) and
  478. (ref.symbol=nil) and (ref.relsymbol=nil);
  479. end;
  480. function is_ref_iy(const ref: treference): Boolean;
  481. begin
  482. result:=(((ref.base=NR_IY) and (ref.index=NR_NO)) or
  483. ((ref.base=NR_NO) and (ref.index=NR_IY))) and
  484. (ref.offset=0) and (ref.scalefactor<=1) and
  485. (ref.symbol=nil) and (ref.relsymbol=nil);
  486. end;
  487. function is_ref_ix_d(const ref: treference): Boolean;
  488. begin
  489. result:=(((ref.base=NR_IX) and (ref.index=NR_NO)) or
  490. ((ref.base=NR_NO) and (ref.index=NR_IX))) and
  491. (ref.offset>=-128) and (ref.offset<=127) and (ref.scalefactor<=1) and
  492. (ref.symbol=nil) and (ref.relsymbol=nil);
  493. end;
  494. function is_ref_iy_d(const ref: treference): Boolean;
  495. begin
  496. result:=(((ref.base=NR_IY) and (ref.index=NR_NO)) or
  497. ((ref.base=NR_NO) and (ref.index=NR_IY))) and
  498. (ref.offset>=-128) and (ref.offset<=127) and (ref.scalefactor<=1) and
  499. (ref.symbol=nil) and (ref.relsymbol=nil);
  500. end;
  501. function is_ref_opertype(const ref: treference; opertype: toperandtype): Boolean;
  502. begin
  503. case opertype of
  504. OT_REF_ADDR16:
  505. result:=is_ref_addr16(ref);
  506. OT_REF_BC:
  507. result:=is_ref_bc(ref);
  508. OT_REF_DE:
  509. result:=is_ref_de(ref);
  510. OT_REF_HL:
  511. result:=is_ref_hl(ref);
  512. OT_REF_SP:
  513. result:=is_ref_sp(ref);
  514. OT_REF_IX:
  515. result:=is_ref_ix(ref);
  516. OT_REF_IY:
  517. result:=is_ref_iy(ref);
  518. OT_REF_IX_d:
  519. result:=is_ref_ix_d(ref);
  520. OT_REF_IY_d:
  521. result:=is_ref_iy_d(ref);
  522. else
  523. internalerror(2020041801);
  524. end;
  525. end;
  526. function is_ref_in_opertypes(const ref: treference; const refopertypes: trefoperandtypes): Boolean;
  527. var
  528. ot: trefoperandtype;
  529. begin
  530. result:=true;
  531. for ot:=low(trefoperandtypes) to high(trefoperandtypes) do
  532. if (ot in refopertypes) and is_ref_opertype(ref,ot) then
  533. exit;
  534. result:=false;
  535. end;
  536. {****************************************************************************
  537. Instruction table
  538. *****************************************************************************}
  539. procedure BuildInsTabCache;
  540. var
  541. i : longint;
  542. begin
  543. new(instabcache);
  544. FillChar(instabcache^,sizeof(tinstabcache),$ff);
  545. i:=0;
  546. while (i<InsTabEntries) do
  547. begin
  548. if InsTabCache^[InsTab[i].OPcode]=-1 then
  549. InsTabCache^[InsTab[i].OPcode]:=i;
  550. inc(i);
  551. end;
  552. end;
  553. procedure InitAsm;
  554. begin
  555. if not assigned(instabcache) then
  556. BuildInsTabCache;
  557. end;
  558. procedure DoneAsm;
  559. begin
  560. if assigned(instabcache) then
  561. begin
  562. dispose(instabcache);
  563. instabcache:=nil;
  564. end;
  565. end;
  566. begin
  567. cai_cpu:=taicpu;
  568. cai_align:=tai_align;
  569. end.