rarv32gas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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(200309202);
  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(200309202);
  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. end;
  534. {*****************************************************************************
  535. trv32attreader
  536. *****************************************************************************}
  537. procedure trv32attreader.BuildOpCode(instr : trvinstruction);
  538. var
  539. operandnum : longint;
  540. Begin
  541. { opcode }
  542. if (actasmtoken<>AS_OPCODE) then
  543. Begin
  544. Message(asmr_e_invalid_or_missing_opcode);
  545. RecoverConsume(true);
  546. exit;
  547. end;
  548. { Fill the instr object with the current state }
  549. with instr do
  550. begin
  551. Opcode:=ActOpcode;
  552. condition:=ActCondition;
  553. end;
  554. { We are reading operands, so opcode will be an AS_ID }
  555. operandnum:=1;
  556. Consume(AS_OPCODE);
  557. { Zero operand opcode ? }
  558. if actasmtoken in [AS_SEPARATOR,AS_END] then
  559. begin
  560. operandnum:=0;
  561. exit;
  562. end;
  563. { Read the operands }
  564. repeat
  565. case actasmtoken of
  566. AS_COMMA: { Operand delimiter }
  567. Begin
  568. if operandnum>Max_Operands then
  569. Message(asmr_e_too_many_operands)
  570. else
  571. begin
  572. { condition operands doesn't set the operand but write to the
  573. condition field of the instruction
  574. }
  575. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  576. Inc(operandnum);
  577. end;
  578. Consume(AS_COMMA);
  579. end;
  580. AS_SEPARATOR,
  581. AS_END : { End of asm operands for this opcode }
  582. begin
  583. break;
  584. end;
  585. else
  586. BuildOperand(instr.Operands[operandnum] as trvoperand);
  587. end; { end case }
  588. until false;
  589. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  590. dec(operandnum);
  591. instr.Ops:=operandnum;
  592. end;
  593. function trv32attreader.is_register(const s: string): boolean;
  594. type
  595. treg2str = record
  596. name : string[3];
  597. reg : tregister;
  598. end;
  599. const
  600. extraregs : array[0..31] of treg2str = (
  601. (name: 'A0'; reg : NR_X10),
  602. (name: 'A1'; reg : NR_X11),
  603. (name: 'A2'; reg : NR_X12),
  604. (name: 'A3'; reg : NR_X13),
  605. (name: 'A4'; reg : NR_X14),
  606. (name: 'A5'; reg : NR_X15),
  607. (name: 'A6'; reg : NR_X16),
  608. (name: 'A7'; reg : NR_X17),
  609. (name: 'RA'; reg : NR_X1),
  610. (name: 'SP'; reg : NR_X2),
  611. (name: 'GP'; reg : NR_X3),
  612. (name: 'TP'; reg : NR_X4),
  613. (name: 'T0'; reg : NR_X5),
  614. (name: 'T1'; reg : NR_X6),
  615. (name: 'T2'; reg : NR_X7),
  616. (name: 'S0'; reg : NR_X8),
  617. (name: 'FP'; reg : NR_X8),
  618. (name: 'S1'; reg : NR_X9),
  619. (name: 'S2'; reg : NR_X18),
  620. (name: 'S3'; reg : NR_X19),
  621. (name: 'S4'; reg : NR_X20),
  622. (name: 'S5'; reg : NR_X21),
  623. (name: 'S6'; reg : NR_X22),
  624. (name: 'S7'; reg : NR_X23),
  625. (name: 'S8'; reg : NR_X24),
  626. (name: 'S9'; reg : NR_X25),
  627. (name: 'S10';reg : NR_X26),
  628. (name: 'S11';reg : NR_X27),
  629. (name: 'T3'; reg : NR_X28),
  630. (name: 'T4'; reg : NR_X29),
  631. (name: 'T5'; reg : NR_X30),
  632. (name: 'T6'; reg : NR_X31)
  633. );
  634. var
  635. i : longint;
  636. begin
  637. result:=inherited is_register(s);
  638. { reg found?
  639. possible aliases are always 2 char
  640. }
  641. if result or (not (length(s) in [2,3])) then
  642. exit;
  643. for i:=low(extraregs) to high(extraregs) do
  644. begin
  645. if s=extraregs[i].name then
  646. begin
  647. actasmregister:=extraregs[i].reg;
  648. result:=true;
  649. actasmtoken:=AS_REGISTER;
  650. exit;
  651. end;
  652. end;
  653. end;
  654. function trv32attreader.is_asmopcode(const s: string):boolean;
  655. var
  656. cond : tasmcond;
  657. hs : string;
  658. Begin
  659. { making s a value parameter would break other assembler readers }
  660. hs:=s;
  661. is_asmopcode:=false;
  662. { clear op code }
  663. actopcode:=A_None;
  664. { clear condition }
  665. fillchar(actcondition,sizeof(actcondition),0);
  666. { check for direction hint }
  667. actopcode := tasmop(ptruint(iasmops.find(hs)));
  668. if actopcode <> A_NONE then
  669. begin
  670. actasmtoken:=AS_OPCODE;
  671. is_asmopcode:=true;
  672. exit;
  673. end;
  674. { not found, check branch instructions }
  675. if hs[1]='B' then
  676. begin
  677. { we can search here without an extra table which is sorted by string length
  678. because we take the whole remaining string without the leading B }
  679. actopcode := A_Bxx;
  680. for cond:=low(TAsmCond) to high(TAsmCond) do
  681. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  682. begin
  683. actcondition:=cond;
  684. actasmtoken:=AS_OPCODE;
  685. is_asmopcode:=true;
  686. exit;
  687. end;
  688. end;
  689. end;
  690. procedure trv32attreader.handleopcode;
  691. var
  692. instr : trvinstruction;
  693. begin
  694. instr:=trvinstruction.Create(trvoperand);
  695. BuildOpcode(instr);
  696. instr.condition := actcondition;
  697. {
  698. instr.AddReferenceSizes;
  699. instr.SetInstructionOpsize;
  700. instr.CheckOperandSizes;
  701. }
  702. instr.ConcatInstruction(curlist);
  703. instr.Free;
  704. end;
  705. {*****************************************************************************
  706. Initialize
  707. *****************************************************************************}
  708. const
  709. asmmode_rv32_standard_info : tasmmodeinfo =
  710. (
  711. id : asmmode_standard;
  712. idtxt : 'STANDARD';
  713. casmreader : trv32attreader;
  714. );
  715. initialization
  716. RegisterAsmMode(asmmode_rv32_standard_info);
  717. end.