raz80asm.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. {
  2. Copyright (c) 1998-2008 by Carl Eric Codere and Peter Vreman
  3. Does the parsing for the Z80 styled inline assembler.
  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 raz80asm;
  18. {$i fpcdefs.inc}
  19. Interface
  20. uses
  21. rasm,
  22. raz80,
  23. cpubase;
  24. type
  25. tasmtoken = (
  26. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_INTNUM,
  27. AS_COMMA,AS_LPAREN,
  28. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
  29. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,AS_DOLLAR,
  30. AS_HASH,AS_LSBRACKET,AS_RSBRACKET,AS_LBRACKET,AS_RBRACKET,
  31. AS_EQUAL,
  32. {------------------ Assembler directives --------------------}
  33. AS_DEFB,AS_DEFW
  34. );
  35. tasmkeyword = string[10];
  36. const
  37. { These tokens should be modified accordingly to the modifications }
  38. { in the different enumerations. }
  39. firstdirective = AS_DEFB;
  40. lastdirective = AS_DEFW;
  41. token2str : array[tasmtoken] of tasmkeyword=(
  42. '','Label','LLabel','string','integer',
  43. ',','(',
  44. ')',':','.','+','-','*',
  45. ';','identifier','register','opcode','/','$',
  46. '#','{','}','[',']',
  47. '=',
  48. 'defb','defw');
  49. type
  50. tz80reader = class(tasmreader)
  51. actasmtoken : tasmtoken;
  52. //function is_asmopcode(const s: string):boolean;override;
  53. function is_register(const s:string):boolean;
  54. //procedure handleopcode;override;
  55. //procedure BuildReference(oper : tz80operand);
  56. //procedure BuildOperand(oper : tz80operand);
  57. //procedure BuildOpCode(instr : tz80instruction);
  58. //procedure ReadSym(oper : tz80operand);
  59. procedure ConvertCalljmp(instr : tz80instruction);
  60. end;
  61. Implementation
  62. uses
  63. { helpers }
  64. cutils,
  65. { global }
  66. globtype,globals,verbose,
  67. systems,
  68. { aasm }
  69. cpuinfo,aasmbase,aasmtai,aasmdata,aasmcpu,
  70. { symtable }
  71. symconst,symbase,symtype,symsym,symtable,
  72. { parser }
  73. scanner,
  74. procinfo,
  75. rabase,rautils,
  76. cgbase,cgutils,cgobj
  77. ;
  78. {*****************************************************************************
  79. tz80reader
  80. *****************************************************************************}
  81. function tz80reader.is_register(const s:string):boolean;
  82. begin
  83. is_register:=false;
  84. actasmregister:=std_regnum_search(lower(s));
  85. if actasmregister<>NR_NO then
  86. begin
  87. is_register:=true;
  88. actasmtoken:=AS_REGISTER;
  89. end;
  90. end;
  91. //procedure tz80reader.ReadSym(oper : tz80operand);
  92. // var
  93. // tempstr, mangledname : string;
  94. // typesize,l,k : aint;
  95. // begin
  96. // tempstr:=actasmpattern;
  97. // Consume(AS_ID);
  98. // { typecasting? }
  99. // if (actasmtoken=AS_LPAREN) and
  100. // SearchType(tempstr,typesize) then
  101. // begin
  102. // oper.hastype:=true;
  103. // Consume(AS_LPAREN);
  104. // BuildOperand(oper);
  105. // Consume(AS_RPAREN);
  106. // if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  107. // oper.SetSize(typesize,true);
  108. // end
  109. // else
  110. // if not oper.SetupVar(tempstr,false) then
  111. // Message1(sym_e_unknown_id,tempstr);
  112. // { record.field ? }
  113. // if actasmtoken=AS_DOT then
  114. // begin
  115. // BuildRecordOffsetSize(tempstr,l,k,mangledname,false);
  116. // if (mangledname<>'') then
  117. // Message(asmr_e_invalid_reference_syntax);
  118. // inc(oper.opr.ref.offset,l);
  119. // end;
  120. // end;
  121. //Procedure tz80attreader.BuildReference(oper : tz80operand);
  122. //
  123. // procedure Consume_RParen;
  124. // begin
  125. // if actasmtoken<>AS_RPAREN then
  126. // Begin
  127. // Message(asmr_e_invalid_reference_syntax);
  128. // RecoverConsume(true);
  129. // end
  130. // else
  131. // begin
  132. // Consume(AS_RPAREN);
  133. // if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  134. // Begin
  135. // Message(asmr_e_invalid_reference_syntax);
  136. // RecoverConsume(true);
  137. // end;
  138. // end;
  139. // end;
  140. //procedure read_index;
  141. // begin
  142. // Consume(AS_COMMA);
  143. // if actasmtoken=AS_REGISTER then
  144. // Begin
  145. // oper.opr.ref.index:=actasmregister;
  146. // Consume(AS_REGISTER);
  147. // end
  148. // else if actasmtoken=AS_HASH then
  149. // begin
  150. // Consume(AS_HASH);
  151. // inc(oper.opr.ref.offset,BuildConstExpression(false,true));
  152. // end;
  153. // end;
  154. //begin
  155. // Consume(AS_LPAREN);
  156. // if actasmtoken=AS_REGISTER then
  157. // begin
  158. // oper.opr.ref.base:=actasmregister;
  159. // Consume(AS_REGISTER);
  160. // { can either be a register or a right parenthesis }
  161. // { (reg) }
  162. // if actasmtoken=AS_LPAREN then
  163. // Begin
  164. // Consume_RParen;
  165. // exit;
  166. // end;
  167. // if actasmtoken=AS_PLUS then
  168. // begin
  169. // consume(AS_PLUS);
  170. // oper.opr.ref.addressmode:=AM_POSTINCREMENT;
  171. // end;
  172. // end {end case }
  173. // else
  174. // Begin
  175. // Message(asmr_e_invalid_reference_syntax);
  176. // RecoverConsume(false);
  177. // end;
  178. //end;
  179. //Procedure tz80reader.BuildOperand(oper : tz80operand);
  180. // var
  181. // expr : string;
  182. // typesize,l : aint;
  183. //
  184. //
  185. // procedure AddLabelOperand(hl:tasmlabel);
  186. // begin
  187. // if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) { and
  188. // is_calljmp(actopcode) } then
  189. // begin
  190. // oper.opr.typ:=OPR_SYMBOL;
  191. // oper.opr.symbol:=hl;
  192. // end
  193. // else
  194. // begin
  195. // oper.InitRef;
  196. // oper.opr.ref.symbol:=hl;
  197. // end;
  198. // end;
  199. //
  200. //
  201. // procedure MaybeRecordOffset;
  202. // var
  203. // mangledname: string;
  204. // hasdot : boolean;
  205. // l,
  206. // toffset,
  207. // tsize : aint;
  208. // begin
  209. // if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  210. // exit;
  211. // l:=0;
  212. // mangledname:='';
  213. // hasdot:=(actasmtoken=AS_DOT);
  214. // if hasdot then
  215. // begin
  216. // if expr<>'' then
  217. // begin
  218. // BuildRecordOffsetSize(expr,toffset,tsize,mangledname,false);
  219. // if (oper.opr.typ<>OPR_CONSTANT) and
  220. // (mangledname<>'') then
  221. // Message(asmr_e_wrong_sym_type);
  222. // inc(l,toffset);
  223. // oper.SetSize(tsize,true);
  224. // end;
  225. // end;
  226. // if actasmtoken in [AS_PLUS,AS_MINUS] then
  227. // inc(l,BuildConstExpression(true,false));
  228. // case oper.opr.typ of
  229. // OPR_LOCAL :
  230. // begin
  231. // { don't allow direct access to fields of parameters, because that
  232. // will generate buggy code. Allow it only for explicit typecasting }
  233. // if hasdot and
  234. // (not oper.hastype) and
  235. // (tabstractnormalvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  236. // (current_procinfo.procdef.proccalloption<>pocall_register) then
  237. // Message(asmr_e_cannot_access_field_directly_for_parameters);
  238. // inc(oper.opr.localsymofs,l)
  239. // end;
  240. // OPR_CONSTANT :
  241. // inc(oper.opr.val,l);
  242. // OPR_REFERENCE :
  243. // if (mangledname<>'') then
  244. // begin
  245. // if (oper.opr.val<>0) then
  246. // Message(asmr_e_wrong_sym_type);
  247. // oper.opr.typ:=OPR_SYMBOL;
  248. // oper.opr.symbol:=current_asmdata.RefAsmSymbol(mangledname,AT_FUNCTION);
  249. // end
  250. // else
  251. // inc(oper.opr.val,l);
  252. // OPR_SYMBOL:
  253. // Message(asmr_e_invalid_symbol_ref);
  254. // else
  255. // internalerror(200309221);
  256. // end;
  257. // end;
  258. //
  259. //
  260. // function MaybeBuildReference:boolean;
  261. // { Try to create a reference, if not a reference is found then false
  262. // is returned }
  263. // begin
  264. // MaybeBuildReference:=true;
  265. // case actasmtoken of
  266. // AS_INTNUM,
  267. // AS_MINUS,
  268. // AS_PLUS:
  269. // Begin
  270. // oper.opr.ref.offset:=BuildConstExpression(True,False);
  271. // if actasmtoken<>AS_LPAREN then
  272. // Message(asmr_e_invalid_reference_syntax)
  273. // else
  274. // BuildReference(oper);
  275. // end;
  276. // AS_LPAREN:
  277. // BuildReference(oper);
  278. // AS_ID: { only a variable is allowed ... }
  279. // Begin
  280. // ReadSym(oper);
  281. // case actasmtoken of
  282. // AS_END,
  283. // AS_SEPARATOR,
  284. // AS_COMMA: ;
  285. // AS_LPAREN:
  286. // BuildReference(oper);
  287. // else
  288. // Begin
  289. // Message(asmr_e_invalid_reference_syntax);
  290. // Consume(actasmtoken);
  291. // end;
  292. // end; {end case }
  293. // end;
  294. // else
  295. // MaybeBuildReference:=false;
  296. // end; { end case }
  297. // end;
  298. //
  299. //
  300. // var
  301. // tempreg : tregister;
  302. // ireg : tsuperregister;
  303. // hl : tasmlabel;
  304. // ofs : longint;
  305. // registerset : tcpuregisterset;
  306. // tempstr : string;
  307. // tempsymtyp : tasmsymtype;
  308. // Begin
  309. // expr:='';
  310. // case actasmtoken of
  311. // AS_LBRACKET: { Memory reference or constant expression }
  312. // Begin
  313. // oper.InitRef;
  314. // BuildReference(oper);
  315. // end;
  316. //
  317. // AS_INTNUM,
  318. // AS_MINUS,
  319. // AS_PLUS:
  320. // Begin
  321. // if (actasmtoken=AS_MINUS) and
  322. // (actopcode in [A_LD,A_ST]) then
  323. // begin
  324. // { Special handling of predecrement addressing }
  325. // oper.InitRef;
  326. // oper.opr.ref.addressmode:=AM_PREDRECEMENT;
  327. //
  328. // consume(AS_MINUS);
  329. //
  330. // if actasmtoken=AS_REGISTER then
  331. // begin
  332. // oper.opr.ref.base:=actasmregister;
  333. // consume(AS_REGISTER);
  334. // end
  335. // else
  336. // begin
  337. // Message(asmr_e_invalid_reference_syntax);
  338. // RecoverConsume(false);
  339. // end;
  340. // end
  341. // else
  342. // begin
  343. // { Constant memory offset }
  344. // { This must absolutely be followed by ( }
  345. // oper.InitRef;
  346. // oper.opr.ref.offset:=BuildConstExpression(True,False);
  347. //
  348. // { absolute memory addresss? }
  349. // if actopcode in [A_LDS,A_STS] then
  350. // BuildReference(oper)
  351. // else
  352. // begin
  353. // ofs:=oper.opr.ref.offset;
  354. // BuildConstantOperand(oper);
  355. // inc(oper.opr.val,ofs);
  356. // end;
  357. // end;
  358. // end;
  359. //
  360. // AS_ID: { A constant expression, or a Variable ref. }
  361. // Begin
  362. // if (actasmpattern='LO8') or (actasmpattern='HI8') then
  363. // begin
  364. // { Low or High part of a constant (or constant
  365. // memory location) }
  366. // oper.InitRef;
  367. // if actasmpattern='LO8' then
  368. // oper.opr.ref.refaddr:=addr_lo8
  369. // else
  370. // oper.opr.ref.refaddr:=addr_hi8;
  371. // Consume(actasmtoken);
  372. // Consume(AS_LPAREN);
  373. // BuildConstSymbolExpression(false, true,false,l,tempstr,tempsymtyp);
  374. // if not assigned(oper.opr.ref.symbol) then
  375. // oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr,tempsymtyp)
  376. // else
  377. // Message(asmr_e_cant_have_multiple_relocatable_symbols);
  378. // case oper.opr.typ of
  379. // OPR_CONSTANT :
  380. // inc(oper.opr.val,l);
  381. // OPR_LOCAL :
  382. // inc(oper.opr.localsymofs,l);
  383. // OPR_REFERENCE :
  384. // inc(oper.opr.ref.offset,l);
  385. // else
  386. // internalerror(200309202);
  387. // end;
  388. // Consume(AS_RPAREN);
  389. // end
  390. // { Local Label ? }
  391. // else if is_locallabel(actasmpattern) then
  392. // begin
  393. // CreateLocalLabel(actasmpattern,hl,false);
  394. // Consume(AS_ID);
  395. // AddLabelOperand(hl);
  396. // end
  397. // { Check for label }
  398. // else if SearchLabel(actasmpattern,hl,false) then
  399. // begin
  400. // Consume(AS_ID);
  401. // AddLabelOperand(hl);
  402. // end
  403. // else
  404. // { probably a variable or normal expression }
  405. // { or a procedure (such as in CALL ID) }
  406. // Begin
  407. // { is it a constant ? }
  408. // if SearchIConstant(actasmpattern,l) then
  409. // Begin
  410. // if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  411. // Message(asmr_e_invalid_operand_type);
  412. // BuildConstantOperand(oper);
  413. // end
  414. // else
  415. // begin
  416. // expr:=actasmpattern;
  417. // Consume(AS_ID);
  418. // { typecasting? }
  419. // if (actasmtoken=AS_LPAREN) and
  420. // SearchType(expr,typesize) then
  421. // begin
  422. // oper.hastype:=true;
  423. // Consume(AS_LPAREN);
  424. // BuildOperand(oper);
  425. // Consume(AS_RPAREN);
  426. // if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  427. // oper.SetSize(typesize,true);
  428. // end
  429. // else
  430. // begin
  431. // if not(oper.SetupVar(expr,false)) then
  432. // Begin
  433. // { look for special symbols ... }
  434. // if expr= '__HIGH' then
  435. // begin
  436. // consume(AS_LPAREN);
  437. // if not oper.setupvar('high'+actasmpattern,false) then
  438. // Message1(sym_e_unknown_id,'high'+actasmpattern);
  439. // consume(AS_ID);
  440. // consume(AS_RPAREN);
  441. // end
  442. // else
  443. // if expr = '__RESULT' then
  444. // oper.SetUpResult
  445. // else
  446. // if expr = '__SELF' then
  447. // oper.SetupSelf
  448. // else
  449. // if expr = '__OLDEBP' then
  450. // oper.SetupOldEBP
  451. // else
  452. // Message1(sym_e_unknown_id,expr);
  453. // end;
  454. // end;
  455. // end;
  456. // if actasmtoken=AS_DOT then
  457. // MaybeRecordOffset;
  458. // { add a constant expression? }
  459. // if (actasmtoken=AS_PLUS) then
  460. // begin
  461. // l:=BuildConstExpression(true,false);
  462. // case oper.opr.typ of
  463. // OPR_CONSTANT :
  464. // inc(oper.opr.val,l);
  465. // OPR_LOCAL :
  466. // inc(oper.opr.localsymofs,l);
  467. // OPR_REFERENCE :
  468. // inc(oper.opr.ref.offset,l);
  469. // else
  470. // internalerror(200309202);
  471. // end;
  472. // end
  473. // end;
  474. // { Do we have a indexing reference, then parse it also }
  475. // if actasmtoken=AS_LPAREN then
  476. // BuildReference(oper);
  477. // end;
  478. //
  479. // { Register, a variable reference or a constant reference }
  480. // AS_REGISTER:
  481. // Begin
  482. // { save the type of register used. }
  483. // tempreg:=actasmregister;
  484. // Consume(AS_REGISTER);
  485. // if (actasmtoken=AS_PLUS) then
  486. // begin
  487. // oper.opr.typ:=OPR_REFERENCE;
  488. //
  489. // reference_reset_base(oper.opr.ref,tempreg,0,1,[]);
  490. // oper.opr.ref.addressmode:=AM_POSTINCREMENT;
  491. //
  492. // consume(AS_PLUS);
  493. // end
  494. // else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  495. // Begin
  496. // if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  497. // Message(asmr_e_invalid_operand_type);
  498. // oper.opr.typ:=OPR_REGISTER;
  499. // oper.opr.reg:=tempreg;
  500. // end
  501. // else
  502. // Message(asmr_e_syn_operand);
  503. // end;
  504. //
  505. // AS_END,
  506. // AS_SEPARATOR,
  507. // AS_COMMA: ;
  508. // else
  509. // Begin
  510. // Message(asmr_e_syn_operand);
  511. // Consume(actasmtoken);
  512. // end;
  513. // end; { end case }
  514. // end;
  515. //procedure tz80reader.BuildOpCode(instr : tz80instruction);
  516. // var
  517. // operandnum : longint;
  518. // Begin
  519. // { opcode }
  520. // if (actasmtoken<>AS_OPCODE) then
  521. // Begin
  522. // Message(asmr_e_invalid_or_missing_opcode);
  523. // RecoverConsume(true);
  524. // exit;
  525. // end;
  526. // { Fill the instr object with the current state }
  527. // with instr do
  528. // begin
  529. // Opcode:=ActOpcode;
  530. // condition:=ActCondition;
  531. // end;
  532. //
  533. // { We are reading operands, so opcode will be an AS_ID }
  534. // operandnum:=1;
  535. // Consume(AS_OPCODE);
  536. // { Zero operand opcode ? }
  537. // if actasmtoken in [AS_SEPARATOR,AS_END] then
  538. // begin
  539. // operandnum:=0;
  540. // exit;
  541. // end;
  542. // { Read the operands }
  543. // repeat
  544. // case actasmtoken of
  545. // AS_COMMA: { Operand delimiter }
  546. // Begin
  547. // if operandnum>Max_Operands then
  548. // Message(asmr_e_too_many_operands)
  549. // else
  550. // Inc(operandnum);
  551. // Consume(AS_COMMA);
  552. // end;
  553. // AS_SEPARATOR,
  554. // AS_END : { End of asm operands for this opcode }
  555. // begin
  556. // break;
  557. // end;
  558. // else
  559. // BuildOperand(instr.Operands[operandnum] as tz80operand);
  560. // end; { end case }
  561. // until false;
  562. // instr.Ops:=operandnum;
  563. // end;
  564. //function tz80reader.is_asmopcode(const s: string):boolean;
  565. //
  566. // const
  567. // { sorted by length so longer postfixes will match first }
  568. // postfix2strsorted : array[1..19] of string[2] = (
  569. // 'EP','SB','BT','SH',
  570. // 'IA','IB','DA','DB','FD','FA','ED','EA',
  571. // 'B','D','E','P','T','H','S');
  572. //
  573. // var
  574. // len,
  575. // j,
  576. // sufidx : longint;
  577. // hs : string;
  578. // maxlen : longint;
  579. // icond : tasmcond;
  580. // Begin
  581. // { making s a value parameter would break other assembler readers }
  582. // hs:=s;
  583. // is_asmopcode:=false;
  584. //
  585. // { clear op code }
  586. // actopcode:=A_None;
  587. //
  588. // actcondition:=C_None;
  589. //
  590. // { first, handle B else BLS is read wrong }
  591. // if ((copy(hs,1,2)='BR') and (length(hs)=4)) then
  592. // begin
  593. // for icond:=low(tasmcond) to high(tasmcond) do
  594. // begin
  595. // if copy(hs,2,3)=uppercond2str[icond] then
  596. // begin
  597. // actopcode:=A_BRxx;
  598. // actasmtoken:=AS_OPCODE;
  599. // actcondition:=icond;
  600. // is_asmopcode:=true;
  601. // exit;
  602. // end;
  603. // end;
  604. // end;
  605. // maxlen:=max(length(hs),5);
  606. // actopcode:=A_NONE;
  607. // for j:=maxlen downto 1 do
  608. // begin
  609. // actopcode:=tasmop(PtrUInt(iasmops.Find(copy(hs,1,j))));
  610. // if actopcode<>A_NONE then
  611. // begin
  612. // actasmtoken:=AS_OPCODE;
  613. // { strip op code }
  614. // delete(hs,1,j);
  615. // break;
  616. // end;
  617. // end;
  618. // if actopcode=A_NONE then
  619. // exit;
  620. // { search for condition, conditions are always 2 chars }
  621. // if length(hs)>1 then
  622. // begin
  623. // for icond:=low(tasmcond) to high(tasmcond) do
  624. // begin
  625. // if copy(hs,1,2)=uppercond2str[icond] then
  626. // begin
  627. // actcondition:=icond;
  628. // { strip condition }
  629. // delete(hs,1,2);
  630. // break;
  631. // end;
  632. // end;
  633. // end;
  634. // { if we stripped all postfixes, it's a valid opcode }
  635. // is_asmopcode:=length(hs)=0;
  636. // end;
  637. procedure tz80reader.ConvertCalljmp(instr : tz80instruction);
  638. var
  639. newopr : toprrec;
  640. begin
  641. if instr.Operands[1].opr.typ=OPR_REFERENCE then
  642. begin
  643. newopr.typ:=OPR_SYMBOL;
  644. newopr.symbol:=instr.Operands[1].opr.ref.symbol;
  645. newopr.symofs:=instr.Operands[1].opr.ref.offset;
  646. if (instr.Operands[1].opr.ref.base<>NR_NO) or
  647. (instr.Operands[1].opr.ref.index<>NR_NO) then
  648. Message(asmr_e_syn_operand);
  649. instr.Operands[1].opr:=newopr;
  650. end;
  651. end;
  652. //procedure tz80reader.handleopcode;
  653. // var
  654. // instr : tz80instruction;
  655. // begin
  656. // instr:=tz80instruction.Create(tz80operand);
  657. // BuildOpcode(instr);
  658. { // if is_calljmp(instr.opcode) then
  659. // ConvertCalljmp(instr); }
  660. // {
  661. // instr.AddReferenceSizes;
  662. // instr.SetInstructionOpsize;
  663. // instr.CheckOperandSizes;
  664. // }
  665. // instr.ConcatInstruction(curlist);
  666. // instr.Free;
  667. // end;
  668. {*****************************************************************************
  669. Initialize
  670. *****************************************************************************}
  671. const
  672. { asmmode_z80_att_info : tasmmodeinfo =
  673. (
  674. id : asmmode_z80_gas;
  675. idtxt : 'GAS';
  676. casmreader : tz80attreader;
  677. );}
  678. asmmode_z80_standard_info : tasmmodeinfo =
  679. (
  680. id : asmmode_standard;
  681. idtxt : 'STANDARD';
  682. casmreader : tz80reader;
  683. );
  684. initialization
  685. // RegisterAsmMode(asmmode_z80_att_info);
  686. RegisterAsmMode(asmmode_z80_standard_info);
  687. end.