ra386att.pas 63 KB

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