rautils.pas 47 KB

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