rautils.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. {
  2. $Id$
  3. Copyright (c) 1998 Carl Eric Codere
  4. This unit implements some support routines for assembler parsing
  5. independent of the processor
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. **********************************************************************}
  18. Unit RAUtils;
  19. Interface
  20. Uses
  21. strings,
  22. cobjects,
  23. globtype,systems,verbose,globals,files,
  24. symconst,symtable,aasm,cpubase,cpuasm
  25. {$ifdef NEWCG}
  26. ,cgbase
  27. {$else}
  28. ,hcodegen
  29. {$endif}
  30. ;
  31. Const
  32. RPNMax = 10; { I think you only need 4, but just to be safe }
  33. OpMax = 25;
  34. maxoperands = 3; { Maximum operands for assembler instructions }
  35. {---------------------------------------------------------------------
  36. Local Label Management
  37. ---------------------------------------------------------------------}
  38. Type
  39. { Each local label has this structure associated with it }
  40. PLocalLabel = ^TLocalLabel;
  41. TLocalLabel = object(TNamedIndexObject)
  42. Emitted : boolean;
  43. constructor Init(const n:string);
  44. function Getpasmlabel:pasmlabel;
  45. private
  46. lab : pasmlabel;
  47. end;
  48. PLocalLabelList = ^TLocalLabelList;
  49. TLocalLabelList = Object(TDictionary)
  50. procedure CheckEmitted;
  51. end;
  52. var
  53. LocalLabelList : PLocalLabelList;
  54. function CreateLocalLabel(const s: string; var hl: pasmlabel; emit:boolean):boolean;
  55. Function SearchLabel(const s: string; var hl: pasmlabel;emit:boolean): boolean;
  56. {---------------------------------------------------------------------
  57. Instruction management
  58. ---------------------------------------------------------------------}
  59. type
  60. TOprType=(OPR_NONE,OPR_CONSTANT,OPR_SYMBOL,OPR_REFERENCE,OPR_REGISTER);
  61. TOprRec = record
  62. case typ:TOprType of
  63. OPR_NONE : ();
  64. OPR_CONSTANT : (val:longint);
  65. OPR_SYMBOL : (symbol:PAsmSymbol;symofs:longint);
  66. OPR_REFERENCE : (ref:treference);
  67. OPR_REGISTER : (reg:tregister);
  68. end;
  69. POperand = ^TOperand;
  70. TOperand = object
  71. size : topsize;
  72. hasvar : boolean; { if the operand is loaded with a variable }
  73. opr : TOprRec;
  74. constructor init;
  75. destructor done;virtual;
  76. Procedure BuildOperand;virtual;
  77. Procedure SetSize(_size:longint);
  78. Function SetupResult:boolean;
  79. Function SetupSelf:boolean;
  80. Function SetupOldEBP:boolean;
  81. Function SetupVar(const hs:string): Boolean;
  82. Function SetupDirectVar(const hs:string): Boolean;
  83. Procedure InitRef;
  84. end;
  85. PInstruction = ^TInstruction;
  86. TInstruction = object
  87. opcode : tasmop;
  88. opsize : topsize;
  89. condition : tasmcond;
  90. ops : byte;
  91. operands : array[1..maxoperands] of POperand;
  92. constructor init;
  93. destructor done;virtual;
  94. Procedure InitOperands;virtual;
  95. Procedure BuildOpcode;virtual;
  96. procedure ConcatInstruction(p:PAasmoutput);virtual;
  97. Procedure SwapOperands;
  98. end;
  99. {---------------------------------------------------------------------}
  100. { Expression parser types }
  101. {---------------------------------------------------------------------}
  102. TExprOperator = record
  103. ch: char; { operator }
  104. is_prefix: boolean; { was it a prefix, possible prefixes are +,- and not }
  105. end;
  106. String15 = String[15];
  107. {**********************************************************************}
  108. { The following operators are supported: }
  109. { '+' : addition }
  110. { '-' : subtraction }
  111. { '*' : multiplication }
  112. { '/' : modulo division }
  113. { '^' : exclusive or }
  114. { '<' : shift left }
  115. { '>' : shift right }
  116. { '&' : bitwise and }
  117. { '|' : bitwise or }
  118. { '~' : bitwise complement }
  119. { '%' : modulo division }
  120. { nnn: longint numbers }
  121. { ( and ) parenthesis }
  122. {**********************************************************************}
  123. TExprParse = Object
  124. public
  125. Constructor Init;
  126. Destructor Done;
  127. Function Evaluate(Expr: String): longint;
  128. Function Priority(_Operator: Char): Integer; virtual;
  129. private
  130. RPNStack : Array[1..RPNMax] of longint; { Stack For RPN calculator }
  131. RPNTop : Integer;
  132. OpStack : Array[1..OpMax] of TExprOperator; { Operator stack For conversion }
  133. OpTop : Integer;
  134. Procedure RPNPush(Num: Longint);
  135. Function RPNPop: Longint;
  136. Procedure RPNCalc(token: String15; prefix: boolean);
  137. Procedure OpPush(_Operator: char; prefix: boolean);
  138. { In reality returns TExprOperaotr }
  139. Procedure OpPop(var _Operator:TExprOperator);
  140. end;
  141. { Evaluate an expression string to a longint }
  142. Function CalculateExpression(const expression: string): longint;
  143. {---------------------------------------------------------------------}
  144. { String routines }
  145. {---------------------------------------------------------------------}
  146. Function ValDecimal(const S:String):longint;
  147. Function ValOctal(const S:String):longint;
  148. Function ValBinary(const S:String):longint;
  149. Function ValHexaDecimal(const S:String):longint;
  150. Function PadZero(Var s: String; n: byte): Boolean;
  151. Function EscapeToPascal(const s:string): string;
  152. {---------------------------------------------------------------------
  153. Symbol helper routines
  154. ---------------------------------------------------------------------}
  155. Function GetRecordOffsetSize(s:string;Var Offset: longint;var Size:longint):boolean;
  156. Function SearchRecordType(const s:string): boolean;
  157. Function SearchIConstant(const s:string; var l:longint): boolean;
  158. {---------------------------------------------------------------------
  159. Instruction generation routines
  160. ---------------------------------------------------------------------}
  161. Procedure ConcatPasString(p : paasmoutput;s:string);
  162. Procedure ConcatDirect(p : paasmoutput;s:string);
  163. Procedure ConcatLabel(p: paasmoutput;var l : pasmlabel);
  164. Procedure ConcatConstant(p : paasmoutput;value: longint; maxvalue: longint);
  165. Procedure ConcatConstSymbol(p : paasmoutput;const sym:string;l:longint);
  166. Procedure ConcatRealConstant(p : paasmoutput;value: bestreal; real_typ : tfloattype);
  167. Procedure ConcatString(p : paasmoutput;s:string);
  168. procedure ConcatAlign(p:paasmoutput;l:longint);
  169. Procedure ConcatPublic(p:paasmoutput;const s : string);
  170. Procedure ConcatLocal(p:paasmoutput;const s : string);
  171. Procedure ConcatGlobalBss(const s : string;size : longint);
  172. Procedure ConcatLocalBss(const s : string;size : longint);
  173. Implementation
  174. {*************************************************************************
  175. TExprParse
  176. *************************************************************************}
  177. Constructor TExprParse.Init;
  178. Begin
  179. end;
  180. Procedure TExprParse.RPNPush(Num : longint);
  181. { Add an operand to the top of the RPN stack }
  182. begin
  183. if RPNTop < RPNMax then
  184. begin
  185. Inc(RPNTop);
  186. RPNStack[RPNTop]:=Num;
  187. end
  188. else
  189. Message(asmr_e_ev_stack_overflow);
  190. end;
  191. Function TExprParse.RPNPop : longint;
  192. { Get the operand at the top of the RPN stack }
  193. begin
  194. if RPNTop > 0 then
  195. begin
  196. RPNPop:=RPNStack[RPNTop];
  197. Dec(RPNTop);
  198. end
  199. else
  200. Message(asmr_e_ev_stack_underflow);
  201. end;
  202. Procedure TExprParse.RPNCalc(Token : String15; prefix:boolean); { RPN Calculator }
  203. Var
  204. Temp : longint;
  205. LocalError : Integer;
  206. begin
  207. { Handle operators }
  208. if (Length(Token) = 1) and (Token[1] in ['+', '-', '*', '/','&','|','%','^','~','<','>']) then
  209. Case Token[1] of
  210. '+' :
  211. Begin
  212. if not prefix then
  213. RPNPush(RPNPop + RPNPop);
  214. end;
  215. '-' :
  216. Begin
  217. if prefix then
  218. RPNPush(-(RPNPop))
  219. else
  220. RPNPush(RPNPop - RPNPop);
  221. end;
  222. '*' : RPNPush(RPNPop * RPNPop);
  223. '&' : RPNPush(RPNPop AND RPNPop);
  224. '|' : RPNPush(RPNPop OR RPNPop);
  225. '~' : RPNPush(NOT RPNPop);
  226. '<' : RPNPush(RPNPop SHL RPNPop);
  227. '>' : RPNPush(RPNPop SHR RPNPop);
  228. '%' :
  229. begin
  230. Temp:=RPNPop;
  231. if Temp <> 0 then
  232. RPNPush(RPNPop mod Temp)
  233. else
  234. Message(asmr_e_ev_zero_divide);
  235. end;
  236. '^' : RPNPush(RPNPop XOR RPNPop);
  237. '/' :
  238. begin
  239. Temp:=RPNPop;
  240. if Temp <> 0 then
  241. RPNPush(RPNPop div Temp)
  242. else
  243. Message(asmr_e_ev_zero_divide);
  244. end;
  245. end
  246. else
  247. begin
  248. { Convert String to number and add to stack }
  249. if token='-2147483648' then
  250. begin
  251. temp:=$80000000;
  252. localerror:=0;
  253. end
  254. else
  255. Val(Token, Temp, LocalError);
  256. if LocalError = 0 then
  257. RPNPush(Temp)
  258. else
  259. Message(asmr_e_ev_invalid_number);
  260. end;
  261. end;
  262. Procedure TExprParse.OpPush(_Operator : char;prefix: boolean);
  263. { Add an operator onto top of the stack }
  264. begin
  265. if OpTop < OpMax then
  266. begin
  267. Inc(OpTop);
  268. OpStack[OpTop].ch:=_Operator;
  269. OpStack[OpTop].is_prefix:=prefix;
  270. end
  271. else
  272. Message(asmr_e_ev_stack_overflow);
  273. end;
  274. Procedure TExprParse.OpPop(var _Operator:TExprOperator);
  275. { Get operator at the top of the stack }
  276. begin
  277. if OpTop > 0 then
  278. begin
  279. _Operator:=OpStack[OpTop];
  280. Dec(OpTop);
  281. end
  282. else
  283. Message(asmr_e_ev_stack_underflow);
  284. end;
  285. Function TExprParse.Priority(_Operator : Char) : Integer;
  286. { Return priority of operator }
  287. { The greater the priority, the higher the precedence }
  288. begin
  289. Case _Operator OF
  290. '(' :
  291. Priority:=0;
  292. '+', '-' :
  293. Priority:=1;
  294. '*', '/','%','<','>' :
  295. Priority:=2;
  296. '|','&','^','~' :
  297. Priority:=0;
  298. else
  299. Message(asmr_e_ev_invalid_op);
  300. end;
  301. end;
  302. Function TExprParse.Evaluate(Expr : String):longint;
  303. Var
  304. I : Integer;
  305. Token : String15;
  306. opr : TExprOperator;
  307. begin
  308. Evaluate:=0;
  309. { Reset stacks }
  310. OpTop :=0;
  311. RPNTop:=0;
  312. Token :='';
  313. { nothing to do ? }
  314. if Expr='' then
  315. exit;
  316. For I:=1 to Length(Expr) DO
  317. begin
  318. if Expr[I] in ['0'..'9'] then
  319. begin { Build multi-digit numbers }
  320. Token:=Token + Expr[I];
  321. if I = Length(Expr) then { Send last one to calculator }
  322. RPNCalc(Token,false);
  323. end
  324. else
  325. if Expr[I] in ['+', '-', '*', '/', '(', ')','^','&','|','%','~','<','>'] then
  326. begin
  327. if Token <> '' then
  328. begin { Send last built number to calc. }
  329. RPNCalc(Token,false);
  330. Token:='';
  331. end;
  332. Case Expr[I] OF
  333. '(' : OpPush('(',false);
  334. ')' : begin
  335. While OpStack[OpTop].ch <> '(' DO
  336. Begin
  337. OpPop(opr);
  338. RPNCalc(opr.ch,opr.is_prefix);
  339. end;
  340. OpPop(opr); { Pop off and ignore the '(' }
  341. end;
  342. '+','-','~' : Begin
  343. { workaround for -2147483648 }
  344. if (expr[I]='-') and (expr[i+1] in ['0'..'9']) then
  345. begin
  346. token:='-';
  347. expr[i]:='+';
  348. end;
  349. { if start of expression then surely a prefix }
  350. { or if previous char was also an operator }
  351. if (I = 1) or (not (Expr[I-1] in ['0'..'9','(',')'])) then
  352. OpPush(Expr[I],true)
  353. else
  354. Begin
  355. { Evaluate all higher priority operators }
  356. While (OpTop > 0) AND (Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
  357. Begin
  358. OpPop(opr);
  359. RPNCalc(opr.ch,opr.is_prefix);
  360. end;
  361. OpPush(Expr[I],false);
  362. End;
  363. end;
  364. '*', '/',
  365. '^','|','&',
  366. '%','<','>' : begin
  367. While (OpTop > 0) and (Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
  368. Begin
  369. OpPop(opr);
  370. RPNCalc(opr.ch,opr.is_prefix);
  371. end;
  372. OpPush(Expr[I],false);
  373. end;
  374. end; { Case }
  375. end
  376. else
  377. Message(asmr_e_ev_invalid_op); { Handle bad input error }
  378. end;
  379. { Pop off the remaining operators }
  380. While OpTop > 0 do
  381. Begin
  382. OpPop(opr);
  383. RPNCalc(opr.ch,opr.is_prefix);
  384. end;
  385. { The result is stored on the top of the stack }
  386. Evaluate:=RPNPop;
  387. end;
  388. Destructor TExprParse.Done;
  389. Begin
  390. end;
  391. Function CalculateExpression(const expression: string): longint;
  392. var
  393. expr: TExprParse;
  394. Begin
  395. expr.Init;
  396. CalculateExpression:=expr.Evaluate(expression);
  397. expr.Done;
  398. end;
  399. {*************************************************************************}
  400. { String conversions/utils }
  401. {*************************************************************************}
  402. Function EscapeToPascal(const s:string): string;
  403. { converts a C styled string - which contains escape }
  404. { characters to a pascal style string. }
  405. var
  406. i,len : longint;
  407. hs : string;
  408. temp : string;
  409. c : char;
  410. Begin
  411. hs:='';
  412. len:=0;
  413. i:=0;
  414. while (i<length(s)) and (len<255) do
  415. begin
  416. Inc(i);
  417. if (s[i]='\') and (i<length(s)) then
  418. Begin
  419. inc(i);
  420. case s[i] of
  421. '\' :
  422. c:='\';
  423. 'b':
  424. c:=#8;
  425. 'f':
  426. c:=#12;
  427. 'n':
  428. c:=#10;
  429. 'r':
  430. c:=#13;
  431. 't':
  432. c:=#9;
  433. '"':
  434. c:='"';
  435. '0'..'7':
  436. Begin
  437. temp:=s[i];
  438. temp:=temp+s[i+1];
  439. temp:=temp+s[i+2];
  440. inc(i,2);
  441. c:=chr(ValOctal(temp));
  442. end;
  443. 'x':
  444. Begin
  445. temp:=s[i+1];
  446. temp:=temp+s[i+2];
  447. inc(i,2);
  448. c:=chr(ValHexaDecimal(temp));
  449. end;
  450. else
  451. Begin
  452. Message1(asmr_e_escape_seq_ignored,s[i]);
  453. c:=s[i];
  454. end;
  455. end;
  456. end
  457. else
  458. c:=s[i];
  459. inc(len);
  460. hs[len]:=c;
  461. end;
  462. hs[0]:=chr(len);
  463. EscapeToPascal:=hs;
  464. end;
  465. Function ValDecimal(const S:String):longint;
  466. { Converts a decimal string to longint }
  467. var
  468. vs,c : longint;
  469. Begin
  470. vs:=0;
  471. for c:=1 to length(s) do
  472. begin
  473. vs:=vs*10;
  474. if s[c] in ['0'..'9'] then
  475. inc(vs,ord(s[c])-ord('0'))
  476. else
  477. begin
  478. Message1(asmr_e_error_converting_decimal,s);
  479. ValDecimal:=0;
  480. exit;
  481. end;
  482. end;
  483. ValDecimal:=vs;
  484. end;
  485. Function ValOctal(const S:String):longint;
  486. { Converts an octal string to longint }
  487. var
  488. vs,c : longint;
  489. Begin
  490. vs:=0;
  491. for c:=1 to length(s) do
  492. begin
  493. vs:=vs shl 3;
  494. if s[c] in ['0'..'7'] then
  495. inc(vs,ord(s[c])-ord('0'))
  496. else
  497. begin
  498. Message1(asmr_e_error_converting_octal,s);
  499. ValOctal:=0;
  500. exit;
  501. end;
  502. end;
  503. ValOctal:=vs;
  504. end;
  505. Function ValBinary(const S:String):longint;
  506. { Converts a binary string to longint }
  507. var
  508. vs,c : longint;
  509. Begin
  510. vs:=0;
  511. for c:=1 to length(s) do
  512. begin
  513. vs:=vs shl 1;
  514. if s[c] in ['0'..'1'] then
  515. inc(vs,ord(s[c])-ord('0'))
  516. else
  517. begin
  518. Message1(asmr_e_error_converting_binary,s);
  519. ValBinary:=0;
  520. exit;
  521. end;
  522. end;
  523. ValBinary:=vs;
  524. end;
  525. Function ValHexadecimal(const S:String):longint;
  526. { Converts a binary string to longint }
  527. var
  528. vs,c : longint;
  529. Begin
  530. vs:=0;
  531. for c:=1 to length(s) do
  532. begin
  533. vs:=vs shl 4;
  534. case s[c] of
  535. '0'..'9' :
  536. inc(vs,ord(s[c])-ord('0'));
  537. 'A'..'F' :
  538. inc(vs,ord(s[c])-ord('A')+10);
  539. 'a'..'f' :
  540. inc(vs,ord(s[c])-ord('a')+10);
  541. else
  542. begin
  543. Message1(asmr_e_error_converting_hexadecimal,s);
  544. ValHexadecimal:=0;
  545. exit;
  546. end;
  547. end;
  548. end;
  549. ValHexadecimal:=vs;
  550. end;
  551. Function PadZero(Var s: String; n: byte): Boolean;
  552. Begin
  553. PadZero:=TRUE;
  554. { Do some error checking first }
  555. if Length(s) = n then
  556. exit
  557. else
  558. if Length(s) > n then
  559. Begin
  560. PadZero:=FALSE;
  561. delete(s,n+1,length(s));
  562. exit;
  563. end
  564. else
  565. PadZero:=TRUE;
  566. { Fill it up with the specified character }
  567. fillchar(s[length(s)+1],n-1,#0);
  568. s[0]:=chr(n);
  569. end;
  570. {****************************************************************************
  571. TOperand
  572. ****************************************************************************}
  573. constructor TOperand.init;
  574. begin
  575. size:=S_NO;
  576. hasvar:=false;
  577. FillChar(Opr,sizeof(Opr),0);
  578. end;
  579. destructor TOperand.done;
  580. begin
  581. end;
  582. Procedure TOperand.SetSize(_size:longint);
  583. begin
  584. if (size = S_NO) and (_size<extended_size) then
  585. Begin
  586. case _size of
  587. 1 : size:=S_B;
  588. 2 : size:=S_W{ could be S_IS};
  589. 4 : size:=S_L{ could be S_IL or S_FS};
  590. 8 : size:=S_IQ{ could be S_D or S_FL};
  591. extended_size : size:=S_FX;
  592. end;
  593. end;
  594. end;
  595. Function TOperand.SetupResult:boolean;
  596. Begin
  597. SetupResult:=false;
  598. { replace by correct offset. }
  599. if assigned(procinfo^.retdef) and
  600. (procinfo^.retdef<>pdef(voiddef)) then
  601. begin
  602. opr.ref.offset:=procinfo^.retoffset;
  603. opr.ref.base:= procinfo^.framepointer;
  604. { always assume that the result is valid. }
  605. procinfo^.funcret_state:=vs_assigned;
  606. SetupResult:=true;
  607. end
  608. else
  609. Message(asmr_e_void_function);
  610. end;
  611. Function TOperand.SetupSelf:boolean;
  612. Begin
  613. SetupSelf:=false;
  614. if assigned(procinfo^._class) then
  615. Begin
  616. opr.typ:=OPR_REFERENCE;
  617. opr.ref.offset:=procinfo^.selfpointer_offset;
  618. opr.ref.base:=procinfo^.framepointer;
  619. opr.ref.options:=ref_selffixup;
  620. SetupSelf:=true;
  621. end
  622. else
  623. Message(asmr_e_cannot_use_SELF_outside_a_method);
  624. end;
  625. Function TOperand.SetupOldEBP:boolean;
  626. Begin
  627. SetupOldEBP:=false;
  628. if lexlevel>normal_function_level then
  629. Begin
  630. opr.typ:=OPR_REFERENCE;
  631. opr.ref.offset:=procinfo^.framepointer_offset;
  632. opr.ref.base:=procinfo^.framepointer;
  633. SetupOldEBP:=true;
  634. end
  635. else
  636. Message(asmr_e_cannot_use_OLDEBP_outside_nested_procedure);
  637. end;
  638. Function TOperand.SetupVar(const hs:string): Boolean;
  639. { search and sets up the correct fields in the Instr record }
  640. { for the NON-constant identifier passed to the routine. }
  641. { if not found returns FALSE. }
  642. var
  643. sym : psym;
  644. harrdef : parraydef;
  645. Begin
  646. SetupVar:=false;
  647. { are we in a routine ? }
  648. getsym(hs,false);
  649. sym:=srsym;
  650. if sym=nil then
  651. exit;
  652. case sym^.typ of
  653. varsym :
  654. begin
  655. { we always assume in asm statements that }
  656. { that the variable is valid. }
  657. pvarsym(sym)^.varstate:=vs_used;
  658. inc(pvarsym(sym)^.refs);
  659. case pvarsym(sym)^.owner^.symtabletype of
  660. objectsymtable :
  661. begin
  662. { this is not allowed, because we don't know if the self
  663. register is still free, and loading it first is also
  664. not possible, because this could break code }
  665. opr.typ:=OPR_CONSTANT;
  666. opr.val:=pvarsym(sym)^.address;
  667. hasvar:=true;
  668. SetupVar:=true;
  669. Exit;
  670. end;
  671. unitsymtable,
  672. globalsymtable,
  673. staticsymtable :
  674. opr.ref.symbol:=newasmsymbol(pvarsym(sym)^.mangledname);
  675. parasymtable :
  676. begin
  677. opr.ref.base:=procinfo^.framepointer;
  678. opr.ref.offset:=pvarsym(sym)^.address;
  679. opr.ref.offsetfixup:=aktprocsym^.definition^.parast^.address_fixup;
  680. opr.ref.options:=ref_parafixup;
  681. end;
  682. localsymtable :
  683. begin
  684. if (vo_is_external in pvarsym(sym)^.varoptions) then
  685. opr.ref.symbol:=newasmsymbol(pvarsym(sym)^.mangledname)
  686. else
  687. begin
  688. opr.ref.base:=procinfo^.framepointer;
  689. opr.ref.offset:=-(pvarsym(sym)^.address);
  690. opr.ref.options:=ref_localfixup;
  691. opr.ref.offsetfixup:=aktprocsym^.definition^.localst^.address_fixup;
  692. end;
  693. end;
  694. end;
  695. case pvarsym(sym)^.definition^.deftype of
  696. orddef,
  697. enumdef,
  698. pointerdef,
  699. floatdef :
  700. SetSize(pvarsym(sym)^.getsize);
  701. arraydef :
  702. begin
  703. { for arrays try to get the element size, take care of
  704. multiple indexes }
  705. harrdef:=Parraydef(PVarsym(sym)^.definition);
  706. while assigned(harrdef^.definition) and
  707. (harrdef^.definition^.deftype=arraydef) do
  708. harrdef:=parraydef(harrdef^.definition);
  709. SetSize(harrdef^.elesize);
  710. end;
  711. end;
  712. hasvar:=true;
  713. SetupVar:=true;
  714. Exit;
  715. end;
  716. typedconstsym :
  717. begin
  718. opr.ref.symbol:=newasmsymbol(ptypedconstsym(sym)^.mangledname);
  719. case ptypedconstsym(sym)^.definition^.deftype of
  720. orddef,
  721. enumdef,
  722. pointerdef,
  723. floatdef :
  724. SetSize(ptypedconstsym(sym)^.getsize);
  725. arraydef :
  726. begin
  727. { for arrays try to get the element size, take care of
  728. multiple indexes }
  729. harrdef:=Parraydef(PTypedConstSym(sym)^.definition);
  730. while assigned(harrdef^.definition) and
  731. (harrdef^.definition^.deftype=arraydef) do
  732. harrdef:=parraydef(harrdef^.definition);
  733. SetSize(harrdef^.elesize);
  734. end;
  735. end;
  736. hasvar:=true;
  737. SetupVar:=true;
  738. Exit;
  739. end;
  740. constsym :
  741. begin
  742. if pconstsym(sym)^.consttype in [constint,constchar,constbool] then
  743. begin
  744. opr.typ:=OPR_CONSTANT;
  745. opr.val:=pconstsym(sym)^.value;
  746. hasvar:=true;
  747. SetupVar:=true;
  748. Exit;
  749. end;
  750. end;
  751. typesym :
  752. begin
  753. if ptypesym(sym)^.definition^.deftype in [recorddef,objectdef] then
  754. begin
  755. opr.typ:=OPR_CONSTANT;
  756. opr.val:=0;
  757. hasvar:=true;
  758. SetupVar:=TRUE;
  759. Exit;
  760. end;
  761. end;
  762. procsym :
  763. begin
  764. if assigned(pprocsym(sym)^.definition^.nextoverloaded) then
  765. Message(asmr_w_calling_overload_func);
  766. opr.typ:=OPR_SYMBOL;
  767. opr.symbol:=newasmsymbol(pprocsym(sym)^.definition^.mangledname);
  768. hasvar:=true;
  769. SetupVar:=TRUE;
  770. Exit;
  771. end;
  772. else
  773. begin
  774. Message(asmr_e_unsupported_symbol_type);
  775. exit;
  776. end;
  777. end;
  778. end;
  779. { looks for internal names of variables and routines }
  780. Function TOperand.SetupDirectVar(const hs:string): Boolean;
  781. {$ifndef OLDDIRECTVAR}
  782. var
  783. p : pasmsymbol;
  784. begin
  785. SetupDirectVar:=false;
  786. p:=getasmsymbol(hs);
  787. if assigned(p) then
  788. begin
  789. opr.ref.symbol:=p;
  790. hasvar:=true;
  791. SetupDirectVar:=true;
  792. end;
  793. end;
  794. {$else}
  795. var
  796. p : pai_external;
  797. Begin
  798. SearchDirectVar:=false;
  799. { search in the list of internals }
  800. p:=search_assembler_symbol(internals,hs,EXT_ANY);
  801. if p=nil then
  802. p:=search_assembler_symbol(externals,hs,EXT_ANY);
  803. if p<>nil then
  804. begin
  805. instr.operands[operandnum].opr.ref.symbol:=p^.sym;
  806. case p^.exttyp of
  807. EXT_BYTE : instr.operands[operandnum].size:=S_B;
  808. EXT_WORD : instr.operands[operandnum].size:=S_W;
  809. EXT_NEAR,EXT_FAR,EXT_PROC,EXT_DWORD,EXT_CODEPTR,EXT_DATAPTR:
  810. instr.operands[operandnum].size:=S_L;
  811. EXT_QWORD : instr.operands[operandnum].size:=S_FL;
  812. EXT_TBYTE : instr.operands[operandnum].size:=S_FX;
  813. else
  814. { this is in the case where the instruction is LEA }
  815. { or something like that, in that case size is not }
  816. { important. }
  817. instr.operands[operandnum].size:=S_NO;
  818. end;
  819. instr.operands[operandnum].hasvar:=true;
  820. SearchDirectVar:=TRUE;
  821. Exit;
  822. end;
  823. end;
  824. {$endif}
  825. procedure TOperand.InitRef;
  826. {*********************************************************************}
  827. { Description: This routine first check if the opcode is of }
  828. { type OPR_NONE, or OPR_REFERENCE , if not it gives out an error. }
  829. { If the operandtype = OPR_NONE or <> OPR_REFERENCE then it sets up }
  830. { the operand type to OPR_REFERENCE, as well as setting up the ref }
  831. { to point to the default segment. }
  832. {*********************************************************************}
  833. Begin
  834. case opr.typ of
  835. OPR_REFERENCE:
  836. exit;
  837. OPR_NONE: ;
  838. else
  839. Message(asmr_e_invalid_operand_type);
  840. end;
  841. opr.typ := OPR_REFERENCE;
  842. reset_reference(opr.ref);
  843. end;
  844. procedure TOperand.BuildOperand;
  845. begin
  846. abstract;
  847. end;
  848. {****************************************************************************
  849. TInstruction
  850. ****************************************************************************}
  851. constructor TInstruction.init;
  852. Begin
  853. Opcode:=A_NONE;
  854. Opsize:=S_NO;
  855. Condition:=C_NONE;
  856. Ops:=0;
  857. InitOperands;
  858. end;
  859. destructor TInstruction.done;
  860. var
  861. i : longint;
  862. Begin
  863. for i:=1 to 3 do
  864. Dispose(Operands[i],Done);
  865. end;
  866. procedure TInstruction.InitOperands;
  867. var
  868. i : longint;
  869. begin
  870. for i:=1 to 3 do
  871. New(Operands[i],init);
  872. end;
  873. Procedure TInstruction.SwapOperands;
  874. Var
  875. p : POperand;
  876. Begin
  877. case Ops of
  878. 2 :
  879. begin
  880. p:=Operands[1];
  881. Operands[1]:=Operands[2];
  882. Operands[2]:=p;
  883. end;
  884. 3 :
  885. begin
  886. p:=Operands[1];
  887. Operands[1]:=Operands[3];
  888. Operands[3]:=p;
  889. end;
  890. end;
  891. end;
  892. procedure TInstruction.ConcatInstruction(p:PAasmOutput);
  893. begin
  894. abstract;
  895. end;
  896. procedure TInstruction.BuildOpcode;
  897. begin
  898. abstract;
  899. end;
  900. {***************************************************************************
  901. TLocalLabel
  902. ***************************************************************************}
  903. constructor TLocalLabel.Init(const n:string);
  904. begin
  905. inherited InitName(n);
  906. lab:=nil;
  907. emitted:=false;
  908. end;
  909. function TLocalLabel.Getpasmlabel:pasmlabel;
  910. begin
  911. if not assigned(lab) then
  912. begin
  913. getlabel(lab);
  914. { this label is forced to be used so it's always written }
  915. inc(lab^.refs);
  916. end;
  917. Getpasmlabel:=lab;
  918. end;
  919. {***************************************************************************
  920. TLocalLabelList
  921. ***************************************************************************}
  922. procedure LocalLabelEmitted(p:PNamedIndexObject);{$ifndef FPC}far;{$endif}
  923. begin
  924. if not PLocalLabel(p)^.emitted then
  925. Message1(asmr_e_unknown_label_identifier,p^.name);
  926. end;
  927. procedure TLocalLabelList.CheckEmitted;
  928. begin
  929. ForEach({$ifndef TP}@{$endif}LocalLabelEmitted)
  930. end;
  931. function CreateLocalLabel(const s: string; var hl: pasmlabel; emit:boolean):boolean;
  932. var
  933. lab : PLocalLabel;
  934. Begin
  935. CreateLocalLabel:=true;
  936. { Check if it already is defined }
  937. lab:=PLocalLabel(LocalLabelList^.Search(s));
  938. if not assigned(lab) then
  939. begin
  940. new(lab,init(s));
  941. LocalLabelList^.Insert(lab);
  942. end;
  943. { set emitted flag and check for dup syms }
  944. if emit then
  945. begin
  946. if lab^.Emitted then
  947. begin
  948. Message1(asmr_e_dup_local_sym,lab^.Name);
  949. CreateLocalLabel:=false;
  950. end;
  951. lab^.Emitted:=true;
  952. end;
  953. hl:=lab^.Getpasmlabel;
  954. end;
  955. {****************************************************************************
  956. Symbol table helper routines
  957. ****************************************************************************}
  958. Function SearchRecordType(const s:string): boolean;
  959. Begin
  960. SearchRecordType:=false;
  961. { Check the constants in symtable }
  962. getsym(s,false);
  963. if srsym <> nil then
  964. Begin
  965. case srsym^.typ of
  966. typesym :
  967. begin
  968. if ptypesym(srsym)^.definition^.deftype in [recorddef,objectdef] then
  969. begin
  970. SearchRecordType:=true;
  971. exit;
  972. end;
  973. end;
  974. end;
  975. end;
  976. end;
  977. Function SearchIConstant(const s:string; var l:longint): boolean;
  978. {**********************************************************************}
  979. { Description: Searches for a CONSTANT of name s in either the local }
  980. { symbol list, then in the global symbol list, and returns the value }
  981. { of that constant in l. Returns TRUE if successfull, if not found, }
  982. { or if the constant is not of correct type, then returns FALSE }
  983. { Remarks: Also handle TRUE and FALSE returning in those cases 1 and 0 }
  984. { respectively. }
  985. {**********************************************************************}
  986. Begin
  987. SearchIConstant:=false;
  988. { check for TRUE or FALSE reserved words first }
  989. if s = 'TRUE' then
  990. Begin
  991. SearchIConstant:=TRUE;
  992. l:=1;
  993. exit;
  994. end;
  995. if s = 'FALSE' then
  996. Begin
  997. SearchIConstant:=TRUE;
  998. l:=0;
  999. exit;
  1000. end;
  1001. { Check the constants in symtable }
  1002. getsym(s,false);
  1003. if srsym <> nil then
  1004. Begin
  1005. case srsym^.typ of
  1006. constsym :
  1007. begin
  1008. if (pconstsym(srsym)^.consttype in [constord,constint,constchar,constbool]) then
  1009. Begin
  1010. l:=pconstsym(srsym)^.value;
  1011. SearchIConstant:=TRUE;
  1012. exit;
  1013. end;
  1014. end;
  1015. enumsym:
  1016. Begin
  1017. l:=penumsym(srsym)^.value;
  1018. SearchIConstant:=TRUE;
  1019. exit;
  1020. end;
  1021. end;
  1022. end;
  1023. end;
  1024. Function GetRecordOffsetSize(s:string;Var Offset: longint;var Size:longint):boolean;
  1025. { search and returns the offset and size of records/objects of the base }
  1026. { with field name setup in field. }
  1027. { returns FALSE if not found. }
  1028. { used when base is a variable or a typed constant name. }
  1029. var
  1030. st : psymtable;
  1031. harrdef : parraydef;
  1032. sym : psym;
  1033. i : longint;
  1034. base : string;
  1035. Begin
  1036. GetRecordOffsetSize:=FALSE;
  1037. Offset:=0;
  1038. Size:=0;
  1039. i:=pos('.',s);
  1040. if i=0 then
  1041. i:=255;
  1042. base:=Copy(s,1,i-1);
  1043. delete(s,1,i);
  1044. if base='SELF' then
  1045. st:=procinfo^._class^.symtable
  1046. else
  1047. begin
  1048. getsym(base,false);
  1049. sym:=srsym;
  1050. st:=nil;
  1051. { we can start with a var,type,typedconst }
  1052. case sym^.typ of
  1053. varsym :
  1054. begin
  1055. case pvarsym(sym)^.definition^.deftype of
  1056. recorddef :
  1057. st:=precorddef(pvarsym(sym)^.definition)^.symtable;
  1058. objectdef :
  1059. st:=pobjectdef(pvarsym(sym)^.definition)^.symtable;
  1060. end;
  1061. end;
  1062. typesym :
  1063. begin
  1064. case ptypesym(sym)^.definition^.deftype of
  1065. recorddef :
  1066. st:=precorddef(ptypesym(sym)^.definition)^.symtable;
  1067. objectdef :
  1068. st:=pobjectdef(ptypesym(sym)^.definition)^.symtable;
  1069. end;
  1070. end;
  1071. typedconstsym :
  1072. begin
  1073. case pvarsym(sym)^.definition^.deftype of
  1074. recorddef :
  1075. st:=precorddef(ptypedconstsym(sym)^.definition)^.symtable;
  1076. objectdef :
  1077. st:=pobjectdef(ptypedconstsym(sym)^.definition)^.symtable;
  1078. end;
  1079. end;
  1080. end;
  1081. end;
  1082. { now walk all recordsymtables }
  1083. while assigned(st) and (s<>'') do
  1084. begin
  1085. { load next field in base }
  1086. i:=pos('.',s);
  1087. if i=0 then
  1088. i:=255;
  1089. base:=Copy(s,1,i-1);
  1090. delete(s,1,i);
  1091. sym:=st^.search(base);
  1092. if not assigned(sym) then
  1093. begin
  1094. GetRecordOffsetSize:=false;
  1095. exit;
  1096. end;
  1097. st:=nil;
  1098. case sym^.typ of
  1099. varsym :
  1100. begin
  1101. inc(Offset,pvarsym(sym)^.address);
  1102. Size:=PVarsym(sym)^.getsize;
  1103. case pvarsym(sym)^.definition^.deftype of
  1104. arraydef :
  1105. begin
  1106. { for arrays try to get the element size, take care of
  1107. multiple indexes }
  1108. harrdef:=Parraydef(PVarsym(sym)^.definition);
  1109. while assigned(harrdef^.definition) and
  1110. (harrdef^.definition^.deftype=arraydef) do
  1111. harrdef:=parraydef(harrdef^.definition);
  1112. size:=harrdef^.elesize;
  1113. end;
  1114. recorddef :
  1115. st:=precorddef(pvarsym(sym)^.definition)^.symtable;
  1116. objectdef :
  1117. st:=pobjectdef(pvarsym(sym)^.definition)^.symtable;
  1118. end;
  1119. end;
  1120. end;
  1121. end;
  1122. GetRecordOffsetSize:=(s='');
  1123. end;
  1124. Function SearchLabel(const s: string; var hl: pasmlabel;emit:boolean): boolean;
  1125. var
  1126. sym : psym;
  1127. hs : string;
  1128. Begin
  1129. hl:=nil;
  1130. SearchLabel:=false;
  1131. { Check for pascal labels, which are case insensetive }
  1132. hs:=upper(s);
  1133. getsym(hs,false);
  1134. sym:=srsym;
  1135. if sym=nil then
  1136. exit;
  1137. case sym^.typ of
  1138. labelsym :
  1139. begin
  1140. hl:=plabelsym(sym)^.lab;
  1141. if emit then
  1142. plabelsym(sym)^.defined:=true;
  1143. SearchLabel:=true;
  1144. exit;
  1145. end;
  1146. end;
  1147. end;
  1148. {*************************************************************************}
  1149. { Instruction Generation Utilities }
  1150. {*************************************************************************}
  1151. Procedure ConcatString(p : paasmoutput;s:string);
  1152. {*********************************************************************}
  1153. { PROCEDURE ConcatString(s:string); }
  1154. { Description: This routine adds the character chain pointed to in }
  1155. { s to the instruction linked list. }
  1156. {*********************************************************************}
  1157. Var
  1158. pc: PChar;
  1159. Begin
  1160. getmem(pc,length(s)+1);
  1161. p^.concat(new(pai_string,init_length_pchar(strpcopy(pc,s),length(s))));
  1162. end;
  1163. Procedure ConcatPasString(p : paasmoutput;s:string);
  1164. {*********************************************************************}
  1165. { PROCEDURE ConcatPasString(s:string); }
  1166. { Description: This routine adds the character chain pointed to in }
  1167. { s to the instruction linked list, contrary to ConcatString it }
  1168. { uses a pascal style string, so it conserves null characters. }
  1169. {*********************************************************************}
  1170. Begin
  1171. p^.concat(new(pai_string,init(s)));
  1172. end;
  1173. Procedure ConcatDirect(p : paasmoutput;s:string);
  1174. {*********************************************************************}
  1175. { PROCEDURE ConcatDirect(s:string) }
  1176. { Description: This routine output the string directly to the asm }
  1177. { output, it is only sed when writing special labels in AT&T mode, }
  1178. { and should not be used without due consideration, since it may }
  1179. { cause problems. }
  1180. {*********************************************************************}
  1181. Var
  1182. pc: PChar;
  1183. Begin
  1184. getmem(pc,length(s)+1);
  1185. p^.concat(new(pai_direct,init(strpcopy(pc,s))));
  1186. end;
  1187. Procedure ConcatConstant(p: paasmoutput; value: longint; maxvalue: longint);
  1188. {*********************************************************************}
  1189. { PROCEDURE ConcatConstant(value: longint; maxvalue: longint); }
  1190. { Description: This routine adds the value constant to the current }
  1191. { instruction linked list. }
  1192. { maxvalue -> indicates the size of the data to initialize: }
  1193. { $ff -> create a byte node. }
  1194. { $ffff -> create a word node. }
  1195. { $ffffffff -> create a dword node. }
  1196. {*********************************************************************}
  1197. Begin
  1198. if (maxvalue <> $ffffffff) and (value > maxvalue) then
  1199. Begin
  1200. Message(asmr_e_constant_out_of_bounds);
  1201. { assuming a value of maxvalue }
  1202. value:=maxvalue;
  1203. end;
  1204. if maxvalue = $ff then
  1205. p^.concat(new(pai_const,init_8bit(byte(value))))
  1206. else
  1207. if maxvalue = $ffff then
  1208. p^.concat(new(pai_const,init_16bit(word(value))))
  1209. else
  1210. if maxvalue = $ffffffff then
  1211. p^.concat(new(pai_const,init_32bit(longint(value))));
  1212. end;
  1213. Procedure ConcatConstSymbol(p : paasmoutput;const sym:string;l:longint);
  1214. begin
  1215. p^.concat(new(pai_const_symbol,initname_offset(sym,l)));
  1216. end;
  1217. Procedure ConcatRealConstant(p : paasmoutput;value: bestreal; real_typ : tfloattype);
  1218. {***********************************************************************}
  1219. { PROCEDURE ConcatRealConstant(value: bestreal; real_typ : tfloattype); }
  1220. { Description: This routine adds the value constant to the current }
  1221. { instruction linked list. }
  1222. { real_typ -> indicates the type of the real data to initialize: }
  1223. { s32real -> create a single node. }
  1224. { s64real -> create a double node. }
  1225. { s80real -> create an extended node. }
  1226. { s64bit -> create a comp node. }
  1227. { f32bit -> create a fixed node. (not used normally) }
  1228. {***********************************************************************}
  1229. Begin
  1230. case real_typ of
  1231. s32real : p^.concat(new(pai_real_32bit,init(value)));
  1232. s64real : p^.concat(new(pai_real_64bit,init(value)));
  1233. s80real : p^.concat(new(pai_real_80bit,init(value)));
  1234. s64comp : p^.concat(new(pai_comp_64bit,init(value)));
  1235. f32bit : p^.concat(new(pai_const,init_32bit(trunc(value*$10000))));
  1236. end;
  1237. end;
  1238. Procedure ConcatLabel(p: paasmoutput;var l : pasmlabel);
  1239. {*********************************************************************}
  1240. { PROCEDURE ConcatLabel }
  1241. { Description: This routine either emits a label or a labeled }
  1242. { instruction to the linked list of instructions. }
  1243. {*********************************************************************}
  1244. begin
  1245. p^.concat(new(pai_label,init(l)));
  1246. end;
  1247. procedure ConcatAlign(p:paasmoutput;l:longint);
  1248. {*********************************************************************}
  1249. { PROCEDURE ConcatPublic }
  1250. { Description: This routine emits an global definition to the }
  1251. { linked list of instructions.(used by AT&T styled asm) }
  1252. {*********************************************************************}
  1253. begin
  1254. p^.concat(new(pai_align,init(l)));
  1255. end;
  1256. procedure ConcatPublic(p:paasmoutput;const s : string);
  1257. {*********************************************************************}
  1258. { PROCEDURE ConcatPublic }
  1259. { Description: This routine emits an global definition to the }
  1260. { linked list of instructions.(used by AT&T styled asm) }
  1261. {*********************************************************************}
  1262. begin
  1263. p^.concat(new(pai_symbol,initname_global(s,0)));
  1264. end;
  1265. procedure ConcatLocal(p:paasmoutput;const s : string);
  1266. {*********************************************************************}
  1267. { PROCEDURE ConcatLocal }
  1268. { Description: This routine emits an local definition to the }
  1269. { linked list of instructions. }
  1270. {*********************************************************************}
  1271. begin
  1272. p^.concat(new(pai_symbol,initname(s,0)));
  1273. end;
  1274. Procedure ConcatGlobalBss(const s : string;size : longint);
  1275. {*********************************************************************}
  1276. { PROCEDURE ConcatGlobalBss }
  1277. { Description: This routine emits an global datablock to the }
  1278. { linked list of instructions. }
  1279. {*********************************************************************}
  1280. begin
  1281. bsssegment^.concat(new(pai_datablock,init_global(s,size)));
  1282. end;
  1283. Procedure ConcatLocalBss(const s : string;size : longint);
  1284. {*********************************************************************}
  1285. { PROCEDURE ConcatLocalBss }
  1286. { Description: This routine emits a local datablcok to the }
  1287. { linked list of instructions. }
  1288. {*********************************************************************}
  1289. begin
  1290. bsssegment^.concat(new(pai_datablock,init(s,size)));
  1291. end;
  1292. end.
  1293. {
  1294. $Log$
  1295. Revision 1.30 1999-11-17 17:05:04 pierre
  1296. * Notes/hints changes
  1297. Revision 1.29 1999/11/09 23:06:46 peter
  1298. * esi_offset -> selfpointer_offset to be newcg compatible
  1299. * hcogegen -> cgbase fixes for newcg
  1300. Revision 1.28 1999/11/06 14:34:26 peter
  1301. * truncated log to 20 revs
  1302. Revision 1.27 1999/09/27 23:44:58 peter
  1303. * procinfo is now a pointer
  1304. * support for result setting in sub procedure
  1305. Revision 1.26 1999/09/08 16:04:04 peter
  1306. * better support for object fields and more error checks for
  1307. field accesses which create buggy code
  1308. Revision 1.25 1999/09/04 20:29:11 florian
  1309. * bug 577 fixed
  1310. Revision 1.24 1999/08/27 14:37:50 peter
  1311. * fixed crash with typedconst array
  1312. Revision 1.23 1999/08/13 21:28:38 peter
  1313. * more reference types support
  1314. * arraydef size returns elementsize, also for multiple indexing array
  1315. Revision 1.22 1999/08/04 00:23:28 florian
  1316. * renamed i386asm and i386base to cpuasm and cpubase
  1317. Revision 1.21 1999/08/03 22:03:12 peter
  1318. * moved bitmask constants to sets
  1319. * some other type/const renamings
  1320. Revision 1.20 1999/07/29 20:54:06 peter
  1321. * write .size also
  1322. Revision 1.19 1999/06/02 22:44:17 pierre
  1323. * previous wrong log corrected
  1324. Revision 1.18 1999/06/02 22:25:47 pierre
  1325. * changed $ifdef FPC @ into $ifndef TP
  1326. Revision 1.17 1999/05/27 19:45:01 peter
  1327. * removed oldasm
  1328. * plabel -> pasmlabel
  1329. * -a switches to source writing automaticly
  1330. * assembler readers OOPed
  1331. * asmsymbol automaticly external
  1332. * jumptables and other label fixes for asm readers
  1333. Revision 1.16 1999/05/21 13:55:18 peter
  1334. * NEWLAB for label as symbol
  1335. Revision 1.15 1999/05/12 00:17:11 peter
  1336. * fixed error which was shown for all 32bit consts
  1337. Revision 1.14 1999/05/11 16:27:23 peter
  1338. * support for pointerdef
  1339. Revision 1.13 1999/05/06 09:05:27 peter
  1340. * generic write_float and str_float
  1341. * fixed constant float conversions
  1342. Revision 1.12 1999/05/05 22:22:04 peter
  1343. * updated messages
  1344. Revision 1.11 1999/05/02 22:41:57 peter
  1345. * moved section names to systems
  1346. * fixed nasm,intel writer
  1347. Revision 1.10 1999/05/01 13:24:41 peter
  1348. * merged nasm compiler
  1349. * old asm moved to oldasm/
  1350. Revision 1.8 1999/04/26 23:26:19 peter
  1351. * redesigned record offset parsing to support nested records
  1352. * normal compiler uses the redesigned SetupVar()
  1353. Revision 1.7 1999/04/14 09:07:48 peter
  1354. * asm reader improvements
  1355. }