asmutils.pas 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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. { 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. {*************************************************************************}
  706. { Local label utilities }
  707. {*************************************************************************}
  708. Constructor TAsmLabelList.Init;
  709. Begin
  710. First := nil;
  711. Last := nil;
  712. end;
  713. Procedure TAsmLabelList.Insert(s:string; lab: PLabel; emitted: boolean);
  714. {*********************************************************************}
  715. { Description: Insert a node at the end of the list with lab and }
  716. { and the name in s. The name is allocated on the heap. }
  717. { Duplicates are not allowed. }
  718. { Indicate in emitted if this label itself has been emitted, or is it}
  719. { a simple labeled instruction? }
  720. {*********************************************************************}
  721. Begin
  722. if search(s) = nil then
  723. Begin
  724. if First = nil then
  725. Begin
  726. New(First);
  727. Last := First;
  728. end
  729. else
  730. Begin
  731. New(Last^.Next);
  732. Last := Last^.Next;
  733. end;
  734. Last^.name := NewPasStr(s);
  735. Last^.Lab := lab;
  736. Last^.Next := nil;
  737. Last^.emitted := emitted;
  738. end;
  739. end;
  740. Function TAsmLabelList.Search(const s: string): PAsmLabel;
  741. {*********************************************************************}
  742. { Description: This routine searches for a label named s in the }
  743. { linked list, returns a pointer to the label if found, otherwise }
  744. { returns nil. }
  745. {*********************************************************************}
  746. Var
  747. asmlab: PAsmLabel;
  748. Begin
  749. asmlab := First;
  750. if First = nil then
  751. Begin
  752. Search := nil;
  753. exit;
  754. end;
  755. While (asmlab^.name^ <> s) and (asmlab^.Next <> nil) do
  756. asmlab := asmlab^.Next;
  757. if asmlab^.name^ = s then
  758. search := asmlab
  759. else
  760. search := nil;
  761. end;
  762. Destructor TAsmLabelList.Done;
  763. {*********************************************************************}
  764. { Description: This routine takes care of deallocating all nodes }
  765. { in the linked list, as well as deallocating the string pointers }
  766. { of these nodes. }
  767. { }
  768. { Remark: The PLabel field is NOT freed, the compiler takes care of }
  769. { this. }
  770. {*********************************************************************}
  771. Var
  772. temp: PAsmLabel;
  773. temp1: PAsmLabel;
  774. Begin
  775. temp := First;
  776. while temp <> nil do
  777. Begin
  778. Freemem(Temp^.name, length(Temp^.name^)+1);
  779. Temp1 := Temp^.Next;
  780. Dispose(Temp);
  781. Temp := Temp1;
  782. { The plabel could be deleted here, but let us not do }
  783. { it, FPC will do it instead. }
  784. end;
  785. end;
  786. Function TAsmLabelList.newpasstr(s: string): PString;
  787. {*********************************************************************}
  788. { FUNCTION NewPasStr(s:string): PString }
  789. { Description: This routine allocates a string on the heap and }
  790. { returns a pointer to the allocated string. }
  791. { }
  792. { Remarks: The string allocated should not be modified, since it's }
  793. { length will be less then 255. }
  794. { Remarks: It is assumed that HeapError will be called if an }
  795. { allocation fails. }
  796. {*********************************************************************}
  797. Var
  798. StrPtr: PString;
  799. Begin
  800. GetMem(StrPtr, length(s)+1);
  801. Move(s,StrPtr^,length(s)+1);
  802. newpasstr:= Strptr;
  803. end;
  804. {*************************************************************************}
  805. { Symbol table helper routines }
  806. {*************************************************************************}
  807. Procedure SwapOperands(Var instr: TInstruction);
  808. Var
  809. tempopr: TOperand;
  810. Begin
  811. if instr.numops = 2 then
  812. Begin
  813. tempopr := instr.operands[1];
  814. instr.operands[1] := instr.operands[2];
  815. instr.operands[2] := tempopr;
  816. end
  817. else
  818. if instr.numops = 3 then
  819. Begin
  820. tempopr := instr.operands[1];
  821. instr.operands[1] := instr.operands[3];
  822. instr.operands[3] := tempopr;
  823. end;
  824. end;
  825. Function SearchIConstant(const s:string; var l:longint): boolean;
  826. {**********************************************************************}
  827. { Description: Searches for a CONSTANT of name s in either the local }
  828. { symbol list, then in the global symbol list, and returns the value }
  829. { of that constant in l. Returns TRUE if successfull, if not found, }
  830. { or if the constant is not of correct type, then returns FALSE }
  831. { Remarks: Also handle TRUE and FALSE returning in those cases 1 and 0 }
  832. { respectively. }
  833. {**********************************************************************}
  834. var
  835. sym: psym;
  836. Begin
  837. SearchIConstant := FALSE;
  838. { check for TRUE or FALSE reserved words first }
  839. if s = 'TRUE' then
  840. Begin
  841. SearchIConstant := TRUE;
  842. l := 1;
  843. end
  844. else
  845. if s = 'FALSE' then
  846. Begin
  847. SearchIConstant := TRUE;
  848. l := 0;
  849. end
  850. else
  851. if assigned(aktprocsym) then
  852. Begin
  853. if assigned(aktprocsym^.definition) then
  854. Begin
  855. { Check the local constants }
  856. if assigned(aktprocsym^.definition^.localst) then
  857. sym := aktprocsym^.definition^.localst^.search(s)
  858. else
  859. sym := nil;
  860. if assigned(sym) then
  861. Begin
  862. if (sym^.typ = constsym) and (pconstsym(sym)^.consttype in
  863. [constord,constint,constchar,constbool]) then
  864. Begin
  865. l:=pconstsym(sym)^.value;
  866. SearchIConstant := TRUE;
  867. exit;
  868. end;
  869. end;
  870. end;
  871. end;
  872. { Check the global constants }
  873. getsym(s,false);
  874. if srsym <> nil then
  875. Begin
  876. if (srsym^.typ=constsym) and (pconstsym(srsym)^.consttype in
  877. [constord,constint,constchar,constbool]) then
  878. Begin
  879. l:=pconstsym(srsym)^.value;
  880. SearchIConstant := TRUE;
  881. exit;
  882. end;
  883. end;
  884. end;
  885. Procedure SetupResult(Var Instr:TInstruction; operandnum: byte);
  886. {**********************************************************************}
  887. { Description: This routine changes the correct fields and correct }
  888. { offset in the reference, so that it points to the __RESULT or }
  889. { @Result variable (depending on the inline asm). }
  890. { Resturns a reference with all correct offset correctly set up. }
  891. { The Operand should already point to a treference on entry. }
  892. {**********************************************************************}
  893. Begin
  894. { replace by correct offset. }
  895. if assigned(procinfo.retdef) and
  896. (procinfo.retdef<>pdef(voiddef)) then
  897. begin
  898. instr.operands[operandnum].ref.offset := procinfo.retoffset;
  899. instr.operands[operandnum].ref.base := procinfo.framepointer;
  900. { always assume that the result is valid. }
  901. procinfo.funcret_is_valid:=true;
  902. end
  903. else
  904. Message(assem_e_invalid_symbol_ref);
  905. end;
  906. {$ifdef i386}
  907. Procedure FWaitWarning;
  908. begin
  909. if (target_info.target=target_GO32V2) and (cs_fp_emulation in aktmoduleswitches) then
  910. Message(assem_w_fwait_emu_prob);
  911. end;
  912. {$endif i386}
  913. Function GetVarOffset(var Instr: TInstruction;const base: string; const field: string;
  914. Var Offset: longint; operandnum: byte):boolean;
  915. { search and returns the offset of records/objects of the base }
  916. { with field name setup in field. }
  917. { returns FALSE if not found. }
  918. { used when base is a variable or a typed constant name. }
  919. var
  920. sym:psym;
  921. p: psym;
  922. Begin
  923. GetVarOffset := FALSE;
  924. Offset := 0;
  925. { local list }
  926. if assigned(aktprocsym) then
  927. begin
  928. if assigned(aktprocsym^.definition^.localst) then
  929. sym:=aktprocsym^.definition^.localst^.search(base)
  930. else
  931. sym:=nil;
  932. if assigned(sym) then
  933. begin
  934. { field of local record variable. }
  935. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=recorddef) then
  936. begin
  937. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  938. if assigned(pvarsym(p)) then
  939. Begin
  940. Offset := pvarsym(p)^.address;
  941. { the current size is NOT overriden if it already }
  942. { exists, such as in the case of a byte ptr, in }
  943. { front of the identifier. }
  944. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  945. Begin
  946. case pvarsym(p)^.getsize of
  947. 1: instr.operands[operandnum].size := S_B;
  948. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  949. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  950. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  951. extended_size: instr.operands[operandnum].size := S_FX;
  952. else
  953. { this is in the case where the instruction is LEA }
  954. { or something like that, in that case size is not }
  955. { important. }
  956. instr.operands[operandnum].size := S_NO;
  957. end; { end case }
  958. end;
  959. GetVarOffset := TRUE;
  960. Exit;
  961. end;
  962. end
  963. else
  964. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=objectdef) then
  965. begin
  966. if assigned(pobjectdef(pvarsym(sym)^.definition)^.publicsyms) then
  967. begin
  968. p:=pvarsym(pobjectdef(pvarsym(sym)^.definition)^.publicsyms^.search(field));
  969. if assigned(pvarsym(p)) then
  970. Begin
  971. Offset := pvarsym(p)^.address;
  972. { the current size is NOT overriden if it already }
  973. { exists, such as in the case of a byte ptr, in }
  974. { front of the identifier. }
  975. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  976. Begin
  977. case pvarsym(p)^.getsize of
  978. 1: instr.operands[operandnum].size := S_B;
  979. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  980. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  981. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  982. extended_size: instr.operands[operandnum].size := S_FX;
  983. else
  984. { this is in the case where the instruction is LEA }
  985. { or something like that, in that case size is not }
  986. { important. }
  987. instr.operands[operandnum].size := S_NO;
  988. end; { end case }
  989. end;
  990. GetVarOffset := TRUE;
  991. Exit;
  992. end;
  993. end;
  994. end;
  995. end
  996. else
  997. begin
  998. { field of local record parameter to routine. }
  999. if assigned(aktprocsym^.definition^.parast) then
  1000. sym:=aktprocsym^.definition^.parast^.search(base)
  1001. else
  1002. sym:=nil;
  1003. if assigned(sym) then
  1004. begin
  1005. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=recorddef)
  1006. then
  1007. begin
  1008. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  1009. if assigned(p) then
  1010. Begin
  1011. Offset := pvarsym(p)^.address;
  1012. GetVarOffset := TRUE;
  1013. { the current size is NOT overriden if it already }
  1014. { exists, such as in the case of a byte ptr, in }
  1015. { front of the identifier. }
  1016. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1017. Begin
  1018. case pvarsym(p)^.getsize of
  1019. 1: instr.operands[operandnum].size := S_B;
  1020. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1021. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1022. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1023. extended_size: instr.operands[operandnum].size := S_FX;
  1024. else
  1025. { this is in the case where the instruction is LEA }
  1026. { or something like that, in that case size is not }
  1027. { important. }
  1028. instr.operands[operandnum].size := S_NO;
  1029. end; { end case }
  1030. end;
  1031. Exit;
  1032. end;
  1033. end { endif }
  1034. else
  1035. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=objectdef) then
  1036. begin
  1037. if assigned(pobjectdef(pvarsym(sym)^.definition)^.publicsyms) then
  1038. begin
  1039. p:=pvarsym(pobjectdef(pvarsym(sym)^.definition)^.publicsyms^.search(field));
  1040. if assigned(pvarsym(p)) then
  1041. Begin
  1042. Offset := pvarsym(p)^.address;
  1043. { the current size is NOT overriden if it already }
  1044. { exists, such as in the case of a byte ptr, in }
  1045. { front of the identifier. }
  1046. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1047. Begin
  1048. case pvarsym(p)^.getsize of
  1049. 1: instr.operands[operandnum].size := S_B;
  1050. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1051. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1052. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1053. extended_size: instr.operands[operandnum].size := S_FX;
  1054. else
  1055. { this is in the case where the instruction is LEA }
  1056. { or something like that, in that case size is not }
  1057. { important. }
  1058. instr.operands[operandnum].size := S_NO;
  1059. end; { end case }
  1060. end;
  1061. GetVarOffset := TRUE;
  1062. Exit;
  1063. end;
  1064. end;
  1065. end;
  1066. end;
  1067. end;
  1068. end; { endif assigned(aktprocsym) }
  1069. { not found.. .now look for global variables. }
  1070. getsym(base,false);
  1071. sym:=srsym;
  1072. if assigned(sym) then
  1073. Begin
  1074. { field of global record variable. }
  1075. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=recorddef) then
  1076. begin
  1077. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  1078. if assigned(p) then
  1079. Begin
  1080. Offset := pvarsym(p)^.address;
  1081. GetVarOffset := TRUE;
  1082. { the current size is NOT overriden if it already }
  1083. { exists, such as in the case of a byte ptr, in }
  1084. { front of the identifier. }
  1085. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1086. Begin
  1087. case pvarsym(p)^.getsize of
  1088. 1: instr.operands[operandnum].size := S_B;
  1089. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1090. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1091. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1092. extended_size: instr.operands[operandnum].size := S_FX;
  1093. else
  1094. { this is in the case where the instruction is LEA }
  1095. { or something like that, in that case size is not }
  1096. { important. }
  1097. instr.operands[operandnum].size := S_NO;
  1098. end; { end case }
  1099. end;
  1100. Exit;
  1101. end;
  1102. end
  1103. else
  1104. { field of global record type constant. }
  1105. if (sym^.typ=typedconstsym) and (ptypedconstsym(sym)^.definition^.deftype=recorddef)
  1106. then
  1107. begin
  1108. p:=pvarsym(precdef(pvarsym(sym)^.definition)^.symtable^.search(field));
  1109. if assigned(p) then
  1110. Begin
  1111. Offset := pvarsym(p)^.address;
  1112. GetVarOffset := TRUE;
  1113. { the current size is NOT overriden if it already }
  1114. { exists, such as in the case of a byte ptr, in }
  1115. { front of the identifier. }
  1116. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1117. Begin
  1118. case pvarsym(p)^.getsize of
  1119. 1: instr.operands[operandnum].size := S_B;
  1120. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1121. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1122. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1123. extended_size: instr.operands[operandnum].size := S_FX;
  1124. else
  1125. { this is in the case where the instruction is LEA }
  1126. { or something like that, in that case size is not }
  1127. { important. }
  1128. instr.operands[operandnum].size := S_NO;
  1129. end; { end case }
  1130. end;
  1131. Exit;
  1132. end;
  1133. end
  1134. else
  1135. if (sym^.typ=varsym) and (pvarsym(sym)^.definition^.deftype=objectdef) then
  1136. begin
  1137. if assigned(pobjectdef(pvarsym(sym)^.definition)^.publicsyms) then
  1138. begin
  1139. p:=pvarsym(pobjectdef(pvarsym(sym)^.definition)^.publicsyms^.search(field));
  1140. if assigned(pvarsym(p)) then
  1141. Begin
  1142. Offset := pvarsym(p)^.address;
  1143. { the current size is NOT overriden if it already }
  1144. { exists, such as in the case of a byte ptr, in }
  1145. { front of the identifier. }
  1146. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1147. Begin
  1148. case pvarsym(p)^.getsize of
  1149. 1: instr.operands[operandnum].size := S_B;
  1150. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1151. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1152. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1153. extended_size: instr.operands[operandnum].size := S_FX;
  1154. else
  1155. { this is in the case where the instruction is LEA }
  1156. { or something like that, in that case size is not }
  1157. { important. }
  1158. instr.operands[operandnum].size := S_NO;
  1159. end; { end case }
  1160. end;
  1161. GetVarOffset := TRUE;
  1162. Exit;
  1163. end;
  1164. end;
  1165. end;
  1166. end; { end looking for global variables .. }
  1167. end;
  1168. Function GetTypeOffset(var instr: TInstruction; const base: string; const field: string;
  1169. Var Offset: longint; operandnum: byte):boolean;
  1170. { search and returns the offset of records/objects of the base }
  1171. { with field name setup in field. }
  1172. { returns 0 if not found. }
  1173. { used when base is a variable or a typed constant name. }
  1174. var
  1175. sym:psym;
  1176. p: psym;
  1177. Begin
  1178. Offset := 0;
  1179. GetTypeOffset := FALSE;
  1180. { local list }
  1181. if assigned(aktprocsym) then
  1182. begin
  1183. if assigned(aktprocsym^.definition^.localst) then
  1184. sym:=aktprocsym^.definition^.localst^.search(base)
  1185. else
  1186. sym:=nil;
  1187. if assigned(sym) then
  1188. begin
  1189. { field of local record type. }
  1190. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=recorddef) then
  1191. begin
  1192. p:=precdef(ptypesym(sym)^.definition)^.symtable^.search(field);
  1193. if assigned(p) then
  1194. Begin
  1195. Offset := pvarsym(p)^.address;
  1196. { the current size is NOT overriden if it already }
  1197. { exists, such as in the case of a byte ptr, in }
  1198. { front of the identifier. }
  1199. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1200. Begin
  1201. case pvarsym(p)^.getsize of
  1202. 1: instr.operands[operandnum].size := S_B;
  1203. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1204. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1205. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1206. extended_size: instr.operands[operandnum].size := S_FX;
  1207. else
  1208. { this is in the case where the instruction is LEA }
  1209. { or something like that, in that case size is not }
  1210. { important. }
  1211. instr.operands[operandnum].size := S_NO;
  1212. end; { end case }
  1213. end;
  1214. GetTypeOffset := TRUE;
  1215. Exit;
  1216. end;
  1217. end;
  1218. end
  1219. else
  1220. begin
  1221. { field of local record type to routine. }
  1222. if assigned(aktprocsym^.definition^.parast) then
  1223. sym:=aktprocsym^.definition^.parast^.search(base)
  1224. else
  1225. sym:=nil;
  1226. if assigned(sym) then
  1227. begin
  1228. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=recorddef)
  1229. then
  1230. begin
  1231. p:=precdef(ptypesym(sym)^.definition)^.symtable^.search(field);
  1232. if assigned(p) then
  1233. Begin
  1234. Offset := pvarsym(p)^.address;
  1235. { the current size is NOT overriden if it already }
  1236. { exists, such as in the case of a byte ptr, in }
  1237. { front of the identifier. }
  1238. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1239. Begin
  1240. case pvarsym(p)^.getsize of
  1241. 1: instr.operands[operandnum].size := S_B;
  1242. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1243. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1244. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1245. extended_size: instr.operands[operandnum].size := S_FX;
  1246. else
  1247. { this is in the case where the instruction is LEA }
  1248. { or something like that, in that case size is not }
  1249. { important. }
  1250. instr.operands[operandnum].size := S_NO;
  1251. end; { end case }
  1252. end;
  1253. GetTypeOffset := TRUE;
  1254. Exit;
  1255. end;
  1256. end; { endif }
  1257. end; {endif }
  1258. end; { endif }
  1259. end;
  1260. { not found.. .now look for global types. }
  1261. getsym(base,false);
  1262. sym:=srsym;
  1263. if assigned(sym) then
  1264. Begin
  1265. { field of global record types. }
  1266. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=recorddef) then
  1267. begin
  1268. p:=precdef(ptypesym(sym)^.definition)^.symtable^.search(field);
  1269. if assigned(p) then
  1270. Begin
  1271. Offset := pvarsym(p)^.address;
  1272. { the current size is NOT overriden if it already }
  1273. { exists, such as in the case of a byte ptr, in }
  1274. { front of the identifier. }
  1275. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1276. Begin
  1277. case pvarsym(p)^.getsize of
  1278. 1: instr.operands[operandnum].size := S_B;
  1279. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1280. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1281. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1282. extended_size: instr.operands[operandnum].size := S_FX;
  1283. else
  1284. { this is in the case where the instruction is LEA }
  1285. { or something like that, in that case size is not }
  1286. { important. }
  1287. instr.operands[operandnum].size := S_NO;
  1288. end; { end case }
  1289. end;
  1290. GetTypeOffset := TRUE;
  1291. Exit;
  1292. end
  1293. end
  1294. else
  1295. { public field names of objects }
  1296. if (sym^.typ=typesym) and (ptypesym(sym)^.definition^.deftype=objectdef)then
  1297. begin
  1298. if assigned(pobjectdef(ptypesym(sym)^.definition)^.publicsyms) then
  1299. Begin
  1300. p:=pobjectdef(ptypesym(sym)^.definition)^.publicsyms^.search(field);
  1301. if assigned(p) then
  1302. Begin
  1303. Offset := pvarsym(p)^.address;
  1304. { the current size is NOT overriden if it already }
  1305. { exists, such as in the case of a byte ptr, in }
  1306. { front of the identifier. }
  1307. if instr.operands[operandnum].size = S_NO then
  1308. Begin
  1309. case pvarsym(p)^.getsize of
  1310. 1: instr.operands[operandnum].size := S_B;
  1311. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1312. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1313. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1314. extended_size: instr.operands[operandnum].size := S_FX;
  1315. else
  1316. { this is in the case where the instruction is LEA }
  1317. { or something like that, in that case size is not }
  1318. { important. }
  1319. instr.operands[operandnum].size := S_NO;
  1320. end; { end case }
  1321. end;
  1322. GetTypeOffset := TRUE;
  1323. Exit;
  1324. end
  1325. end;
  1326. end;
  1327. end; { end looking for global variables .. }
  1328. end;
  1329. Function CreateVarInstr(var Instr: TInstruction; const hs:string;operandnum:byte): Boolean;
  1330. { search and sets up the correct fields in the Instr record }
  1331. { for the NON-constant identifier passed to the routine. }
  1332. { if not found returns FALSE. }
  1333. var
  1334. sym : psym;
  1335. l : longint;
  1336. Begin
  1337. CreateVarInstr := FALSE;
  1338. { are we in a routine ? }
  1339. if assigned(aktprocsym) then
  1340. begin
  1341. { search the local list for the name of this variable. }
  1342. if assigned(aktprocsym^.definition^.localst) then
  1343. sym:=aktprocsym^.definition^.localst^.search(hs)
  1344. else
  1345. sym:=nil;
  1346. if assigned(sym) then
  1347. begin
  1348. case sym^.typ of
  1349. typedconstsym,
  1350. varsym : begin
  1351. { we always assume in asm statements that }
  1352. { that the variable is valid. }
  1353. pvarsym(sym)^.is_valid:=1;
  1354. if pvarsym(sym)^.owner^.symtabletype=staticsymtable then
  1355. begin
  1356. if assigned(instr.operands[operandnum].ref.symbol) then
  1357. FreeMem(instr.operands[operandnum].ref.symbol,length(instr.operands[operandnum].ref.symbol^)+1);
  1358. instr.operands[operandnum].ref.symbol:=newpasstr(pvarsym(sym)^.mangledname);
  1359. end
  1360. else
  1361. begin
  1362. instr.operands[operandnum].ref.base := procinfo.framepointer;
  1363. instr.operands[operandnum].ref.offset := -(pvarsym(sym)^.address);
  1364. end;
  1365. { the current size is NOT overriden if it already }
  1366. { exists, such as in the case of a byte ptr, in }
  1367. { front of the identifier. }
  1368. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1369. Begin
  1370. case pvarsym(sym)^.getsize of
  1371. 1: instr.operands[operandnum].size := S_B;
  1372. 2: instr.operands[operandnum].size := S_W{ could be S_IS};
  1373. 4: instr.operands[operandnum].size := S_L{ could be S_IL or S_FS};
  1374. 8: instr.operands[operandnum].size := S_IQ{ could be S_D or S_FL};
  1375. extended_size: instr.operands[operandnum].size := S_FX;
  1376. else
  1377. { this is in the case where the instruction is LEA }
  1378. { or something like that, in that case size is not }
  1379. { important. }
  1380. instr.operands[operandnum].size := S_NO;
  1381. end; { end case }
  1382. end;
  1383. { ok, finished for thir variable. }
  1384. CreateVarInstr := TRUE;
  1385. Exit;
  1386. end;
  1387. procsym : begin
  1388. { free the memory before changing the symbol name. }
  1389. if assigned(instr.operands[operandnum].ref.symbol) then
  1390. FreeMem(instr.operands[operandnum].ref.symbol,length(instr.operands[operandnum].ref.symbol^)+1);
  1391. instr.operands[operandnum].operandtype:=OPR_SYMBOL;
  1392. instr.operands[operandnum].symbol:=newpasstr(pprocsym(sym)^.definition^.mangledname);
  1393. CreateVarInstr := TRUE;
  1394. Exit;
  1395. end
  1396. else
  1397. begin
  1398. Message(assem_e_unsupported_symbol_type);
  1399. exit;
  1400. end;
  1401. end;
  1402. end;
  1403. { now check for parameters passed to routine }
  1404. if assigned(aktprocsym^.definition^.parast) then
  1405. sym:=aktprocsym^.definition^.parast^.search(hs)
  1406. else
  1407. sym:=nil;
  1408. if assigned(sym) then
  1409. begin
  1410. case sym^.typ of
  1411. varsym : begin
  1412. l:=pvarsym(sym)^.address;
  1413. { set offset }
  1414. inc(l,aktprocsym^.definition^.parast^.call_offset);
  1415. pvarsym(sym)^.is_valid:=1;
  1416. instr.operands[operandnum].ref.base := procinfo.framepointer;
  1417. instr.operands[operandnum].ref.offset := l;
  1418. { the current size is NOT overriden if it already }
  1419. { exists, such as in the case of a byte ptr, in }
  1420. { front of the identifier. }
  1421. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1422. Begin
  1423. case pvarsym(sym)^.getsize of
  1424. 1: instr.operands[operandnum].size := S_B;
  1425. 2: instr.operands[operandnum].size := S_W;
  1426. 4: instr.operands[operandnum].size := S_L;
  1427. 8: instr.operands[operandnum].size := S_IQ;
  1428. extended_size: instr.operands[operandnum].size := S_FX;
  1429. else
  1430. { this is in the case where the instruction is LEA }
  1431. { or something like that, in that case size is not }
  1432. { important. }
  1433. instr.operands[operandnum].size := S_NO;
  1434. end; { end case }
  1435. end; { endif }
  1436. CreateVarInstr := TRUE;
  1437. Exit;
  1438. end;
  1439. else
  1440. begin
  1441. Message(assem_e_unsupported_symbol_type);
  1442. exit;
  1443. end;
  1444. end; { case }
  1445. end; { endif }
  1446. end;
  1447. { not found.. .now look for global variables. }
  1448. getsym(hs,false);
  1449. sym:=srsym;
  1450. if assigned(sym) then
  1451. Begin
  1452. case sym^.typ of
  1453. varsym,
  1454. typedconstsym : Begin
  1455. { free the memory before changing the symbol name. }
  1456. if assigned(instr.operands[operandnum].ref.symbol) then
  1457. FreeMem(instr.operands[operandnum].ref.symbol,
  1458. length(instr.operands[operandnum].ref.symbol^)+1);
  1459. instr.operands[operandnum].ref.symbol:=newpasstr(sym^.mangledname);
  1460. { the current size is NOT overriden if it already }
  1461. { exists, such as in the case of a byte ptr, in }
  1462. { front of the identifier. }
  1463. if (instr.operands[operandnum].size = S_NO) or (instr.operands[operandnum].overriden = FALSE) then
  1464. Begin
  1465. case pvarsym(sym)^.getsize of
  1466. 1: instr.operands[operandnum].size := S_B;
  1467. 2: instr.operands[operandnum].size := S_W;
  1468. 4: instr.operands[operandnum].size := S_L;
  1469. 8: instr.operands[operandnum].size := S_IQ;
  1470. else
  1471. { this is in the case where the instruction is LEA }
  1472. { or something like that, in that case size is not }
  1473. { important. }
  1474. instr.operands[operandnum].size := S_NO;
  1475. end;
  1476. end
  1477. else
  1478. if (instr.operands[operandnum].size = S_NO) and (sym^.typ = typedconstsym) then
  1479. Begin
  1480. { only these are valid sizes, otherwise prefixes are }
  1481. { required. }
  1482. case ptypedconstsym(sym)^.definition^.size of
  1483. 1: instr.operands[operandnum].size := S_B;
  1484. 2: instr.operands[operandnum].size := S_W;
  1485. 4: instr.operands[operandnum].size := S_L;
  1486. 8: instr.operands[operandnum].size := S_IQ;
  1487. else
  1488. { this is in the case where the instruction is LEA }
  1489. { or something like that, in that case size is not }
  1490. { important. }
  1491. instr.operands[operandnum].size := S_NO;
  1492. end;
  1493. end; { endif }
  1494. CreateVarInstr := TRUE;
  1495. Exit;
  1496. end;
  1497. procsym : begin
  1498. if assigned(pprocsym(sym)^.definition^.nextoverloaded) then
  1499. Message(assem_w_calling_overload_func);
  1500. { free the memory before changing the symbol name. }
  1501. if assigned(instr.operands[operandnum].ref.symbol) then
  1502. FreeMem(instr.operands[operandnum].ref.symbol,length(instr.operands[operandnum].ref.symbol^)+1);
  1503. instr.operands[operandnum].operandtype:=OPR_SYMBOL;
  1504. instr.operands[operandnum].symbol:=newpasstr(pprocsym(sym)^.definition^.mangledname);
  1505. CreateVarInstr := TRUE;
  1506. Exit;
  1507. end;
  1508. else
  1509. begin
  1510. Message(assem_e_unsupported_symbol_type);
  1511. exit;
  1512. end;
  1513. end; {case}
  1514. end; { end looking for global variables .. }
  1515. end;
  1516. Function SearchLabel(const s: string; var hl: plabel): boolean;
  1517. {**********************************************************************}
  1518. { Description: Searches for a pascal label definition, first in the }
  1519. { local symbol list and then in the global symbol list. If found then }
  1520. { return pointer to label and return true, otherwise returns false. }
  1521. {**********************************************************************}
  1522. var
  1523. sym: psym;
  1524. Begin
  1525. SearchLabel := FALSE;
  1526. if assigned(aktprocsym) then
  1527. Begin
  1528. { Check the local constants }
  1529. if assigned(aktprocsym^.definition) then
  1530. Begin
  1531. if assigned(aktprocsym^.definition^.localst) then
  1532. sym := aktprocsym^.definition^.localst^.search(s)
  1533. else
  1534. sym := nil;
  1535. if assigned(sym) then
  1536. Begin
  1537. if (sym^.typ = labelsym) then
  1538. Begin
  1539. hl:=plabelsym(sym)^.number;
  1540. SearchLabel := TRUE;
  1541. exit;
  1542. end;
  1543. end;
  1544. end;
  1545. end;
  1546. { Check the global label symbols... }
  1547. getsym(s,false);
  1548. if srsym <> nil then
  1549. Begin
  1550. if (srsym^.typ=labelsym) then
  1551. Begin
  1552. hl:=plabelsym(srsym)^.number;
  1553. SearchLabel:= TRUE;
  1554. exit;
  1555. end;
  1556. end;
  1557. end;
  1558. {*************************************************************************}
  1559. { Instruction Generation Utilities }
  1560. {*************************************************************************}
  1561. Procedure ConcatString(p : paasmoutput;s:string);
  1562. {*********************************************************************}
  1563. { PROCEDURE ConcatString(s:string); }
  1564. { Description: This routine adds the character chain pointed to in }
  1565. { s to the instruction linked list. }
  1566. {*********************************************************************}
  1567. Var
  1568. pc: PChar;
  1569. Begin
  1570. getmem(pc,length(s)+1);
  1571. p^.concat(new(pai_string,init_length_pchar(strpcopy(pc,s),length(s))));
  1572. end;
  1573. Procedure ConcatPasString(p : paasmoutput;s:string);
  1574. {*********************************************************************}
  1575. { PROCEDURE ConcatPasString(s:string); }
  1576. { Description: This routine adds the character chain pointed to in }
  1577. { s to the instruction linked list, contrary to ConcatString it }
  1578. { uses a pascal style string, so it conserves null characters. }
  1579. {*********************************************************************}
  1580. Begin
  1581. p^.concat(new(pai_string,init(s)));
  1582. end;
  1583. Procedure ConcatDirect(p : paasmoutput;s:string);
  1584. {*********************************************************************}
  1585. { PROCEDURE ConcatDirect(s:string) }
  1586. { Description: This routine output the string directly to the asm }
  1587. { output, it is only sed when writing special labels in AT&T mode, }
  1588. { and should not be used without due consideration, since it may }
  1589. { cause problems. }
  1590. {*********************************************************************}
  1591. Var
  1592. pc: PChar;
  1593. Begin
  1594. getmem(pc,length(s)+1);
  1595. p^.concat(new(pai_direct,init(strpcopy(pc,s))));
  1596. end;
  1597. Procedure ConcatConstant(p: paasmoutput; value: longint; maxvalue: longint);
  1598. {*********************************************************************}
  1599. { PROCEDURE ConcatConstant(value: longint; maxvalue: longint); }
  1600. { Description: This routine adds the value constant to the current }
  1601. { instruction linked list. }
  1602. { maxvalue -> indicates the size of the data to initialize: }
  1603. { $ff -> create a byte node. }
  1604. { $ffff -> create a word node. }
  1605. { $ffffffff -> create a dword node. }
  1606. {*********************************************************************}
  1607. Begin
  1608. if value > maxvalue then
  1609. Begin
  1610. Message(assem_e_constant_out_of_bounds);
  1611. { assuming a value of maxvalue }
  1612. value := maxvalue;
  1613. end;
  1614. if maxvalue = $ff then
  1615. p^.concat(new(pai_const,init_8bit(byte(value))))
  1616. else
  1617. if maxvalue = $ffff then
  1618. p^.concat(new(pai_const,init_16bit(word(value))))
  1619. else
  1620. if maxvalue = $ffffffff then
  1621. p^.concat(new(pai_const,init_32bit(longint(value))));
  1622. end;
  1623. Procedure ConcatRealConstant(p : paasmoutput;value: bestreal; real_typ : tfloattype);
  1624. {***********************************************************************}
  1625. { PROCEDURE ConcatRealConstant(value: bestreal; real_typ : tfloattype); }
  1626. { Description: This routine adds the value constant to the current }
  1627. { instruction linked list. }
  1628. { real_typ -> indicates the type of the real data to initialize: }
  1629. { s32real -> create a single node. }
  1630. { s64real -> create a double node. }
  1631. { s80real -> create an extended node. }
  1632. { s64bit -> create a comp node. }
  1633. { f32bit -> create a fixed node. (not used normally) }
  1634. {***********************************************************************}
  1635. Begin
  1636. case real_typ of
  1637. s32real : p^.concat(new(pai_single,init(value)));
  1638. s64real : p^.concat(new(pai_double,init(value)));
  1639. s80real : p^.concat(new(pai_extended,init(value)));
  1640. s64bit : p^.concat(new(pai_comp,init(value)));
  1641. f32bit : p^.concat(new(pai_const,init_32bit(trunc(value*$10000))));
  1642. end;
  1643. end;
  1644. Procedure ConcatLabel(p: paasmoutput;op : tasmop;var l : plabel);
  1645. {*********************************************************************}
  1646. { PROCEDURE ConcatLabel }
  1647. { Description: This routine either emits a label or a labeled }
  1648. { instruction to the linked list of instructions. }
  1649. {*********************************************************************}
  1650. begin
  1651. if op=A_LABEL then
  1652. p^.concat(new(pai_label,init(l)))
  1653. else
  1654. p^.concat(new(pai_labeled,init(op,l)))
  1655. end;
  1656. procedure ConcatPublic(p:paasmoutput;const s : string);
  1657. {*********************************************************************}
  1658. { PROCEDURE ConcatPublic }
  1659. { Description: This routine emits an global definition to the }
  1660. { linked list of instructions.(used by AT&T styled asm) }
  1661. {*********************************************************************}
  1662. begin
  1663. p^.concat(new(pai_symbol,init_global(s)));
  1664. { concat_internal(s,EXT_NEAR); done in aasm }
  1665. end;
  1666. procedure ConcatLocal(p:paasmoutput;const s : string);
  1667. {*********************************************************************}
  1668. { PROCEDURE ConcatLocal }
  1669. { Description: This routine emits an local definition to the }
  1670. { linked list of instructions. }
  1671. {*********************************************************************}
  1672. begin
  1673. p^.concat(new(pai_symbol,init(s)));
  1674. { concat_internal(s,EXT_NEAR); done in aasm }
  1675. end;
  1676. Procedure ConcatGlobalBss(const s : string;size : longint);
  1677. {*********************************************************************}
  1678. { PROCEDURE ConcatGlobalBss }
  1679. { Description: This routine emits an global datablock to the }
  1680. { linked list of instructions. }
  1681. {*********************************************************************}
  1682. begin
  1683. bsssegment^.concat(new(pai_datablock,init_global(s,size)));
  1684. { concat_internal(s,EXT_NEAR); done in aasm }
  1685. end;
  1686. Procedure ConcatLocalBss(const s : string;size : longint);
  1687. {*********************************************************************}
  1688. { PROCEDURE ConcatLocalBss }
  1689. { Description: This routine emits a local datablcok to the }
  1690. { linked list of instructions. }
  1691. {*********************************************************************}
  1692. begin
  1693. bsssegment^.concat(new(pai_datablock,init(s,size)));
  1694. { concat_internal(s,EXT_NEAR); done in aasm }
  1695. end;
  1696. { add to list of external labels }
  1697. Procedure ConcatExternal(const s : string;typ : texternal_typ);
  1698. {*********************************************************************}
  1699. { PROCEDURE ConcatExternal }
  1700. { Description: This routine emits an external definition to the }
  1701. { linked list of instructions.(used by AT&T styled asm) }
  1702. {*********************************************************************}
  1703. { check if in internal list and remove it there }
  1704. var p : pai_external;
  1705. begin
  1706. p:=search_assembler_symbol(internals,s,typ);
  1707. if p<>nil then internals^.remove(p);
  1708. concat_external(s,typ);
  1709. end;
  1710. { add to internal list of labels }
  1711. Procedure ConcatInternal(const s : string;typ : texternal_typ);
  1712. {*********************************************************************}
  1713. { PROCEDURE ConcatInternal }
  1714. { Description: This routine emits an internal definition of a symbol }
  1715. { (used by AT&T styled asm for undefined labels) }
  1716. {*********************************************************************}
  1717. begin
  1718. concat_internal(s,typ);
  1719. end;
  1720. end.
  1721. {
  1722. $Log$
  1723. Revision 1.9 1998-09-24 17:54:15 carl
  1724. * bugfixes from fix branch
  1725. Revision 1.8.2.1 1998/09/24 17:46:25 carl
  1726. * support for objects in asm statements
  1727. Revision 1.8 1998/08/27 00:43:06 carl
  1728. +} now record offsets searches set the operand sizes
  1729. Revision 1.7 1998/08/18 20:51:32 peter
  1730. * fixed bug 42
  1731. Revision 1.6 1998/08/10 14:49:40 peter
  1732. + localswitches, moduleswitches, globalswitches splitting
  1733. Revision 1.5 1998/07/14 21:46:38 peter
  1734. * updated messages file
  1735. Revision 1.4 1998/06/04 23:51:31 peter
  1736. * m68k compiles
  1737. + .def file creation moved to gendef.pas so it could also be used
  1738. for win32
  1739. Revision 1.3 1998/05/31 14:13:30 peter
  1740. * fixed call bugs with assembler readers
  1741. + OPR_SYMBOL to hold a symbol in the asm parser
  1742. * fixed staticsymtable vars which were acessed through %ebp instead of
  1743. name
  1744. Revision 1.2 1998/04/29 10:33:43 pierre
  1745. + added some code for ansistring (not complete nor working yet)
  1746. * corrected operator overloading
  1747. * corrected nasm output
  1748. + started inline procedures
  1749. + added starstarn : use ** for exponentiation (^ gave problems)
  1750. + started UseTokenInfo cond to get accurate positions
  1751. }