rarv32gas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Does the parsing for the Risc-V32 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 rarv32gas;
  18. {$i fpcdefs.inc}
  19. Interface
  20. uses
  21. raatt,rarv32,rarvgas;
  22. type
  23. trv32attreader = class(trvattreader)
  24. function is_register(const s: string): boolean; override;
  25. function is_asmopcode(const s: string):boolean;override;
  26. procedure handleopcode;override;
  27. procedure BuildReference(oper : trvoperand);
  28. procedure BuildOperand(oper : trvoperand);
  29. procedure BuildOpCode(instr : trvinstruction);
  30. procedure ReadAt(oper : trvoperand);
  31. procedure ReadSym(oper : trvoperand);
  32. end;
  33. Implementation
  34. uses
  35. { helpers }
  36. cutils,
  37. { global }
  38. globtype,globals,verbose,
  39. systems,
  40. { aasm }
  41. cpubase,aasmbase,aasmtai,aasmdata,aasmcpu,
  42. { symtable }
  43. symconst,symdef,symsym,
  44. { parser }
  45. procinfo,
  46. rabase,rautils,
  47. cgbase,cgobj,cgrv
  48. ;
  49. procedure trv32attreader.ReadSym(oper : trvoperand);
  50. var
  51. tempstr, mangledname : string;
  52. l,k,typesize : tcgint;
  53. begin
  54. tempstr:=actasmpattern;
  55. Consume(AS_ID);
  56. { typecasting? }
  57. if (actasmtoken=AS_LPAREN) and
  58. SearchType(tempstr,typesize) then
  59. begin
  60. oper.hastype:=true;
  61. Consume(AS_LPAREN);
  62. BuildOperand(oper);
  63. Consume(AS_RPAREN);
  64. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  65. oper.SetSize(typesize,true);
  66. end
  67. else
  68. if not oper.SetupVar(tempstr,false) then
  69. Message1(sym_e_unknown_id,tempstr);
  70. { record.field ? }
  71. if actasmtoken=AS_DOT then
  72. begin
  73. BuildRecordOffsetSize(tempstr,l,k,mangledname,false);
  74. if (mangledname<>'') then
  75. Message(asmr_e_invalid_reference_syntax);
  76. inc(oper.opr.ref.offset,l);
  77. end;
  78. end;
  79. procedure trv32attreader.ReadAt(oper : trvoperand);
  80. begin
  81. { check for ...@ }
  82. if actasmtoken=AS_AT then
  83. begin
  84. if (oper.opr.ref.symbol=nil) and
  85. (oper.opr.ref.offset = 0) then
  86. Message(asmr_e_invalid_reference_syntax);
  87. Consume(AS_AT);
  88. if actasmtoken=AS_ID then
  89. begin
  90. {if upper(actasmpattern)='L' then
  91. oper.opr.ref.refaddr:=addr_low
  92. else if upper(actasmpattern)='HI' then
  93. oper.opr.ref.refaddr:=addr_high
  94. else if upper(actasmpattern)='HA' then
  95. oper.opr.ref.refaddr:=addr_higha
  96. else}
  97. Message(asmr_e_invalid_reference_syntax);
  98. Consume(AS_ID);
  99. end
  100. else
  101. Message(asmr_e_invalid_reference_syntax);
  102. end;
  103. end;
  104. Procedure trv32attreader.BuildReference(oper : trvoperand);
  105. procedure Consume_RParen;
  106. begin
  107. if actasmtoken <> AS_RPAREN then
  108. Begin
  109. Message(asmr_e_invalid_reference_syntax);
  110. RecoverConsume(true);
  111. end
  112. else
  113. begin
  114. Consume(AS_RPAREN);
  115. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  116. Begin
  117. Message(asmr_e_invalid_reference_syntax);
  118. RecoverConsume(true);
  119. end;
  120. end;
  121. end;
  122. var
  123. l : tcgint;
  124. relsym: string;
  125. asmsymtyp: tasmsymtype;
  126. isflags: tindsymflags;
  127. begin
  128. Consume(AS_LPAREN);
  129. Case actasmtoken of
  130. AS_INTNUM,
  131. AS_MINUS,
  132. AS_PLUS:
  133. Begin
  134. { offset(offset) is invalid }
  135. If oper.opr.Ref.Offset <> 0 Then
  136. Begin
  137. Message(asmr_e_invalid_reference_syntax);
  138. RecoverConsume(true);
  139. End
  140. Else
  141. Begin
  142. oper.opr.Ref.Offset:=BuildConstExpression(false,true);
  143. Consume(AS_RPAREN);
  144. if actasmtoken=AS_AT then
  145. ReadAt(oper);
  146. end;
  147. exit;
  148. End;
  149. AS_REGISTER: { (reg ... }
  150. Begin
  151. if ((oper.opr.typ=OPR_REFERENCE) and (oper.opr.ref.base<>NR_NO)) or
  152. ((oper.opr.typ=OPR_LOCAL) and (oper.opr.localsym.localloc.loc<>LOC_REGISTER)) then
  153. message(asmr_e_cannot_index_relative_var);
  154. oper.opr.ref.base:=actasmregister;
  155. Consume(AS_REGISTER);
  156. Consume_RParen;
  157. end; {end case }
  158. AS_ID:
  159. Begin
  160. ReadSym(oper);
  161. case actasmtoken of
  162. AS_PLUS:
  163. begin
  164. { add a constant expression? }
  165. l:=BuildConstExpression(true,true);
  166. case oper.opr.typ of
  167. OPR_CONSTANT :
  168. inc(oper.opr.val,l);
  169. OPR_LOCAL :
  170. inc(oper.opr.localsymofs,l);
  171. OPR_REFERENCE :
  172. inc(oper.opr.ref.offset,l);
  173. else
  174. internalerror(2003092008);
  175. end;
  176. end;
  177. AS_MINUS:
  178. begin
  179. Consume(AS_MINUS);
  180. BuildConstSymbolExpression(false,true,false,l,relsym,asmsymtyp);
  181. if (relsym<>'') then
  182. begin
  183. if (oper.opr.typ = OPR_REFERENCE) then
  184. oper.opr.ref.relsymbol:=current_asmdata.RefAsmSymbol(relsym,AT_DATA)
  185. else
  186. begin
  187. Message(asmr_e_invalid_reference_syntax);
  188. RecoverConsume(false);
  189. end
  190. end
  191. else
  192. begin
  193. case oper.opr.typ of
  194. OPR_CONSTANT :
  195. dec(oper.opr.val,l);
  196. OPR_LOCAL :
  197. dec(oper.opr.localsymofs,l);
  198. OPR_REFERENCE :
  199. dec(oper.opr.ref.offset,l);
  200. else
  201. internalerror(2007092601);
  202. end;
  203. end;
  204. end;
  205. else
  206. ;
  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 trv32attreader.BuildOperand(oper : trvoperand);
  237. var
  238. expr : string;
  239. typesize,l : tcgint;
  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 : tcgint;
  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. var
  349. tempreg : tregister;
  350. hl : tasmlabel;
  351. ofs : aint;
  352. refaddr: trefaddr;
  353. entered_paren: Boolean;
  354. Begin
  355. expr:='';
  356. entered_paren:=false;
  357. refaddr:=addr_full;
  358. if actasmtoken=AS_MOD then
  359. begin
  360. consume(AS_MOD);
  361. if actasmtoken<>AS_ID then
  362. begin
  363. Message(asmr_e_invalid_reference_syntax);
  364. RecoverConsume(false);
  365. end
  366. else
  367. begin
  368. if lower(actasmpattern)='pcrel_hi' then
  369. refaddr:=addr_pcrel_hi20
  370. else if lower(actasmpattern)='pcrel_lo' then
  371. refaddr:=addr_pcrel_lo12
  372. else if lower(actasmpattern)='hi' then
  373. refaddr:=addr_hi20
  374. else if lower(actasmpattern)='lo' then
  375. refaddr:=addr_lo12
  376. else
  377. begin
  378. Message(asmr_e_invalid_reference_syntax);
  379. RecoverConsume(false);
  380. end;
  381. consume(AS_ID);
  382. consume(AS_LPAREN);
  383. entered_paren:=true;
  384. end;
  385. end;
  386. case actasmtoken of
  387. AS_LPAREN: { Memory reference or constant expression }
  388. Begin
  389. oper.InitRef;
  390. BuildReference(oper);
  391. end;
  392. AS_INTNUM,
  393. AS_MINUS,
  394. AS_PLUS:
  395. Begin
  396. { Constant memory offset }
  397. { This must absolutely be followed by ( }
  398. oper.InitRef;
  399. oper.opr.ref.offset:=BuildConstExpression(True,False);
  400. if actasmtoken<>AS_LPAREN then
  401. begin
  402. ofs:=oper.opr.ref.offset;
  403. BuildConstantOperand(oper);
  404. inc(oper.opr.val,ofs);
  405. end
  406. else
  407. BuildReference(oper);
  408. end;
  409. AS_ID: { A constant expression, or a Variable ref. }
  410. Begin
  411. { Local Label ? }
  412. if is_locallabel(actasmpattern) then
  413. begin
  414. CreateLocalLabel(actasmpattern,hl,false);
  415. Consume(AS_ID);
  416. AddLabelOperand(hl);
  417. end
  418. else
  419. { Check for label }
  420. if SearchLabel(actasmpattern,hl,false) then
  421. begin
  422. Consume(AS_ID);
  423. AddLabelOperand(hl);
  424. end
  425. else
  426. { probably a variable or normal expression }
  427. { or a procedure (such as in CALL ID) }
  428. Begin
  429. { is it a constant ? }
  430. if SearchIConstant(actasmpattern,l) then
  431. Begin
  432. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  433. Message(asmr_e_invalid_operand_type);
  434. BuildConstantOperand(oper);
  435. end
  436. else
  437. begin
  438. expr:=actasmpattern;
  439. Consume(AS_ID);
  440. { typecasting? }
  441. if (actasmtoken=AS_LPAREN) and
  442. SearchType(expr,typesize) then
  443. begin
  444. oper.hastype:=true;
  445. Consume(AS_LPAREN);
  446. BuildOperand(oper);
  447. Consume(AS_RPAREN);
  448. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  449. oper.SetSize(typesize,true);
  450. end
  451. else
  452. begin
  453. if oper.SetupVar(expr,false) then
  454. ReadAt(oper)
  455. else
  456. Begin
  457. { look for special symbols ... }
  458. if expr= '__HIGH' then
  459. begin
  460. consume(AS_LPAREN);
  461. if not oper.setupvar('high'+actasmpattern,false) then
  462. Message1(sym_e_unknown_id,'high'+actasmpattern);
  463. consume(AS_ID);
  464. consume(AS_RPAREN);
  465. end
  466. else
  467. if expr = '__RESULT' then
  468. oper.SetUpResult
  469. else
  470. if expr = '__SELF' then
  471. oper.SetupSelf
  472. else
  473. if expr = '__OLDEBP' then
  474. oper.SetupOldEBP
  475. else
  476. Message1(sym_e_unknown_id,expr);
  477. end;
  478. end;
  479. end;
  480. if actasmtoken=AS_DOT then
  481. MaybeRecordOffset;
  482. { add a constant expression? }
  483. if (actasmtoken=AS_PLUS) then
  484. begin
  485. l:=BuildConstExpression(true,entered_paren);
  486. case oper.opr.typ of
  487. OPR_CONSTANT :
  488. inc(oper.opr.val,l);
  489. OPR_LOCAL :
  490. inc(oper.opr.localsymofs,l);
  491. OPR_REFERENCE :
  492. inc(oper.opr.ref.offset,l);
  493. else
  494. internalerror(2003092009);
  495. end;
  496. end
  497. end;
  498. { Do we have a indexing reference, then parse it also }
  499. if actasmtoken=AS_LPAREN then
  500. BuildReference(oper);
  501. end;
  502. AS_REGISTER: { Register, a variable reference or a constant reference }
  503. Begin
  504. { save the type of register used. }
  505. tempreg:=actasmregister;
  506. Consume(AS_REGISTER);
  507. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  508. begin
  509. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  510. Message(asmr_e_invalid_operand_type);
  511. oper.opr.typ:=OPR_REGISTER;
  512. oper.opr.reg:=tempreg;
  513. end
  514. else
  515. Message(asmr_e_syn_operand);
  516. end;
  517. AS_END,
  518. AS_SEPARATOR,
  519. AS_COMMA: ;
  520. else
  521. Begin
  522. Message(asmr_e_syn_operand);
  523. Consume(actasmtoken);
  524. end;
  525. end; { end case }
  526. if refaddr<>addr_full then
  527. begin
  528. if oper.opr.typ<>OPR_REFERENCE then
  529. oper.InitRef;
  530. oper.opr.ref.refaddr:=refaddr;
  531. Consume(AS_RPAREN);
  532. end
  533. else if (oper.opr.typ=OPR_REFERENCE) and
  534. (oper.opr.ref.refaddr=addr_no) and
  535. assigned(oper.opr.ref.symbol) then
  536. oper.opr.ref.refaddr:=addr_full;
  537. end;
  538. {*****************************************************************************
  539. trv32attreader
  540. *****************************************************************************}
  541. procedure trv32attreader.BuildOpCode(instr : trvinstruction);
  542. var
  543. operandnum : longint;
  544. Begin
  545. { opcode }
  546. if (actasmtoken<>AS_OPCODE) then
  547. Begin
  548. Message(asmr_e_invalid_or_missing_opcode);
  549. RecoverConsume(true);
  550. exit;
  551. end;
  552. { Fill the instr object with the current state }
  553. with instr do
  554. begin
  555. Opcode:=ActOpcode;
  556. condition:=ActCondition;
  557. end;
  558. { We are reading operands, so opcode will be an AS_ID }
  559. operandnum:=1;
  560. Consume(AS_OPCODE);
  561. { Zero operand opcode ? }
  562. if actasmtoken in [AS_SEPARATOR,AS_END] then
  563. begin
  564. operandnum:=0;
  565. exit;
  566. end;
  567. { Read the operands }
  568. repeat
  569. case actasmtoken of
  570. AS_COMMA: { Operand delimiter }
  571. Begin
  572. if operandnum>Max_Operands then
  573. Message(asmr_e_too_many_operands)
  574. else
  575. begin
  576. { condition operands doesn't set the operand but write to the
  577. condition field of the instruction
  578. }
  579. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  580. Inc(operandnum);
  581. end;
  582. Consume(AS_COMMA);
  583. end;
  584. AS_SEPARATOR,
  585. AS_END : { End of asm operands for this opcode }
  586. begin
  587. break;
  588. end;
  589. else
  590. BuildOperand(instr.Operands[operandnum] as trvoperand);
  591. end; { end case }
  592. until false;
  593. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  594. dec(operandnum);
  595. instr.Ops:=operandnum;
  596. end;
  597. function trv32attreader.is_register(const s: string): boolean;
  598. type
  599. treg2str = record
  600. name : string[3];
  601. reg : tregister;
  602. end;
  603. const
  604. extraregs : array[0..31] of treg2str = (
  605. (name: 'A0'; reg : NR_X10),
  606. (name: 'A1'; reg : NR_X11),
  607. (name: 'A2'; reg : NR_X12),
  608. (name: 'A3'; reg : NR_X13),
  609. (name: 'A4'; reg : NR_X14),
  610. (name: 'A5'; reg : NR_X15),
  611. (name: 'A6'; reg : NR_X16),
  612. (name: 'A7'; reg : NR_X17),
  613. (name: 'RA'; reg : NR_X1),
  614. (name: 'SP'; reg : NR_X2),
  615. (name: 'GP'; reg : NR_X3),
  616. (name: 'TP'; reg : NR_X4),
  617. (name: 'T0'; reg : NR_X5),
  618. (name: 'T1'; reg : NR_X6),
  619. (name: 'T2'; reg : NR_X7),
  620. (name: 'S0'; reg : NR_X8),
  621. (name: 'FP'; reg : NR_X8),
  622. (name: 'S1'; reg : NR_X9),
  623. (name: 'S2'; reg : NR_X18),
  624. (name: 'S3'; reg : NR_X19),
  625. (name: 'S4'; reg : NR_X20),
  626. (name: 'S5'; reg : NR_X21),
  627. (name: 'S6'; reg : NR_X22),
  628. (name: 'S7'; reg : NR_X23),
  629. (name: 'S8'; reg : NR_X24),
  630. (name: 'S9'; reg : NR_X25),
  631. (name: 'S10';reg : NR_X26),
  632. (name: 'S11';reg : NR_X27),
  633. (name: 'T3'; reg : NR_X28),
  634. (name: 'T4'; reg : NR_X29),
  635. (name: 'T5'; reg : NR_X30),
  636. (name: 'T6'; reg : NR_X31)
  637. );
  638. var
  639. i : longint;
  640. begin
  641. result:=inherited is_register(s);
  642. { reg found?
  643. possible aliases are always 2 char
  644. }
  645. if result or (not (length(s) in [2,3])) then
  646. exit;
  647. for i:=low(extraregs) to high(extraregs) do
  648. begin
  649. if s=extraregs[i].name then
  650. begin
  651. actasmregister:=extraregs[i].reg;
  652. result:=true;
  653. actasmtoken:=AS_REGISTER;
  654. exit;
  655. end;
  656. end;
  657. end;
  658. function trv32attreader.is_asmopcode(const s: string):boolean;
  659. var
  660. cond : tasmcond;
  661. hs : string;
  662. Begin
  663. { making s a value parameter would break other assembler readers }
  664. hs:=s;
  665. is_asmopcode:=false;
  666. { clear op code }
  667. actopcode:=A_None;
  668. { clear condition }
  669. fillchar(actcondition,sizeof(actcondition),0);
  670. { check for direction hint }
  671. actopcode := tasmop(ptruint(iasmops.find(hs)));
  672. if actopcode <> A_NONE then
  673. begin
  674. actasmtoken:=AS_OPCODE;
  675. is_asmopcode:=true;
  676. exit;
  677. end;
  678. { not found, check branch instructions }
  679. if hs[1]='B' then
  680. begin
  681. { we can search here without an extra table which is sorted by string length
  682. because we take the whole remaining string without the leading B }
  683. actopcode := A_Bxx;
  684. for cond:=low(TAsmCond) to high(TAsmCond) do
  685. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  686. begin
  687. actcondition:=cond;
  688. actasmtoken:=AS_OPCODE;
  689. is_asmopcode:=true;
  690. exit;
  691. end;
  692. end;
  693. end;
  694. procedure trv32attreader.handleopcode;
  695. var
  696. instr : trvinstruction;
  697. begin
  698. instr:=trvinstruction.Create(trvoperand);
  699. BuildOpcode(instr);
  700. instr.condition := actcondition;
  701. {
  702. instr.AddReferenceSizes;
  703. instr.SetInstructionOpsize;
  704. instr.CheckOperandSizes;
  705. }
  706. instr.ConcatInstruction(curlist);
  707. instr.Free;
  708. end;
  709. {*****************************************************************************
  710. Initialize
  711. *****************************************************************************}
  712. const
  713. asmmode_rv32_standard_info : tasmmodeinfo =
  714. (
  715. id : asmmode_standard;
  716. idtxt : 'STANDARD';
  717. casmreader : trv32attreader;
  718. );
  719. initialization
  720. RegisterAsmMode(asmmode_rv32_standard_info);
  721. end.