ra386att.pas 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Carl Eric Codere and Peter Vreman
  4. Does the parsing for the AT&T styled inline assembler.
  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. }
  18. Unit Ra386att;
  19. {$i defines.inc}
  20. Interface
  21. uses
  22. node;
  23. function assemble: tnode;
  24. Implementation
  25. uses
  26. { common }
  27. cutils,cclasses,
  28. { global }
  29. globtype,globals,verbose,
  30. systems,
  31. { aasm }
  32. cpubase,aasm,
  33. { symtable }
  34. symconst,symbase,symtype,symsym,symtable,types,
  35. { pass 1 }
  36. nbas,
  37. { parser }
  38. scanner,
  39. ra386,rautils,
  40. { codegen }
  41. cgbase
  42. ;
  43. type
  44. tasmtoken = (
  45. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_INTNUM,
  46. AS_REALNUM,AS_COMMA,AS_LPAREN,
  47. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
  48. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,AS_DOLLAR,
  49. {------------------ Assembler directives --------------------}
  50. AS_DB,AS_DW,AS_DD,AS_DQ,AS_GLOBAL,
  51. AS_ALIGN,AS_BALIGN,AS_P2ALIGN,AS_ASCII,
  52. AS_ASCIIZ,AS_LCOMM,AS_COMM,AS_SINGLE,AS_DOUBLE,AS_EXTENDED,
  53. AS_DATA,AS_TEXT,AS_END,
  54. {------------------ Assembler Operators --------------------}
  55. AS_TYPE,AS_MOD,AS_SHL,AS_SHR,AS_NOT,AS_AND,AS_OR,AS_XOR,AS_NOR);
  56. tasmkeyword = string[10];
  57. const
  58. { These tokens should be modified accordingly to the modifications }
  59. { in the different enumerations. }
  60. firstdirective = AS_DB;
  61. lastdirective = AS_END;
  62. _count_asmprefixes = 5;
  63. _count_asmspecialops = 25;
  64. _count_asmoverrides = 3;
  65. token2str : array[tasmtoken] of tasmkeyword=(
  66. '','Label','LLabel','string','integer',
  67. 'float',',','(',
  68. ')',':','.','+','-','*',
  69. ';','identifier','register','opcode','/','$',
  70. '.byte','.word','.long','.quad','.globl',
  71. '.align','.balign','.p2align','.ascii',
  72. '.asciz','.lcomm','.comm','.single','.double','.tfloat',
  73. '.data','.text','END',
  74. 'TYPE','%','<<','>>','!','&','|','^','~');
  75. const
  76. newline = #10;
  77. firsttoken : boolean = TRUE;
  78. var
  79. _asmsorted : boolean;
  80. curlist : TAAsmoutput;
  81. c : char;
  82. actasmtoken : tasmtoken;
  83. prevasmtoken : tasmtoken;
  84. actasmpattern : string;
  85. actopcode : tasmop;
  86. actasmregister : tregister;
  87. actopsize : topsize;
  88. actcondition : tasmcond;
  89. iasmops : tdictionary;
  90. iasmregs : ^reg2strtable;
  91. Procedure SetupTables;
  92. { creates uppercased symbol tables for speed access }
  93. var
  94. i : tasmop;
  95. j : tregister;
  96. str2opentry: tstr2opentry;
  97. Begin
  98. { opcodes }
  99. iasmops:=TDictionary.Create;
  100. iasmops.delete_doubles:=true;
  101. for i:=firstop to lastop do
  102. begin
  103. str2opentry:=tstr2opentry.createname(upper(att_op2str[i]));
  104. str2opentry.op:=i;
  105. iasmops.insert(str2opentry);
  106. end;
  107. { registers }
  108. new(iasmregs);
  109. for j:=firstreg to lastreg do
  110. iasmregs^[j] := upper(att_reg2str[j]);
  111. end;
  112. {---------------------------------------------------------------------}
  113. { Routines for the tokenizing }
  114. {---------------------------------------------------------------------}
  115. function is_asmopcode(const s: string):boolean;
  116. const
  117. { We need first to check the long prefixes, else we get probs
  118. with things like movsbl }
  119. att_sizesuffixstr : array[0..9] of string[2] = (
  120. '','BW','BL','WL','B','W','L','S','Q','T'
  121. );
  122. att_sizesuffix : array[0..9] of topsize = (
  123. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_FS,S_IQ,S_FX
  124. );
  125. att_sizefpusuffix : array[0..9] of topsize = (
  126. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_IQ,S_FX
  127. );
  128. att_sizefpuintsuffix : array[0..9] of topsize = (
  129. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
  130. );
  131. var
  132. str2opentry: tstr2opentry;
  133. cond : string[4];
  134. cnd : tasmcond;
  135. len,
  136. j,
  137. sufidx : longint;
  138. Begin
  139. is_asmopcode:=FALSE;
  140. actopcode:=A_None;
  141. actcondition:=C_None;
  142. actopsize:=S_NO;
  143. { search for all possible suffixes }
  144. for sufidx:=low(att_sizesuffixstr) to high(att_sizesuffixstr) do
  145. begin
  146. len:=length(s)-length(att_sizesuffixstr[sufidx]);
  147. if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
  148. begin
  149. { here we search the entire table... }
  150. str2opentry:=nil;
  151. if {(length(s)>0) and} (len>0) then
  152. str2opentry:=tstr2opentry(iasmops.search(copy(s,1,len)));
  153. if assigned(str2opentry) then
  154. begin
  155. actopcode:=str2opentry.op;
  156. if att_needsuffix[actopcode]=attsufFPU then
  157. actopsize:=att_sizefpusuffix[sufidx]
  158. else if att_needsuffix[actopcode]=attsufFPUint then
  159. actopsize:=att_sizefpuintsuffix[sufidx]
  160. else
  161. actopsize:=att_sizesuffix[sufidx];
  162. actasmtoken:=AS_OPCODE;
  163. is_asmopcode:=TRUE;
  164. exit;
  165. end;
  166. { not found, check condition opcodes }
  167. j:=0;
  168. while (j<CondAsmOps) do
  169. begin
  170. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  171. begin
  172. cond:=Copy(s,Length(CondAsmOpStr[j])+1,len-Length(CondAsmOpStr[j]));
  173. if cond<>'' then
  174. begin
  175. for cnd:=low(TasmCond) to high(TasmCond) do
  176. if Cond=Upper(cond2str[cnd]) then
  177. begin
  178. actopcode:=CondASmOp[j];
  179. if att_needsuffix[actopcode]=attsufFPU then
  180. actopsize:=att_sizefpusuffix[sufidx]
  181. else if att_needsuffix[actopcode]=attsufFPUint then
  182. actopsize:=att_sizefpuintsuffix[sufidx]
  183. else
  184. actopsize:=att_sizesuffix[sufidx];
  185. actcondition:=cnd;
  186. actasmtoken:=AS_OPCODE;
  187. is_asmopcode:=TRUE;
  188. exit;
  189. end;
  190. end;
  191. end;
  192. inc(j);
  193. end;
  194. end;
  195. end;
  196. end;
  197. Function is_asmdirective(const s: string):boolean;
  198. var
  199. i : tasmtoken;
  200. hs : string;
  201. Begin
  202. { GNU as is also not casesensitive with this }
  203. hs:=lower(s);
  204. for i:=firstdirective to lastdirective do
  205. if hs=token2str[i] then
  206. begin
  207. actasmtoken:=i;
  208. is_asmdirective:=true;
  209. exit;
  210. end;
  211. is_asmdirective:=false;
  212. end;
  213. Function is_register(const s: string):boolean;
  214. Var
  215. i : tregister;
  216. Begin
  217. actasmregister:=R_NO;
  218. for i:=firstreg to lastreg do
  219. if s=iasmregs^[i] then
  220. begin
  221. actasmtoken:=AS_REGISTER;
  222. actasmregister:=i;
  223. is_register:=true;
  224. exit;
  225. end;
  226. is_register:=false;
  227. end;
  228. Function is_locallabel(const s: string):boolean;
  229. begin
  230. is_locallabel:=(length(s)>=2) and (s[1]='.') and (s[2]='L');
  231. end;
  232. Procedure GetToken;
  233. var
  234. len : longint;
  235. srsym : tsym;
  236. srsymtable : tsymtable;
  237. begin
  238. { save old token and reset new token }
  239. prevasmtoken:=actasmtoken;
  240. actasmtoken:=AS_NONE;
  241. { reset }
  242. actasmpattern:='';
  243. { while space and tab , continue scan... }
  244. while c in [' ',#9] do
  245. c:=current_scanner.asmgetchar;
  246. { get token pos }
  247. if not (c in [newline,#13,'{',';']) then
  248. current_scanner.gettokenpos;
  249. { Local Label, Label, Directive, Prefix or Opcode }
  250. if firsttoken and not(c in [newline,#13,'{',';']) then
  251. begin
  252. firsttoken:=FALSE;
  253. len:=0;
  254. { directive or local label }
  255. if c = '.' then
  256. begin
  257. inc(len);
  258. actasmpattern[len]:=c;
  259. { Let us point to the next character }
  260. c:=current_scanner.asmgetchar;
  261. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  262. begin
  263. inc(len);
  264. actasmpattern[len]:=c;
  265. c:=current_scanner.asmgetchar;
  266. end;
  267. actasmpattern[0]:=chr(len);
  268. { this is a local label... }
  269. if (c=':') and is_locallabel(actasmpattern) then
  270. Begin
  271. { local variables are case sensitive }
  272. actasmtoken:=AS_LLABEL;
  273. c:=current_scanner.asmgetchar;
  274. firsttoken:=true;
  275. exit;
  276. end
  277. { must be a directive }
  278. else
  279. Begin
  280. { directives are case sensitive!! }
  281. if is_asmdirective(actasmpattern) then
  282. exit;
  283. Message1(asmr_e_not_directive_or_local_symbol,actasmpattern);
  284. end;
  285. end;
  286. { only opcodes and global labels are allowed now. }
  287. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  288. begin
  289. inc(len);
  290. actasmpattern[len]:=c;
  291. c:=current_scanner.asmgetchar;
  292. end;
  293. actasmpattern[0]:=chr(len);
  294. { Label ? }
  295. if c = ':' then
  296. begin
  297. actasmtoken:=AS_LABEL;
  298. { let us point to the next character }
  299. c:=current_scanner.asmgetchar;
  300. firsttoken:=true;
  301. exit;
  302. end;
  303. { Opcode ? }
  304. If is_asmopcode(upper(actasmpattern)) then
  305. Begin
  306. uppervar(actasmpattern);
  307. exit;
  308. end;
  309. { End of assemblerblock ? }
  310. if upper(actasmpattern) = 'END' then
  311. begin
  312. actasmtoken:=AS_END;
  313. exit;
  314. end;
  315. message1(asmr_e_unknown_opcode,actasmpattern);
  316. actasmtoken:=AS_NONE;
  317. end
  318. else { else firsttoken }
  319. { Here we must handle all possible cases }
  320. begin
  321. case c of
  322. '.' : { possiblities : - local label reference , such as in jmp @local1 }
  323. { - field of object/record }
  324. { - directive. }
  325. begin
  326. if (prevasmtoken in [AS_ID,AS_RPAREN]) then
  327. begin
  328. c:=current_scanner.asmgetchar;
  329. actasmtoken:=AS_DOT;
  330. exit;
  331. end;
  332. actasmpattern:=c;
  333. c:=current_scanner.asmgetchar;
  334. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  335. begin
  336. actasmpattern:=actasmpattern + c;
  337. c:=current_scanner.asmgetchar;
  338. end;
  339. if is_asmdirective(actasmpattern) then
  340. exit;
  341. { local label references and directives }
  342. { are case sensitive }
  343. actasmtoken:=AS_ID;
  344. exit;
  345. end;
  346. { identifier, register, prefix or directive }
  347. '_','A'..'Z','a'..'z':
  348. begin
  349. len:=0;
  350. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  351. begin
  352. inc(len);
  353. actasmpattern[len]:=c;
  354. c:=current_scanner.asmgetchar;
  355. end;
  356. actasmpattern[0]:=chr(len);
  357. uppervar(actasmpattern);
  358. { Opcode, can only be when the previous was a prefix }
  359. If is_prefix(actopcode) and is_asmopcode(actasmpattern) then
  360. Begin
  361. uppervar(actasmpattern);
  362. exit;
  363. end;
  364. { check for end which is a reserved word unlike the opcodes }
  365. if actasmpattern = 'END' then
  366. Begin
  367. actasmtoken:=AS_END;
  368. exit;
  369. end;
  370. if actasmpattern = 'TYPE' then
  371. Begin
  372. actasmtoken:=AS_TYPE;
  373. exit;
  374. end;
  375. { if next is a '.' and this is a unitsym then we also need to
  376. parse the identifier }
  377. if (c='.') then
  378. begin
  379. searchsym(actasmpattern,srsym,srsymtable);
  380. if assigned(srsym) and
  381. (srsym.typ=unitsym) and
  382. (srsym.owner.unitid=0) then
  383. begin
  384. actasmpattern:=actasmpattern+c;
  385. c:=current_scanner.asmgetchar;
  386. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  387. begin
  388. actasmpattern:=actasmpattern + upcase(c);
  389. c:=current_scanner.asmgetchar;
  390. end;
  391. end;
  392. end;
  393. actasmtoken:=AS_ID;
  394. exit;
  395. end;
  396. '%' : { register or modulo }
  397. begin
  398. len:=1;
  399. actasmpattern[len]:='%';
  400. c:=current_scanner.asmgetchar;
  401. { to be a register there must be a letter and not a number }
  402. if c in ['0'..'9'] then
  403. begin
  404. actasmtoken:=AS_MOD;
  405. {Message(asmr_w_modulo_not_supported);}
  406. end
  407. else
  408. begin
  409. while c in ['a'..'z','A'..'Z','0'..'9'] do
  410. Begin
  411. inc(len);
  412. actasmpattern[len]:=c;
  413. c:=current_scanner.asmgetchar;
  414. end;
  415. actasmpattern[0]:=chr(len);
  416. uppervar(actasmpattern);
  417. if (actasmpattern = '%ST') and (c='(') then
  418. Begin
  419. actasmpattern:=actasmpattern+c;
  420. c:=current_scanner.asmgetchar;
  421. if c in ['0'..'9'] then
  422. actasmpattern:=actasmpattern + c
  423. else
  424. Message(asmr_e_invalid_fpu_register);
  425. c:=current_scanner.asmgetchar;
  426. if c <> ')' then
  427. Message(asmr_e_invalid_fpu_register)
  428. else
  429. Begin
  430. actasmpattern:=actasmpattern + c;
  431. c:=current_scanner.asmgetchar; { let us point to next character. }
  432. end;
  433. end;
  434. if is_register(actasmpattern) then
  435. exit;
  436. Message(asmr_e_invalid_register);
  437. actasmtoken:=AS_NONE;
  438. end;
  439. end;
  440. '1'..'9': { integer number }
  441. begin
  442. len:=0;
  443. while c in ['0'..'9'] do
  444. Begin
  445. inc(len);
  446. actasmpattern[len]:=c;
  447. c:=current_scanner.asmgetchar;
  448. end;
  449. actasmpattern[0]:=chr(len);
  450. actasmpattern:=tostr(ValDecimal(actasmpattern));
  451. actasmtoken:=AS_INTNUM;
  452. exit;
  453. end;
  454. '0' : { octal,hexa,real or binary number. }
  455. begin
  456. actasmpattern:=c;
  457. c:=current_scanner.asmgetchar;
  458. case upcase(c) of
  459. 'B': { binary }
  460. Begin
  461. c:=current_scanner.asmgetchar;
  462. while c in ['0','1'] do
  463. Begin
  464. actasmpattern:=actasmpattern + c;
  465. c:=current_scanner.asmgetchar;
  466. end;
  467. actasmpattern:=tostr(ValBinary(actasmpattern));
  468. actasmtoken:=AS_INTNUM;
  469. exit;
  470. end;
  471. 'D': { real }
  472. Begin
  473. c:=current_scanner.asmgetchar;
  474. { get ridd of the 0d }
  475. if (c in ['+','-']) then
  476. begin
  477. actasmpattern:=c;
  478. c:=current_scanner.asmgetchar;
  479. end
  480. else
  481. actasmpattern:='';
  482. while c in ['0'..'9'] do
  483. Begin
  484. actasmpattern:=actasmpattern + c;
  485. c:=current_scanner.asmgetchar;
  486. end;
  487. if c='.' then
  488. begin
  489. actasmpattern:=actasmpattern + c;
  490. c:=current_scanner.asmgetchar;
  491. while c in ['0'..'9'] do
  492. Begin
  493. actasmpattern:=actasmpattern + c;
  494. c:=current_scanner.asmgetchar;
  495. end;
  496. if upcase(c) = 'E' then
  497. begin
  498. actasmpattern:=actasmpattern + c;
  499. c:=current_scanner.asmgetchar;
  500. if (c in ['+','-']) then
  501. begin
  502. actasmpattern:=actasmpattern + c;
  503. c:=current_scanner.asmgetchar;
  504. end;
  505. while c in ['0'..'9'] do
  506. Begin
  507. actasmpattern:=actasmpattern + c;
  508. c:=current_scanner.asmgetchar;
  509. end;
  510. end;
  511. actasmtoken:=AS_REALNUM;
  512. exit;
  513. end
  514. else
  515. begin
  516. Message1(asmr_e_invalid_float_const,actasmpattern+c);
  517. actasmtoken:=AS_NONE;
  518. end;
  519. end;
  520. 'X': { hexadecimal }
  521. Begin
  522. c:=current_scanner.asmgetchar;
  523. while c in ['0'..'9','a'..'f','A'..'F'] do
  524. Begin
  525. actasmpattern:=actasmpattern + c;
  526. c:=current_scanner.asmgetchar;
  527. end;
  528. actasmpattern:=tostr(ValHexaDecimal(actasmpattern));
  529. actasmtoken:=AS_INTNUM;
  530. exit;
  531. end;
  532. '1'..'7': { octal }
  533. begin
  534. actasmpattern:=actasmpattern + c;
  535. while c in ['0'..'7'] do
  536. Begin
  537. actasmpattern:=actasmpattern + c;
  538. c:=current_scanner.asmgetchar;
  539. end;
  540. actasmpattern:=tostr(ValOctal(actasmpattern));
  541. actasmtoken:=AS_INTNUM;
  542. exit;
  543. end;
  544. else { octal number zero value...}
  545. Begin
  546. actasmpattern:=tostr(ValOctal(actasmpattern));
  547. actasmtoken:=AS_INTNUM;
  548. exit;
  549. end;
  550. end; { end case }
  551. end;
  552. '&' :
  553. begin
  554. c:=current_scanner.asmgetchar;
  555. actasmtoken:=AS_AND;
  556. end;
  557. '''' : { char }
  558. begin
  559. current_scanner.in_asm_string:=true;
  560. actasmpattern:='';
  561. repeat
  562. c:=current_scanner.asmgetchar;
  563. case c of
  564. '\' :
  565. begin
  566. { copy also the next char so \" is parsed correctly }
  567. actasmpattern:=actasmpattern+c;
  568. c:=current_scanner.asmgetchar;
  569. actasmpattern:=actasmpattern+c;
  570. end;
  571. '''' :
  572. begin
  573. c:=current_scanner.asmgetchar;
  574. break;
  575. end;
  576. newline:
  577. Message(scan_f_string_exceeds_line);
  578. else
  579. actasmpattern:=actasmpattern+c;
  580. end;
  581. until false;
  582. actasmpattern:=EscapeToPascal(actasmpattern);
  583. actasmtoken:=AS_STRING;
  584. current_scanner.in_asm_string:=false;
  585. exit;
  586. end;
  587. '"' : { string }
  588. begin
  589. current_scanner.in_asm_string:=true;
  590. actasmpattern:='';
  591. repeat
  592. c:=current_scanner.asmgetchar;
  593. case c of
  594. '\' :
  595. begin
  596. { copy also the next char so \" is parsed correctly }
  597. actasmpattern:=actasmpattern+c;
  598. c:=current_scanner.asmgetchar;
  599. actasmpattern:=actasmpattern+c;
  600. end;
  601. '"' :
  602. begin
  603. c:=current_scanner.asmgetchar;
  604. break;
  605. end;
  606. newline:
  607. Message(scan_f_string_exceeds_line);
  608. else
  609. actasmpattern:=actasmpattern+c;
  610. end;
  611. until false;
  612. actasmpattern:=EscapeToPascal(actasmpattern);
  613. actasmtoken:=AS_STRING;
  614. current_scanner.in_asm_string:=false;
  615. exit;
  616. end;
  617. '$' :
  618. begin
  619. actasmtoken:=AS_DOLLAR;
  620. c:=current_scanner.asmgetchar;
  621. exit;
  622. end;
  623. ',' :
  624. begin
  625. actasmtoken:=AS_COMMA;
  626. c:=current_scanner.asmgetchar;
  627. exit;
  628. end;
  629. '<' :
  630. begin
  631. actasmtoken:=AS_SHL;
  632. c:=current_scanner.asmgetchar;
  633. if c = '<' then
  634. c:=current_scanner.asmgetchar;
  635. exit;
  636. end;
  637. '>' :
  638. begin
  639. actasmtoken:=AS_SHL;
  640. c:=current_scanner.asmgetchar;
  641. if c = '>' then
  642. c:=current_scanner.asmgetchar;
  643. exit;
  644. end;
  645. '|' :
  646. begin
  647. actasmtoken:=AS_OR;
  648. c:=current_scanner.asmgetchar;
  649. exit;
  650. end;
  651. '^' :
  652. begin
  653. actasmtoken:=AS_XOR;
  654. c:=current_scanner.asmgetchar;
  655. exit;
  656. end;
  657. '!' :
  658. begin
  659. Message(asmr_e_nor_not_supported);
  660. c:=current_scanner.asmgetchar;
  661. actasmtoken:=AS_NONE;
  662. exit;
  663. end;
  664. '(' :
  665. begin
  666. actasmtoken:=AS_LPAREN;
  667. c:=current_scanner.asmgetchar;
  668. exit;
  669. end;
  670. ')' :
  671. begin
  672. actasmtoken:=AS_RPAREN;
  673. c:=current_scanner.asmgetchar;
  674. exit;
  675. end;
  676. ':' :
  677. begin
  678. actasmtoken:=AS_COLON;
  679. c:=current_scanner.asmgetchar;
  680. exit;
  681. end;
  682. '+' :
  683. begin
  684. actasmtoken:=AS_PLUS;
  685. c:=current_scanner.asmgetchar;
  686. exit;
  687. end;
  688. '-' :
  689. begin
  690. actasmtoken:=AS_MINUS;
  691. c:=current_scanner.asmgetchar;
  692. exit;
  693. end;
  694. '*' :
  695. begin
  696. actasmtoken:=AS_STAR;
  697. c:=current_scanner.asmgetchar;
  698. exit;
  699. end;
  700. '/' :
  701. begin
  702. c:=current_scanner.asmgetchar;
  703. actasmtoken:=AS_SLASH;
  704. exit;
  705. end;
  706. '{',#13,newline,';' :
  707. begin
  708. { the comment is read by asmgetchar }
  709. c:=current_scanner.asmgetchar;
  710. firsttoken:=TRUE;
  711. actasmtoken:=AS_SEPARATOR;
  712. exit;
  713. end;
  714. else
  715. current_scanner.illegal_char(c);
  716. end;
  717. end;
  718. end;
  719. function consume(t : tasmtoken):boolean;
  720. begin
  721. Consume:=true;
  722. if t<>actasmtoken then
  723. begin
  724. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  725. Consume:=false;
  726. end;
  727. repeat
  728. gettoken;
  729. until actasmtoken<>AS_NONE;
  730. end;
  731. procedure RecoverConsume(allowcomma:boolean);
  732. begin
  733. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  734. begin
  735. if allowcomma and (actasmtoken=AS_COMMA) then
  736. break;
  737. Consume(actasmtoken);
  738. end;
  739. end;
  740. {*****************************************************************************
  741. Parsing Helpers
  742. *****************************************************************************}
  743. Procedure BuildRecordOffsetSize(const expr: string;var offset:longint;var size:longint);
  744. { Description: This routine builds up a record offset after a AS_DOT }
  745. { token is encountered. }
  746. { On entry actasmtoken should be equal to AS_DOT }
  747. var
  748. s : string;
  749. Begin
  750. offset:=0;
  751. size:=0;
  752. s:=expr;
  753. while (actasmtoken=AS_DOT) do
  754. begin
  755. Consume(AS_DOT);
  756. if actasmtoken=AS_ID then
  757. s:=s+'.'+actasmpattern;
  758. if not Consume(AS_ID) then
  759. begin
  760. RecoverConsume(true);
  761. break;
  762. end;
  763. end;
  764. if not GetRecordOffsetSize(s,offset,size) then
  765. Message(asmr_e_building_record_offset);
  766. end;
  767. Procedure BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:longint;var asmsym:string);
  768. var
  769. hs,tempstr,expr : string;
  770. parenlevel,l,k : longint;
  771. errorflag : boolean;
  772. prevtok : tasmtoken;
  773. sym : tsym;
  774. srsymtable : tsymtable;
  775. hl : tasmlabel;
  776. Begin
  777. asmsym:='';
  778. value:=0;
  779. errorflag:=FALSE;
  780. tempstr:='';
  781. expr:='';
  782. parenlevel:=0;
  783. Repeat
  784. Case actasmtoken of
  785. AS_LPAREN:
  786. Begin
  787. { Exit if ref? }
  788. if allowref and (prevasmtoken in [AS_INTNUM,AS_ID]) then
  789. break;
  790. Consume(AS_LPAREN);
  791. expr:=expr + '(';
  792. inc(parenlevel);
  793. end;
  794. AS_RPAREN:
  795. Begin
  796. { end of ref ? }
  797. if (parenlevel=0) and betweenbracket then
  798. break;
  799. Consume(AS_RPAREN);
  800. expr:=expr + ')';
  801. dec(parenlevel);
  802. end;
  803. AS_SHL:
  804. Begin
  805. Consume(AS_SHL);
  806. expr:=expr + '<';
  807. end;
  808. AS_SHR:
  809. Begin
  810. Consume(AS_SHR);
  811. expr:=expr + '>';
  812. end;
  813. AS_SLASH:
  814. Begin
  815. Consume(AS_SLASH);
  816. expr:=expr + '/';
  817. end;
  818. AS_MOD:
  819. Begin
  820. Consume(AS_MOD);
  821. expr:=expr + '%';
  822. end;
  823. AS_STAR:
  824. Begin
  825. Consume(AS_STAR);
  826. expr:=expr + '*';
  827. end;
  828. AS_PLUS:
  829. Begin
  830. Consume(AS_PLUS);
  831. expr:=expr + '+';
  832. end;
  833. AS_MINUS:
  834. Begin
  835. Consume(AS_MINUS);
  836. expr:=expr + '-';
  837. end;
  838. AS_AND:
  839. Begin
  840. Consume(AS_AND);
  841. expr:=expr + '&';
  842. end;
  843. AS_NOT:
  844. Begin
  845. Consume(AS_NOT);
  846. expr:=expr + '~';
  847. end;
  848. AS_XOR:
  849. Begin
  850. Consume(AS_XOR);
  851. expr:=expr + '^';
  852. end;
  853. AS_OR:
  854. Begin
  855. Consume(AS_OR);
  856. expr:=expr + '|';
  857. end;
  858. AS_INTNUM:
  859. Begin
  860. expr:=expr + actasmpattern;
  861. Consume(AS_INTNUM);
  862. end;
  863. AS_DOLLAR:
  864. begin
  865. Consume(AS_DOLLAR);
  866. if actasmtoken<>AS_ID then
  867. Message(asmr_e_dollar_without_identifier);
  868. end;
  869. AS_STRING:
  870. Begin
  871. l:=0;
  872. case Length(actasmpattern) of
  873. 1 :
  874. l:=ord(actasmpattern[1]);
  875. 2 :
  876. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  877. 3 :
  878. l:=ord(actasmpattern[3]) +
  879. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  880. 4 :
  881. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  882. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  883. else
  884. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  885. end;
  886. str(l, tempstr);
  887. expr:=expr + tempstr;
  888. Consume(AS_STRING);
  889. end;
  890. AS_TYPE:
  891. begin
  892. l:=0;
  893. Consume(AS_TYPE);
  894. if actasmtoken<>AS_ID then
  895. Message(asmr_e_type_without_identifier)
  896. else
  897. begin
  898. tempstr:=actasmpattern;
  899. Consume(AS_ID);
  900. if actasmtoken=AS_DOT then
  901. BuildRecordOffsetSize(tempstr,k,l)
  902. else
  903. begin
  904. searchsym(tempstr,sym,srsymtable);
  905. if assigned(sym) then
  906. begin
  907. case sym.typ of
  908. varsym :
  909. l:=tvarsym(sym).getsize;
  910. typedconstsym :
  911. l:=ttypedconstsym(sym).getsize;
  912. typesym :
  913. l:=ttypesym(sym).restype.def.size;
  914. else
  915. Message(asmr_e_wrong_sym_type);
  916. end;
  917. end
  918. else
  919. Message1(sym_e_unknown_id,tempstr);
  920. end;
  921. end;
  922. str(l, tempstr);
  923. expr:=expr + tempstr;
  924. end;
  925. AS_ID:
  926. Begin
  927. hs:='';
  928. tempstr:=actasmpattern;
  929. prevtok:=prevasmtoken;
  930. consume(AS_ID);
  931. if SearchIConstant(tempstr,l) then
  932. begin
  933. str(l, tempstr);
  934. expr:=expr + tempstr;
  935. end
  936. else
  937. begin
  938. if is_locallabel(tempstr) then
  939. begin
  940. CreateLocalLabel(tempstr,hl,false);
  941. hs:=hl.name
  942. end
  943. else
  944. if SearchLabel(tempstr,hl,false) then
  945. hs:=hl.name
  946. else
  947. begin
  948. searchsym(tempstr,sym,srsymtable);
  949. if assigned(sym) then
  950. begin
  951. case sym.typ of
  952. varsym :
  953. begin
  954. if sym.owner.symtabletype in [localsymtable,parasymtable] then
  955. Message(asmr_e_no_local_or_para_allowed);
  956. hs:=tvarsym(sym).mangledname;
  957. end;
  958. typedconstsym :
  959. hs:=ttypedconstsym(sym).mangledname;
  960. procsym :
  961. hs:=tprocsym(sym).mangledname;
  962. typesym :
  963. begin
  964. if not(ttypesym(sym).restype.def.deftype in [recorddef,objectdef]) then
  965. Message(asmr_e_wrong_sym_type);
  966. end;
  967. else
  968. Message(asmr_e_wrong_sym_type);
  969. end;
  970. end
  971. else
  972. Message1(sym_e_unknown_id,tempstr);
  973. end;
  974. { symbol found? }
  975. if hs<>'' then
  976. begin
  977. if needofs and (prevtok<>AS_DOLLAR) then
  978. Message(asmr_e_need_dollar);
  979. if asmsym='' then
  980. asmsym:=hs
  981. else
  982. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  983. if (expr='') or (expr[length(expr)]='+') then
  984. begin
  985. { don't remove the + if there could be a record field }
  986. if actasmtoken<>AS_DOT then
  987. delete(expr,length(expr),1);
  988. end
  989. else
  990. Message(asmr_e_only_add_relocatable_symbol);
  991. end;
  992. if actasmtoken=AS_DOT then
  993. begin
  994. BuildRecordOffsetSize(tempstr,l,k);
  995. str(l, tempstr);
  996. expr:=expr + tempstr;
  997. end
  998. else
  999. begin
  1000. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1001. delete(expr,length(expr),1);
  1002. end;
  1003. end;
  1004. { check if there are wrong operator used like / or mod etc. }
  1005. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_LPAREN,AS_END]) then
  1006. Message(asmr_e_only_add_relocatable_symbol);
  1007. end;
  1008. AS_END,
  1009. AS_SEPARATOR,
  1010. AS_COMMA:
  1011. Begin
  1012. break;
  1013. end;
  1014. else
  1015. Begin
  1016. { write error only once. }
  1017. if not errorflag then
  1018. Message(asmr_e_invalid_constant_expression);
  1019. { consume tokens until we find COMMA or SEPARATOR }
  1020. Consume(actasmtoken);
  1021. errorflag:=TRUE;
  1022. end;
  1023. end;
  1024. Until false;
  1025. { calculate expression }
  1026. if not ErrorFlag then
  1027. value:=CalculateExpression(expr)
  1028. else
  1029. value:=0;
  1030. end;
  1031. Function BuildConstExpression(allowref,betweenbracket:boolean): longint;
  1032. var
  1033. l : longint;
  1034. hs : string;
  1035. begin
  1036. BuildConstSymbolExpression(allowref,betweenbracket,false,l,hs);
  1037. if hs<>'' then
  1038. Message(asmr_e_relocatable_symbol_not_allowed);
  1039. BuildConstExpression:=l;
  1040. end;
  1041. {****************************************************************************
  1042. T386ATTOperand
  1043. ****************************************************************************}
  1044. type
  1045. T386ATTOperand=class(T386Operand)
  1046. Procedure BuildOperand;override;
  1047. private
  1048. Procedure BuildReference;
  1049. Procedure BuildConstant;
  1050. end;
  1051. Procedure T386ATTOperand.BuildReference;
  1052. procedure Consume_RParen;
  1053. begin
  1054. if actasmtoken <> AS_RPAREN then
  1055. Begin
  1056. Message(asmr_e_invalid_reference_syntax);
  1057. RecoverConsume(true);
  1058. end
  1059. else
  1060. begin
  1061. Consume(AS_RPAREN);
  1062. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  1063. Begin
  1064. Message(asmr_e_invalid_reference_syntax);
  1065. RecoverConsume(true);
  1066. end;
  1067. end;
  1068. end;
  1069. procedure Consume_Scale;
  1070. var
  1071. l : longint;
  1072. begin
  1073. { we have to process the scaling }
  1074. l:=BuildConstExpression(false,true);
  1075. if ((l = 2) or (l = 4) or (l = 8) or (l = 1)) then
  1076. opr.ref.scalefactor:=l
  1077. else
  1078. Begin
  1079. Message(asmr_e_wrong_scale_factor);
  1080. opr.ref.scalefactor:=0;
  1081. end;
  1082. end;
  1083. Begin
  1084. Consume(AS_LPAREN);
  1085. Case actasmtoken of
  1086. AS_INTNUM,
  1087. AS_MINUS,
  1088. AS_PLUS: { absolute offset, such as fs:(0x046c) }
  1089. Begin
  1090. { offset(offset) is invalid }
  1091. If opr.Ref.Offset <> 0 Then
  1092. Begin
  1093. Message(asmr_e_invalid_reference_syntax);
  1094. RecoverConsume(true);
  1095. End
  1096. Else
  1097. Begin
  1098. opr.Ref.Offset:=BuildConstExpression(false,true);
  1099. Consume_RParen;
  1100. end;
  1101. exit;
  1102. End;
  1103. AS_REGISTER: { (reg ... }
  1104. Begin
  1105. { Check if there is already a base (mostly ebp,esp) than this is
  1106. not allowed,becuase it will give crashing code }
  1107. if opr.ref.base<>R_NO then
  1108. Message(asmr_e_cannot_index_relative_var);
  1109. opr.ref.base:=actasmregister;
  1110. Consume(AS_REGISTER);
  1111. { can either be a register or a right parenthesis }
  1112. { (reg) }
  1113. if actasmtoken=AS_RPAREN then
  1114. Begin
  1115. Consume_RParen;
  1116. exit;
  1117. end;
  1118. { (reg,reg .. }
  1119. Consume(AS_COMMA);
  1120. if actasmtoken=AS_REGISTER then
  1121. Begin
  1122. opr.ref.index:=actasmregister;
  1123. Consume(AS_REGISTER);
  1124. { check for scaling ... }
  1125. case actasmtoken of
  1126. AS_RPAREN:
  1127. Begin
  1128. Consume_RParen;
  1129. exit;
  1130. end;
  1131. AS_COMMA:
  1132. Begin
  1133. Consume(AS_COMMA);
  1134. Consume_Scale;
  1135. Consume_RParen;
  1136. end;
  1137. else
  1138. Begin
  1139. Message(asmr_e_invalid_reference_syntax);
  1140. RecoverConsume(false);
  1141. end;
  1142. end; { end case }
  1143. end
  1144. else
  1145. Begin
  1146. Message(asmr_e_invalid_reference_syntax);
  1147. RecoverConsume(false);
  1148. end;
  1149. end; {end case }
  1150. AS_COMMA: { (, ... can either be scaling, or index }
  1151. Begin
  1152. Consume(AS_COMMA);
  1153. { Index }
  1154. if (actasmtoken=AS_REGISTER) then
  1155. Begin
  1156. opr.ref.index:=actasmregister;
  1157. Consume(AS_REGISTER);
  1158. { check for scaling ... }
  1159. case actasmtoken of
  1160. AS_RPAREN:
  1161. Begin
  1162. Consume_RParen;
  1163. exit;
  1164. end;
  1165. AS_COMMA:
  1166. Begin
  1167. Consume(AS_COMMA);
  1168. Consume_Scale;
  1169. Consume_RParen;
  1170. end;
  1171. else
  1172. Begin
  1173. Message(asmr_e_invalid_reference_syntax);
  1174. RecoverConsume(false);
  1175. end;
  1176. end; {end case }
  1177. end
  1178. { Scaling }
  1179. else
  1180. Begin
  1181. Consume_Scale;
  1182. Consume_RParen;
  1183. exit;
  1184. end;
  1185. end;
  1186. else
  1187. Begin
  1188. Message(asmr_e_invalid_reference_syntax);
  1189. RecoverConsume(false);
  1190. end;
  1191. end;
  1192. end;
  1193. Procedure T386ATTOperand.BuildConstant;
  1194. var
  1195. l : longint;
  1196. tempstr : string;
  1197. begin
  1198. BuildConstSymbolExpression(false,false,true,l,tempstr);
  1199. if tempstr<>'' then
  1200. begin
  1201. opr.typ:=OPR_SYMBOL;
  1202. opr.symofs:=l;
  1203. opr.symbol:=newasmsymbol(tempstr);
  1204. end
  1205. else
  1206. begin
  1207. opr.typ:=OPR_CONSTANT;
  1208. opr.val:=l;
  1209. end;
  1210. end;
  1211. Procedure T386ATTOperand.BuildOperand;
  1212. var
  1213. tempstr,tempstr2,
  1214. expr : string;
  1215. l,k : longint;
  1216. procedure AddLabelOperand(hl:tasmlabel);
  1217. begin
  1218. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  1219. is_calljmp(actopcode) then
  1220. begin
  1221. opr.typ:=OPR_SYMBOL;
  1222. opr.symbol:=hl;
  1223. end
  1224. else
  1225. begin
  1226. InitRef;
  1227. opr.ref.symbol:=hl;
  1228. end;
  1229. end;
  1230. procedure MaybeRecordOffset;
  1231. var
  1232. hasdot : boolean;
  1233. l,
  1234. toffset,
  1235. tsize : longint;
  1236. begin
  1237. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  1238. exit;
  1239. l:=0;
  1240. hasdot:=(actasmtoken=AS_DOT);
  1241. if hasdot then
  1242. begin
  1243. if expr<>'' then
  1244. begin
  1245. BuildRecordOffsetSize(expr,toffset,tsize);
  1246. inc(l,toffset);
  1247. SetSize(tsize,true);
  1248. end;
  1249. end;
  1250. if actasmtoken in [AS_PLUS,AS_MINUS] then
  1251. inc(l,BuildConstExpression(true,false));
  1252. if opr.typ=OPR_REFERENCE then
  1253. begin
  1254. if hasdot and (not hastype) and (opr.ref.options=ref_parafixup) then
  1255. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1256. inc(opr.ref.offset,l)
  1257. end
  1258. else
  1259. inc(opr.val,l);
  1260. end;
  1261. function MaybeBuildReference:boolean;
  1262. { Try to create a reference, if not a reference is found then false
  1263. is returned }
  1264. begin
  1265. MaybeBuildReference:=true;
  1266. case actasmtoken of
  1267. AS_INTNUM,
  1268. AS_MINUS,
  1269. AS_PLUS:
  1270. Begin
  1271. opr.ref.offset:=BuildConstExpression(True,False);
  1272. if actasmtoken<>AS_LPAREN then
  1273. Message(asmr_e_invalid_reference_syntax)
  1274. else
  1275. BuildReference;
  1276. end;
  1277. AS_LPAREN:
  1278. BuildReference;
  1279. AS_ID: { only a variable is allowed ... }
  1280. Begin
  1281. tempstr:=actasmpattern;
  1282. Consume(AS_ID);
  1283. { typecasting? }
  1284. if (actasmtoken=AS_LPAREN) and
  1285. SearchType(tempstr) then
  1286. begin
  1287. hastype:=true;
  1288. Consume(AS_LPAREN);
  1289. tempstr2:=actasmpattern;
  1290. Consume(AS_ID);
  1291. Consume(AS_RPAREN);
  1292. if not SetupVar(tempstr2,false) then
  1293. Message1(sym_e_unknown_id,tempstr2);
  1294. end
  1295. else
  1296. if not SetupVar(tempstr,false) then
  1297. Message1(sym_e_unknown_id,tempstr);
  1298. { record.field ? }
  1299. if actasmtoken=AS_DOT then
  1300. begin
  1301. BuildRecordOffsetSize(tempstr,l,k);
  1302. inc(opr.ref.offset,l);
  1303. end;
  1304. case actasmtoken of
  1305. AS_END,
  1306. AS_SEPARATOR,
  1307. AS_COMMA: ;
  1308. AS_LPAREN: BuildReference;
  1309. else
  1310. Begin
  1311. Message(asmr_e_invalid_reference_syntax);
  1312. Consume(actasmtoken);
  1313. end;
  1314. end; {end case }
  1315. end;
  1316. else
  1317. MaybeBuildReference:=false;
  1318. end; { end case }
  1319. end;
  1320. var
  1321. tempreg : tregister;
  1322. hl : tasmlabel;
  1323. Begin
  1324. expr:='';
  1325. case actasmtoken of
  1326. AS_LPAREN: { Memory reference or constant expression }
  1327. Begin
  1328. InitRef;
  1329. BuildReference;
  1330. end;
  1331. AS_DOLLAR: { Constant expression }
  1332. Begin
  1333. Consume(AS_DOLLAR);
  1334. BuildConstant;
  1335. end;
  1336. AS_INTNUM,
  1337. AS_MINUS,
  1338. AS_PLUS:
  1339. Begin
  1340. { Constant memory offset }
  1341. { This must absolutely be followed by ( }
  1342. InitRef;
  1343. opr.ref.offset:=BuildConstExpression(True,False);
  1344. if actasmtoken<>AS_LPAREN then
  1345. Message(asmr_e_invalid_reference_syntax)
  1346. else
  1347. BuildReference;
  1348. end;
  1349. AS_STAR: { Call from memory address }
  1350. Begin
  1351. Consume(AS_STAR);
  1352. if actasmtoken=AS_REGISTER then
  1353. begin
  1354. opr.typ:=OPR_REGISTER;
  1355. opr.reg:=actasmregister;
  1356. size:=reg_2_opsize[actasmregister];
  1357. Consume(AS_REGISTER);
  1358. end
  1359. else
  1360. begin
  1361. InitRef;
  1362. if not MaybeBuildReference then
  1363. Message(asmr_e_syn_operand);
  1364. end;
  1365. { this is only allowed for call's and jmp's }
  1366. if not is_calljmp(actopcode) then
  1367. Message(asmr_e_syn_operand);
  1368. end;
  1369. AS_ID: { A constant expression, or a Variable ref. }
  1370. Begin
  1371. { Local Label ? }
  1372. if is_locallabel(actasmpattern) then
  1373. begin
  1374. CreateLocalLabel(actasmpattern,hl,false);
  1375. Consume(AS_ID);
  1376. AddLabelOperand(hl);
  1377. end
  1378. else
  1379. { Check for label }
  1380. if SearchLabel(actasmpattern,hl,false) then
  1381. begin
  1382. Consume(AS_ID);
  1383. AddLabelOperand(hl);
  1384. end
  1385. else
  1386. { probably a variable or normal expression }
  1387. { or a procedure (such as in CALL ID) }
  1388. Begin
  1389. { is it a constant ? }
  1390. if SearchIConstant(actasmpattern,l) then
  1391. Begin
  1392. if not (opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1393. Message(asmr_e_invalid_operand_type);
  1394. BuildConstant;
  1395. end
  1396. else
  1397. begin
  1398. InitRef;
  1399. expr:=actasmpattern;
  1400. Consume(AS_ID);
  1401. { typecasting? }
  1402. if (actasmtoken=AS_LPAREN) and
  1403. SearchType(expr) then
  1404. begin
  1405. hastype:=true;
  1406. Consume(AS_LPAREN);
  1407. tempstr:=actasmpattern;
  1408. Consume(AS_ID);
  1409. Consume(AS_RPAREN);
  1410. if SetupVar(tempstr,false) then
  1411. begin
  1412. MaybeRecordOffset;
  1413. { add a constant expression? }
  1414. if (actasmtoken=AS_PLUS) then
  1415. begin
  1416. l:=BuildConstExpression(true,false);
  1417. if opr.typ=OPR_CONSTANT then
  1418. inc(opr.val,l)
  1419. else
  1420. inc(opr.ref.offset,l);
  1421. end
  1422. end
  1423. else
  1424. Message1(sym_e_unknown_id,tempstr);
  1425. end
  1426. else
  1427. begin
  1428. if SetupVar(expr,false) then
  1429. begin
  1430. MaybeRecordOffset;
  1431. { add a constant expression? }
  1432. if (actasmtoken=AS_PLUS) then
  1433. begin
  1434. l:=BuildConstExpression(true,false);
  1435. if opr.typ=OPR_CONSTANT then
  1436. inc(opr.val,l)
  1437. else
  1438. inc(opr.ref.offset,l);
  1439. end
  1440. end
  1441. else
  1442. Begin
  1443. { look for special symbols ... }
  1444. if expr = '__RESULT' then
  1445. SetUpResult
  1446. else
  1447. if expr = '__SELF' then
  1448. SetupSelf
  1449. else
  1450. if expr = '__OLDEBP' then
  1451. SetupOldEBP
  1452. else
  1453. { check for direct symbolic names }
  1454. { only if compiling the system unit }
  1455. if (cs_compilesystem in aktmoduleswitches) then
  1456. begin
  1457. if not SetupDirectVar(expr) then
  1458. Begin
  1459. { not found, finally ... add it anyways ... }
  1460. Message1(asmr_w_id_supposed_external,expr);
  1461. opr.ref.symbol:=newasmsymbol(expr);
  1462. end;
  1463. end
  1464. else
  1465. Message1(sym_e_unknown_id,expr);
  1466. end;
  1467. end;
  1468. end;
  1469. end;
  1470. { Do we have a indexing reference, then parse it also }
  1471. if actasmtoken=AS_LPAREN then
  1472. begin
  1473. if (opr.typ=OPR_CONSTANT) then
  1474. begin
  1475. l:=opr.val;
  1476. opr.typ:=OPR_REFERENCE;
  1477. reset_reference(opr.Ref);
  1478. opr.Ref.Offset:=l;
  1479. end;
  1480. BuildReference;
  1481. end;
  1482. end;
  1483. AS_REGISTER: { Register, a variable reference or a constant reference }
  1484. Begin
  1485. { save the type of register used. }
  1486. tempreg:=actasmregister;
  1487. Consume(AS_REGISTER);
  1488. if actasmtoken = AS_COLON then
  1489. Begin
  1490. Consume(AS_COLON);
  1491. InitRef;
  1492. opr.ref.segment:=tempreg;
  1493. { This must absolutely be followed by a reference }
  1494. if not MaybeBuildReference then
  1495. Begin
  1496. Message(asmr_e_invalid_seg_override);
  1497. Consume(actasmtoken);
  1498. end;
  1499. end
  1500. { Simple register }
  1501. else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  1502. Begin
  1503. if not (opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1504. Message(asmr_e_invalid_operand_type);
  1505. opr.typ:=OPR_REGISTER;
  1506. opr.reg:=tempreg;
  1507. size:=reg_2_opsize[tempreg];
  1508. end
  1509. else
  1510. Message(asmr_e_syn_operand);
  1511. end;
  1512. AS_END,
  1513. AS_SEPARATOR,
  1514. AS_COMMA: ;
  1515. else
  1516. Begin
  1517. Message(asmr_e_syn_operand);
  1518. Consume(actasmtoken);
  1519. end;
  1520. end; { end case }
  1521. end;
  1522. {*****************************************************************************
  1523. T386ATTInstruction
  1524. *****************************************************************************}
  1525. type
  1526. T386AttInstruction=class(T386Instruction)
  1527. procedure InitOperands;override;
  1528. procedure BuildOpcode;override;
  1529. end;
  1530. procedure T386AttInstruction.InitOperands;
  1531. var
  1532. i : longint;
  1533. begin
  1534. for i:=1to 3 do
  1535. Operands[i]:=T386AttOperand.Create;
  1536. end;
  1537. Procedure T386AttInstruction.BuildOpCode;
  1538. var
  1539. operandnum : longint;
  1540. PrefixOp,OverrideOp: tasmop;
  1541. Begin
  1542. PrefixOp:=A_None;
  1543. OverrideOp:=A_None;
  1544. { prefix seg opcode / prefix opcode }
  1545. repeat
  1546. if is_prefix(actopcode) then
  1547. begin
  1548. PrefixOp:=ActOpcode;
  1549. opcode:=ActOpcode;
  1550. condition:=ActCondition;
  1551. opsize:=ActOpsize;
  1552. ConcatInstruction(curlist);
  1553. Consume(AS_OPCODE);
  1554. end
  1555. else
  1556. if is_override(actopcode) then
  1557. begin
  1558. OverrideOp:=ActOpcode;
  1559. opcode:=ActOpcode;
  1560. condition:=ActCondition;
  1561. opsize:=ActOpsize;
  1562. ConcatInstruction(curlist);
  1563. Consume(AS_OPCODE);
  1564. end
  1565. else
  1566. break;
  1567. { allow for newline as in gas styled syntax }
  1568. while actasmtoken=AS_SEPARATOR do
  1569. Consume(AS_SEPARATOR);
  1570. until (actasmtoken<>AS_OPCODE);
  1571. { opcode }
  1572. if (actasmtoken <> AS_OPCODE) then
  1573. Begin
  1574. Message(asmr_e_invalid_or_missing_opcode);
  1575. RecoverConsume(true);
  1576. exit;
  1577. end;
  1578. { Fill the instr object with the current state }
  1579. Opcode:=ActOpcode;
  1580. condition:=ActCondition;
  1581. opsize:=ActOpsize;
  1582. { Valid combination of prefix/override and instruction ? }
  1583. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1584. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1585. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1586. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1587. { We are reading operands, so opcode will be an AS_ID }
  1588. operandnum:=1;
  1589. Consume(AS_OPCODE);
  1590. { Zero operand opcode ? }
  1591. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1592. begin
  1593. operandnum:=0;
  1594. exit;
  1595. end;
  1596. { Read the operands }
  1597. repeat
  1598. case actasmtoken of
  1599. AS_COMMA: { Operand delimiter }
  1600. Begin
  1601. if operandnum > MaxOperands then
  1602. Message(asmr_e_too_many_operands)
  1603. else
  1604. Inc(operandnum);
  1605. Consume(AS_COMMA);
  1606. end;
  1607. AS_SEPARATOR,
  1608. AS_END : { End of asm operands for this opcode }
  1609. begin
  1610. break;
  1611. end;
  1612. else
  1613. Operands[operandnum].BuildOperand;
  1614. end; { end case }
  1615. until false;
  1616. Ops:=operandnum;
  1617. end;
  1618. Procedure BuildConstant(maxvalue: longint);
  1619. var
  1620. asmsym,
  1621. expr: string;
  1622. value : longint;
  1623. Begin
  1624. Repeat
  1625. Case actasmtoken of
  1626. AS_STRING:
  1627. Begin
  1628. expr:=actasmpattern;
  1629. if length(expr) > 1 then
  1630. Message(asmr_e_string_not_allowed_as_const);
  1631. Consume(AS_STRING);
  1632. Case actasmtoken of
  1633. AS_COMMA: Consume(AS_COMMA);
  1634. AS_END,
  1635. AS_SEPARATOR: ;
  1636. else
  1637. Message(asmr_e_invalid_string_expression);
  1638. end; { end case }
  1639. ConcatString(curlist,expr);
  1640. end;
  1641. AS_INTNUM,
  1642. AS_PLUS,
  1643. AS_MINUS,
  1644. AS_LPAREN,
  1645. AS_NOT,
  1646. AS_ID :
  1647. Begin
  1648. BuildConstSymbolExpression(false,false,false,value,asmsym);
  1649. if asmsym<>'' then
  1650. begin
  1651. if maxvalue<>longint($ffffffff) then
  1652. Message(asmr_w_32bit_const_for_address);
  1653. ConcatConstSymbol(curlist,asmsym,value)
  1654. end
  1655. else
  1656. ConcatConstant(curlist,value,maxvalue);
  1657. end;
  1658. AS_COMMA:
  1659. Consume(AS_COMMA);
  1660. AS_END,
  1661. AS_SEPARATOR:
  1662. break;
  1663. else
  1664. begin
  1665. Message(asmr_e_syn_constant);
  1666. RecoverConsume(false);
  1667. end
  1668. end; { end case }
  1669. Until false;
  1670. end;
  1671. Procedure BuildRealConstant(typ : tfloattype);
  1672. var
  1673. expr : string;
  1674. r : bestreal;
  1675. code : integer;
  1676. negativ : boolean;
  1677. errorflag: boolean;
  1678. Begin
  1679. errorflag:=FALSE;
  1680. Repeat
  1681. negativ:=false;
  1682. expr:='';
  1683. if actasmtoken=AS_PLUS then
  1684. Consume(AS_PLUS)
  1685. else
  1686. if actasmtoken=AS_MINUS then
  1687. begin
  1688. negativ:=true;
  1689. consume(AS_MINUS);
  1690. end;
  1691. Case actasmtoken of
  1692. AS_INTNUM:
  1693. Begin
  1694. expr:=actasmpattern;
  1695. Consume(AS_INTNUM);
  1696. if negativ then
  1697. expr:='-'+expr;
  1698. val(expr,r,code);
  1699. if code<>0 then
  1700. Begin
  1701. r:=0;
  1702. Message(asmr_e_invalid_float_expr);
  1703. End;
  1704. ConcatRealConstant(curlist,r,typ);
  1705. end;
  1706. AS_REALNUM:
  1707. Begin
  1708. expr:=actasmpattern;
  1709. Consume(AS_REALNUM);
  1710. { in ATT syntax you have 0d in front of the real }
  1711. { should this be forced ? yes i think so, as to }
  1712. { conform to gas as much as possible. }
  1713. if (expr[1]='0') and (upper(expr[2])='D') then
  1714. Delete(expr,1,2);
  1715. if negativ then
  1716. expr:='-'+expr;
  1717. val(expr,r,code);
  1718. if code<>0 then
  1719. Begin
  1720. r:=0;
  1721. Message(asmr_e_invalid_float_expr);
  1722. End;
  1723. ConcatRealConstant(curlist,r,typ);
  1724. end;
  1725. AS_COMMA:
  1726. begin
  1727. Consume(AS_COMMA);
  1728. end;
  1729. AS_END,
  1730. AS_SEPARATOR:
  1731. begin
  1732. break;
  1733. end;
  1734. else
  1735. Begin
  1736. Consume(actasmtoken);
  1737. if not errorflag then
  1738. Message(asmr_e_invalid_float_expr);
  1739. errorflag:=TRUE;
  1740. end;
  1741. end;
  1742. Until false;
  1743. end;
  1744. Procedure BuildStringConstant(asciiz: boolean);
  1745. var
  1746. expr: string;
  1747. errorflag : boolean;
  1748. Begin
  1749. errorflag:=FALSE;
  1750. Repeat
  1751. Case actasmtoken of
  1752. AS_STRING:
  1753. Begin
  1754. expr:=actasmpattern;
  1755. if asciiz then
  1756. expr:=expr+#0;
  1757. ConcatPasString(curlist,expr);
  1758. Consume(AS_STRING);
  1759. end;
  1760. AS_COMMA:
  1761. begin
  1762. Consume(AS_COMMA);
  1763. end;
  1764. AS_END,
  1765. AS_SEPARATOR:
  1766. begin
  1767. break;
  1768. end;
  1769. else
  1770. Begin
  1771. Consume(actasmtoken);
  1772. if not errorflag then
  1773. Message(asmr_e_invalid_string_expression);
  1774. errorflag:=TRUE;
  1775. end;
  1776. end;
  1777. Until false;
  1778. end;
  1779. Function Assemble: tnode;
  1780. Var
  1781. hl : tasmlabel;
  1782. commname : string;
  1783. lastsec : tsection;
  1784. l1,l2 : longint;
  1785. instr : T386ATTInstruction;
  1786. Begin
  1787. Message1(asmr_d_start_reading,'AT&T');
  1788. firsttoken:=TRUE;
  1789. if assigned(aktprocsym.definition.funcretsym) and
  1790. (is_fpu(aktprocsym.definition.rettype.def) or
  1791. ret_in_acc(aktprocsym.definition.rettype.def)) then
  1792. tfuncretsym(aktprocsym.definition.funcretsym).funcretstate:=vs_assigned;
  1793. { sets up all opcode and register tables in uppercase }
  1794. if not _asmsorted then
  1795. Begin
  1796. SetupTables;
  1797. _asmsorted:=TRUE;
  1798. end;
  1799. curlist:=TAAsmoutput.Create;
  1800. lastsec:=sec_code;
  1801. { setup label linked list }
  1802. LocalLabelList:=TLocalLabelList.Create;
  1803. { start tokenizer }
  1804. c:=current_scanner.asmgetchar;
  1805. gettoken;
  1806. { main loop }
  1807. repeat
  1808. case actasmtoken of
  1809. AS_LLABEL:
  1810. Begin
  1811. if CreateLocalLabel(actasmpattern,hl,true) then
  1812. ConcatLabel(curlist,hl);
  1813. Consume(AS_LLABEL);
  1814. end;
  1815. AS_LABEL:
  1816. Begin
  1817. if SearchLabel(upper(actasmpattern),hl,true) then
  1818. ConcatLabel(curlist,hl)
  1819. else
  1820. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1821. Consume(AS_LABEL);
  1822. end;
  1823. AS_DW:
  1824. Begin
  1825. Consume(AS_DW);
  1826. BuildConstant($ffff);
  1827. end;
  1828. AS_DATA:
  1829. Begin
  1830. curList.Concat(Tai_section.Create(sec_data));
  1831. lastsec:=sec_data;
  1832. Consume(AS_DATA);
  1833. end;
  1834. AS_TEXT:
  1835. Begin
  1836. curList.Concat(Tai_section.Create(sec_code));
  1837. lastsec:=sec_code;
  1838. Consume(AS_TEXT);
  1839. end;
  1840. AS_DB:
  1841. Begin
  1842. Consume(AS_DB);
  1843. BuildConstant($ff);
  1844. end;
  1845. AS_DD:
  1846. Begin
  1847. Consume(AS_DD);
  1848. BuildConstant(longint($ffffffff));
  1849. end;
  1850. AS_DQ:
  1851. Begin
  1852. Consume(AS_DQ);
  1853. BuildRealConstant(s64comp);
  1854. end;
  1855. AS_SINGLE:
  1856. Begin
  1857. Consume(AS_SINGLE);
  1858. BuildRealConstant(s32real);
  1859. end;
  1860. AS_DOUBLE:
  1861. Begin
  1862. Consume(AS_DOUBLE);
  1863. BuildRealConstant(s64real);
  1864. end;
  1865. AS_EXTENDED:
  1866. Begin
  1867. Consume(AS_EXTENDED);
  1868. BuildRealConstant(s80real);
  1869. end;
  1870. AS_GLOBAL:
  1871. Begin
  1872. Consume(AS_GLOBAL);
  1873. if actasmtoken=AS_ID then
  1874. ConcatPublic(curlist,actasmpattern);
  1875. Consume(AS_ID);
  1876. if actasmtoken<>AS_SEPARATOR then
  1877. Consume(AS_SEPARATOR);
  1878. end;
  1879. AS_ALIGN:
  1880. Begin
  1881. Consume(AS_ALIGN);
  1882. l1:=BuildConstExpression(false,false);
  1883. if (target_info.target in [target_i386_GO32V1,target_i386_GO32V2]) then
  1884. begin
  1885. l2:=1;
  1886. if (l1>=0) and (l1<=16) then
  1887. while (l1>0) do
  1888. begin
  1889. l2:=2*l2;
  1890. dec(l1);
  1891. end;
  1892. l1:=l2;
  1893. end;
  1894. ConcatAlign(curlist,l1);
  1895. Message(asmr_n_align_is_target_specific);
  1896. if actasmtoken<>AS_SEPARATOR then
  1897. Consume(AS_SEPARATOR);
  1898. end;
  1899. AS_BALIGN:
  1900. Begin
  1901. Consume(AS_BALIGN);
  1902. ConcatAlign(curlist,BuildConstExpression(false,false));
  1903. if actasmtoken<>AS_SEPARATOR then
  1904. Consume(AS_SEPARATOR);
  1905. end;
  1906. AS_P2ALIGN:
  1907. Begin
  1908. Consume(AS_P2ALIGN);
  1909. l1:=BuildConstExpression(false,false);
  1910. l2:=1;
  1911. if (l1>=0) and (l1<=16) then
  1912. while (l1>0) do
  1913. begin
  1914. l2:=2*l2;
  1915. dec(l1);
  1916. end;
  1917. l1:=l2;
  1918. ConcatAlign(curlist,l1);
  1919. if actasmtoken<>AS_SEPARATOR then
  1920. Consume(AS_SEPARATOR);
  1921. end;
  1922. AS_ASCIIZ:
  1923. Begin
  1924. Consume(AS_ASCIIZ);
  1925. BuildStringConstant(TRUE);
  1926. end;
  1927. AS_ASCII:
  1928. Begin
  1929. Consume(AS_ASCII);
  1930. BuildStringConstant(FALSE);
  1931. end;
  1932. AS_LCOMM:
  1933. Begin
  1934. Consume(AS_LCOMM);
  1935. commname:=actasmpattern;
  1936. Consume(AS_ID);
  1937. Consume(AS_COMMA);
  1938. ConcatLocalBss(commname,BuildConstExpression(false,false));
  1939. if actasmtoken<>AS_SEPARATOR then
  1940. Consume(AS_SEPARATOR);
  1941. end;
  1942. AS_COMM:
  1943. Begin
  1944. Consume(AS_COMM);
  1945. commname:=actasmpattern;
  1946. Consume(AS_ID);
  1947. Consume(AS_COMMA);
  1948. ConcatGlobalBss(commname,BuildConstExpression(false,false));
  1949. if actasmtoken<>AS_SEPARATOR then
  1950. Consume(AS_SEPARATOR);
  1951. end;
  1952. AS_OPCODE:
  1953. Begin
  1954. instr:=T386ATTInstruction.Create;
  1955. instr.BuildOpcode;
  1956. instr.AddReferenceSizes;
  1957. instr.SetInstructionOpsize;
  1958. instr.CheckOperandSizes;
  1959. instr.ConcatInstruction(curlist);
  1960. instr.Free;
  1961. end;
  1962. AS_SEPARATOR:
  1963. Begin
  1964. Consume(AS_SEPARATOR);
  1965. end;
  1966. AS_END:
  1967. begin
  1968. break; { end assembly block }
  1969. end;
  1970. else
  1971. Begin
  1972. Message(asmr_e_syntax_error);
  1973. RecoverConsume(false);
  1974. end;
  1975. end;
  1976. until false;
  1977. { Check LocalLabelList }
  1978. LocalLabelList.CheckEmitted;
  1979. LocalLabelList.Free;
  1980. { are we back in the code section? }
  1981. if lastsec<>sec_code then
  1982. begin
  1983. Message(asmr_w_assembler_code_not_returned_to_text);
  1984. curList.Concat(Tai_section.Create(sec_code));
  1985. end;
  1986. { Return the list in an asmnode }
  1987. assemble:=casmnode.create(curlist);
  1988. Message1(asmr_d_finish_reading,'AT&T');
  1989. end;
  1990. {*****************************************************************************
  1991. Initialize
  1992. *****************************************************************************}
  1993. const
  1994. asmmode_i386_att_info : tasmmodeinfo =
  1995. (
  1996. id : asmmode_i386_att;
  1997. idtxt : 'ATT'
  1998. );
  1999. initialization
  2000. RegisterAsmMode(asmmode_i386_att_info);
  2001. finalization
  2002. if assigned(iasmops) then
  2003. iasmops.Free;
  2004. if assigned(iasmregs) then
  2005. dispose(iasmregs);
  2006. end.
  2007. {
  2008. $Log$
  2009. Revision 1.14 2001-08-26 13:37:02 florian
  2010. * some cg reorganisation
  2011. * some PPC updates
  2012. Revision 1.13 2001/08/06 21:40:50 peter
  2013. * funcret moved from tprocinfo to tprocdef
  2014. Revision 1.12 2001/04/18 22:02:03 peter
  2015. * registration of targets and assemblers
  2016. Revision 1.11 2001/04/13 20:06:05 peter
  2017. * allow unit.identifier in asm readers
  2018. Revision 1.10 2001/04/13 18:20:21 peter
  2019. * scanner object to class
  2020. Revision 1.9 2001/04/13 01:22:21 peter
  2021. * symtable change to classes
  2022. * range check generation and errors fixed, make cycle DEBUG=1 works
  2023. * memory leaks fixed
  2024. Revision 1.8 2001/03/25 12:29:45 peter
  2025. * offset_fixup fixes (merged)
  2026. Revision 1.7 2001/03/11 22:58:52 peter
  2027. * getsym redesign, removed the globals srsym,srsymtable
  2028. Revision 1.6 2000/12/25 00:07:34 peter
  2029. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  2030. tlinkedlist objects)
  2031. Revision 1.5 2000/12/07 17:19:46 jonas
  2032. * new constant handling: from now on, hex constants >$7fffffff are
  2033. parsed as unsigned constants (otherwise, $80000000 got sign extended
  2034. and became $ffffffff80000000), all constants in the longint range
  2035. become longints, all constants >$7fffffff and <=cardinal($ffffffff)
  2036. are cardinals and the rest are int64's.
  2037. * added lots of longint typecast to prevent range check errors in the
  2038. compiler and rtl
  2039. * type casts of symbolic ordinal constants are now preserved
  2040. * fixed bug where the original resulttype wasn't restored correctly
  2041. after doing a 64bit rangecheck
  2042. Revision 1.4 2000/11/30 20:27:51 peter
  2043. * merged fix for bug 1229
  2044. Revision 1.3 2000/11/29 00:30:50 florian
  2045. * unused units removed from uses clause
  2046. * some changes for widestrings
  2047. Revision 1.2 2000/10/31 22:02:57 peter
  2048. * symtable splitted, no real code changes
  2049. Revision 1.1 2000/10/15 09:47:43 peter
  2050. * moved to i386/
  2051. Revision 1.6 2000/10/14 10:14:52 peter
  2052. * moehrendorf oct 2000 rewrite
  2053. Revision 1.5 2000/09/24 21:19:51 peter
  2054. * delphi compile fixes
  2055. Revision 1.4 2000/09/24 15:06:26 peter
  2056. * use defines.inc
  2057. Revision 1.3 2000/08/27 16:11:52 peter
  2058. * moved some util functions from globals,cobjects to cutils
  2059. * splitted files into finput,fmodule
  2060. Revision 1.2 2000/07/13 11:32:48 michael
  2061. + removed logs
  2062. }