rautils.pas 47 KB

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