asmutils.pas 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939
  1. {
  2. $Id$
  3. Copyright (c) 1998 Carl Eric Codere
  4. This unit implements some support routines for assembler parsing
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. **********************************************************************}
  17. Unit AsmUtils;
  18. {*************************************************************************}
  19. { This unit implements some objects as well as utilities which will be }
  20. { used by all inline assembler parsers (non-processor specific). }
  21. { }
  22. { Main routines/objects herein: }
  23. { o Object TExprParse is a simple expression parser to resolve assembler }
  24. { expressions. (Based generally on some code by Thai Tran from SWAG). }
  25. { o Object TInstruction is a simple object used for instructions }
  26. { o Record TOperand is a simple record used to store information on }
  27. { each operand. }
  28. { o String conversion routines from octal,binary and hex to decimal. }
  29. { o A linked list object/record for local labels }
  30. { o Routines for retrieving symbols (local and global) }
  31. { o Object for a linked list of strings (with duplicate strings not }
  32. { allowed). }
  33. { o Non-processor dependant routines for adding instructions to the }
  34. { instruction list. }
  35. {*************************************************************************}
  36. {--------------------------------------------------------------------}
  37. { LEFT TO DO: }
  38. { o Fix the remaining bugs in the expression parser, such as with }
  39. { 4+-3 }
  40. { o Add support for local typed constants search. }
  41. { o Add support for private/protected fields in method assembler }
  42. { routines. }
  43. {--------------------------------------------------------------------}
  44. Interface
  45. Uses
  46. symtable,aasm,hcodegen,verbose,systems,globals,files,strings,
  47. cobjects,
  48. {$ifdef i386}
  49. i386;
  50. {$endif}
  51. {$ifdef m68k}
  52. m68k;
  53. {$endif}
  54. Const
  55. RPNMax = 10; { I think you only need 4, but just to be safe }
  56. OpMax = 25;
  57. maxoperands = 3; { Maximum operands for assembler instructions }
  58. Type
  59. {---------------------------------------------------------------------}
  60. { Label Management types }
  61. {---------------------------------------------------------------------}
  62. PAsmLabel = ^TAsmLabel;
  63. { Each local label has this structure associated with it }
  64. TAsmLabel = record
  65. name: PString; { pointer to a pascal string name of label }
  66. lab: PLabel; { pointer to a label as defined in FPC }
  67. emitted: boolean; { as the label itself been emitted ? }
  68. next: PAsmLabel; { next node }
  69. end;
  70. TAsmLabelList = Object
  71. public
  72. First: PAsmLabel;
  73. Constructor Init;
  74. Destructor Done;
  75. Procedure Insert(s:string; lab: PLabel; emitted: boolean);
  76. Function Search(const s: string): PAsmLabel;
  77. private
  78. Last: PAsmLabel;
  79. Function NewPasStr(s:string): PString;
  80. end;
  81. {---------------------------------------------------------------------}
  82. { Instruction management types }
  83. {---------------------------------------------------------------------}
  84. toperandtype = (OPR_NONE,OPR_REFERENCE,OPR_CONSTANT,OPR_REGISTER,OPR_LABINSTR,
  85. OPR_REGLIST,OPR_SYMBOL);
  86. { When the TReference field isintvalue = TRUE }
  87. { then offset points to an ABSOLUTE address }
  88. { otherwise isintvalue should always be false }
  89. { Special cases: }
  90. { For the M68k Target, size is UNUSED, the }
  91. { opcode determines the size of the }
  92. { instruction. }
  93. { DIVS/DIVU/MULS/MULU of the form dn,dn:dn }
  94. { is stored as three operands!! }
  95. { Each instruction operand can be of this type }
  96. TOperand = record
  97. size: topsize;
  98. opinfo: longint; { ao_xxxx flags }
  99. overriden : boolean; { indicates if the opcode has been overriden }
  100. { by a pseudo-opcode such as DWORD PTR }
  101. case operandtype:toperandtype of
  102. { the size of the opr_none field should be at least equal to each }
  103. { other field as to facilitate initialization. }
  104. OPR_NONE: (l: array[1..sizeof(treference)] of byte);
  105. OPR_REFERENCE: (ref:treference);
  106. OPR_CONSTANT: (val: longint);
  107. OPR_REGISTER: (reg:tregister);
  108. OPR_LABINSTR: (hl: plabel);
  109. { Register list such as in the movem instruction }
  110. OPR_REGLIST: (list: set of tregister);
  111. OPR_SYMBOL : (symbol:pstring);
  112. end;
  113. TInstruction = object
  114. public
  115. operands: array[1..maxoperands] of TOperand;
  116. { if numops = zero, a size may still be valid in operands[1] }
  117. { it still should be checked. }
  118. numops: byte;
  119. { set to TRUE if the instruction is labeled. }
  120. labeled: boolean;
  121. { This is used for instructions such A_CMPSB... etc, to determine }
  122. { the size of the instruction. }
  123. stropsize: topsize;
  124. procedure init;
  125. procedure done;
  126. { sets up the prefix field with the instruction pointed to in s }
  127. procedure addprefix(tok: tasmop);
  128. { sets up the instruction with the instruction pointed to in s }
  129. procedure addinstr(tok: tasmop);
  130. { get the current instruction of this object }
  131. function getinstruction: tasmop;
  132. { get the current prefix of this instruction }
  133. function getprefix: tasmop;
  134. private
  135. prefix: tasmop;
  136. instruction: tasmop;
  137. end;
  138. {---------------------------------------------------------------------}
  139. { Expression parser types }
  140. {---------------------------------------------------------------------}
  141. { expression parser error codes }
  142. texpr_error =
  143. (zero_divide, { divide by zero. }
  144. stack_overflow, { stack overflow. }
  145. stack_underflow, { stack underflow. }
  146. invalid_number, { invalid conversion }
  147. invalid_op); { invalid operator }
  148. TExprOperator = record
  149. ch: char; { operator }
  150. is_prefix: boolean; { was it a prefix, possible prefixes are +,- and not }
  151. end;
  152. String15 = String[15];
  153. {**********************************************************************}
  154. { The following operators are supported: }
  155. { '+' : addition }
  156. { '-' : subtraction }
  157. { '*' : multiplication }
  158. { '/' : modulo division }
  159. { '^' : exclusive or }
  160. { '<' : shift left }
  161. { '>' : shift right }
  162. { '&' : bitwise and }
  163. { '|' : bitwise or }
  164. { '~' : bitwise complement }
  165. { '%' : modulo division }
  166. { nnn: longint numbers }
  167. { ( and ) parenthesis }
  168. {**********************************************************************}
  169. TExprParse = Object
  170. public
  171. Constructor Init;
  172. Destructor Done;
  173. Function Evaluate(Expr: String): longint;
  174. Procedure Error(anerror: texpr_error); virtual;
  175. Function Priority(_Operator: Char): Integer; virtual;
  176. private
  177. RPNStack : Array[1..RPNMax] of longint; { Stack For RPN calculator }
  178. RPNTop : Integer;
  179. OpStack : Array[1..OpMax] of TExprOperator; { Operator stack For conversion }
  180. OpTop : Integer;
  181. Procedure RPNPush(Num: Longint);
  182. Function RPNPop: Longint;
  183. Procedure RPNCalc(token: String15; prefix: boolean);
  184. Procedure OpPush(_Operator: char; prefix: boolean);
  185. { In reality returns TExprOperaotr }
  186. Procedure OpPop(var _Operator:TExprOperator);
  187. end;
  188. {---------------------------------------------------------------------}
  189. { String routines }
  190. {---------------------------------------------------------------------}
  191. {*********************************************************************}
  192. { PROCEDURE PadZero; }
  193. { Description: Makes sure that the string specified is of the given }
  194. { length, by padding it with binary zeros, or truncating if necessary}
  195. { Remark: The return value is determined BEFORE any eventual padding.}
  196. { Return Value: TRUE = if length of string s was <= then n }
  197. { FALSE = if length of string s was > then n }
  198. {*********************************************************************}
  199. Function PadZero(Var s: String; n: byte): Boolean;
  200. { Converts an Hex digit string to a Decimal string }
  201. { Returns '' if there was an error. }
  202. Function HexToDec(const S:String): String;
  203. { Converts a binary digit string to a Decimal string }
  204. { Returns '' if there was an error. }
  205. Function BinaryToDec(const S:String): String;
  206. { Converts an octal digit string to a Decimal string }
  207. { Returns '' if there was an error. }
  208. Function OctalToDec(const S:String): String;
  209. { Converts a string containing C styled escape sequences to }
  210. { a pascal style string. }
  211. Function EscapeToPascal(const s:string): string;
  212. Procedure ConcatPasString(p : paasmoutput;s:string);
  213. { Writes the string s directly to the assembler output }
  214. Procedure ConcatDirect(p : paasmoutput;s:string);
  215. {---------------------------------------------------------------------}
  216. { Symbol helper routines }
  217. {---------------------------------------------------------------------}
  218. Function GetTypeOffset(var Instr: TInstruction; const base: string; const field: string;
  219. Var Offset: longint; operandnum: byte):boolean;
  220. Function GetVarOffset(var Instr: TInstruction;const base: string; const field: string;
  221. Var Offset: longint; operandnum: byte):boolean;
  222. Function SearchIConstant(const s:string; var l:longint): boolean;
  223. Function SearchLabel(const s: string; var hl: plabel): boolean;
  224. Function CreateVarInstr(var Instr: TInstruction; const hs:string;
  225. operandnum:byte):boolean;
  226. {*********************************************************************}
  227. { FUNCTION NewPasStr(s:string): PString }
  228. { Description: This routine allocates a string on the heap and }
  229. { returns a pointer to the allocated string. }
  230. { }
  231. { Remarks: The string allocated should not be modified, since it's }
  232. { length will be less then 255. }
  233. { Remarks: It is assumed that HeapError will be called if an }
  234. { allocation fails. }
  235. {*********************************************************************}
  236. Function newpasstr(s: string): Pointer;
  237. Procedure SetupResult(Var Instr:TInstruction; operandnum: byte);
  238. {$ifdef i386}
  239. Procedure FWaitWarning;
  240. {$endif}
  241. {---------------------------------------------------------------------}
  242. { Instruction generation routines }
  243. {---------------------------------------------------------------------}
  244. { swaps in the case of a 2/3 operand opcode the destination and the }
  245. { source as to put it in AT&T style instruction format. }
  246. Procedure SwapOperands(Var instr: TInstruction);
  247. Procedure ConcatLabel(p : paasmoutput;op : tasmop;var l : plabel);
  248. Procedure ConcatConstant(p : paasmoutput;value: longint; maxvalue: longint);
  249. Procedure ConcatRealConstant(p : paasmoutput;value: bestreal; real_typ : tfloattype);
  250. Procedure ConcatString(p : paasmoutput;s:string);
  251. Procedure ConcatPublic(p:paasmoutput;const s : string);
  252. Procedure ConcatLocal(p:paasmoutput;const s : string);
  253. Procedure ConcatGlobalBss(const s : string;size : longint);
  254. Procedure ConcatLocalBss(const s : string;size : longint);
  255. { add to list of external labels }
  256. Procedure ConcatExternal(const s : string;typ : texternal_typ);
  257. { add to internal list of labels }
  258. Procedure ConcatInternal(const s : string;typ : texternal_typ);
  259. Implementation
  260. {*************************************************************************}
  261. { Expression Parser }
  262. {*************************************************************************}
  263. Constructor TExprParse.Init;
  264. Begin
  265. end;
  266. Procedure TExprParse.Error(anerror:texpr_error);
  267. var
  268. t : tmsgconst;
  269. Begin
  270. case anerror of
  271. zero_divide: t:=assem_f_ev_zero_divide;
  272. stack_overflow: t:=assem_f_ev_stack_overflow;
  273. stack_underflow: t:=assem_f_ev_stack_underflow;
  274. invalid_number: t:=assem_f_ev_invalid_number;
  275. invalid_op: t:=assem_f_ev_invalid_op;
  276. else
  277. t:=assem_f_ev_unknown;
  278. end;
  279. Message(t);
  280. end;
  281. Procedure TExprParse.RPNPush(Num : longint); { Add an operand to the top of the RPN stack }
  282. begin
  283. if RPNTop < RPNMax then
  284. begin
  285. Inc(RPNTop);
  286. RPNStack[RPNTop] := Num;
  287. end
  288. else
  289. Error(stack_overflow); { Put some error handler here }
  290. end;
  291. Function TExprParse.RPNPop : longint; { Get the operand at the top of the RPN stack }
  292. begin
  293. if RPNTop > 0 then
  294. begin
  295. RPNPop := RPNStack[RPNTop];
  296. Dec(RPNTop);
  297. end
  298. else { Put some error handler here }
  299. Error(stack_underflow);
  300. end;
  301. Procedure TExprParse.RPNCalc(Token : String15; prefix:boolean); { RPN Calculator }
  302. Var
  303. Temp : longint;
  304. LocalError : Integer;
  305. begin
  306. { Write(Token, ' '); This just outputs the RPN expression }
  307. if (Length(Token) = 1) and (Token[1] in ['+', '-', '*', '/','&','|','%','^','~','<','>']) then
  308. Case Token[1] of { Handle operators }
  309. '+' : Begin
  310. if prefix then
  311. else
  312. RPNPush(RPNPop + RPNPop);
  313. end;
  314. '-' : Begin
  315. if prefix then
  316. RPNPush(-(RPNPop))
  317. else
  318. RPNPush(RPNPop - RPNPop);
  319. end;
  320. '*' : RPNPush(RPNPop * RPNPop);
  321. '&' : RPNPush(RPNPop AND RPNPop);
  322. '|' : RPNPush(RPNPop OR RPNPop);
  323. '~' : RPNPush(NOT RPNPop);
  324. '<' : RPNPush(RPNPop SHL RPNPop);
  325. '>' : RPNPush(RPNPop SHR RPNPop);
  326. '%' : begin
  327. Temp := RPNPop;
  328. if Temp <> 0 then
  329. RPNPush(RPNPop mod Temp)
  330. else Error(zero_divide); { Handle divide by zero error }
  331. end;
  332. '^' : RPNPush(RPNPop XOR RPNPop);
  333. '/' :
  334. begin
  335. Temp := RPNPop;
  336. if Temp <> 0 then
  337. RPNPush(RPNPop div Temp)
  338. else Error(zero_divide);{ Handle divide by 0 error }
  339. end;
  340. end
  341. else
  342. begin { Convert String to number and add to stack }
  343. if token='-2147483648' then
  344. begin
  345. temp:=$80000000;
  346. localerror:=0;
  347. end
  348. else
  349. Val(Token, Temp, LocalError);
  350. if LocalError = 0 then
  351. RPNPush(Temp)
  352. else Error(invalid_number);{ Handle error }
  353. end;
  354. end;
  355. Procedure TExprParse.OpPush(_Operator : char;prefix: boolean); { Add an operator onto top of the stack }
  356. begin
  357. if OpTop < OpMax then
  358. begin
  359. Inc(OpTop);
  360. OpStack[OpTop].ch := _Operator;
  361. OpStack[OpTop].is_prefix := prefix;
  362. end
  363. else Error(stack_overflow); { Put some error handler here }
  364. end;
  365. Procedure TExprParse.OpPop(var _Operator:TExprOperator); { Get operator at the top of the stack }
  366. begin
  367. if OpTop > 0 then
  368. begin
  369. _Operator := OpStack[OpTop];
  370. Dec(OpTop);
  371. end
  372. else Error(stack_underflow); { Put some error handler here }
  373. end;
  374. Function TExprParse.Priority(_Operator : Char) : Integer; { Return priority of operator }
  375. { The greater the priority, the higher the precedence }
  376. begin
  377. Case _Operator OF
  378. '(' : Priority := 0;
  379. '+', '-' : Priority := 1;
  380. '*', '/','%','<','>' : Priority := 2;
  381. '|','&','^','~': Priority := 0;
  382. else Error(invalid_op);{ More error handling }
  383. end;
  384. end;
  385. Function TExprParse.Evaluate(Expr : String):longint;
  386. Var
  387. I : Integer;
  388. Token : String15;
  389. opr: TExprOperator;
  390. begin
  391. OpTop := 0; { Reset stacks }
  392. RPNTop := 0;
  393. Token := '';
  394. For I := 1 to Length(Expr) DO
  395. begin
  396. if Expr[I] in ['0'..'9'] then
  397. begin { Build multi-digit numbers }
  398. Token := Token + Expr[I];
  399. if I = Length(Expr) then { Send last one to calculator }
  400. RPNCalc(Token,false);
  401. end
  402. else
  403. if Expr[I] in ['+', '-', '*', '/', '(', ')','^','&','|','%','~','<','>'] then
  404. begin
  405. if Token <> '' then
  406. begin { Send last built number to calc. }
  407. RPNCalc(Token,false);
  408. Token := '';
  409. end;
  410. Case Expr[I] OF
  411. '(' : OpPush('(',false);
  412. ')' : begin
  413. While OpStack[OpTop].ch <> '(' DO
  414. Begin
  415. OpPop(opr);
  416. RPNCalc(opr.ch,opr.is_prefix);
  417. end;
  418. OpPop(opr); { Pop off and ignore the '(' }
  419. end;
  420. '+','-','~' : Begin
  421. { workaround for -2147483648 }
  422. if (expr[I]='-') and (expr[i+1] in ['0'..'9']) then
  423. begin
  424. token:='-';
  425. expr[i]:='+';
  426. end;
  427. { if start of expression then surely a prefix }
  428. { or if previous char was also an operator }
  429. if (I = 1) or (not (Expr[I-1] in ['0'..'9','(',')'])) then
  430. OpPush(Expr[I],true)
  431. else
  432. Begin
  433. { Evaluate all higher priority operators }
  434. While (OpTop > 0) AND (Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
  435. Begin
  436. OpPop(opr);
  437. RPNCalc(opr.ch,opr.is_prefix);
  438. end;
  439. OpPush(Expr[I],false);
  440. End;
  441. end;
  442. '*', '/',
  443. '^','|','&',
  444. '%','<','>' : begin
  445. While (OpTop > 0) and (Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
  446. Begin
  447. OpPop(opr);
  448. RPNCalc(opr.ch,opr.is_prefix);
  449. end;
  450. OpPush(Expr[I],false);
  451. end;
  452. end; { Case }
  453. end
  454. else
  455. Error(invalid_op); { Handle bad input error }
  456. end;
  457. { Pop off the remaining operators }
  458. While OpTop > 0 do
  459. Begin
  460. OpPop(opr);
  461. RPNCalc(opr.ch,opr.is_prefix);
  462. end;
  463. { The result is stored on the top of the stack }
  464. Evaluate := RPNPop;
  465. end;
  466. Destructor TExprParse.Done;
  467. Begin
  468. end;
  469. {*************************************************************************}
  470. { String conversions/utils }
  471. {*************************************************************************}
  472. Function newpasstr(s: string): Pointer;
  473. Var
  474. StrPtr: PString;
  475. Begin
  476. GetMem(StrPtr, length(s)+1);
  477. Move(s,StrPtr^,length(s)+1);
  478. newpasstr:= Strptr;
  479. end;
  480. Function EscapeToPascal(const s:string): string;
  481. { converts a C styled string - which contains escape }
  482. { characters to a pascal style string. }
  483. var
  484. i,j: word;
  485. str: string;
  486. temp: string;
  487. value: byte;
  488. code: integer;
  489. Begin
  490. str:='';
  491. i:=1;
  492. j:=1;
  493. repeat
  494. if s[i] = '\' then
  495. Begin
  496. Inc(i);
  497. if i > 255 then
  498. Begin
  499. EscapeToPascal:=str;
  500. exit;
  501. end;
  502. case s[i] of
  503. '\': insert('\',str,j);
  504. 'b': insert(#08,str,j);
  505. 'f': insert(#12,str,j);
  506. 'n': insert(#10,str,j);
  507. 'r': insert(#13,str,j);
  508. 't': insert(#09,str,j);
  509. '"': insert('"',str,j);
  510. { octal number }
  511. '0'..'7': Begin
  512. temp:=s[i];
  513. temp:=temp+s[i+1];
  514. temp:=temp+s[i+2];
  515. inc(i,2);
  516. val(octaltodec(temp),value,code);
  517. if (code <> 0) then
  518. Message(assem_w_invalid_numeric);
  519. insert(chr(value),str,j);
  520. end;
  521. { hexadecimal number }
  522. 'x': Begin
  523. temp:=s[i+1];
  524. temp:=temp+s[i+2];
  525. inc(i,2);
  526. val(hextodec(temp),value,code);
  527. if (code <> 0) then
  528. Message(assem_w_invalid_numeric);
  529. insert(chr(value),str,j);
  530. end;
  531. else
  532. Begin
  533. Message1(assem_e_escape_seq_ignored,s[i]);
  534. insert(s[i],str,j);
  535. end;
  536. end; {end case }
  537. Inc(i);
  538. end
  539. else
  540. Begin
  541. Insert(s[i],str,j);
  542. Inc(i);
  543. if i > 255 then
  544. Begin
  545. EscapeToPascal:=str;
  546. exit;
  547. end;
  548. end;
  549. Inc(j);
  550. until (i > length(s)) or (j > 255);
  551. EscapeToPascal:=str;
  552. end;
  553. Function OctalToDec(const S:String): String;
  554. { Converts an octal string to a Decimal string }
  555. { Returns '' if there was an error. }
  556. var vs: longint;
  557. c: byte;
  558. st: string;
  559. Begin
  560. vs := 0;
  561. for c:=1 to length(s) do
  562. begin
  563. case s[c] of
  564. '0': vs:=vs shl 3;
  565. '1': vs:=vs shl 3+1;
  566. '2': vs:=vs shl 3+2;
  567. '3': vs:=vs shl 3+3;
  568. '4': vs:=vs shl 3+4;
  569. '5': vs:=vs shl 3+5;
  570. '6': vs:=vs shl 3+6;
  571. '7': vs:=vs shl 3+7;
  572. else
  573. begin
  574. OctalToDec := '';
  575. exit;
  576. end;
  577. end;
  578. end;
  579. str(vs,st);
  580. OctalToDec := st;
  581. end;
  582. Function BinaryToDec(const S:String): String;
  583. { Converts a binary string to a Decimal string }
  584. { Returns '' if there was an error. }
  585. var vs: longint;
  586. c: byte;
  587. st: string;
  588. Begin
  589. vs := 0;
  590. for c:=1 to length(s) do
  591. begin
  592. if s[c] = '0' then
  593. vs:=vs shl 1
  594. else
  595. if s[c]='1' then
  596. vs:=vs shl 1+1
  597. else
  598. begin
  599. BinaryToDec := '';
  600. exit;
  601. end;
  602. end;
  603. str(vs,st);
  604. BinaryToDec := st;
  605. end;
  606. Function HexToDec(const S:String): String;
  607. var vs: longint;
  608. c: byte;
  609. st: string;
  610. Begin
  611. vs := 0;
  612. for c:=1 to length(s) do
  613. begin
  614. case upcase(s[c]) of
  615. '0': vs:=vs shl 4;
  616. '1': vs:=vs shl 4+1;
  617. '2': vs:=vs shl 4+2;
  618. '3': vs:=vs shl 4+3;
  619. '4': vs:=vs shl 4+4;
  620. '5': vs:=vs shl 4+5;
  621. '6': vs:=vs shl 4+6;
  622. '7': vs:=vs shl 4+7;
  623. '8': vs:=vs shl 4+8;
  624. '9': vs:=vs shl 4+9;
  625. 'A': vs:=vs shl 4+10;
  626. 'B': vs:=vs shl 4+11;
  627. 'C': vs:=vs shl 4+12;
  628. 'D': vs:=vs shl 4+13;
  629. 'E': vs:=vs shl 4+14;
  630. 'F': vs:=vs shl 4+15;
  631. else
  632. begin
  633. HexToDec := '';
  634. exit;
  635. end;
  636. end;
  637. end;
  638. str(vs,st);
  639. HexToDec := st;
  640. end;
  641. Function PadZero(Var s: String; n: byte): Boolean;
  642. Begin
  643. PadZero := TRUE;
  644. { Do some error checking first }
  645. if Length(s) = n then
  646. exit
  647. else
  648. if Length(s) > n then
  649. Begin
  650. PadZero := FALSE;
  651. delete(s,n+1,length(s));
  652. exit;
  653. end
  654. else
  655. PadZero := TRUE;
  656. { Fill it up with the specified character }
  657. fillchar(s[length(s)+1],n-1,#0);
  658. s[0] := chr(n);
  659. end;
  660. {*************************************************************************}
  661. { Instruction utilities }
  662. {*************************************************************************}
  663. Procedure TInstruction.init;
  664. var
  665. k: integer;
  666. Begin
  667. numops := 0;
  668. labeled := FALSE;
  669. stropsize := S_NO;
  670. prefix := A_NONE;
  671. instruction := A_NONE;
  672. for k:=1 to maxoperands do
  673. begin
  674. operands[k].size := S_NO;
  675. operands[k].overriden := FALSE;
  676. operands[k].operandtype := OPR_NONE;
  677. { init to zeros }
  678. fillchar(operands[k].l, sizeof(operands[k].l),#0);
  679. end;
  680. end;
  681. Procedure TInstruction.addprefix(tok: tasmop);
  682. Begin
  683. if tok = A_NONE then
  684. Message(assem_e_syn_prefix_not_found);
  685. if Prefix = A_NONE then
  686. Prefix := tok
  687. else
  688. Message(assem_e_syn_try_add_more_prefix);
  689. end;
  690. Procedure TInstruction.addinstr(tok: tasmop);
  691. Begin
  692. if tok = A_NONE then
  693. Message(assem_e_syn_opcode_not_found);
  694. Instruction := tok;
  695. end;
  696. function TInstruction.getinstruction: tasmop;
  697. Begin
  698. getinstruction := Instruction;
  699. end;
  700. { get the current prefix of this instruction }
  701. function TInstruction.getprefix: tasmop;
  702. Begin
  703. getprefix := prefix;
  704. end;
  705. Procedure TInstruction.done;
  706. var
  707. k: integer;
  708. Begin
  709. for k:=1 to numops do
  710. begin
  711. if (operands[k].operandtype=OPR_REFERENCE) and
  712. assigned(operands[k].ref.symbol) then
  713. stringdispose(operands[k].ref.symbol);
  714. if (operands[k].operandtype=OPR_SYMBOL) and
  715. assigned(operands[k].symbol) then
  716. stringdispose(operands[k].symbol);
  717. end;
  718. end;
  719. {*************************************************************************}
  720. { Local label utilities }
  721. {*************************************************************************}
  722. Constructor TAsmLabelList.Init;
  723. Begin
  724. First := nil;
  725. Last := nil;
  726. end;
  727. Procedure TAsmLabelList.Insert(s:string; lab: PLabel; emitted: boolean);
  728. {*********************************************************************}
  729. { Description: Insert a node at the end of the list with lab and }
  730. { and the name in s. The name is allocated on the heap. }
  731. { Duplicates are not allowed. }
  732. { Indicate in emitted if this label itself has been emitted, or is it}
  733. { a simple labeled instruction? }
  734. {*********************************************************************}
  735. Begin
  736. if search(s) = nil then
  737. Begin
  738. if First = nil then
  739. Begin
  740. New(First);
  741. Last := First;
  742. end
  743. else
  744. Begin
  745. New(Last^.Next);
  746. Last := Last^.Next;
  747. end;
  748. Last^.name := NewPasStr(s);
  749. Last^.Lab := lab;
  750. Last^.Next := nil;
  751. Last^.emitted := emitted;
  752. end;
  753. end;
  754. Function TAsmLabelList.Search(const s: string): PAsmLabel;
  755. {*********************************************************************}
  756. { Description: This routine searches for a label named s in the }
  757. { linked list, returns a pointer to the label if found, otherwise }
  758. { returns nil. }
  759. {*********************************************************************}
  760. Var
  761. asmlab: PAsmLabel;
  762. Begin
  763. asmlab := First;
  764. if First = nil then
  765. Begin
  766. Search := nil;
  767. exit;
  768. end;
  769. While (asmlab^.name^ <> s) and (asmlab^.Next <> nil) do
  770. asmlab := asmlab^.Next;
  771. if asmlab^.name^ = s then
  772. search := asmlab
  773. else
  774. search := nil;
  775. end;
  776. Destructor TAsmLabelList.Done;
  777. {*********************************************************************}
  778. { Description: This routine takes care of deallocating all nodes }
  779. { in the linked list, as well as deallocating the string pointers }
  780. { of these nodes. }
  781. { }
  782. { Remark: The PLabel field is NOT freed, the compiler takes care of }
  783. { this. }
  784. {*********************************************************************}
  785. Var
  786. temp: PAsmLabel;
  787. temp1: PAsmLabel;
  788. Begin
  789. temp := First;
  790. while temp <> nil do
  791. Begin
  792. Freemem(Temp^.name, length(Temp^.name^)+1);
  793. Temp1 := Temp^.Next;
  794. Dispose(Temp);
  795. Temp := Temp1;
  796. { The plabel could be deleted here, but let us not do }
  797. { it, FPC will do it instead. }
  798. end;
  799. end;
  800. Function TAsmLabelList.newpasstr(s: string): PString;
  801. {*********************************************************************}
  802. { FUNCTION NewPasStr(s:string): PString }
  803. { Description: This routine allocates a string on the heap and }
  804. { returns a pointer to the allocated string. }
  805. { }
  806. { Remarks: The string allocated should not be modified, since it's }
  807. { length will be less then 255. }
  808. { Remarks: It is assumed that HeapError will be called if an }
  809. { allocation fails. }
  810. {*********************************************************************}
  811. Var
  812. StrPtr: PString;
  813. Begin
  814. GetMem(StrPtr, length(s)+1);
  815. Move(s,StrPtr^,length(s)+1);
  816. newpasstr:= Strptr;
  817. end;
  818. {*************************************************************************}
  819. { Symbol table helper routines }
  820. {*************************************************************************}
  821. Procedure SwapOperands(Var instr: TInstruction);
  822. Var
  823. tempopr: TOperand;
  824. Begin
  825. if instr.numops = 2 then
  826. Begin
  827. tempopr := instr.operands[1];
  828. instr.operands[1] := instr.operands[2];
  829. instr.operands[2] := tempopr;
  830. end
  831. else
  832. if instr.numops = 3 then
  833. Begin
  834. tempopr := instr.operands[1];
  835. instr.operands[1] := instr.operands[3];
  836. instr.operands[3] := tempopr;
  837. end;
  838. end;
  839. Function SearchIConstant(const s:string; var l:longint): boolean;
  840. {**********************************************************************}
  841. { Description: Searches for a CONSTANT of name s in either the local }
  842. { symbol list, then in the global symbol list, and returns the value }
  843. { of that constant in l. Returns TRUE if successfull, if not found, }
  844. { or if the constant is not of correct type, then returns FALSE }
  845. { Remarks: Also handle TRUE and FALSE returning in those cases 1 and 0 }
  846. { respectively. }
  847. {**********************************************************************}
  848. var
  849. sym: psym;
  850. Begin
  851. SearchIConstant := FALSE;
  852. { check for TRUE or FALSE reserved words first }
  853. if s = 'TRUE' then
  854. Begin
  855. SearchIConstant := TRUE;
  856. l := 1;
  857. end
  858. else
  859. if s = 'FALSE' then
  860. Begin
  861. SearchIConstant := TRUE;
  862. l := 0;
  863. end
  864. else
  865. if assigned(aktprocsym) then
  866. Begin
  867. if assigned(aktprocsym^.definition) then
  868. Begin
  869. { Check the local constants }
  870. if assigned(aktprocsym^.definition^.localst) then
  871. sym := aktprocsym^.definition^.localst^.search(s)
  872. else
  873. sym := nil;
  874. if assigned(sym) then
  875. Begin
  876. if (sym^.typ = constsym) and (pconstsym(sym)^.consttype in
  877. [constord,constint,constchar,constbool]) then
  878. Begin
  879. l:=pconstsym(sym)^.value;
  880. SearchIConstant := TRUE;
  881. exit;
  882. end;
  883. end;
  884. end;
  885. end;
  886. { Check the global constants }
  887. getsym(s,false);
  888. if srsym <> nil then
  889. Begin
  890. if (srsym^.typ=constsym) and (pconstsym(srsym)^.consttype in
  891. [constord,constint,constchar,constbool]) then
  892. Begin
  893. l:=pconstsym(srsym)^.value;
  894. SearchIConstant := TRUE;
  895. exit;
  896. end;
  897. end;
  898. end;
  899. Procedure SetupResult(Var Instr:TInstruction; operandnum: byte);
  900. {**********************************************************************}
  901. { Description: This routine changes the correct fields and correct }
  902. { offset in the reference, so that it points to the __RESULT or }
  903. { @Result variable (depending on the inline asm). }
  904. { Resturns a reference with all correct offset correctly set up. }
  905. { The Operand should already point to a treference on entry. }
  906. {**********************************************************************}
  907. Begin
  908. { replace by correct offset. }
  909. if assigned(procinfo.retdef) and
  910. (procinfo.retdef<>pdef(voiddef)) then
  911. begin
  912. instr.operands[operandnum].ref.offset := procinfo.retoffset;
  913. instr.operands[operandnum].ref.base := procinfo.framepointer;
  914. { always assume that the result is valid. }
  915. procinfo.funcret_is_valid:=true;
  916. end
  917. else
  918. Message(assem_e_invalid_symbol_ref);
  919. end;
  920. {$ifdef i386}
  921. Procedure FWaitWarning;
  922. begin
  923. if (target_info.target=target_i386_GO32V2) and (cs_fp_emulation in aktmoduleswitches) then
  924. Message(assem_w_fwait_emu_prob);
  925. end;
  926. {$endif i386}
  927. Function GetVarOffset(var Instr: TInstruction;const base: string; const field: string;
  928. Var Offset: longint; operandnum: byte):boolean;
  929. { search and returns the offset of records/objects of the base }
  930. { with field name setup in field. }
  931. { returns FALSE if not found. }
  932. { used when base is a variable or a typed constant name. }
  933. var
  934. sym:psym;
  935. p: psym;
  936. Begin
  937. GetVarOffset := FALSE;
  938. Offset := 0;
  939. { local list }
  940. if assigned(aktprocsym) then
  941. begin
  942. if assigned(aktprocsym^.definition^.localst) then
  943. sym:=aktprocsym^.definition^.localst^.search(base)
  944. else
  945. sym:=nil;
  946. if assigned(sym) then
  947. begin
  948. { field of local record variable. }
  949. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=recorddef) then
  950. begin
  951. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  952. if assigned(pvarsym(p)) then
  953. Begin
  954. Offset := pvarsym(p)^.address;
  955. { the current size is NOT overriden if it already }
  956. { exists, such as in the case of a byte ptr, in }
  957. { front of the identifier. }
  958. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  959. Begin
  960. case pvarsym(p)^.getsize of
  961. 1: instr.operands[operandnum].size := S_B;
  962. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  963. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  964. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  965. extended_size: instr.operands[operandnum].size := S_FX;
  966. else
  967. { this is in the case where the instruction is LEA }
  968. { or something like that, in that case size is not }
  969. { important. }
  970. instr.operands[operandnum].size := S_NO;
  971. end; { end case }
  972. end;
  973. GetVarOffset := TRUE;
  974. Exit;
  975. end;
  976. end
  977. else
  978. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=objectdef) then
  979. begin
  980. if assigned(pobjectdef(pvarsym(sym)^.definition)^.publicsyms) then
  981. begin
  982. p:=pvarsym(pobjectdef(pvarsym(sym)^.definition)^.publicsyms^.search(field));
  983. if assigned(pvarsym(p)) then
  984. Begin
  985. Offset := pvarsym(p)^.address;
  986. { the current size is NOT overriden if it already }
  987. { exists, such as in the case of a byte ptr, in }
  988. { front of the identifier. }
  989. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  990. Begin
  991. case pvarsym(p)^.getsize of
  992. 1: instr.operands[operandnum].size := S_B;
  993. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  994. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  995. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  996. extended_size: instr.operands[operandnum].size := S_FX;
  997. else
  998. { this is in the case where the instruction is LEA }
  999. { or something like that, in that case size is not }
  1000. { important. }
  1001. instr.operands[operandnum].size := S_NO;
  1002. end; { end case }
  1003. end;
  1004. GetVarOffset := TRUE;
  1005. Exit;
  1006. end;
  1007. end;
  1008. end;
  1009. end
  1010. else
  1011. begin
  1012. { field of local record parameter to routine. }
  1013. if assigned(aktprocsym^.definition^.parast) then
  1014. sym:=aktprocsym^.definition^.parast^.search(base)
  1015. else
  1016. sym:=nil;
  1017. if assigned(sym) then
  1018. begin
  1019. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=recorddef)
  1020. then
  1021. begin
  1022. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  1023. if assigned(p) then
  1024. Begin
  1025. Offset := pvarsym(p)^.address;
  1026. GetVarOffset := TRUE;
  1027. { the current size is NOT overriden if it already }
  1028. { exists, such as in the case of a byte ptr, in }
  1029. { front of the identifier. }
  1030. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1031. Begin
  1032. case pvarsym(p)^.getsize of
  1033. 1: instr.operands[operandnum].size := S_B;
  1034. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1035. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1036. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1037. extended_size: instr.operands[operandnum].size := S_FX;
  1038. else
  1039. { this is in the case where the instruction is LEA }
  1040. { or something like that, in that case size is not }
  1041. { important. }
  1042. instr.operands[operandnum].size := S_NO;
  1043. end; { end case }
  1044. end;
  1045. Exit;
  1046. end;
  1047. end { endif }
  1048. else
  1049. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=objectdef) then
  1050. begin
  1051. if assigned(pobjectdef(pvarsym(sym)^.definition)^.publicsyms) then
  1052. begin
  1053. p:=pvarsym(pobjectdef(pvarsym(sym)^.definition)^.publicsyms^.search(field));
  1054. if assigned(pvarsym(p)) then
  1055. Begin
  1056. Offset := pvarsym(p)^.address;
  1057. { the current size is NOT overriden if it already }
  1058. { exists, such as in the case of a byte ptr, in }
  1059. { front of the identifier. }
  1060. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1061. Begin
  1062. case pvarsym(p)^.getsize of
  1063. 1: instr.operands[operandnum].size := S_B;
  1064. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1065. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1066. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1067. extended_size: instr.operands[operandnum].size := S_FX;
  1068. else
  1069. { this is in the case where the instruction is LEA }
  1070. { or something like that, in that case size is not }
  1071. { important. }
  1072. instr.operands[operandnum].size := S_NO;
  1073. end; { end case }
  1074. end;
  1075. GetVarOffset := TRUE;
  1076. Exit;
  1077. end;
  1078. end;
  1079. end;
  1080. end;
  1081. end;
  1082. end; { endif assigned(aktprocsym) }
  1083. { not found.. .now look for global variables. }
  1084. getsym(base,false);
  1085. sym:=srsym;
  1086. if assigned(sym) then
  1087. Begin
  1088. { field of global record variable. }
  1089. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=recorddef) then
  1090. begin
  1091. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  1092. if assigned(p) then
  1093. Begin
  1094. Offset := pvarsym(p)^.address;
  1095. GetVarOffset := TRUE;
  1096. { the current size is NOT overriden if it already }
  1097. { exists, such as in the case of a byte ptr, in }
  1098. { front of the identifier. }
  1099. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1100. Begin
  1101. case pvarsym(p)^.getsize of
  1102. 1: instr.operands[operandnum].size := S_B;
  1103. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1104. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1105. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1106. extended_size: instr.operands[operandnum].size := S_FX;
  1107. else
  1108. { this is in the case where the instruction is LEA }
  1109. { or something like that, in that case size is not }
  1110. { important. }
  1111. instr.operands[operandnum].size := S_NO;
  1112. end; { end case }
  1113. end;
  1114. Exit;
  1115. end;
  1116. end
  1117. else
  1118. { field of global record type constant. }
  1119. if (sym^.typ=typedconstsym) and (ptypedconstsym(sym)^.definition^.deftype=recorddef)
  1120. then
  1121. begin
  1122. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  1123. if assigned(p) then
  1124. Begin
  1125. Offset := pvarsym(p)^.address;
  1126. GetVarOffset := TRUE;
  1127. { the current size is NOT overriden if it already }
  1128. { exists, such as in the case of a byte ptr, in }
  1129. { front of the identifier. }
  1130. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1131. Begin
  1132. case pvarsym(p)^.getsize of
  1133. 1: instr.operands[operandnum].size := S_B;
  1134. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1135. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1136. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1137. extended_size: instr.operands[operandnum].size := S_FX;
  1138. else
  1139. { this is in the case where the instruction is LEA }
  1140. { or something like that, in that case size is not }
  1141. { important. }
  1142. instr.operands[operandnum].size := S_NO;
  1143. end; { end case }
  1144. end;
  1145. Exit;
  1146. end;
  1147. end
  1148. else
  1149. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=objectdef) then
  1150. begin
  1151. if assigned(pobjectdef(pvarsym(sym)^.definition)^.publicsyms) then
  1152. begin
  1153. p:=pvarsym(pobjectdef(pvarsym(sym)^.definition)^.publicsyms^.search(field));
  1154. if assigned(pvarsym(p)) then
  1155. Begin
  1156. Offset := pvarsym(p)^.address;
  1157. { the current size is NOT overriden if it already }
  1158. { exists, such as in the case of a byte ptr, in }
  1159. { front of the identifier. }
  1160. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1161. Begin
  1162. case pvarsym(p)^.getsize of
  1163. 1: instr.operands[operandnum].size := S_B;
  1164. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1165. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1166. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1167. extended_size: instr.operands[operandnum].size := S_FX;
  1168. else
  1169. { this is in the case where the instruction is LEA }
  1170. { or something like that, in that case size is not }
  1171. { important. }
  1172. instr.operands[operandnum].size := S_NO;
  1173. end; { end case }
  1174. end;
  1175. GetVarOffset := TRUE;
  1176. Exit;
  1177. end;
  1178. end;
  1179. end;
  1180. end; { end looking for global variables .. }
  1181. end;
  1182. Function GetTypeOffset(var instr: TInstruction; const base: string; const field: string;
  1183. Var Offset: longint; operandnum: byte):boolean;
  1184. { search and returns the offset of records/objects of the base }
  1185. { with field name setup in field. }
  1186. { returns 0 if not found. }
  1187. { used when base is a variable or a typed constant name. }
  1188. var
  1189. sym:psym;
  1190. p: psym;
  1191. Begin
  1192. Offset := 0;
  1193. GetTypeOffset := FALSE;
  1194. { local list }
  1195. if assigned(aktprocsym) then
  1196. begin
  1197. if assigned(aktprocsym^.definition^.localst) then
  1198. sym:=aktprocsym^.definition^.localst^.search(base)
  1199. else
  1200. sym:=nil;
  1201. if assigned(sym) then
  1202. begin
  1203. { field of local record type. }
  1204. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=recorddef) then
  1205. begin
  1206. p:=precdef(ptypesym(sym)^.definition)^.symtable^.search(field);
  1207. if assigned(p) then
  1208. Begin
  1209. Offset := pvarsym(p)^.address;
  1210. { the current size is NOT overriden if it already }
  1211. { exists, such as in the case of a byte ptr, in }
  1212. { front of the identifier. }
  1213. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1214. Begin
  1215. case pvarsym(p)^.getsize of
  1216. 1: instr.operands[operandnum].size := S_B;
  1217. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1218. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1219. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1220. extended_size: instr.operands[operandnum].size := S_FX;
  1221. else
  1222. { this is in the case where the instruction is LEA }
  1223. { or something like that, in that case size is not }
  1224. { important. }
  1225. instr.operands[operandnum].size := S_NO;
  1226. end; { end case }
  1227. end;
  1228. GetTypeOffset := TRUE;
  1229. Exit;
  1230. end;
  1231. end;
  1232. end
  1233. else
  1234. begin
  1235. { field of local record type to routine. }
  1236. if assigned(aktprocsym^.definition^.parast) then
  1237. sym:=aktprocsym^.definition^.parast^.search(base)
  1238. else
  1239. sym:=nil;
  1240. if assigned(sym) then
  1241. begin
  1242. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=recorddef)
  1243. then
  1244. begin
  1245. p:=precdef(ptypesym(sym)^.definition)^.symtable^.search(field);
  1246. if assigned(p) then
  1247. Begin
  1248. Offset := pvarsym(p)^.address;
  1249. { the current size is NOT overriden if it already }
  1250. { exists, such as in the case of a byte ptr, in }
  1251. { front of the identifier. }
  1252. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1253. Begin
  1254. case pvarsym(p)^.getsize of
  1255. 1: instr.operands[operandnum].size := S_B;
  1256. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1257. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1258. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1259. extended_size: instr.operands[operandnum].size := S_FX;
  1260. else
  1261. { this is in the case where the instruction is LEA }
  1262. { or something like that, in that case size is not }
  1263. { important. }
  1264. instr.operands[operandnum].size := S_NO;
  1265. end; { end case }
  1266. end;
  1267. GetTypeOffset := TRUE;
  1268. Exit;
  1269. end;
  1270. end; { endif }
  1271. end; {endif }
  1272. end; { endif }
  1273. end;
  1274. { not found.. .now look for global types. }
  1275. getsym(base,false);
  1276. sym:=srsym;
  1277. if assigned(sym) then
  1278. Begin
  1279. { field of global record types. }
  1280. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=recorddef) then
  1281. begin
  1282. p:=precdef(ptypesym(sym)^.definition)^.symtable^.search(field);
  1283. if assigned(p) then
  1284. Begin
  1285. Offset := pvarsym(p)^.address;
  1286. { the current size is NOT overriden if it already }
  1287. { exists, such as in the case of a byte ptr, in }
  1288. { front of the identifier. }
  1289. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1290. Begin
  1291. case pvarsym(p)^.getsize of
  1292. 1: instr.operands[operandnum].size := S_B;
  1293. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1294. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1295. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1296. extended_size: instr.operands[operandnum].size := S_FX;
  1297. else
  1298. { this is in the case where the instruction is LEA }
  1299. { or something like that, in that case size is not }
  1300. { important. }
  1301. instr.operands[operandnum].size := S_NO;
  1302. end; { end case }
  1303. end;
  1304. GetTypeOffset := TRUE;
  1305. Exit;
  1306. end
  1307. end
  1308. else
  1309. { public field names of objects }
  1310. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=objectdef)then
  1311. begin
  1312. if assigned(pobjectdef(ptypesym(sym)^.definition)^.publicsyms) then
  1313. Begin
  1314. p:=pobjectdef(ptypesym(sym)^.definition)^.publicsyms^.search(field);
  1315. if assigned(p) then
  1316. Begin
  1317. Offset := pvarsym(p)^.address;
  1318. { the current size is NOT overriden if it already }
  1319. { exists, such as in the case of a byte ptr, in }
  1320. { front of the identifier. }
  1321. if instr.operands[operandnum].size = S_NO then
  1322. Begin
  1323. case pvarsym(p)^.getsize of
  1324. 1: instr.operands[operandnum].size := S_B;
  1325. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1326. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1327. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1328. extended_size: instr.operands[operandnum].size := S_FX;
  1329. else
  1330. { this is in the case where the instruction is LEA }
  1331. { or something like that, in that case size is not }
  1332. { important. }
  1333. instr.operands[operandnum].size := S_NO;
  1334. end; { end case }
  1335. end;
  1336. GetTypeOffset := TRUE;
  1337. Exit;
  1338. end
  1339. end;
  1340. end;
  1341. end; { end looking for global variables .. }
  1342. end;
  1343. Function CreateVarInstr(var Instr: TInstruction; const hs:string;operandnum:byte): Boolean;
  1344. { search and sets up the correct fields in the Instr record }
  1345. { for the NON-constant identifier passed to the routine. }
  1346. { if not found returns FALSE. }
  1347. var
  1348. sym : psym;
  1349. l : longint;
  1350. Begin
  1351. CreateVarInstr := FALSE;
  1352. { are we in a routine ? }
  1353. if assigned(aktprocsym) then
  1354. begin
  1355. { search the local list for the name of this variable. }
  1356. if assigned(aktprocsym^.definition^.localst) then
  1357. sym:=aktprocsym^.definition^.localst^.search(hs)
  1358. else
  1359. sym:=nil;
  1360. if assigned(sym) then
  1361. begin
  1362. case sym^.typ of
  1363. typedconstsym,
  1364. varsym : begin
  1365. { we always assume in asm statements that }
  1366. { that the variable is valid. }
  1367. pvarsym(sym)^.is_valid:=1;
  1368. if pvarsym(sym)^.owner^.symtabletype=staticsymtable then
  1369. begin
  1370. if assigned(instr.operands[operandnum].ref.symbol) then
  1371. FreeMem(instr.operands[operandnum].ref.symbol,length(instr.operands[operandnum].ref.symbol^)+1);
  1372. instr.operands[operandnum].ref.symbol:=newpasstr(pvarsym(sym)^.mangledname);
  1373. end
  1374. else
  1375. begin
  1376. instr.operands[operandnum].ref.base := procinfo.framepointer;
  1377. instr.operands[operandnum].ref.offset := -(pvarsym(sym)^.address);
  1378. end;
  1379. { the current size is NOT overriden if it already }
  1380. { exists, such as in the case of a byte ptr, in }
  1381. { front of the identifier. }
  1382. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1383. Begin
  1384. case pvarsym(sym)^.getsize of
  1385. 1: instr.operands[operandnum].size := S_B;
  1386. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1387. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1388. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1389. extended_size: instr.operands[operandnum].size := S_FX;
  1390. else
  1391. { this is in the case where the instruction is LEA }
  1392. { or something like that, in that case size is not }
  1393. { important. }
  1394. instr.operands[operandnum].size := S_NO;
  1395. end; { end case }
  1396. end;
  1397. { ok, finished for thir variable. }
  1398. CreateVarInstr := TRUE;
  1399. Exit;
  1400. end;
  1401. procsym : begin
  1402. { free the memory before changing the symbol name. }
  1403. if assigned(instr.operands[operandnum].ref.symbol) then
  1404. FreeMem(instr.operands[operandnum].ref.symbol,length(instr.operands[operandnum].ref.symbol^)+1);
  1405. instr.operands[operandnum].operandtype:=OPR_SYMBOL;
  1406. instr.operands[operandnum].symbol:=newpasstr(pprocsym(sym)^.definition^.mangledname);
  1407. CreateVarInstr := TRUE;
  1408. Exit;
  1409. end
  1410. else
  1411. begin
  1412. Message(assem_e_unsupported_symbol_type);
  1413. exit;
  1414. end;
  1415. end;
  1416. end;
  1417. { now check for parameters passed to routine }
  1418. if assigned(aktprocsym^.definition^.parast) then
  1419. sym:=aktprocsym^.definition^.parast^.search(hs)
  1420. else
  1421. sym:=nil;
  1422. if assigned(sym) then
  1423. begin
  1424. case sym^.typ of
  1425. varsym : begin
  1426. l:=pvarsym(sym)^.address;
  1427. { set offset }
  1428. inc(l,aktprocsym^.definition^.parast^.call_offset);
  1429. pvarsym(sym)^.is_valid:=1;
  1430. instr.operands[operandnum].ref.base := procinfo.framepointer;
  1431. instr.operands[operandnum].ref.offset := l;
  1432. { the current size is NOT overriden if it already }
  1433. { exists, such as in the case of a byte ptr, in }
  1434. { front of the identifier. }
  1435. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1436. Begin
  1437. case pvarsym(sym)^.getsize of
  1438. 1: instr.operands[operandnum].size := S_B;
  1439. 2: instr.operands[operandnum].size := S_W;
  1440. 4: instr.operands[operandnum].size := S_L;
  1441. 8: instr.operands[operandnum].size := S_IQ;
  1442. extended_size: instr.operands[operandnum].size := S_FX;
  1443. else
  1444. { this is in the case where the instruction is LEA }
  1445. { or something like that, in that case size is not }
  1446. { important. }
  1447. instr.operands[operandnum].size := S_NO;
  1448. end; { end case }
  1449. end; { endif }
  1450. CreateVarInstr := TRUE;
  1451. Exit;
  1452. end;
  1453. else
  1454. begin
  1455. Message(assem_e_unsupported_symbol_type);
  1456. exit;
  1457. end;
  1458. end; { case }
  1459. end; { endif }
  1460. end;
  1461. { not found.. .now look for global variables. }
  1462. getsym(hs,false);
  1463. sym:=srsym;
  1464. if assigned(sym) then
  1465. Begin
  1466. case sym^.typ of
  1467. varsym,
  1468. typedconstsym : Begin
  1469. { free the memory before changing the symbol name. }
  1470. if assigned(instr.operands[operandnum].ref.symbol) then
  1471. FreeMem(instr.operands[operandnum].ref.symbol,
  1472. length(instr.operands[operandnum].ref.symbol^)+1);
  1473. instr.operands[operandnum].ref.symbol:=newpasstr(sym^.mangledname);
  1474. { the current size is NOT overriden if it already }
  1475. { exists, such as in the case of a byte ptr, in }
  1476. { front of the identifier. }
  1477. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1478. Begin
  1479. case pvarsym(sym)^.getsize of
  1480. 1: instr.operands[operandnum].size := S_B;
  1481. 2: instr.operands[operandnum].size := S_W;
  1482. 4: instr.operands[operandnum].size := S_L;
  1483. 8: instr.operands[operandnum].size := S_IQ;
  1484. else
  1485. { this is in the case where the instruction is LEA }
  1486. { or something like that, in that case size is not }
  1487. { important. }
  1488. instr.operands[operandnum].size := S_NO;
  1489. end;
  1490. end
  1491. else
  1492. if (instr.operands[operandnum].size = S_NO) and (sym^.typ = typedconstsym) then
  1493. Begin
  1494. { only these are valid sizes, otherwise prefixes are }
  1495. { required. }
  1496. case ptypedconstsym(sym)^.definition^.size of
  1497. 1: instr.operands[operandnum].size := S_B;
  1498. 2: instr.operands[operandnum].size := S_W;
  1499. 4: instr.operands[operandnum].size := S_L;
  1500. 8: instr.operands[operandnum].size := S_IQ;
  1501. else
  1502. { this is in the case where the instruction is LEA }
  1503. { or something like that, in that case size is not }
  1504. { important. }
  1505. instr.operands[operandnum].size := S_NO;
  1506. end;
  1507. end; { endif }
  1508. CreateVarInstr := TRUE;
  1509. Exit;
  1510. end;
  1511. procsym : begin
  1512. if assigned(pprocsym(sym)^.definition^.nextoverloaded) then
  1513. Message(assem_w_calling_overload_func);
  1514. { free the memory before changing the symbol name. }
  1515. if assigned(instr.operands[operandnum].ref.symbol) then
  1516. FreeMem(instr.operands[operandnum].ref.symbol,length(instr.operands[operandnum].ref.symbol^)+1);
  1517. instr.operands[operandnum].operandtype:=OPR_SYMBOL;
  1518. instr.operands[operandnum].symbol:=newpasstr(pprocsym(sym)^.definition^.mangledname);
  1519. CreateVarInstr := TRUE;
  1520. Exit;
  1521. end;
  1522. else
  1523. begin
  1524. Message(assem_e_unsupported_symbol_type);
  1525. exit;
  1526. end;
  1527. end; {case}
  1528. end; { end looking for global variables .. }
  1529. end;
  1530. Function SearchLabel(const s: string; var hl: plabel): boolean;
  1531. {**********************************************************************}
  1532. { Description: Searches for a pascal label definition, first in the }
  1533. { local symbol list and then in the global symbol list. If found then }
  1534. { return pointer to label and return true, otherwise returns false. }
  1535. {**********************************************************************}
  1536. var
  1537. sym: psym;
  1538. Begin
  1539. SearchLabel := FALSE;
  1540. if assigned(aktprocsym) then
  1541. Begin
  1542. { Check the local constants }
  1543. if assigned(aktprocsym^.definition) then
  1544. Begin
  1545. if assigned(aktprocsym^.definition^.localst) then
  1546. sym := aktprocsym^.definition^.localst^.search(s)
  1547. else
  1548. sym := nil;
  1549. if assigned(sym) then
  1550. Begin
  1551. if (sym^.typ = labelsym) then
  1552. Begin
  1553. hl:=plabelsym(sym)^.number;
  1554. SearchLabel := TRUE;
  1555. exit;
  1556. end;
  1557. end;
  1558. end;
  1559. end;
  1560. { Check the global label symbols... }
  1561. getsym(s,false);
  1562. if srsym <> nil then
  1563. Begin
  1564. if (srsym^.typ=labelsym) then
  1565. Begin
  1566. hl:=plabelsym(srsym)^.number;
  1567. SearchLabel:= TRUE;
  1568. exit;
  1569. end;
  1570. end;
  1571. end;
  1572. {*************************************************************************}
  1573. { Instruction Generation Utilities }
  1574. {*************************************************************************}
  1575. Procedure ConcatString(p : paasmoutput;s:string);
  1576. {*********************************************************************}
  1577. { PROCEDURE ConcatString(s:string); }
  1578. { Description: This routine adds the character chain pointed to in }
  1579. { s to the instruction linked list. }
  1580. {*********************************************************************}
  1581. Var
  1582. pc: PChar;
  1583. Begin
  1584. getmem(pc,length(s)+1);
  1585. p^.concat(new(pai_string,init_length_pchar(strpcopy(pc,s),length(s))));
  1586. end;
  1587. Procedure ConcatPasString(p : paasmoutput;s:string);
  1588. {*********************************************************************}
  1589. { PROCEDURE ConcatPasString(s:string); }
  1590. { Description: This routine adds the character chain pointed to in }
  1591. { s to the instruction linked list, contrary to ConcatString it }
  1592. { uses a pascal style string, so it conserves null characters. }
  1593. {*********************************************************************}
  1594. Begin
  1595. p^.concat(new(pai_string,init(s)));
  1596. end;
  1597. Procedure ConcatDirect(p : paasmoutput;s:string);
  1598. {*********************************************************************}
  1599. { PROCEDURE ConcatDirect(s:string) }
  1600. { Description: This routine output the string directly to the asm }
  1601. { output, it is only sed when writing special labels in AT&T mode, }
  1602. { and should not be used without due consideration, since it may }
  1603. { cause problems. }
  1604. {*********************************************************************}
  1605. Var
  1606. pc: PChar;
  1607. Begin
  1608. getmem(pc,length(s)+1);
  1609. p^.concat(new(pai_direct,init(strpcopy(pc,s))));
  1610. end;
  1611. Procedure ConcatConstant(p: paasmoutput; value: longint; maxvalue: longint);
  1612. {*********************************************************************}
  1613. { PROCEDURE ConcatConstant(value: longint; maxvalue: longint); }
  1614. { Description: This routine adds the value constant to the current }
  1615. { instruction linked list. }
  1616. { maxvalue -> indicates the size of the data to initialize: }
  1617. { $ff -> create a byte node. }
  1618. { $ffff -> create a word node. }
  1619. { $ffffffff -> create a dword node. }
  1620. {*********************************************************************}
  1621. Begin
  1622. if value > maxvalue then
  1623. Begin
  1624. Message(assem_e_constant_out_of_bounds);
  1625. { assuming a value of maxvalue }
  1626. value := maxvalue;
  1627. end;
  1628. if maxvalue = $ff then
  1629. p^.concat(new(pai_const,init_8bit(byte(value))))
  1630. else
  1631. if maxvalue = $ffff then
  1632. p^.concat(new(pai_const,init_16bit(word(value))))
  1633. else
  1634. if maxvalue = $ffffffff then
  1635. p^.concat(new(pai_const,init_32bit(longint(value))));
  1636. end;
  1637. Procedure ConcatRealConstant(p : paasmoutput;value: bestreal; real_typ : tfloattype);
  1638. {***********************************************************************}
  1639. { PROCEDURE ConcatRealConstant(value: bestreal; real_typ : tfloattype); }
  1640. { Description: This routine adds the value constant to the current }
  1641. { instruction linked list. }
  1642. { real_typ -> indicates the type of the real data to initialize: }
  1643. { s32real -> create a single node. }
  1644. { s64real -> create a double node. }
  1645. { s80real -> create an extended node. }
  1646. { s64bit -> create a comp node. }
  1647. { f32bit -> create a fixed node. (not used normally) }
  1648. {***********************************************************************}
  1649. Begin
  1650. case real_typ of
  1651. s32real : p^.concat(new(pai_single,init(value)));
  1652. s64real : p^.concat(new(pai_double,init(value)));
  1653. s80real : p^.concat(new(pai_extended,init(value)));
  1654. s64bit : p^.concat(new(pai_comp,init(value)));
  1655. f32bit : p^.concat(new(pai_const,init_32bit(trunc(value*$10000))));
  1656. end;
  1657. end;
  1658. Procedure ConcatLabel(p: paasmoutput;op : tasmop;var l : plabel);
  1659. {*********************************************************************}
  1660. { PROCEDURE ConcatLabel }
  1661. { Description: This routine either emits a label or a labeled }
  1662. { instruction to the linked list of instructions. }
  1663. {*********************************************************************}
  1664. begin
  1665. if op=A_LABEL then
  1666. p^.concat(new(pai_label,init(l)))
  1667. else
  1668. p^.concat(new(pai_labeled,init(op,l)))
  1669. end;
  1670. procedure ConcatPublic(p:paasmoutput;const s : string);
  1671. {*********************************************************************}
  1672. { PROCEDURE ConcatPublic }
  1673. { Description: This routine emits an global definition to the }
  1674. { linked list of instructions.(used by AT&T styled asm) }
  1675. {*********************************************************************}
  1676. begin
  1677. p^.concat(new(pai_symbol,init_global(s)));
  1678. { concat_internal(s,EXT_NEAR); done in aasm }
  1679. end;
  1680. procedure ConcatLocal(p:paasmoutput;const s : string);
  1681. {*********************************************************************}
  1682. { PROCEDURE ConcatLocal }
  1683. { Description: This routine emits an local definition to the }
  1684. { linked list of instructions. }
  1685. {*********************************************************************}
  1686. begin
  1687. p^.concat(new(pai_symbol,init(s)));
  1688. { concat_internal(s,EXT_NEAR); done in aasm }
  1689. end;
  1690. Procedure ConcatGlobalBss(const s : string;size : longint);
  1691. {*********************************************************************}
  1692. { PROCEDURE ConcatGlobalBss }
  1693. { Description: This routine emits an global datablock to the }
  1694. { linked list of instructions. }
  1695. {*********************************************************************}
  1696. begin
  1697. bsssegment^.concat(new(pai_datablock,init_global(s,size)));
  1698. { concat_internal(s,EXT_NEAR); done in aasm }
  1699. end;
  1700. Procedure ConcatLocalBss(const s : string;size : longint);
  1701. {*********************************************************************}
  1702. { PROCEDURE ConcatLocalBss }
  1703. { Description: This routine emits a local datablcok to the }
  1704. { linked list of instructions. }
  1705. {*********************************************************************}
  1706. begin
  1707. bsssegment^.concat(new(pai_datablock,init(s,size)));
  1708. { concat_internal(s,EXT_NEAR); done in aasm }
  1709. end;
  1710. { add to list of external labels }
  1711. Procedure ConcatExternal(const s : string;typ : texternal_typ);
  1712. {*********************************************************************}
  1713. { PROCEDURE ConcatExternal }
  1714. { Description: This routine emits an external definition to the }
  1715. { linked list of instructions.(used by AT&T styled asm) }
  1716. {*********************************************************************}
  1717. { check if in internal list and remove it there }
  1718. var p : pai_external;
  1719. begin
  1720. p:=search_assembler_symbol(internals,s,typ);
  1721. if p<>nil then internals^.remove(p);
  1722. concat_external(s,typ);
  1723. end;
  1724. { add to internal list of labels }
  1725. Procedure ConcatInternal(const s : string;typ : texternal_typ);
  1726. {*********************************************************************}
  1727. { PROCEDURE ConcatInternal }
  1728. { Description: This routine emits an internal definition of a symbol }
  1729. { (used by AT&T styled asm for undefined labels) }
  1730. {*********************************************************************}
  1731. begin
  1732. concat_internal(s,typ);
  1733. end;
  1734. end.
  1735. {
  1736. $Log$
  1737. Revision 1.12 1998-10-14 11:28:13 florian
  1738. * emitpushreferenceaddress gets now the asmlist as parameter
  1739. * m68k version compiles with -duseansistrings
  1740. Revision 1.11 1998/10/13 16:49:59 pierre
  1741. * undid some changes of Peter that made the compiler wrong
  1742. for m68k (I had to reinsert some ifdefs)
  1743. * removed several memory leaks under m68k
  1744. * removed the meory leaks for assembler readers
  1745. * cross compiling shoud work again better
  1746. ( crosscompiling sysamiga works
  1747. but as68k still complain about some code !)
  1748. Revision 1.10 1998/10/13 13:10:10 peter
  1749. * new style for m68k/i386 infos and enums
  1750. Revision 1.9 1998/09/24 17:54:15 carl
  1751. * bugfixes from fix branch
  1752. Revision 1.8.2.1 1998/09/24 17:46:25 carl
  1753. * support for objects in asm statements
  1754. Revision 1.8 1998/08/27 00:43:06 carl
  1755. +} now record offsets searches set the operand sizes
  1756. Revision 1.7 1998/08/18 20:51:32 peter
  1757. * fixed bug 42
  1758. Revision 1.6 1998/08/10 14:49:40 peter
  1759. + localswitches, moduleswitches, globalswitches splitting
  1760. Revision 1.5 1998/07/14 21:46:38 peter
  1761. * updated messages file
  1762. Revision 1.4 1998/06/04 23:51:31 peter
  1763. * m68k compiles
  1764. + .def file creation moved to gendef.pas so it could also be used
  1765. for win32
  1766. Revision 1.3 1998/05/31 14:13:30 peter
  1767. * fixed call bugs with assembler readers
  1768. + OPR_SYMBOL to hold a symbol in the asm parser
  1769. * fixed staticsymtable vars which were acessed through %ebp instead of
  1770. name
  1771. Revision 1.2 1998/04/29 10:33:43 pierre
  1772. + added some code for ansistring (not complete nor working yet)
  1773. * corrected operator overloading
  1774. * corrected nasm output
  1775. + started inline procedures
  1776. + added starstarn : use ** for exponentiation (^ gave problems)
  1777. + started UseTokenInfo cond to get accurate positions
  1778. }