rarv32gas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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;
  22. type
  23. trv32attreader = class(tattreader)
  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. end;
  206. Consume(AS_RPAREN);
  207. if actasmtoken=AS_AT then
  208. ReadAt(oper);
  209. End;
  210. AS_COMMA: { (, ... can either be scaling, or index }
  211. Begin
  212. Consume(AS_COMMA);
  213. { Index }
  214. if (actasmtoken=AS_REGISTER) then
  215. Begin
  216. oper.opr.ref.index:=actasmregister;
  217. Consume(AS_REGISTER);
  218. { check for scaling ... }
  219. Consume_RParen;
  220. end
  221. else
  222. begin
  223. Message(asmr_e_invalid_reference_syntax);
  224. RecoverConsume(false);
  225. end;
  226. end;
  227. else
  228. Begin
  229. Message(asmr_e_invalid_reference_syntax);
  230. RecoverConsume(false);
  231. end;
  232. end;
  233. end;
  234. Procedure trv32attreader.BuildOperand(oper : trvoperand);
  235. var
  236. expr : string;
  237. typesize,l : tcgint;
  238. procedure AddLabelOperand(hl:tasmlabel);
  239. begin
  240. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  241. is_calljmp(actopcode) then
  242. begin
  243. oper.opr.typ:=OPR_SYMBOL;
  244. oper.opr.symbol:=hl;
  245. end
  246. else
  247. begin
  248. oper.InitRef;
  249. oper.opr.ref.symbol:=hl;
  250. end;
  251. end;
  252. procedure MaybeRecordOffset;
  253. var
  254. mangledname: string;
  255. hasdot : boolean;
  256. l,
  257. toffset,
  258. tsize : tcgint;
  259. begin
  260. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  261. exit;
  262. l:=0;
  263. hasdot:=(actasmtoken=AS_DOT);
  264. if hasdot then
  265. begin
  266. if expr<>'' then
  267. begin
  268. BuildRecordOffsetSize(expr,toffset,tsize,mangledname,false);
  269. if (oper.opr.typ<>OPR_CONSTANT) and
  270. (mangledname<>'') then
  271. Message(asmr_e_wrong_sym_type);
  272. inc(l,toffset);
  273. oper.SetSize(tsize,true);
  274. end;
  275. end;
  276. if actasmtoken in [AS_PLUS,AS_MINUS] then
  277. inc(l,BuildConstExpression(true,false));
  278. case oper.opr.typ of
  279. OPR_LOCAL :
  280. begin
  281. { don't allow direct access to fields of parameters, because that
  282. will generate buggy code. Allow it only for explicit typecasting }
  283. if hasdot and
  284. (not oper.hastype) and
  285. (tabstractvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  286. (current_procinfo.procdef.proccalloption<>pocall_register) then
  287. Message(asmr_e_cannot_access_field_directly_for_parameters);
  288. inc(oper.opr.localsymofs,l)
  289. end;
  290. OPR_CONSTANT :
  291. if (mangledname<>'') then
  292. begin
  293. if (oper.opr.val<>0) then
  294. Message(asmr_e_wrong_sym_type);
  295. oper.opr.typ:=OPR_SYMBOL;
  296. oper.opr.symbol:=current_asmdata.DefineAsmSymbol(mangledname,AB_EXTERNAL,AT_FUNCTION,voidcodepointertype);
  297. end
  298. else
  299. inc(oper.opr.val,l);
  300. OPR_REFERENCE :
  301. inc(oper.opr.ref.offset,l);
  302. OPR_SYMBOL:
  303. Message(asmr_e_invalid_symbol_ref);
  304. else
  305. internalerror(200309221);
  306. end;
  307. end;
  308. function MaybeBuildReference:boolean;
  309. { Try to create a reference, if not a reference is found then false
  310. is returned }
  311. begin
  312. MaybeBuildReference:=true;
  313. case actasmtoken of
  314. AS_INTNUM,
  315. AS_MINUS,
  316. AS_PLUS:
  317. Begin
  318. oper.opr.ref.offset:=BuildConstExpression(True,False);
  319. if actasmtoken<>AS_LPAREN then
  320. Message(asmr_e_invalid_reference_syntax)
  321. else
  322. BuildReference(oper);
  323. end;
  324. AS_LPAREN:
  325. BuildReference(oper);
  326. AS_ID: { only a variable is allowed ... }
  327. Begin
  328. ReadSym(oper);
  329. case actasmtoken of
  330. AS_END,
  331. AS_SEPARATOR,
  332. AS_COMMA: ;
  333. AS_LPAREN:
  334. BuildReference(oper);
  335. else
  336. Begin
  337. Message(asmr_e_invalid_reference_syntax);
  338. Consume(actasmtoken);
  339. end;
  340. end; {end case }
  341. end;
  342. else
  343. MaybeBuildReference:=false;
  344. end; { end case }
  345. end;
  346. var
  347. tempreg : tregister;
  348. hl : tasmlabel;
  349. ofs : aint;
  350. refaddr: trefaddr;
  351. Begin
  352. expr:='';
  353. refaddr:=addr_full;
  354. if actasmtoken=AS_MOD then
  355. begin
  356. consume(AS_MOD);
  357. if actasmtoken<>AS_ID then
  358. begin
  359. Message(asmr_e_invalid_reference_syntax);
  360. RecoverConsume(false);
  361. end
  362. else
  363. begin
  364. if lower(actasmpattern)='pcrel_hi' then
  365. refaddr:=addr_pcrel_hi20
  366. else if lower(actasmpattern)='pcrel_lo' then
  367. refaddr:=addr_pcrel_lo12
  368. else if lower(actasmpattern)='hi' then
  369. refaddr:=addr_hi20
  370. else if lower(actasmpattern)='lo' then
  371. refaddr:=addr_lo12
  372. else
  373. begin
  374. Message(asmr_e_invalid_reference_syntax);
  375. RecoverConsume(false);
  376. end;
  377. consume(AS_ID);
  378. consume(AS_LPAREN);
  379. end;
  380. end;
  381. case actasmtoken of
  382. AS_LPAREN: { Memory reference or constant expression }
  383. Begin
  384. oper.InitRef;
  385. BuildReference(oper);
  386. end;
  387. AS_INTNUM,
  388. AS_MINUS,
  389. AS_PLUS:
  390. Begin
  391. { Constant memory offset }
  392. { This must absolutely be followed by ( }
  393. oper.InitRef;
  394. oper.opr.ref.offset:=BuildConstExpression(True,False);
  395. if actasmtoken<>AS_LPAREN then
  396. begin
  397. ofs:=oper.opr.ref.offset;
  398. BuildConstantOperand(oper);
  399. inc(oper.opr.val,ofs);
  400. end
  401. else
  402. BuildReference(oper);
  403. end;
  404. AS_ID: { A constant expression, or a Variable ref. }
  405. Begin
  406. { Local Label ? }
  407. if is_locallabel(actasmpattern) then
  408. begin
  409. CreateLocalLabel(actasmpattern,hl,false);
  410. Consume(AS_ID);
  411. AddLabelOperand(hl);
  412. end
  413. else
  414. { Check for label }
  415. if SearchLabel(actasmpattern,hl,false) then
  416. begin
  417. Consume(AS_ID);
  418. AddLabelOperand(hl);
  419. end
  420. else
  421. { probably a variable or normal expression }
  422. { or a procedure (such as in CALL ID) }
  423. Begin
  424. { is it a constant ? }
  425. if SearchIConstant(actasmpattern,l) then
  426. Begin
  427. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  428. Message(asmr_e_invalid_operand_type);
  429. BuildConstantOperand(oper);
  430. end
  431. else
  432. begin
  433. expr:=actasmpattern;
  434. Consume(AS_ID);
  435. { typecasting? }
  436. if (actasmtoken=AS_LPAREN) and
  437. SearchType(expr,typesize) then
  438. begin
  439. oper.hastype:=true;
  440. Consume(AS_LPAREN);
  441. BuildOperand(oper);
  442. Consume(AS_RPAREN);
  443. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  444. oper.SetSize(typesize,true);
  445. end
  446. else
  447. begin
  448. if oper.SetupVar(expr,false) then
  449. ReadAt(oper)
  450. else
  451. Begin
  452. { look for special symbols ... }
  453. if expr= '__HIGH' then
  454. begin
  455. consume(AS_LPAREN);
  456. if not oper.setupvar('high'+actasmpattern,false) then
  457. Message1(sym_e_unknown_id,'high'+actasmpattern);
  458. consume(AS_ID);
  459. consume(AS_RPAREN);
  460. end
  461. else
  462. if expr = '__RESULT' then
  463. oper.SetUpResult
  464. else
  465. if expr = '__SELF' then
  466. oper.SetupSelf
  467. else
  468. if expr = '__OLDEBP' then
  469. oper.SetupOldEBP
  470. else
  471. Message1(sym_e_unknown_id,expr);
  472. end;
  473. end;
  474. end;
  475. if actasmtoken=AS_DOT then
  476. MaybeRecordOffset;
  477. { add a constant expression? }
  478. if (actasmtoken=AS_PLUS) then
  479. begin
  480. l:=BuildConstExpression(true,false);
  481. case oper.opr.typ of
  482. OPR_CONSTANT :
  483. inc(oper.opr.val,l);
  484. OPR_LOCAL :
  485. inc(oper.opr.localsymofs,l);
  486. OPR_REFERENCE :
  487. inc(oper.opr.ref.offset,l);
  488. else
  489. internalerror(200309202);
  490. end;
  491. end
  492. end;
  493. { Do we have a indexing reference, then parse it also }
  494. if actasmtoken=AS_LPAREN then
  495. BuildReference(oper);
  496. end;
  497. AS_REGISTER: { Register, a variable reference or a constant reference }
  498. Begin
  499. { save the type of register used. }
  500. tempreg:=actasmregister;
  501. Consume(AS_REGISTER);
  502. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  503. begin
  504. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  505. Message(asmr_e_invalid_operand_type);
  506. oper.opr.typ:=OPR_REGISTER;
  507. oper.opr.reg:=tempreg;
  508. end
  509. else
  510. Message(asmr_e_syn_operand);
  511. end;
  512. AS_END,
  513. AS_SEPARATOR,
  514. AS_COMMA: ;
  515. else
  516. Begin
  517. Message(asmr_e_syn_operand);
  518. Consume(actasmtoken);
  519. end;
  520. end; { end case }
  521. if refaddr<>addr_full then
  522. begin
  523. if oper.opr.typ<>OPR_REFERENCE then
  524. oper.InitRef;
  525. oper.opr.ref.refaddr:=refaddr;
  526. Consume(AS_RPAREN);
  527. end;
  528. end;
  529. {*****************************************************************************
  530. trv32attreader
  531. *****************************************************************************}
  532. procedure trv32attreader.BuildOpCode(instr : trvinstruction);
  533. var
  534. operandnum : longint;
  535. Begin
  536. { opcode }
  537. if (actasmtoken<>AS_OPCODE) then
  538. Begin
  539. Message(asmr_e_invalid_or_missing_opcode);
  540. RecoverConsume(true);
  541. exit;
  542. end;
  543. { Fill the instr object with the current state }
  544. with instr do
  545. begin
  546. Opcode:=ActOpcode;
  547. condition:=ActCondition;
  548. end;
  549. { We are reading operands, so opcode will be an AS_ID }
  550. operandnum:=1;
  551. Consume(AS_OPCODE);
  552. { Zero operand opcode ? }
  553. if actasmtoken in [AS_SEPARATOR,AS_END] then
  554. begin
  555. operandnum:=0;
  556. exit;
  557. end;
  558. { Read the operands }
  559. repeat
  560. case actasmtoken of
  561. AS_COMMA: { Operand delimiter }
  562. Begin
  563. if operandnum>Max_Operands then
  564. Message(asmr_e_too_many_operands)
  565. else
  566. begin
  567. { condition operands doesn't set the operand but write to the
  568. condition field of the instruction
  569. }
  570. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  571. Inc(operandnum);
  572. end;
  573. Consume(AS_COMMA);
  574. end;
  575. AS_SEPARATOR,
  576. AS_END : { End of asm operands for this opcode }
  577. begin
  578. break;
  579. end;
  580. else
  581. BuildOperand(instr.Operands[operandnum] as trvoperand);
  582. end; { end case }
  583. until false;
  584. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  585. dec(operandnum);
  586. instr.Ops:=operandnum;
  587. end;
  588. function trv32attreader.is_register(const s: string): boolean;
  589. type
  590. treg2str = record
  591. name : string[3];
  592. reg : tregister;
  593. end;
  594. const
  595. extraregs : array[0..31] of treg2str = (
  596. (name: 'A0'; reg : NR_X10),
  597. (name: 'A1'; reg : NR_X11),
  598. (name: 'A2'; reg : NR_X12),
  599. (name: 'A3'; reg : NR_X13),
  600. (name: 'A5'; reg : NR_X14),
  601. (name: 'A6'; reg : NR_X15),
  602. (name: 'A7'; reg : NR_X16),
  603. (name: 'A8'; reg : NR_X17),
  604. (name: 'RA'; reg : NR_X1),
  605. (name: 'SP'; reg : NR_X2),
  606. (name: 'GP'; reg : NR_X3),
  607. (name: 'TP'; reg : NR_X4),
  608. (name: 'T0'; reg : NR_X5),
  609. (name: 'T1'; reg : NR_X6),
  610. (name: 'T2'; reg : NR_X7),
  611. (name: 'S0'; reg : NR_X8),
  612. (name: 'FP'; reg : NR_X8),
  613. (name: 'S1'; reg : NR_X9),
  614. (name: 'S2'; reg : NR_X18),
  615. (name: 'S3'; reg : NR_X19),
  616. (name: 'S4'; reg : NR_X20),
  617. (name: 'S5'; reg : NR_X21),
  618. (name: 'S6'; reg : NR_X22),
  619. (name: 'S7'; reg : NR_X23),
  620. (name: 'S8'; reg : NR_X24),
  621. (name: 'S9'; reg : NR_X25),
  622. (name: 'S10';reg : NR_X26),
  623. (name: 'S11';reg : NR_X27),
  624. (name: 'T3'; reg : NR_X28),
  625. (name: 'T4'; reg : NR_X29),
  626. (name: 'T5'; reg : NR_X30),
  627. (name: 'T6'; reg : NR_X31)
  628. );
  629. var
  630. i : longint;
  631. begin
  632. result:=inherited is_register(s);
  633. { reg found?
  634. possible aliases are always 2 char
  635. }
  636. if result or (not (length(s) in [2,3])) then
  637. exit;
  638. for i:=low(extraregs) to high(extraregs) do
  639. begin
  640. if s=extraregs[i].name then
  641. begin
  642. actasmregister:=extraregs[i].reg;
  643. result:=true;
  644. actasmtoken:=AS_REGISTER;
  645. exit;
  646. end;
  647. end;
  648. end;
  649. function trv32attreader.is_asmopcode(const s: string):boolean;
  650. var
  651. cond : tasmcond;
  652. hs : string;
  653. Begin
  654. { making s a value parameter would break other assembler readers }
  655. hs:=s;
  656. is_asmopcode:=false;
  657. { clear op code }
  658. actopcode:=A_None;
  659. { clear condition }
  660. fillchar(actcondition,sizeof(actcondition),0);
  661. { check for direction hint }
  662. actopcode := tasmop(ptruint(iasmops.find(hs)));
  663. if actopcode <> A_NONE then
  664. begin
  665. actasmtoken:=AS_OPCODE;
  666. is_asmopcode:=true;
  667. exit;
  668. end;
  669. { not found, check branch instructions }
  670. if hs[1]='B' then
  671. begin
  672. { we can search here without an extra table which is sorted by string length
  673. because we take the whole remaining string without the leading B }
  674. actopcode := A_Bxx;
  675. for cond:=low(TAsmCond) to high(TAsmCond) do
  676. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  677. begin
  678. actcondition:=cond;
  679. actasmtoken:=AS_OPCODE;
  680. is_asmopcode:=true;
  681. exit;
  682. end;
  683. end;
  684. end;
  685. procedure trv32attreader.handleopcode;
  686. var
  687. instr : trvinstruction;
  688. begin
  689. instr:=trvinstruction.Create(trvoperand);
  690. BuildOpcode(instr);
  691. instr.condition := actcondition;
  692. {
  693. instr.AddReferenceSizes;
  694. instr.SetInstructionOpsize;
  695. instr.CheckOperandSizes;
  696. }
  697. instr.ConcatInstruction(curlist);
  698. instr.Free;
  699. end;
  700. {*****************************************************************************
  701. Initialize
  702. *****************************************************************************}
  703. const
  704. asmmode_rv32_standard_info : tasmmodeinfo =
  705. (
  706. id : asmmode_standard;
  707. idtxt : 'STANDARD';
  708. casmreader : trv32attreader;
  709. );
  710. initialization
  711. RegisterAsmMode(asmmode_rv32_standard_info);
  712. end.