rautils.pas 47 KB

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