ra386att.pas 59 KB

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