rautils.pas 47 KB

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