asmutils.pas 74 KB

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