rarv32gas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. 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. Begin
  354. expr:='';
  355. refaddr:=addr_full;
  356. if actasmtoken=AS_MOD then
  357. begin
  358. consume(AS_MOD);
  359. if actasmtoken<>AS_ID then
  360. begin
  361. Message(asmr_e_invalid_reference_syntax);
  362. RecoverConsume(false);
  363. end
  364. else
  365. begin
  366. if lower(actasmpattern)='pcrel_hi' then
  367. refaddr:=addr_pcrel_hi20
  368. else if lower(actasmpattern)='pcrel_lo' then
  369. refaddr:=addr_pcrel_lo12
  370. else if lower(actasmpattern)='hi' then
  371. refaddr:=addr_hi20
  372. else if lower(actasmpattern)='lo' then
  373. refaddr:=addr_lo12
  374. else
  375. begin
  376. Message(asmr_e_invalid_reference_syntax);
  377. RecoverConsume(false);
  378. end;
  379. consume(AS_ID);
  380. consume(AS_LPAREN);
  381. end;
  382. end;
  383. case actasmtoken of
  384. AS_LPAREN: { Memory reference or constant expression }
  385. Begin
  386. oper.InitRef;
  387. BuildReference(oper);
  388. end;
  389. AS_INTNUM,
  390. AS_MINUS,
  391. AS_PLUS:
  392. Begin
  393. { Constant memory offset }
  394. { This must absolutely be followed by ( }
  395. oper.InitRef;
  396. oper.opr.ref.offset:=BuildConstExpression(True,False);
  397. if actasmtoken<>AS_LPAREN then
  398. begin
  399. ofs:=oper.opr.ref.offset;
  400. BuildConstantOperand(oper);
  401. inc(oper.opr.val,ofs);
  402. end
  403. else
  404. BuildReference(oper);
  405. end;
  406. AS_ID: { A constant expression, or a Variable ref. }
  407. Begin
  408. { Local Label ? }
  409. if is_locallabel(actasmpattern) then
  410. begin
  411. CreateLocalLabel(actasmpattern,hl,false);
  412. Consume(AS_ID);
  413. AddLabelOperand(hl);
  414. end
  415. else
  416. { Check for label }
  417. if SearchLabel(actasmpattern,hl,false) then
  418. begin
  419. Consume(AS_ID);
  420. AddLabelOperand(hl);
  421. end
  422. else
  423. { probably a variable or normal expression }
  424. { or a procedure (such as in CALL ID) }
  425. Begin
  426. { is it a constant ? }
  427. if SearchIConstant(actasmpattern,l) then
  428. Begin
  429. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  430. Message(asmr_e_invalid_operand_type);
  431. BuildConstantOperand(oper);
  432. end
  433. else
  434. begin
  435. expr:=actasmpattern;
  436. Consume(AS_ID);
  437. { typecasting? }
  438. if (actasmtoken=AS_LPAREN) and
  439. SearchType(expr,typesize) then
  440. begin
  441. oper.hastype:=true;
  442. Consume(AS_LPAREN);
  443. BuildOperand(oper);
  444. Consume(AS_RPAREN);
  445. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  446. oper.SetSize(typesize,true);
  447. end
  448. else
  449. begin
  450. if oper.SetupVar(expr,false) then
  451. ReadAt(oper)
  452. else
  453. Begin
  454. { look for special symbols ... }
  455. if expr= '__HIGH' then
  456. begin
  457. consume(AS_LPAREN);
  458. if not oper.setupvar('high'+actasmpattern,false) then
  459. Message1(sym_e_unknown_id,'high'+actasmpattern);
  460. consume(AS_ID);
  461. consume(AS_RPAREN);
  462. end
  463. else
  464. if expr = '__RESULT' then
  465. oper.SetUpResult
  466. else
  467. if expr = '__SELF' then
  468. oper.SetupSelf
  469. else
  470. if expr = '__OLDEBP' then
  471. oper.SetupOldEBP
  472. else
  473. Message1(sym_e_unknown_id,expr);
  474. end;
  475. end;
  476. end;
  477. if actasmtoken=AS_DOT then
  478. MaybeRecordOffset;
  479. { add a constant expression? }
  480. if (actasmtoken=AS_PLUS) then
  481. begin
  482. l:=BuildConstExpression(true,false);
  483. case oper.opr.typ of
  484. OPR_CONSTANT :
  485. inc(oper.opr.val,l);
  486. OPR_LOCAL :
  487. inc(oper.opr.localsymofs,l);
  488. OPR_REFERENCE :
  489. inc(oper.opr.ref.offset,l);
  490. else
  491. internalerror(200309202);
  492. end;
  493. end
  494. end;
  495. { Do we have a indexing reference, then parse it also }
  496. if actasmtoken=AS_LPAREN then
  497. BuildReference(oper);
  498. end;
  499. AS_REGISTER: { Register, a variable reference or a constant reference }
  500. Begin
  501. { save the type of register used. }
  502. tempreg:=actasmregister;
  503. Consume(AS_REGISTER);
  504. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  505. begin
  506. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  507. Message(asmr_e_invalid_operand_type);
  508. oper.opr.typ:=OPR_REGISTER;
  509. oper.opr.reg:=tempreg;
  510. end
  511. else
  512. Message(asmr_e_syn_operand);
  513. end;
  514. AS_END,
  515. AS_SEPARATOR,
  516. AS_COMMA: ;
  517. else
  518. Begin
  519. Message(asmr_e_syn_operand);
  520. Consume(actasmtoken);
  521. end;
  522. end; { end case }
  523. if refaddr<>addr_full then
  524. begin
  525. if oper.opr.typ<>OPR_REFERENCE then
  526. oper.InitRef;
  527. oper.opr.ref.refaddr:=refaddr;
  528. Consume(AS_RPAREN);
  529. end;
  530. end;
  531. {*****************************************************************************
  532. trv32attreader
  533. *****************************************************************************}
  534. procedure trv32attreader.BuildOpCode(instr : trvinstruction);
  535. var
  536. operandnum : longint;
  537. Begin
  538. { opcode }
  539. if (actasmtoken<>AS_OPCODE) then
  540. Begin
  541. Message(asmr_e_invalid_or_missing_opcode);
  542. RecoverConsume(true);
  543. exit;
  544. end;
  545. { Fill the instr object with the current state }
  546. with instr do
  547. begin
  548. Opcode:=ActOpcode;
  549. condition:=ActCondition;
  550. end;
  551. { We are reading operands, so opcode will be an AS_ID }
  552. operandnum:=1;
  553. Consume(AS_OPCODE);
  554. { Zero operand opcode ? }
  555. if actasmtoken in [AS_SEPARATOR,AS_END] then
  556. begin
  557. operandnum:=0;
  558. exit;
  559. end;
  560. { Read the operands }
  561. repeat
  562. case actasmtoken of
  563. AS_COMMA: { Operand delimiter }
  564. Begin
  565. if operandnum>Max_Operands then
  566. Message(asmr_e_too_many_operands)
  567. else
  568. begin
  569. { condition operands doesn't set the operand but write to the
  570. condition field of the instruction
  571. }
  572. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  573. Inc(operandnum);
  574. end;
  575. Consume(AS_COMMA);
  576. end;
  577. AS_SEPARATOR,
  578. AS_END : { End of asm operands for this opcode }
  579. begin
  580. break;
  581. end;
  582. else
  583. BuildOperand(instr.Operands[operandnum] as trvoperand);
  584. end; { end case }
  585. until false;
  586. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  587. dec(operandnum);
  588. instr.Ops:=operandnum;
  589. end;
  590. function trv32attreader.is_register(const s: string): boolean;
  591. type
  592. treg2str = record
  593. name : string[3];
  594. reg : tregister;
  595. end;
  596. const
  597. extraregs : array[0..31] of treg2str = (
  598. (name: 'A0'; reg : NR_X10),
  599. (name: 'A1'; reg : NR_X11),
  600. (name: 'A2'; reg : NR_X12),
  601. (name: 'A3'; reg : NR_X13),
  602. (name: 'A5'; reg : NR_X14),
  603. (name: 'A6'; reg : NR_X15),
  604. (name: 'A7'; reg : NR_X16),
  605. (name: 'A8'; reg : NR_X17),
  606. (name: 'RA'; reg : NR_X1),
  607. (name: 'SP'; reg : NR_X2),
  608. (name: 'GP'; reg : NR_X3),
  609. (name: 'TP'; reg : NR_X4),
  610. (name: 'T0'; reg : NR_X5),
  611. (name: 'T1'; reg : NR_X6),
  612. (name: 'T2'; reg : NR_X7),
  613. (name: 'S0'; reg : NR_X8),
  614. (name: 'FP'; reg : NR_X8),
  615. (name: 'S1'; reg : NR_X9),
  616. (name: 'S2'; reg : NR_X18),
  617. (name: 'S3'; reg : NR_X19),
  618. (name: 'S4'; reg : NR_X20),
  619. (name: 'S5'; reg : NR_X21),
  620. (name: 'S6'; reg : NR_X22),
  621. (name: 'S7'; reg : NR_X23),
  622. (name: 'S8'; reg : NR_X24),
  623. (name: 'S9'; reg : NR_X25),
  624. (name: 'S10';reg : NR_X26),
  625. (name: 'S11';reg : NR_X27),
  626. (name: 'T3'; reg : NR_X28),
  627. (name: 'T4'; reg : NR_X29),
  628. (name: 'T5'; reg : NR_X30),
  629. (name: 'T6'; reg : NR_X31)
  630. );
  631. var
  632. i : longint;
  633. begin
  634. result:=inherited is_register(s);
  635. { reg found?
  636. possible aliases are always 2 char
  637. }
  638. if result or (not (length(s) in [2,3])) then
  639. exit;
  640. for i:=low(extraregs) to high(extraregs) do
  641. begin
  642. if s=extraregs[i].name then
  643. begin
  644. actasmregister:=extraregs[i].reg;
  645. result:=true;
  646. actasmtoken:=AS_REGISTER;
  647. exit;
  648. end;
  649. end;
  650. end;
  651. function trv32attreader.is_asmopcode(const s: string):boolean;
  652. var
  653. cond : tasmcond;
  654. hs : string;
  655. Begin
  656. { making s a value parameter would break other assembler readers }
  657. hs:=s;
  658. is_asmopcode:=false;
  659. { clear op code }
  660. actopcode:=A_None;
  661. { clear condition }
  662. fillchar(actcondition,sizeof(actcondition),0);
  663. { check for direction hint }
  664. actopcode := tasmop(ptruint(iasmops.find(hs)));
  665. if actopcode <> A_NONE then
  666. begin
  667. actasmtoken:=AS_OPCODE;
  668. is_asmopcode:=true;
  669. exit;
  670. end;
  671. { not found, check branch instructions }
  672. if hs[1]='B' then
  673. begin
  674. { we can search here without an extra table which is sorted by string length
  675. because we take the whole remaining string without the leading B }
  676. actopcode := A_Bxx;
  677. for cond:=low(TAsmCond) to high(TAsmCond) do
  678. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  679. begin
  680. actcondition:=cond;
  681. actasmtoken:=AS_OPCODE;
  682. is_asmopcode:=true;
  683. exit;
  684. end;
  685. end;
  686. end;
  687. procedure trv32attreader.handleopcode;
  688. var
  689. instr : trvinstruction;
  690. begin
  691. instr:=trvinstruction.Create(trvoperand);
  692. BuildOpcode(instr);
  693. instr.condition := actcondition;
  694. {
  695. instr.AddReferenceSizes;
  696. instr.SetInstructionOpsize;
  697. instr.CheckOperandSizes;
  698. }
  699. instr.ConcatInstruction(curlist);
  700. instr.Free;
  701. end;
  702. {*****************************************************************************
  703. Initialize
  704. *****************************************************************************}
  705. const
  706. asmmode_rv32_standard_info : tasmmodeinfo =
  707. (
  708. id : asmmode_standard;
  709. idtxt : 'STANDARD';
  710. casmreader : trv32attreader;
  711. );
  712. initialization
  713. RegisterAsmMode(asmmode_rv32_standard_info);
  714. end.