ra386att.pas 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292
  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. Consume(AS_LPAREN);
  1067. Case actasmtoken of
  1068. AS_INTNUM,
  1069. AS_MINUS,
  1070. AS_PLUS: { absolute offset, such as fs:(0x046c) }
  1071. Begin
  1072. { offset(offset) is invalid }
  1073. If opr.Ref.Offset <> 0 Then
  1074. Begin
  1075. Message(asmr_e_invalid_reference_syntax);
  1076. RecoverConsume(true);
  1077. End
  1078. Else
  1079. Begin
  1080. opr.Ref.Offset:=BuildConstExpression(false,true);
  1081. Consume_RParen;
  1082. end;
  1083. exit;
  1084. End;
  1085. AS_REGISTER: { (reg ... }
  1086. Begin
  1087. { Check if there is already a base (mostly ebp,esp) than this is
  1088. not allowed,becuase it will give crashing code }
  1089. if (opr.ref.base<>NR_NO) then
  1090. message(asmr_e_cannot_index_relative_var);
  1091. opr.ref.base:=actasmregister;
  1092. Consume(AS_REGISTER);
  1093. { can either be a register or a right parenthesis }
  1094. { (reg) }
  1095. if actasmtoken=AS_RPAREN then
  1096. Begin
  1097. Consume_RParen;
  1098. exit;
  1099. end;
  1100. { (reg,reg .. }
  1101. Consume(AS_COMMA);
  1102. if actasmtoken=AS_REGISTER then
  1103. Begin
  1104. opr.ref.index:=actasmregister;
  1105. Consume(AS_REGISTER);
  1106. { check for scaling ... }
  1107. case actasmtoken of
  1108. AS_RPAREN:
  1109. Begin
  1110. Consume_RParen;
  1111. exit;
  1112. end;
  1113. AS_COMMA:
  1114. Begin
  1115. Consume(AS_COMMA);
  1116. Consume_Scale;
  1117. Consume_RParen;
  1118. end;
  1119. else
  1120. Begin
  1121. Message(asmr_e_invalid_reference_syntax);
  1122. RecoverConsume(false);
  1123. end;
  1124. end; { end case }
  1125. end
  1126. else
  1127. Begin
  1128. Message(asmr_e_invalid_reference_syntax);
  1129. RecoverConsume(false);
  1130. end;
  1131. end; {end case }
  1132. AS_COMMA: { (, ... can either be scaling, or index }
  1133. Begin
  1134. Consume(AS_COMMA);
  1135. { Index }
  1136. if (actasmtoken=AS_REGISTER) then
  1137. Begin
  1138. opr.ref.index:=actasmregister;
  1139. Consume(AS_REGISTER);
  1140. { check for scaling ... }
  1141. case actasmtoken of
  1142. AS_RPAREN:
  1143. Begin
  1144. Consume_RParen;
  1145. exit;
  1146. end;
  1147. AS_COMMA:
  1148. Begin
  1149. Consume(AS_COMMA);
  1150. Consume_Scale;
  1151. Consume_RParen;
  1152. end;
  1153. else
  1154. Begin
  1155. Message(asmr_e_invalid_reference_syntax);
  1156. RecoverConsume(false);
  1157. end;
  1158. end; {end case }
  1159. end
  1160. { Scaling }
  1161. else
  1162. Begin
  1163. Consume_Scale;
  1164. Consume_RParen;
  1165. exit;
  1166. end;
  1167. end;
  1168. else
  1169. Begin
  1170. Message(asmr_e_invalid_reference_syntax);
  1171. RecoverConsume(false);
  1172. end;
  1173. end;
  1174. end;
  1175. Procedure T386ATTOperand.BuildConstant;
  1176. var
  1177. l : longint;
  1178. tempstr : string;
  1179. begin
  1180. BuildConstSymbolExpression(false,false,true,l,tempstr);
  1181. if tempstr<>'' then
  1182. begin
  1183. opr.typ:=OPR_SYMBOL;
  1184. opr.symofs:=l;
  1185. opr.symbol:=objectlibrary.newasmsymbol(tempstr);
  1186. end
  1187. else
  1188. begin
  1189. opr.typ:=OPR_CONSTANT;
  1190. opr.val:=l;
  1191. end;
  1192. end;
  1193. Procedure T386ATTOperand.BuildOperand;
  1194. var
  1195. tempstr,tempstr2,
  1196. expr : string;
  1197. l,k : longint;
  1198. procedure AddLabelOperand(hl:tasmlabel);
  1199. begin
  1200. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  1201. is_calljmp(actopcode) then
  1202. begin
  1203. opr.typ:=OPR_SYMBOL;
  1204. opr.symbol:=hl;
  1205. end
  1206. else
  1207. begin
  1208. InitRef;
  1209. opr.ref.symbol:=hl;
  1210. end;
  1211. end;
  1212. procedure MaybeRecordOffset;
  1213. var
  1214. hasdot : boolean;
  1215. l,
  1216. toffset,
  1217. tsize : longint;
  1218. begin
  1219. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  1220. exit;
  1221. l:=0;
  1222. hasdot:=(actasmtoken=AS_DOT);
  1223. if hasdot then
  1224. begin
  1225. if expr<>'' then
  1226. begin
  1227. BuildRecordOffsetSize(expr,toffset,tsize);
  1228. inc(l,toffset);
  1229. SetSize(tsize,true);
  1230. end;
  1231. end;
  1232. if actasmtoken in [AS_PLUS,AS_MINUS] then
  1233. inc(l,BuildConstExpression(true,false));
  1234. case opr.typ of
  1235. OPR_LOCAL :
  1236. begin
  1237. { don't allow direct access to fields of parameters, becuase that
  1238. will generate buggy code. Allow it only for explicit typecasting }
  1239. if hasdot and
  1240. (not hastype) and
  1241. (tvarsym(opr.localsym).owner.symtabletype=parasymtable) and
  1242. (current_procinfo.procdef.proccalloption<>pocall_register) then
  1243. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1244. inc(opr.localsymofs,l)
  1245. end;
  1246. OPR_CONSTANT :
  1247. inc(opr.val,l);
  1248. OPR_REFERENCE :
  1249. inc(opr.ref.offset,l);
  1250. else
  1251. internalerror(200309221);
  1252. end;
  1253. end;
  1254. function MaybeBuildReference:boolean;
  1255. { Try to create a reference, if not a reference is found then false
  1256. is returned }
  1257. begin
  1258. MaybeBuildReference:=true;
  1259. case actasmtoken of
  1260. AS_INTNUM,
  1261. AS_MINUS,
  1262. AS_PLUS:
  1263. Begin
  1264. opr.ref.offset:=BuildConstExpression(True,False);
  1265. if actasmtoken<>AS_LPAREN then
  1266. Message(asmr_e_invalid_reference_syntax)
  1267. else
  1268. BuildReference;
  1269. end;
  1270. AS_LPAREN:
  1271. BuildReference;
  1272. AS_ID: { only a variable is allowed ... }
  1273. Begin
  1274. tempstr:=actasmpattern;
  1275. Consume(AS_ID);
  1276. { typecasting? }
  1277. if (actasmtoken=AS_LPAREN) and
  1278. SearchType(tempstr) then
  1279. begin
  1280. hastype:=true;
  1281. Consume(AS_LPAREN);
  1282. tempstr2:=actasmpattern;
  1283. Consume(AS_ID);
  1284. Consume(AS_RPAREN);
  1285. if not SetupVar(tempstr2,false) then
  1286. Message1(sym_e_unknown_id,tempstr2);
  1287. end
  1288. else
  1289. if not SetupVar(tempstr,false) then
  1290. Message1(sym_e_unknown_id,tempstr);
  1291. { record.field ? }
  1292. if actasmtoken=AS_DOT then
  1293. begin
  1294. BuildRecordOffsetSize(tempstr,l,k);
  1295. inc(opr.ref.offset,l);
  1296. end;
  1297. case actasmtoken of
  1298. AS_END,
  1299. AS_SEPARATOR,
  1300. AS_COMMA: ;
  1301. AS_LPAREN: BuildReference;
  1302. else
  1303. Begin
  1304. Message(asmr_e_invalid_reference_syntax);
  1305. Consume(actasmtoken);
  1306. end;
  1307. end; {end case }
  1308. end;
  1309. else
  1310. MaybeBuildReference:=false;
  1311. end; { end case }
  1312. end;
  1313. const
  1314. regsize_2_size: array[S_B..S_L] of longint = (1,2,4);
  1315. var
  1316. tempreg : tregister;
  1317. hl : tasmlabel;
  1318. Begin
  1319. expr:='';
  1320. case actasmtoken of
  1321. AS_LPAREN: { Memory reference or constant expression }
  1322. Begin
  1323. InitRef;
  1324. BuildReference;
  1325. end;
  1326. AS_DOLLAR: { Constant expression }
  1327. Begin
  1328. Consume(AS_DOLLAR);
  1329. BuildConstant;
  1330. end;
  1331. AS_INTNUM,
  1332. AS_MINUS,
  1333. AS_PLUS:
  1334. Begin
  1335. { Constant memory offset }
  1336. { This must absolutely be followed by ( }
  1337. InitRef;
  1338. opr.ref.offset:=BuildConstExpression(True,False);
  1339. if actasmtoken<>AS_LPAREN then
  1340. Message(asmr_e_invalid_reference_syntax)
  1341. else
  1342. BuildReference;
  1343. end;
  1344. AS_STAR: { Call from memory address }
  1345. Begin
  1346. Consume(AS_STAR);
  1347. if actasmtoken=AS_REGISTER then
  1348. begin
  1349. opr.typ:=OPR_REGISTER;
  1350. opr.reg:=actasmregister;
  1351. SetSize(regsize_2_size[reg2opsize(actasmregister)],true);
  1352. Consume(AS_REGISTER);
  1353. end
  1354. else
  1355. begin
  1356. InitRef;
  1357. if not MaybeBuildReference then
  1358. Message(asmr_e_syn_operand);
  1359. end;
  1360. { this is only allowed for call's and jmp's }
  1361. if not is_calljmp(actopcode) then
  1362. Message(asmr_e_syn_operand);
  1363. end;
  1364. AS_ID: { A constant expression, or a Variable ref. }
  1365. Begin
  1366. { Local Label ? }
  1367. if is_locallabel(actasmpattern) then
  1368. begin
  1369. CreateLocalLabel(actasmpattern,hl,false);
  1370. Consume(AS_ID);
  1371. AddLabelOperand(hl);
  1372. end
  1373. else
  1374. { Check for label }
  1375. if SearchLabel(actasmpattern,hl,false) then
  1376. begin
  1377. Consume(AS_ID);
  1378. AddLabelOperand(hl);
  1379. end
  1380. else
  1381. { probably a variable or normal expression }
  1382. { or a procedure (such as in CALL ID) }
  1383. Begin
  1384. { is it a constant ? }
  1385. if SearchIConstant(actasmpattern,l) then
  1386. Begin
  1387. if not (opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1388. Message(asmr_e_invalid_operand_type);
  1389. BuildConstant;
  1390. end
  1391. else
  1392. begin
  1393. InitRef;
  1394. expr:=actasmpattern;
  1395. Consume(AS_ID);
  1396. { typecasting? }
  1397. if (actasmtoken=AS_LPAREN) and
  1398. SearchType(expr) then
  1399. begin
  1400. hastype:=true;
  1401. Consume(AS_LPAREN);
  1402. tempstr:=actasmpattern;
  1403. Consume(AS_ID);
  1404. Consume(AS_RPAREN);
  1405. if SetupVar(tempstr,false) then
  1406. begin
  1407. MaybeRecordOffset;
  1408. { add a constant expression? }
  1409. if (actasmtoken=AS_PLUS) then
  1410. begin
  1411. l:=BuildConstExpression(true,false);
  1412. if opr.typ=OPR_CONSTANT then
  1413. inc(opr.val,l)
  1414. else
  1415. inc(opr.ref.offset,l);
  1416. end
  1417. end
  1418. else
  1419. Message1(sym_e_unknown_id,tempstr);
  1420. end
  1421. else
  1422. begin
  1423. if SetupVar(expr,false) then
  1424. begin
  1425. MaybeRecordOffset;
  1426. { add a constant expression? }
  1427. if (actasmtoken=AS_PLUS) then
  1428. begin
  1429. l:=BuildConstExpression(true,false);
  1430. case opr.typ of
  1431. OPR_CONSTANT :
  1432. inc(opr.val,l);
  1433. OPR_LOCAL :
  1434. inc(opr.localsymofs,l);
  1435. OPR_REFERENCE :
  1436. inc(opr.ref.offset,l);
  1437. else
  1438. internalerror(200309202);
  1439. end;
  1440. end
  1441. end
  1442. else
  1443. Begin
  1444. { look for special symbols ... }
  1445. if expr = '__RESULT' then
  1446. SetUpResult
  1447. else
  1448. if expr = '__SELF' then
  1449. SetupSelf
  1450. else
  1451. if expr = '__OLDEBP' then
  1452. SetupOldEBP
  1453. else
  1454. { check for direct symbolic names }
  1455. { only if compiling the system unit }
  1456. if (cs_compilesystem in aktmoduleswitches) then
  1457. begin
  1458. if not SetupDirectVar(expr) then
  1459. Begin
  1460. { not found, finally ... add it anyways ... }
  1461. Message1(asmr_w_id_supposed_external,expr);
  1462. opr.ref.symbol:=objectlibrary.newasmsymbol(expr);
  1463. end;
  1464. end
  1465. else
  1466. Message1(sym_e_unknown_id,expr);
  1467. end;
  1468. end;
  1469. end;
  1470. end;
  1471. { Do we have a indexing reference, then parse it also }
  1472. if actasmtoken=AS_LPAREN then
  1473. begin
  1474. if (opr.typ=OPR_CONSTANT) then
  1475. begin
  1476. l:=opr.val;
  1477. opr.typ:=OPR_REFERENCE;
  1478. Fillchar(opr.ref,sizeof(treference),0);
  1479. opr.Ref.Offset:=l;
  1480. end;
  1481. BuildReference;
  1482. end;
  1483. end;
  1484. AS_REGISTER: { Register, a variable reference or a constant reference }
  1485. Begin
  1486. { save the type of register used. }
  1487. tempreg:=actasmregister;
  1488. Consume(AS_REGISTER);
  1489. if actasmtoken = AS_COLON then
  1490. Begin
  1491. Consume(AS_COLON);
  1492. InitRef;
  1493. opr.ref.segment:=tempreg;
  1494. { This must absolutely be followed by a reference }
  1495. if not MaybeBuildReference then
  1496. Begin
  1497. Message(asmr_e_invalid_seg_override);
  1498. Consume(actasmtoken);
  1499. end;
  1500. end
  1501. { Simple register }
  1502. else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  1503. Begin
  1504. if not (opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1505. Message(asmr_e_invalid_operand_type);
  1506. opr.typ:=OPR_REGISTER;
  1507. opr.reg:=tempreg;
  1508. SetSize(tcgsize2size[cg.reg_cgsize(opr.reg)],true);
  1509. end
  1510. else
  1511. Message(asmr_e_syn_operand);
  1512. end;
  1513. AS_END,
  1514. AS_SEPARATOR,
  1515. AS_COMMA: ;
  1516. else
  1517. Begin
  1518. Message(asmr_e_syn_operand);
  1519. Consume(actasmtoken);
  1520. end;
  1521. end; { end case }
  1522. end;
  1523. {*****************************************************************************
  1524. T386ATTInstruction
  1525. *****************************************************************************}
  1526. type
  1527. T386AttInstruction=class(T386Instruction)
  1528. procedure InitOperands;override;
  1529. procedure BuildOpcode;override;
  1530. end;
  1531. procedure T386AttInstruction.InitOperands;
  1532. var
  1533. i : longint;
  1534. begin
  1535. OpOrder:=op_att;
  1536. for i:=1to max_operands do
  1537. Operands[i]:=T386AttOperand.Create;
  1538. end;
  1539. Procedure T386AttInstruction.BuildOpCode;
  1540. var
  1541. operandnum : longint;
  1542. PrefixOp,OverrideOp: tasmop;
  1543. Begin
  1544. PrefixOp:=A_None;
  1545. OverrideOp:=A_None;
  1546. { prefix seg opcode / prefix opcode }
  1547. repeat
  1548. if is_prefix(actopcode) then
  1549. begin
  1550. PrefixOp:=ActOpcode;
  1551. opcode:=ActOpcode;
  1552. condition:=ActCondition;
  1553. opsize:=ActOpsize;
  1554. ConcatInstruction(curlist);
  1555. Consume(AS_OPCODE);
  1556. end
  1557. else
  1558. if is_override(actopcode) then
  1559. begin
  1560. OverrideOp:=ActOpcode;
  1561. opcode:=ActOpcode;
  1562. condition:=ActCondition;
  1563. opsize:=ActOpsize;
  1564. ConcatInstruction(curlist);
  1565. Consume(AS_OPCODE);
  1566. end
  1567. else
  1568. break;
  1569. { allow for newline as in gas styled syntax }
  1570. while actasmtoken=AS_SEPARATOR do
  1571. Consume(AS_SEPARATOR);
  1572. until (actasmtoken<>AS_OPCODE);
  1573. { opcode }
  1574. if (actasmtoken <> AS_OPCODE) then
  1575. Begin
  1576. Message(asmr_e_invalid_or_missing_opcode);
  1577. RecoverConsume(true);
  1578. exit;
  1579. end;
  1580. { Fill the instr object with the current state }
  1581. Opcode:=ActOpcode;
  1582. condition:=ActCondition;
  1583. opsize:=ActOpsize;
  1584. { Valid combination of prefix/override and instruction ? }
  1585. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1586. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1587. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1588. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1589. { We are reading operands, so opcode will be an AS_ID }
  1590. operandnum:=1;
  1591. Consume(AS_OPCODE);
  1592. { Zero operand opcode ? }
  1593. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1594. begin
  1595. operandnum:=0;
  1596. exit;
  1597. end;
  1598. { Read the operands }
  1599. repeat
  1600. case actasmtoken of
  1601. AS_COMMA: { Operand delimiter }
  1602. Begin
  1603. if operandnum > Max_Operands then
  1604. Message(asmr_e_too_many_operands)
  1605. else
  1606. Inc(operandnum);
  1607. Consume(AS_COMMA);
  1608. end;
  1609. AS_SEPARATOR,
  1610. AS_END : { End of asm operands for this opcode }
  1611. begin
  1612. break;
  1613. end;
  1614. else
  1615. Operands[operandnum].BuildOperand;
  1616. end; { end case }
  1617. until false;
  1618. Ops:=operandnum;
  1619. end;
  1620. Procedure BuildConstant(maxvalue: longint);
  1621. var
  1622. asmsym,
  1623. expr: string;
  1624. value : longint;
  1625. Begin
  1626. Repeat
  1627. Case actasmtoken of
  1628. AS_STRING:
  1629. Begin
  1630. expr:=actasmpattern;
  1631. if length(expr) > 1 then
  1632. Message(asmr_e_string_not_allowed_as_const);
  1633. Consume(AS_STRING);
  1634. Case actasmtoken of
  1635. AS_COMMA: Consume(AS_COMMA);
  1636. AS_END,
  1637. AS_SEPARATOR: ;
  1638. else
  1639. Message(asmr_e_invalid_string_expression);
  1640. end; { end case }
  1641. ConcatString(curlist,expr);
  1642. end;
  1643. AS_INTNUM,
  1644. AS_PLUS,
  1645. AS_MINUS,
  1646. AS_LPAREN,
  1647. AS_NOT,
  1648. AS_ID :
  1649. Begin
  1650. BuildConstSymbolExpression(false,false,false,value,asmsym);
  1651. if asmsym<>'' then
  1652. begin
  1653. if maxvalue<>longint($ffffffff) then
  1654. Message(asmr_w_32bit_const_for_address);
  1655. ConcatConstSymbol(curlist,asmsym,value)
  1656. end
  1657. else
  1658. ConcatConstant(curlist,value,maxvalue);
  1659. end;
  1660. AS_COMMA:
  1661. Consume(AS_COMMA);
  1662. AS_END,
  1663. AS_SEPARATOR:
  1664. break;
  1665. else
  1666. begin
  1667. Message(asmr_e_syn_constant);
  1668. RecoverConsume(false);
  1669. end
  1670. end; { end case }
  1671. Until false;
  1672. end;
  1673. Procedure BuildRealConstant(typ : tfloattype);
  1674. var
  1675. expr : string;
  1676. r : bestreal;
  1677. code : integer;
  1678. negativ : boolean;
  1679. errorflag: boolean;
  1680. Begin
  1681. errorflag:=FALSE;
  1682. Repeat
  1683. negativ:=false;
  1684. expr:='';
  1685. if actasmtoken=AS_PLUS then
  1686. Consume(AS_PLUS)
  1687. else
  1688. if actasmtoken=AS_MINUS then
  1689. begin
  1690. negativ:=true;
  1691. consume(AS_MINUS);
  1692. end;
  1693. Case actasmtoken of
  1694. AS_INTNUM:
  1695. Begin
  1696. expr:=actasmpattern;
  1697. Consume(AS_INTNUM);
  1698. if negativ then
  1699. expr:='-'+expr;
  1700. val(expr,r,code);
  1701. if code<>0 then
  1702. Begin
  1703. r:=0;
  1704. Message(asmr_e_invalid_float_expr);
  1705. End;
  1706. ConcatRealConstant(curlist,r,typ);
  1707. end;
  1708. AS_REALNUM:
  1709. Begin
  1710. expr:=actasmpattern;
  1711. Consume(AS_REALNUM);
  1712. { in ATT syntax you have 0d in front of the real }
  1713. { should this be forced ? yes i think so, as to }
  1714. { conform to gas as much as possible. }
  1715. if (expr[1]='0') and (upper(expr[2])='D') then
  1716. Delete(expr,1,2);
  1717. if negativ then
  1718. expr:='-'+expr;
  1719. val(expr,r,code);
  1720. if code<>0 then
  1721. Begin
  1722. r:=0;
  1723. Message(asmr_e_invalid_float_expr);
  1724. End;
  1725. ConcatRealConstant(curlist,r,typ);
  1726. end;
  1727. AS_COMMA:
  1728. begin
  1729. Consume(AS_COMMA);
  1730. end;
  1731. AS_END,
  1732. AS_SEPARATOR:
  1733. begin
  1734. break;
  1735. end;
  1736. else
  1737. Begin
  1738. Consume(actasmtoken);
  1739. if not errorflag then
  1740. Message(asmr_e_invalid_float_expr);
  1741. errorflag:=TRUE;
  1742. end;
  1743. end;
  1744. Until false;
  1745. end;
  1746. Procedure BuildStringConstant(asciiz: boolean);
  1747. var
  1748. expr: string;
  1749. errorflag : boolean;
  1750. Begin
  1751. errorflag:=FALSE;
  1752. Repeat
  1753. Case actasmtoken of
  1754. AS_STRING:
  1755. Begin
  1756. expr:=actasmpattern;
  1757. if asciiz then
  1758. expr:=expr+#0;
  1759. ConcatPasString(curlist,expr);
  1760. Consume(AS_STRING);
  1761. end;
  1762. AS_COMMA:
  1763. begin
  1764. Consume(AS_COMMA);
  1765. end;
  1766. AS_END,
  1767. AS_SEPARATOR:
  1768. begin
  1769. break;
  1770. end;
  1771. else
  1772. Begin
  1773. Consume(actasmtoken);
  1774. if not errorflag then
  1775. Message(asmr_e_invalid_string_expression);
  1776. errorflag:=TRUE;
  1777. end;
  1778. end;
  1779. Until false;
  1780. end;
  1781. Function Assemble: tnode;
  1782. Var
  1783. hl : tasmlabel;
  1784. commname : string;
  1785. lasTSec : TSection;
  1786. l1,l2 : longint;
  1787. instr : T386ATTInstruction;
  1788. Begin
  1789. Message1(asmr_d_start_reading,'AT&T');
  1790. firsttoken:=TRUE;
  1791. { sets up all opcode and register tables in uppercase }
  1792. if not _asmsorted then
  1793. Begin
  1794. SetupTables;
  1795. _asmsorted:=TRUE;
  1796. end;
  1797. curlist:=TAAsmoutput.Create;
  1798. lasTSec:=sec_code;
  1799. { setup label linked list }
  1800. LocalLabelList:=TLocalLabelList.Create;
  1801. { start tokenizer }
  1802. c:=current_scanner.asmgetchar;
  1803. gettoken;
  1804. { main loop }
  1805. repeat
  1806. case actasmtoken of
  1807. AS_LLABEL:
  1808. Begin
  1809. if CreateLocalLabel(actasmpattern,hl,true) then
  1810. ConcatLabel(curlist,hl);
  1811. Consume(AS_LLABEL);
  1812. end;
  1813. AS_LABEL:
  1814. Begin
  1815. if SearchLabel(upper(actasmpattern),hl,true) then
  1816. ConcatLabel(curlist,hl)
  1817. else
  1818. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1819. Consume(AS_LABEL);
  1820. end;
  1821. AS_DW:
  1822. Begin
  1823. Consume(AS_DW);
  1824. BuildConstant($ffff);
  1825. end;
  1826. AS_DATA:
  1827. Begin
  1828. curList.Concat(Tai_section.Create(sec_data));
  1829. lasTSec:=sec_data;
  1830. Consume(AS_DATA);
  1831. end;
  1832. AS_TEXT:
  1833. Begin
  1834. curList.Concat(Tai_section.Create(sec_code));
  1835. lasTSec:=sec_code;
  1836. Consume(AS_TEXT);
  1837. end;
  1838. AS_DB:
  1839. Begin
  1840. Consume(AS_DB);
  1841. BuildConstant($ff);
  1842. end;
  1843. AS_DD:
  1844. Begin
  1845. Consume(AS_DD);
  1846. BuildConstant(longint($ffffffff));
  1847. end;
  1848. AS_DQ:
  1849. Begin
  1850. Consume(AS_DQ);
  1851. BuildRealConstant(s64comp);
  1852. end;
  1853. AS_SINGLE:
  1854. Begin
  1855. Consume(AS_SINGLE);
  1856. BuildRealConstant(s32real);
  1857. end;
  1858. AS_DOUBLE:
  1859. Begin
  1860. Consume(AS_DOUBLE);
  1861. BuildRealConstant(s64real);
  1862. end;
  1863. AS_EXTENDED:
  1864. Begin
  1865. Consume(AS_EXTENDED);
  1866. BuildRealConstant(s80real);
  1867. end;
  1868. AS_GLOBAL:
  1869. Begin
  1870. Consume(AS_GLOBAL);
  1871. if actasmtoken=AS_ID then
  1872. ConcatPublic(curlist,actasmpattern);
  1873. Consume(AS_ID);
  1874. if actasmtoken<>AS_SEPARATOR then
  1875. Consume(AS_SEPARATOR);
  1876. end;
  1877. AS_ALIGN:
  1878. Begin
  1879. Consume(AS_ALIGN);
  1880. l1:=BuildConstExpression(false,false);
  1881. if (target_info.system in [system_i386_GO32V2]) then
  1882. begin
  1883. l2:=1;
  1884. if (l1>=0) and (l1<=16) then
  1885. while (l1>0) do
  1886. begin
  1887. l2:=2*l2;
  1888. dec(l1);
  1889. end;
  1890. l1:=l2;
  1891. end;
  1892. ConcatAlign(curlist,l1);
  1893. Message(asmr_n_align_is_target_specific);
  1894. if actasmtoken<>AS_SEPARATOR then
  1895. Consume(AS_SEPARATOR);
  1896. end;
  1897. AS_BALIGN:
  1898. Begin
  1899. Consume(AS_BALIGN);
  1900. ConcatAlign(curlist,BuildConstExpression(false,false));
  1901. if actasmtoken<>AS_SEPARATOR then
  1902. Consume(AS_SEPARATOR);
  1903. end;
  1904. AS_P2ALIGN:
  1905. Begin
  1906. Consume(AS_P2ALIGN);
  1907. l1:=BuildConstExpression(false,false);
  1908. l2:=1;
  1909. if (l1>=0) and (l1<=16) then
  1910. while (l1>0) do
  1911. begin
  1912. l2:=2*l2;
  1913. dec(l1);
  1914. end;
  1915. l1:=l2;
  1916. ConcatAlign(curlist,l1);
  1917. if actasmtoken<>AS_SEPARATOR then
  1918. Consume(AS_SEPARATOR);
  1919. end;
  1920. AS_ASCIIZ:
  1921. Begin
  1922. Consume(AS_ASCIIZ);
  1923. BuildStringConstant(TRUE);
  1924. end;
  1925. AS_ASCII:
  1926. Begin
  1927. Consume(AS_ASCII);
  1928. BuildStringConstant(FALSE);
  1929. end;
  1930. AS_LCOMM:
  1931. Begin
  1932. Consume(AS_LCOMM);
  1933. commname:=actasmpattern;
  1934. Consume(AS_ID);
  1935. Consume(AS_COMMA);
  1936. ConcatLocalBss(commname,BuildConstExpression(false,false));
  1937. if actasmtoken<>AS_SEPARATOR then
  1938. Consume(AS_SEPARATOR);
  1939. end;
  1940. AS_COMM:
  1941. Begin
  1942. Consume(AS_COMM);
  1943. commname:=actasmpattern;
  1944. Consume(AS_ID);
  1945. Consume(AS_COMMA);
  1946. ConcatGlobalBss(commname,BuildConstExpression(false,false));
  1947. if actasmtoken<>AS_SEPARATOR then
  1948. Consume(AS_SEPARATOR);
  1949. end;
  1950. AS_OPCODE:
  1951. Begin
  1952. instr:=T386ATTInstruction.Create;
  1953. instr.BuildOpcode;
  1954. instr.AddReferenceSizes;
  1955. instr.SetInstructionOpsize;
  1956. instr.CheckOperandSizes;
  1957. instr.ConcatInstruction(curlist);
  1958. instr.Free;
  1959. end;
  1960. AS_SEPARATOR:
  1961. Begin
  1962. Consume(AS_SEPARATOR);
  1963. end;
  1964. AS_END:
  1965. begin
  1966. break; { end assembly block }
  1967. end;
  1968. else
  1969. Begin
  1970. Message(asmr_e_syntax_error);
  1971. RecoverConsume(false);
  1972. end;
  1973. end;
  1974. until false;
  1975. { Check LocalLabelList }
  1976. LocalLabelList.CheckEmitted;
  1977. LocalLabelList.Free;
  1978. { are we back in the code section? }
  1979. if lasTSec<>sec_code then
  1980. begin
  1981. Message(asmr_w_assembler_code_not_returned_to_text);
  1982. curList.Concat(Tai_section.Create(sec_code));
  1983. end;
  1984. { Return the list in an asmnode }
  1985. assemble:=casmnode.create(curlist);
  1986. Message1(asmr_d_finish_reading,'AT&T');
  1987. end;
  1988. {*****************************************************************************
  1989. Initialize
  1990. *****************************************************************************}
  1991. const
  1992. asmmode_i386_att_info : tasmmodeinfo =
  1993. (
  1994. id : asmmode_i386_att;
  1995. idtxt : 'ATT'
  1996. );
  1997. initialization
  1998. RegisterAsmMode(asmmode_i386_att_info);
  1999. finalization
  2000. if assigned(iasmops) then
  2001. iasmops.Free;
  2002. end.
  2003. {
  2004. $Log$
  2005. Revision 1.50 2003-10-07 18:21:18 peter
  2006. * fix crash
  2007. * allow parameter subscription for register parameters
  2008. Revision 1.49 2003/10/01 20:34:49 peter
  2009. * procinfo unit contains tprocinfo
  2010. * cginfo renamed to cgbase
  2011. * moved cgmessage to verbose
  2012. * fixed ppc and sparc compiles
  2013. Revision 1.48 2003/09/23 20:37:53 peter
  2014. * fix global var+offset
  2015. Revision 1.47 2003/09/23 17:56:06 peter
  2016. * locals and paras are allocated in the code generation
  2017. * tvarsym.localloc contains the location of para/local when
  2018. generating code for the current procedure
  2019. Revision 1.46 2003/09/03 15:55:01 peter
  2020. * NEWRA branch merged
  2021. Revision 1.45.2.2 2003/08/31 15:46:26 peter
  2022. * more updates for tregister
  2023. Revision 1.45.2.1 2003/08/28 18:35:08 peter
  2024. * tregister changed to cardinal
  2025. Revision 1.45 2003/05/30 23:57:08 peter
  2026. * more sparc cleanup
  2027. * accumulator removed, splitted in function_return_reg (called) and
  2028. function_result_reg (caller)
  2029. Revision 1.44 2003/05/22 21:32:29 peter
  2030. * removed some unit dependencies
  2031. Revision 1.43 2003/04/30 15:45:35 florian
  2032. * merged more x86-64/i386 code
  2033. Revision 1.42 2003/04/25 12:04:31 florian
  2034. * merged agx64att and ag386att to x86/agx86att
  2035. Revision 1.41 2003/04/21 20:05:10 peter
  2036. * removed some ie checks
  2037. Revision 1.40 2003/03/18 18:15:53 peter
  2038. * changed reg2opsize to function
  2039. Revision 1.39 2003/02/20 15:52:58 pierre
  2040. * fix a range check error
  2041. Revision 1.38 2003/02/19 22:00:16 daniel
  2042. * Code generator converted to new register notation
  2043. - Horribily outdated todo.txt removed
  2044. Revision 1.37 2003/02/03 22:47:14 daniel
  2045. - Removed reg_2_opsize array
  2046. Revision 1.36 2003/01/08 18:43:57 daniel
  2047. * Tregister changed into a record
  2048. Revision 1.35 2002/12/14 15:02:03 carl
  2049. * maxoperands -> max_operands (for portability in rautils.pas)
  2050. * fix some range-check errors with loadconst
  2051. + add ncgadd unit to m68k
  2052. * some bugfix of a_param_reg with LOC_CREFERENCE
  2053. Revision 1.34 2002/12/01 22:08:34 carl
  2054. * some small cleanup (remove some specific operators which are not supported)
  2055. Revision 1.33 2002/11/30 23:16:39 carl
  2056. - removed unused message
  2057. Revision 1.32 2002/11/15 01:58:58 peter
  2058. * merged changes from 1.0.7 up to 04-11
  2059. - -V option for generating bug report tracing
  2060. - more tracing for option parsing
  2061. - errors for cdecl and high()
  2062. - win32 import stabs
  2063. - win32 records<=8 are returned in eax:edx (turned off by default)
  2064. - heaptrc update
  2065. - more info for temp management in .s file with EXTDEBUG
  2066. Revision 1.31 2002/09/03 16:26:28 daniel
  2067. * Make Tprocdef.defs protected
  2068. Revision 1.30 2002/08/13 18:01:52 carl
  2069. * rename swatoperands to swapoperands
  2070. + m68k first compilable version (still needs a lot of testing):
  2071. assembler generator, system information , inline
  2072. assembler reader.
  2073. Revision 1.29 2002/08/12 15:08:42 carl
  2074. + stab register indexes for powerpc (moved from gdb to cpubase)
  2075. + tprocessor enumeration moved to cpuinfo
  2076. + linker in target_info is now a class
  2077. * many many updates for m68k (will soon start to compile)
  2078. - removed some ifdef or correct them for correct cpu
  2079. Revision 1.28 2002/08/11 14:32:31 peter
  2080. * renamed current_library to objectlibrary
  2081. Revision 1.27 2002/08/11 13:24:17 peter
  2082. * saving of asmsymbols in ppu supported
  2083. * asmsymbollist global is removed and moved into a new class
  2084. tasmlibrarydata that will hold the info of a .a file which
  2085. corresponds with a single module. Added librarydata to tmodule
  2086. to keep the library info stored for the module. In the future the
  2087. objectfiles will also be stored to the tasmlibrarydata class
  2088. * all getlabel/newasmsymbol and friends are moved to the new class
  2089. Revision 1.26 2002/07/26 21:15:44 florian
  2090. * rewrote the system handling
  2091. Revision 1.25 2002/07/01 18:46:34 peter
  2092. * internal linker
  2093. * reorganized aasm layer
  2094. Revision 1.24 2002/05/18 13:34:25 peter
  2095. * readded missing revisions
  2096. Revision 1.23 2002/05/16 19:46:52 carl
  2097. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2098. + try to fix temp allocation (still in ifdef)
  2099. + generic constructor calls
  2100. + start of tassembler / tmodulebase class cleanup
  2101. Revision 1.21 2002/04/15 19:12:09 carl
  2102. + target_info.size_of_pointer -> pointer_size
  2103. + some cleanup of unused types/variables
  2104. * move several constants from cpubase to their specific units
  2105. (where they are used)
  2106. + att_Reg2str -> gas_reg2str
  2107. + int_reg2str -> std_reg2str
  2108. Revision 1.20 2002/04/14 17:01:52 carl
  2109. + att_reg2str -> gas_reg2str
  2110. Revision 1.19 2002/04/04 19:06:13 peter
  2111. * removed unused units
  2112. * use tlocation.size in cg.a_*loc*() routines
  2113. Revision 1.18 2002/04/02 17:11:39 peter
  2114. * tlocation,treference update
  2115. * LOC_CONSTANT added for better constant handling
  2116. * secondadd splitted in multiple routines
  2117. * location_force_reg added for loading a location to a register
  2118. of a specified size
  2119. * secondassignment parses now first the right and then the left node
  2120. (this is compatible with Kylix). This saves a lot of push/pop especially
  2121. with string operations
  2122. * adapted some routines to use the new cg methods
  2123. Revision 1.17 2002/03/28 20:48:25 carl
  2124. - remove go32v1 support
  2125. Revision 1.16 2002/01/24 18:25:53 peter
  2126. * implicit result variable generation for assembler routines
  2127. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2128. }