rarv64gas.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. {
  2. Copyright (c) 2016 by Jeppe Johansen
  3. Does the parsing for the RiscV64 GNU AS 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 rarv64gas;
  18. {$I fpcdefs.inc}
  19. interface
  20. uses
  21. raatt, rarvgas, rarv,
  22. cpubase;
  23. type
  24. trv64attreader = class(trvattreader)
  25. actmemoryordering: TMemoryOrdering;
  26. function is_register(const s: string): boolean; override;
  27. function is_asmopcode(const s: string):boolean;override;
  28. procedure handleopcode;override;
  29. procedure BuildReference(oper : trvoperand);
  30. procedure BuildOperand(oper : trvoperand);
  31. procedure BuildOpCode(instr : trvinstruction);
  32. procedure ReadAt(oper : trvoperand);
  33. procedure ReadSym(oper : trvoperand);
  34. end;
  35. implementation
  36. uses
  37. { helpers }
  38. cutils,
  39. { global }
  40. globtype,globals,verbose,
  41. systems,
  42. { aasm }
  43. aasmbase,aasmtai,aasmdata,aasmcpu,
  44. { symtable }
  45. symconst,symsym,symdef,
  46. { parser }
  47. procinfo,
  48. rabase,rautils,
  49. cgbase,cgobj,cgrv
  50. ;
  51. procedure trv64attreader.ReadSym(oper : trvoperand);
  52. var
  53. tempstr, mangledname : string;
  54. typesize,l,k : aint;
  55. begin
  56. tempstr:=actasmpattern;
  57. Consume(AS_ID);
  58. { typecasting? }
  59. if (actasmtoken=AS_LPAREN) and
  60. SearchType(tempstr,typesize) then
  61. begin
  62. oper.hastype:=true;
  63. Consume(AS_LPAREN);
  64. BuildOperand(oper);
  65. Consume(AS_RPAREN);
  66. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  67. oper.SetSize(typesize,true);
  68. end
  69. else
  70. if not oper.SetupVar(tempstr,false) then
  71. Message1(sym_e_unknown_id,tempstr);
  72. { record.field ? }
  73. if actasmtoken=AS_DOT then
  74. begin
  75. BuildRecordOffsetSize(tempstr,l,k,mangledname,false);
  76. if (mangledname<>'') then
  77. Message(asmr_e_invalid_reference_syntax);
  78. inc(oper.opr.ref.offset,l);
  79. end;
  80. end;
  81. procedure trv64attreader.ReadAt(oper : trvoperand);
  82. begin
  83. { check for ...@ }
  84. if actasmtoken=AS_AT then
  85. begin
  86. if (oper.opr.ref.symbol=nil) and
  87. (oper.opr.ref.offset = 0) then
  88. Message(asmr_e_invalid_reference_syntax);
  89. Consume(AS_AT);
  90. if actasmtoken=AS_ID then
  91. begin
  92. {if upper(actasmpattern)='L' then
  93. oper.opr.ref.refaddr:=addr_low
  94. else if upper(actasmpattern)='HI' then
  95. oper.opr.ref.refaddr:=addr_high
  96. else if upper(actasmpattern)='HA' then
  97. oper.opr.ref.refaddr:=addr_higha
  98. else}
  99. Message(asmr_e_invalid_reference_syntax);
  100. Consume(AS_ID);
  101. end
  102. else
  103. Message(asmr_e_invalid_reference_syntax);
  104. end;
  105. end;
  106. procedure trv64attreader.BuildReference(oper: trvoperand);
  107. procedure Consume_RParen;
  108. begin
  109. if actasmtoken <> AS_RPAREN then
  110. Begin
  111. Message(asmr_e_invalid_reference_syntax);
  112. RecoverConsume(true);
  113. end
  114. else
  115. begin
  116. Consume(AS_RPAREN);
  117. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  118. Begin
  119. Message(asmr_e_invalid_reference_syntax);
  120. RecoverConsume(true);
  121. end;
  122. end;
  123. end;
  124. var
  125. l : aint;
  126. relsym: string;
  127. asmsymtyp: tasmsymtype;
  128. isflags: tindsymflags;
  129. begin
  130. Consume(AS_LPAREN);
  131. Case actasmtoken of
  132. AS_INTNUM,
  133. AS_MINUS,
  134. AS_PLUS:
  135. Begin
  136. { offset(offset) is invalid }
  137. If oper.opr.Ref.Offset <> 0 Then
  138. Begin
  139. Message(asmr_e_invalid_reference_syntax);
  140. RecoverConsume(true);
  141. End
  142. Else
  143. Begin
  144. oper.opr.Ref.Offset:=BuildConstExpression(false,true);
  145. Consume(AS_RPAREN);
  146. if actasmtoken=AS_AT then
  147. ReadAt(oper);
  148. end;
  149. exit;
  150. End;
  151. AS_REGISTER: { (reg ... }
  152. Begin
  153. if ((oper.opr.typ=OPR_REFERENCE) and (oper.opr.ref.base<>NR_NO)) or
  154. ((oper.opr.typ=OPR_LOCAL) and (oper.opr.localsym.localloc.loc<>LOC_REGISTER)) then
  155. message(asmr_e_cannot_index_relative_var);
  156. oper.opr.ref.base:=actasmregister;
  157. Consume(AS_REGISTER);
  158. Consume_RParen;
  159. end; {end case }
  160. AS_ID:
  161. Begin
  162. ReadSym(oper);
  163. case actasmtoken of
  164. AS_PLUS:
  165. begin
  166. { add a constant expression? }
  167. l:=BuildConstExpression(true,true);
  168. case oper.opr.typ of
  169. OPR_CONSTANT :
  170. inc(oper.opr.val,l);
  171. OPR_LOCAL :
  172. inc(oper.opr.localsymofs,l);
  173. OPR_REFERENCE :
  174. inc(oper.opr.ref.offset,l);
  175. else
  176. internalerror(200309202);
  177. end;
  178. end;
  179. AS_MINUS:
  180. begin
  181. Consume(AS_MINUS);
  182. BuildConstSymbolExpression(false,true,false,l,relsym,asmsymtyp);
  183. if (relsym<>'') then
  184. begin
  185. if (oper.opr.typ = OPR_REFERENCE) then
  186. oper.opr.ref.relsymbol:=current_asmdata.RefAsmSymbol(relsym,AT_DATA)
  187. else
  188. begin
  189. Message(asmr_e_invalid_reference_syntax);
  190. RecoverConsume(false);
  191. end
  192. end
  193. else
  194. begin
  195. case oper.opr.typ of
  196. OPR_CONSTANT :
  197. dec(oper.opr.val,l);
  198. OPR_LOCAL :
  199. dec(oper.opr.localsymofs,l);
  200. OPR_REFERENCE :
  201. dec(oper.opr.ref.offset,l);
  202. else
  203. internalerror(2007092601);
  204. end;
  205. end;
  206. end;
  207. end;
  208. Consume(AS_RPAREN);
  209. if actasmtoken=AS_AT then
  210. ReadAt(oper);
  211. End;
  212. AS_COMMA: { (, ... can either be scaling, or index }
  213. Begin
  214. Consume(AS_COMMA);
  215. { Index }
  216. if (actasmtoken=AS_REGISTER) then
  217. Begin
  218. oper.opr.ref.index:=actasmregister;
  219. Consume(AS_REGISTER);
  220. { check for scaling ... }
  221. Consume_RParen;
  222. end
  223. else
  224. begin
  225. Message(asmr_e_invalid_reference_syntax);
  226. RecoverConsume(false);
  227. end;
  228. end;
  229. else
  230. Begin
  231. Message(asmr_e_invalid_reference_syntax);
  232. RecoverConsume(false);
  233. end;
  234. end;
  235. end;
  236. procedure trv64attreader.BuildOperand(oper: trvoperand);
  237. var
  238. expr : string;
  239. typesize,l : aint;
  240. procedure AddLabelOperand(hl:tasmlabel);
  241. begin
  242. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  243. is_calljmp(actopcode) then
  244. begin
  245. oper.opr.typ:=OPR_SYMBOL;
  246. oper.opr.symbol:=hl;
  247. end
  248. else
  249. begin
  250. oper.InitRef;
  251. oper.opr.ref.symbol:=hl;
  252. end;
  253. end;
  254. procedure MaybeRecordOffset;
  255. var
  256. mangledname: string;
  257. hasdot : boolean;
  258. l,
  259. toffset,
  260. tsize : aint;
  261. begin
  262. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  263. exit;
  264. l:=0;
  265. hasdot:=(actasmtoken=AS_DOT);
  266. if hasdot then
  267. begin
  268. if expr<>'' then
  269. begin
  270. BuildRecordOffsetSize(expr,toffset,tsize,mangledname,false);
  271. if (oper.opr.typ<>OPR_CONSTANT) and
  272. (mangledname<>'') then
  273. Message(asmr_e_wrong_sym_type);
  274. inc(l,toffset);
  275. oper.SetSize(tsize,true);
  276. end;
  277. end;
  278. if actasmtoken in [AS_PLUS,AS_MINUS] then
  279. inc(l,BuildConstExpression(true,false));
  280. case oper.opr.typ of
  281. OPR_LOCAL :
  282. begin
  283. { don't allow direct access to fields of parameters, because that
  284. will generate buggy code. Allow it only for explicit typecasting }
  285. if hasdot and
  286. (not oper.hastype) and
  287. (tabstractvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  288. (current_procinfo.procdef.proccalloption<>pocall_register) then
  289. Message(asmr_e_cannot_access_field_directly_for_parameters);
  290. inc(oper.opr.localsymofs,l)
  291. end;
  292. OPR_CONSTANT :
  293. if (mangledname<>'') then
  294. begin
  295. if (oper.opr.val<>0) then
  296. Message(asmr_e_wrong_sym_type);
  297. oper.opr.typ:=OPR_SYMBOL;
  298. oper.opr.symbol:=current_asmdata.DefineAsmSymbol(mangledname,AB_EXTERNAL,AT_FUNCTION,voidcodepointertype);
  299. end
  300. else
  301. inc(oper.opr.val,l);
  302. OPR_REFERENCE :
  303. inc(oper.opr.ref.offset,l);
  304. OPR_SYMBOL:
  305. Message(asmr_e_invalid_symbol_ref);
  306. else
  307. internalerror(200309221);
  308. end;
  309. end;
  310. function MaybeBuildReference:boolean;
  311. { Try to create a reference, if not a reference is found then false
  312. is returned }
  313. begin
  314. MaybeBuildReference:=true;
  315. case actasmtoken of
  316. AS_INTNUM,
  317. AS_MINUS,
  318. AS_PLUS:
  319. Begin
  320. oper.opr.ref.offset:=BuildConstExpression(True,False);
  321. if actasmtoken<>AS_LPAREN then
  322. Message(asmr_e_invalid_reference_syntax)
  323. else
  324. BuildReference(oper);
  325. end;
  326. AS_LPAREN:
  327. BuildReference(oper);
  328. AS_ID: { only a variable is allowed ... }
  329. Begin
  330. ReadSym(oper);
  331. case actasmtoken of
  332. AS_END,
  333. AS_SEPARATOR,
  334. AS_COMMA: ;
  335. AS_LPAREN:
  336. BuildReference(oper);
  337. else
  338. Begin
  339. Message(asmr_e_invalid_reference_syntax);
  340. Consume(actasmtoken);
  341. end;
  342. end; {end case }
  343. end;
  344. else
  345. MaybeBuildReference:=false;
  346. end; { end case }
  347. end;
  348. function is_fenceflag(hs : string): boolean;
  349. var
  350. i: longint;
  351. flags: TFenceFlags;
  352. begin
  353. is_fenceflag := false;
  354. flags:=[];
  355. hs:=lower(hs);
  356. if (actopcode in [A_FENCE]) and (length(hs) >= 1) then
  357. begin
  358. for i:=1 to length(hs) do
  359. begin
  360. case hs[i] of
  361. 'i':
  362. Include(flags,ffi);
  363. 'o':
  364. Include(flags,ffo);
  365. 'r':
  366. Include(flags,ffr);
  367. 'w':
  368. Include(flags,ffw);
  369. else
  370. exit;
  371. end;
  372. end;
  373. oper.opr.typ := OPR_FENCEFLAGS;
  374. oper.opr.fenceflags := flags;
  375. exit(true);
  376. end;
  377. end;
  378. var
  379. tempreg : tregister;
  380. hl : tasmlabel;
  381. ofs : aint;
  382. refaddr: trefaddr;
  383. entered_paren: Boolean;
  384. Begin
  385. expr:='';
  386. entered_paren:=false;
  387. refaddr:=addr_full;
  388. if actasmtoken=AS_MOD then
  389. begin
  390. consume(AS_MOD);
  391. if actasmtoken<>AS_ID then
  392. begin
  393. Message(asmr_e_invalid_reference_syntax);
  394. RecoverConsume(false);
  395. end
  396. else
  397. begin
  398. if lower(actasmpattern)='pcrel_hi' then
  399. refaddr:=addr_pcrel_hi20
  400. else if lower(actasmpattern)='pcrel_lo' then
  401. refaddr:=addr_pcrel_lo12
  402. else if lower(actasmpattern)='hi' then
  403. refaddr:=addr_hi20
  404. else if lower(actasmpattern)='lo' then
  405. refaddr:=addr_lo12
  406. else
  407. begin
  408. Message(asmr_e_invalid_reference_syntax);
  409. RecoverConsume(false);
  410. end;
  411. consume(AS_ID);
  412. consume(AS_LPAREN);
  413. entered_paren:=true;
  414. end;
  415. end;
  416. case actasmtoken of
  417. AS_LPAREN: { Memory reference or constant expression }
  418. Begin
  419. oper.InitRef;
  420. BuildReference(oper);
  421. end;
  422. AS_INTNUM,
  423. AS_MINUS,
  424. AS_PLUS:
  425. Begin
  426. { Constant memory offset }
  427. { This must absolutely be followed by ( }
  428. oper.InitRef;
  429. oper.opr.ref.offset:=BuildConstExpression(True,False);
  430. if actasmtoken<>AS_LPAREN then
  431. begin
  432. ofs:=oper.opr.ref.offset;
  433. BuildConstantOperand(oper);
  434. inc(oper.opr.val,ofs);
  435. end
  436. else
  437. BuildReference(oper);
  438. end;
  439. AS_DOT,
  440. AS_ID: { A constant expression, or a Variable ref. }
  441. Begin
  442. if is_fenceflag(actasmpattern) then
  443. begin
  444. consume(AS_ID);
  445. end
  446. else
  447. { Local Label ? }
  448. if is_locallabel(actasmpattern) then
  449. begin
  450. CreateLocalLabel(actasmpattern,hl,false);
  451. Consume(AS_ID);
  452. AddLabelOperand(hl);
  453. end
  454. else
  455. { Check for label }
  456. if SearchLabel(actasmpattern,hl,false) then
  457. begin
  458. Consume(AS_ID);
  459. AddLabelOperand(hl);
  460. end
  461. else
  462. { probably a variable or normal expression }
  463. { or a procedure (such as in CALL ID) }
  464. Begin
  465. { is it a constant ? }
  466. if SearchIConstant(actasmpattern,l) then
  467. Begin
  468. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  469. Message(asmr_e_invalid_operand_type);
  470. BuildConstantOperand(oper);
  471. end
  472. else
  473. begin
  474. expr:=actasmpattern;
  475. Consume(AS_ID);
  476. { typecasting? }
  477. if (actasmtoken=AS_LPAREN) and
  478. SearchType(expr,typesize) then
  479. begin
  480. oper.hastype:=true;
  481. Consume(AS_LPAREN);
  482. BuildOperand(oper);
  483. Consume(AS_RPAREN);
  484. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  485. oper.SetSize(typesize,true);
  486. end
  487. else
  488. begin
  489. if oper.SetupVar(expr,false) then
  490. ReadAt(oper)
  491. else
  492. Begin
  493. { look for special symbols ... }
  494. if expr= '__HIGH' then
  495. begin
  496. consume(AS_LPAREN);
  497. if not oper.setupvar('high'+actasmpattern,false) then
  498. Message1(sym_e_unknown_id,'high'+actasmpattern);
  499. consume(AS_ID);
  500. consume(AS_RPAREN);
  501. end
  502. else
  503. if expr = '__RESULT' then
  504. oper.SetUpResult
  505. else
  506. if expr = '__SELF' then
  507. oper.SetupSelf
  508. else
  509. if expr = '__OLDEBP' then
  510. oper.SetupOldEBP
  511. else
  512. Message1(sym_e_unknown_id,expr);
  513. end;
  514. end;
  515. end;
  516. if actasmtoken=AS_DOT then
  517. MaybeRecordOffset;
  518. { add a constant expression? }
  519. if (actasmtoken=AS_PLUS) then
  520. begin
  521. l:=BuildConstExpression(true,entered_paren);
  522. case oper.opr.typ of
  523. OPR_CONSTANT :
  524. inc(oper.opr.val,l);
  525. OPR_LOCAL :
  526. inc(oper.opr.localsymofs,l);
  527. OPR_REFERENCE :
  528. inc(oper.opr.ref.offset,l);
  529. else
  530. internalerror(200309202);
  531. end;
  532. end
  533. end;
  534. { Do we have a indexing reference, then parse it also }
  535. if actasmtoken=AS_LPAREN then
  536. BuildReference(oper);
  537. end;
  538. AS_REGISTER: { Register, a variable reference or a constant reference }
  539. Begin
  540. { save the type of register used. }
  541. tempreg:=actasmregister;
  542. Consume(AS_REGISTER);
  543. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  544. begin
  545. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  546. Message(asmr_e_invalid_operand_type);
  547. oper.opr.typ:=OPR_REGISTER;
  548. oper.opr.reg:=tempreg;
  549. end
  550. else
  551. Message(asmr_e_syn_operand);
  552. end;
  553. AS_END,
  554. AS_SEPARATOR,
  555. AS_COMMA: ;
  556. else
  557. Begin
  558. Message(asmr_e_syn_operand);
  559. Consume(actasmtoken);
  560. end;
  561. end; { end case }
  562. if refaddr<>addr_full then
  563. begin
  564. if oper.opr.typ<>OPR_REFERENCE then
  565. oper.InitRef;
  566. oper.opr.ref.refaddr:=refaddr;
  567. Consume(AS_RPAREN);
  568. end;
  569. end;
  570. {*****************************************************************************
  571. trv64attreader
  572. *****************************************************************************}
  573. procedure trv64attreader.BuildOpCode(instr : trvinstruction);
  574. var
  575. operandnum : longint;
  576. Begin
  577. { opcode }
  578. if (actasmtoken<>AS_OPCODE) then
  579. Begin
  580. Message(asmr_e_invalid_or_missing_opcode);
  581. RecoverConsume(true);
  582. exit;
  583. end;
  584. { Fill the instr object with the current state }
  585. with instr do
  586. begin
  587. Opcode:=ActOpcode;
  588. condition:=ActCondition;
  589. ordering:=actmemoryordering;
  590. end;
  591. { We are reading operands, so opcode will be an AS_ID }
  592. operandnum:=1;
  593. Consume(AS_OPCODE);
  594. { Zero operand opcode ? }
  595. if actasmtoken in [AS_SEPARATOR,AS_END] then
  596. begin
  597. operandnum:=0;
  598. exit;
  599. end;
  600. { Read the operands }
  601. repeat
  602. case actasmtoken of
  603. AS_COMMA: { Operand delimiter }
  604. Begin
  605. if operandnum>Max_Operands then
  606. Message(asmr_e_too_many_operands)
  607. else
  608. begin
  609. { condition operands doesn't set the operand but write to the
  610. condition field of the instruction
  611. }
  612. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  613. Inc(operandnum);
  614. end;
  615. Consume(AS_COMMA);
  616. end;
  617. AS_SEPARATOR,
  618. AS_END : { End of asm operands for this opcode }
  619. begin
  620. break;
  621. end;
  622. else
  623. BuildOperand(instr.Operands[operandnum] as trvoperand);
  624. end; { end case }
  625. until false;
  626. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  627. dec(operandnum);
  628. instr.Ops:=operandnum;
  629. end;
  630. function trv64attreader.is_register(const s: string): boolean;
  631. type
  632. treg2str = record
  633. name : string[3];
  634. reg : tregister;
  635. end;
  636. const
  637. extraregs : array[0..31] of treg2str = (
  638. (name: 'A0'; reg : NR_X10),
  639. (name: 'A1'; reg : NR_X11),
  640. (name: 'A2'; reg : NR_X12),
  641. (name: 'A3'; reg : NR_X13),
  642. (name: 'A4'; reg : NR_X14),
  643. (name: 'A5'; reg : NR_X15),
  644. (name: 'A6'; reg : NR_X16),
  645. (name: 'A7'; reg : NR_X17),
  646. (name: 'RA'; reg : NR_X1),
  647. (name: 'SP'; reg : NR_X2),
  648. (name: 'GP'; reg : NR_X3),
  649. (name: 'TP'; reg : NR_X4),
  650. (name: 'T0'; reg : NR_X5),
  651. (name: 'T1'; reg : NR_X6),
  652. (name: 'T2'; reg : NR_X7),
  653. (name: 'S0'; reg : NR_X8),
  654. (name: 'FP'; reg : NR_X8),
  655. (name: 'S1'; reg : NR_X9),
  656. (name: 'S2'; reg : NR_X18),
  657. (name: 'S3'; reg : NR_X19),
  658. (name: 'S4'; reg : NR_X20),
  659. (name: 'S5'; reg : NR_X21),
  660. (name: 'S6'; reg : NR_X22),
  661. (name: 'S7'; reg : NR_X23),
  662. (name: 'S8'; reg : NR_X24),
  663. (name: 'S9'; reg : NR_X25),
  664. (name: 'S10';reg : NR_X26),
  665. (name: 'S11';reg : NR_X27),
  666. (name: 'T3'; reg : NR_X28),
  667. (name: 'T4'; reg : NR_X29),
  668. (name: 'T5'; reg : NR_X30),
  669. (name: 'T6'; reg : NR_X31)
  670. );
  671. var
  672. i : longint;
  673. begin
  674. result:=inherited is_register(s);
  675. { reg found?
  676. possible aliases are always 2 char
  677. }
  678. if result or (not (length(s) in [2,3])) then
  679. exit;
  680. for i:=low(extraregs) to high(extraregs) do
  681. begin
  682. if s=extraregs[i].name then
  683. begin
  684. actasmregister:=extraregs[i].reg;
  685. result:=true;
  686. actasmtoken:=AS_REGISTER;
  687. exit;
  688. end;
  689. end;
  690. end;
  691. function trv64attreader.is_asmopcode(const s: string):boolean;
  692. var
  693. cond : tasmcond;
  694. hs, postfix : string;
  695. l: longint;
  696. Begin
  697. { making s a value parameter would break other assembler readers }
  698. hs:=s;
  699. is_asmopcode:=false;
  700. { clear op code }
  701. actopcode:=A_None;
  702. { clear condition }
  703. fillchar(actcondition,sizeof(actcondition),0);
  704. { check for direction hint }
  705. actopcode := tasmop(ptruint(iasmops.find(hs)));
  706. if actopcode <> A_NONE then
  707. begin
  708. actasmtoken:=AS_OPCODE;
  709. is_asmopcode:=true;
  710. exit;
  711. end;
  712. { not found, check branch instructions }
  713. if hs[1]='B' then
  714. begin
  715. { we can search here without an extra table which is sorted by string length
  716. because we take the whole remaining string without the leading B }
  717. actopcode := A_Bxx;
  718. for cond:=low(TAsmCond) to high(TAsmCond) do
  719. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  720. begin
  721. actcondition:=cond;
  722. actasmtoken:=AS_OPCODE;
  723. is_asmopcode:=true;
  724. exit;
  725. end;
  726. end;
  727. { check atomic instructions }
  728. if (pos('AMO',hs)=1) or
  729. (pos('LR', hs)=1) or
  730. (pos('SC', hs)=1) then
  731. begin
  732. l := length(hs)-1;
  733. while l>1 do
  734. begin
  735. actopcode := tasmop(ptruint(iasmops.find(copy(hs,1,l))));
  736. if actopcode <> A_None then
  737. begin
  738. postfix := copy(hs,l+1,length(hs)-l);
  739. if postfix='.AQRL' then actmemoryordering:=[moAq,moRl]
  740. else if postfix='.RL' then actmemoryordering:=[moRl]
  741. else if postfix='.AQ' then actmemoryordering:=[moAq]
  742. else
  743. exit;
  744. actasmtoken:=AS_OPCODE;
  745. is_asmopcode:=true;
  746. exit;
  747. end;
  748. dec(l);
  749. end;
  750. end;
  751. end;
  752. procedure trv64attreader.handleopcode;
  753. var
  754. instr : trvinstruction;
  755. begin
  756. instr:=trvinstruction.Create(trvoperand);
  757. BuildOpcode(instr);
  758. instr.condition := actcondition;
  759. {
  760. instr.AddReferenceSizes;
  761. instr.SetInstructionOpsize;
  762. instr.CheckOperandSizes;
  763. }
  764. instr.ConcatInstruction(curlist);
  765. instr.Free;
  766. actmemoryordering:=[];
  767. end;
  768. {*****************************************************************************
  769. Initialize
  770. *****************************************************************************}
  771. const
  772. asmmode_rv64_standard_info : tasmmodeinfo =
  773. (
  774. id : asmmode_standard;
  775. idtxt : 'STANDARD';
  776. casmreader : trv64attreader;
  777. );
  778. initialization
  779. RegisterAsmMode(asmmode_rv64_standard_info);
  780. end.