rautils.pas 44 KB

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