rautils.pas 47 KB

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