ppudump.pp 166 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237
  1. {
  2. Copyright (c) 1998-2020 by the FPC Development Team
  3. Dumps the contents of a FPC unit file (PPU File)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. program ppudump;
  17. {$i fpcdefs.inc}
  18. {$H+}
  19. {$packenum 1}
  20. {$define IN_PPUDUMP}
  21. uses
  22. { do NOT add symconst or globtype to make merging easier }
  23. { do include symconst and globtype now before splitting 2.5 PM 2011-06-15 }
  24. cutils,
  25. SysUtils,
  26. constexp,
  27. symconst,
  28. ppu,
  29. entfile,
  30. systems,
  31. cpuinfo,
  32. globals,
  33. globtype,
  34. widestr,
  35. tokens,
  36. version,
  37. ppuout,
  38. ppujson,
  39. ppuxml;
  40. const
  41. Title = 'PPU-Analyser';
  42. Copyright = 'Copyright (c) 1998-2020 by the Free Pascal Development Team';
  43. { verbosity }
  44. v_none = $0;
  45. v_header = $1;
  46. v_defs = $2;
  47. v_syms = $4;
  48. v_interface = $8;
  49. v_implementation = $10;
  50. // v_browser = $20;
  51. v_all = $ff;
  52. { not needed anymore $i systems.inc }
  53. { List of all supported cpus }
  54. const
  55. CpuTxt : array[tsystemcpu] of string[16]=
  56. (
  57. { 0 } 'none',
  58. { 1 } 'i386',
  59. { 2 } 'm68k',
  60. { 3 } 'alpha (obsolete)',
  61. { 4 } 'powerpc',
  62. { 5 } 'sparc',
  63. { 6 } 'vis (obsolete)',
  64. { 7 } 'ia64 (obsolete)',
  65. { 8 } 'x86_64',
  66. { 9 } 'mipseb',
  67. { 10 } 'arm',
  68. { 11 } 'powerpc64',
  69. { 12 } 'avr',
  70. { 13 } 'mipsel',
  71. { 14 } 'jvm',
  72. { 15 } 'i8086',
  73. { 16 } 'aarch64',
  74. { 17 } 'wasm32',
  75. { 18 } 'sparc64',
  76. { 19 } 'riscv32',
  77. { 20 } 'riscv64',
  78. { 21 } 'xtensa',
  79. { 22 } 'z80'
  80. );
  81. CpuHasController : array[tsystemcpu] of boolean =
  82. (
  83. { 0 } false {'none'},
  84. { 1 } false {'i386'},
  85. { 2 } false {'m68k'},
  86. { 3 } false {'alpha (obsolete)'},
  87. { 4 } false {'powerpc'},
  88. { 5 } false {'sparc'},
  89. { 6 } false {'vis (obsolete)'},
  90. { 7 } false {'ia64 (obsolete)'},
  91. { 8 } false {'x86_64'},
  92. { 9 } false {'mipseb'},
  93. { 10 } true {'arm'},
  94. { 11 } false {'powerpc64'},
  95. { 12 } true {'avr'},
  96. { 13 } true {'mipsel'},
  97. { 14 } false {'jvm'},
  98. { 15 } false {'i8086'},
  99. { 16 } false {'aarch64'},
  100. { 17 } false {'wasm32'},
  101. { 18 } false {'sparc64'},
  102. { 19 } false {'riscv32'},
  103. { 20 } false {'riscv64'},
  104. { 21 } true {'xtensa'},
  105. { 22 } true {'z80'}
  106. );
  107. { List of all supported system-cpu couples }
  108. const
  109. Targets : array[tsystem] of string[26]=(
  110. { 0 } 'none',
  111. { 1 } 'GO32V1 (obsolete)',
  112. { 2 } 'GO32V2',
  113. { 3 } 'Linux-i386',
  114. { 4 } 'OS/2',
  115. { 5 } 'Win32',
  116. { 6 } 'FreeBSD-i386',
  117. { 7 } 'Amiga',
  118. { 8 } 'Atari',
  119. { 9 } 'MacOSClassic-m68k',
  120. { 10 } 'Linux-m68k',
  121. { 11 } 'PalmOS-m68k',
  122. { 12 } 'Linux-alpha (obsolete)',
  123. { 13 } 'Linux-ppc',
  124. { 14 } 'MacOSClassic-ppc',
  125. { 15 } 'Solaris-i386',
  126. { 16 } 'BeOS-i386',
  127. { 17 } 'NetBSD-i386',
  128. { 18 } 'NetBSD-m68k',
  129. { 19 } 'Netware-i386-clib',
  130. { 20 } 'Qnx-i386',
  131. { 21 } 'WDOSX-i386',
  132. { 22 } 'Solaris-sparc',
  133. { 23 } 'Linux-sparc',
  134. { 24 } 'OpenBSD-i386',
  135. { 25 } 'OpenBSD-m68k (obsolete)',
  136. { 26 } 'Linux-x86-64',
  137. { 27 } 'Darwin-ppc',
  138. { 28 } 'OS/2 via EMX',
  139. { 29 } 'NetBSD-powerpc',
  140. { 30 } 'OpenBSD-powerpc',
  141. { 31 } 'Linux-arm',
  142. { 32 } 'Watcom-i386',
  143. { 33 } 'MorphOS-powerpc',
  144. { 34 } 'FreeBSD-x86-64',
  145. { 35 } 'Netware-i386-libc',
  146. { 36 } 'Amiga-PowerPC',
  147. { 37 } 'Win64-x64',
  148. { 38 } 'WinCE-ARM',
  149. { 39 } 'Win64-iA64 (obsolete)',
  150. { 40 } 'WinCE-i386',
  151. { 41 } 'Linux-x64',
  152. { 42 } 'GBA-arm',
  153. { 43 } 'Linux-powerpc64',
  154. { 44 } 'Darwin-i386',
  155. { 45 } 'PalmOS-arm',
  156. { 46 } 'Darwin-powerpc64',
  157. { 47 } 'NDS-arm',
  158. { 48 } 'Embedded-i386',
  159. { 49 } 'Embedded-m68k',
  160. { 50 } 'Embedded-alpha (obsolete)',
  161. { 51 } 'Embedded-powerpc',
  162. { 52 } 'Embedded-sparc',
  163. { 53 } 'Embedded-vm (obsolete)',
  164. { 54 } 'Embedded-iA64 (obsolete)',
  165. { 55 } 'Embedded-x64',
  166. { 56 } 'Embedded-mips',
  167. { 57 } 'Embedded-arm',
  168. { 58 } 'Embedded-powerpc64',
  169. { 59 } 'Symbian-i386',
  170. { 60 } 'Symbian-arm',
  171. { 61 } 'Darwin-x64',
  172. { 62 } 'Embedded-avr',
  173. { 63 } 'Haiku-i386',
  174. { 64 } 'iOS-ARM',
  175. { 65 } 'Solaris-x86-64',
  176. { 66 } 'Linux-MIPS',
  177. { 67 } 'Linux-MIPSel',
  178. { 68 } 'NativeNT-i386',
  179. { 69 } 'iPhoneSim-i386',
  180. { 70 } 'Wii-powerpc',
  181. { 71 } 'OpenBSD-x86-64',
  182. { 72 } 'NetBSD-x86-64',
  183. { 73 } 'AIX-powerpc',
  184. { 74 } 'AIX-powerpc64',
  185. { 75 } 'Java-JVM',
  186. { 76 } 'Android-JVM',
  187. { 77 } 'Android-arm',
  188. { 78 } 'Android-i386',
  189. { 79 } 'MSDOS-i8086',
  190. { 80 } 'Android-MIPSel',
  191. { 81 } 'Embedded-mipseb',
  192. { 82 } 'Embedded-mipsel',
  193. { 83 } 'AROS-i386',
  194. { 84 } 'AROS-x86-64',
  195. { 85 } 'DragonFly-x86-64',
  196. { 86 } 'iOS-AArch64',
  197. { 87 } 'iPhoneSim-x86-64',
  198. { 88 } 'Linux-AArch64',
  199. { 89 } 'Win16',
  200. { 90 } 'Embedded-i8086',
  201. { 91 } 'AROS-arm',
  202. { 92 } 'WebAssembly-wasm',
  203. { 93 } 'Linux-sparc64',
  204. { 94 } 'Solaris-sparc64',
  205. { 95 } 'NetBSD-arm',
  206. { 96 } 'Linux-RiscV32',
  207. { 97 } 'Linux-RiscV64',
  208. { 98 } 'Embedded-RiscV32',
  209. { 99 } 'Embedded-RiscV64',
  210. { 100 } 'Android-AArch64',
  211. { 101 } 'Android-x86-64',
  212. { 102 } 'Haiku-x86-64',
  213. { 103 } 'Embedded-Xtensa',
  214. { 104 } 'FreeRTos-Xtensa',
  215. { 105 } 'Linux-Xtensa',
  216. { 106 } 'FreeRTos-arm',
  217. { 107 } 'Win64-AArch64',
  218. { 108 } 'Embedded-Z80',
  219. { 109 } 'ZXSpectrum-Z80',
  220. { 110 } 'MSX-DOS-Z80',
  221. { 111 } 'Darwin-AArch64',
  222. { 112 } 'AmstradCPC-Z80',
  223. { 113 } 'SinclairQL-m68k',
  224. { 114 } 'WASI-WASM32'
  225. );
  226. const
  227. { in widestr, we have the following definition
  228. type
  229. tcompilerwidechar = word;
  230. thus widecharsize seems to always be 2 bytes }
  231. widecharsize : longint = 2;
  232. cpu : tsystemcpu = cpu_no;
  233. { This type is defined in scanner.pas unit }
  234. type
  235. tspecialgenerictoken = (
  236. ST_LOADSETTINGS,
  237. ST_LINE,
  238. ST_COLUMN,
  239. ST_FILEINDEX,
  240. ST_LOADMESSAGES,
  241. ST_INVALID);
  242. type
  243. tcpu_i386 = (
  244. cpu_variant_i386_none,
  245. cpu_variant_386,
  246. cpu_variant_486,
  247. cpu_variant_Pentium,
  248. cpu_variant_Pentium2,
  249. cpu_variant_Pentium3,
  250. cpu_variant_Pentium4,
  251. cpu_variant_PentiumM,
  252. cpu_variant_core_i,
  253. cpu_variant_core_avx,
  254. cpu_variant_core_avx2);
  255. tcpu_m68k = (
  256. cpu_variant_m68k_none,
  257. cpu_variant_MC68000,
  258. cpu_variant_MC68020,
  259. cpu_variant_MC68040,
  260. cpu_variant_MC68060,
  261. cpu_variant_isa_a,
  262. cpu_variant_isa_a_p,
  263. cpu_variant_isa_b,
  264. cpu_variant_isa_c,
  265. cpu_variant_cfv4e
  266. );
  267. tcpu_powerpc = (
  268. cpu_variant_powerpc_none,
  269. cpu_variant_ppc604,
  270. cpu_variant_ppc750,
  271. cpu_variant_ppc7400,
  272. cpu_variant_ppc970
  273. );
  274. tcpu_sparc = (
  275. cpu_variant_sparc_none,
  276. cpu_variant_SPARC_V7,
  277. cpu_variant_SPARC_V8,
  278. cpu_variant_SPARC_V9
  279. );
  280. tcpu_x86_64 = (
  281. cpu_variant_x86_64_none,
  282. cpu_variant_athlon64,
  283. cpu_variant_x86_64_core_i,
  284. cpu_variant_x86_64_core_avx,
  285. cpu_variant_x86_64_core_avx2
  286. );
  287. tcpu_mipseb = (
  288. cpu_variant_mipseb_none,
  289. cpu_variant_mips1,
  290. cpu_variant_mips2,
  291. cpu_variant_mips3,
  292. cpu_variant_mips4,
  293. cpu_variant_mips5,
  294. cpu_variant_mips32,
  295. cpu_variant_mips32r2,
  296. cpu_variant_pic32mx
  297. );
  298. tcpu_arm = (
  299. cpu_variant_arm_none,
  300. cpu_variant_armv3,
  301. cpu_variant_armv4,
  302. cpu_variant_armv4t,
  303. cpu_variant_armv5,
  304. cpu_variant_armv5t,
  305. cpu_variant_armv5te,
  306. cpu_variant_armv5tej,
  307. cpu_variant_armv6,
  308. cpu_variant_armv6k,
  309. cpu_variant_armv6t2,
  310. cpu_variant_armv6z,
  311. cpu_variant_armv6m,
  312. cpu_variant_armv7,
  313. cpu_variant_armv7a,
  314. cpu_variant_armv7r,
  315. cpu_variant_armv7m,
  316. cpu_variant_armv7em
  317. );
  318. tcpu_powerpc64 = (
  319. cpu_variant_powerpc64_none,
  320. cpu_variant_powerpc64_ppc970
  321. );
  322. tcpu_avr = (
  323. cpu_variant_avr_none,
  324. cpu_variant_avr1,
  325. cpu_variant_avr2,
  326. cpu_variant_avr25,
  327. cpu_variant_avr3,
  328. cpu_variant_avr31,
  329. cpu_variant_avr35,
  330. cpu_variant_avr4,
  331. cpu_variant_avr5,
  332. cpu_variant_avr51,
  333. cpu_variant_avr6
  334. );
  335. tcpu_mipsel = tcpu_mipseb;
  336. tcpu_jvm = (
  337. cpu_variant_jvm_none,
  338. { jvm, same as cpu_none }
  339. cpu_variant_jvm,
  340. { jvm byte code to be translated into Dalvik bytecode: more type-
  341. sensitive }
  342. cpu_variant_dalvik
  343. );
  344. tcpu_i8086 = (
  345. cpu_variant_i8086_none,
  346. cpu_variant_8086,
  347. cpu_variant_186,
  348. cpu_variant_286,
  349. cpu_variant_i8086_386,
  350. cpu_variant_i8086_486,
  351. cpu_variant_i8086_Pentium,
  352. cpu_variant_i8086_Pentium2,
  353. cpu_variant_i8086_Pentium3,
  354. cpu_variant_i8086_Pentium4,
  355. cpu_variant_i8086_PentiumM
  356. );
  357. tcpu_aarch64 = (
  358. cpu_variant_aarch64_none,
  359. cpu_variant_armv8
  360. );
  361. tcpu_wasm32 = (
  362. cpu_variant_wasm32_none);
  363. tcpu_sparc64 = (
  364. cpu_variant_sparc64_none,
  365. cpu_variant_SPARC64_V9
  366. );
  367. tcpu_riscv32 = (
  368. cpu_variant_riscv32_none,
  369. cpu_variant_rv32imafd,
  370. cpu_variant_rv32ima,
  371. cpu_variant_rv32im,
  372. cpu_variant_rv32i
  373. );
  374. tcpu_riscv64 = (
  375. cpu_variant_riscv64_none,
  376. cpu_variant_rv64imafdc,
  377. cpu_variant_rv64imafd,
  378. cpu_variant_rv64ima,
  379. cpu_variant_rv64im,
  380. cpu_variant_rv64i
  381. );
  382. tcpu_type = record
  383. case tsystemcpu of
  384. cpu_no: { 0 }
  385. ();
  386. cpu_i386: { 1 }
  387. (cpu_i386 : tcpu_i386;);
  388. cpu_m68k: { 2 }
  389. (cpu_m68k : tcpu_m68k;);
  390. obsolete_cpu_alpha: { 3 }
  391. ();
  392. cpu_powerpc: { 4 }
  393. (cpu_powerpc : tcpu_powerpc;);
  394. cpu_sparc: { 5 }
  395. (cpu_sparc : tcpu_sparc;);
  396. obsolete_cpu_vm: { 6 }
  397. ();
  398. obsolete_cpu_ia64: { 7 }
  399. ();
  400. cpu_x86_64: { 8 }
  401. (cpu_x86_64 : tcpu_x86_64;);
  402. cpu_mipseb: { 9 }
  403. (cpu_mipseb : tcpu_mipseb;);
  404. cpu_arm: { 10 }
  405. (cpu_arm : tcpu_arm;);
  406. cpu_powerpc64: { 11 }
  407. (cpu_powerpc64 : tcpu_powerpc64;);
  408. cpu_avr: { 12 }
  409. (cpu_avr : tcpu_avr;);
  410. cpu_mipsel: { 13 }
  411. (cpu_mipsel : tcpu_mipsel;);
  412. cpu_jvm: { 14 }
  413. (cpu_jvm : tcpu_jvm;);
  414. cpu_i8086: { 15 }
  415. (cpu_i8086 : tcpu_i8086;);
  416. cpu_aarch64: { 16 }
  417. (cpu_aarch64 : tcpu_aarch64;);
  418. cpu_wasm32: { 17 }
  419. (cpu_wasm32 : tcpu_wasm32;);
  420. cpu_sparc64: { 18 }
  421. (cpu_sparc64 : tcpu_sparc64;);
  422. cpu_riscv32: { 19 }
  423. (cpu_riscv32 : tcpu_riscv32;);
  424. cpu_riscv64: { 20 }
  425. (cpu_riscv64 : tcpu_riscv64;);
  426. end;
  427. TPpuModuleDef = class(TPpuUnitDef)
  428. ModuleFlags: tmoduleflags;
  429. end;
  430. type
  431. tppudumpfile = class(tppufile)
  432. protected
  433. procedure RaiseAssertion(Code: Longint); override;
  434. end;
  435. var
  436. ppufile : tppudumpfile;
  437. ppuversion : dword;
  438. space : string;
  439. verbose : longint;
  440. derefdata : pbyte;
  441. derefdatalen : longint;
  442. pout: TPpuOutput;
  443. nostdout: boolean;
  444. UnitList: TPpuContainerDef;
  445. CurUnit: TPpuModuleDef;
  446. SkipVersionCheck: boolean;
  447. SymAnsiStr: boolean;
  448. var
  449. { needed during tobjectdef parsing... }
  450. current_defoptions : tdefoptions;
  451. current_objectoptions : tobjectoptions;
  452. current_symtable_options : tsymtableoptions;
  453. {****************************************************************************
  454. Helper Routines
  455. ****************************************************************************}
  456. {****************************************************************************
  457. Routine to read 80-bit reals
  458. ****************************************************************************
  459. }
  460. {$PUSH}
  461. {$WARN 6018 OFF} { Turn off unreachable code warning }
  462. { On platforms with sizeof(ext) <> 10 the code below will cause an unreachable
  463. code warning, which will cause compilation failures with -Sew (KB) }
  464. type
  465. TSplit80bitReal = packed record
  466. case byte of
  467. 0: (bytes: Array[0..9] of byte);
  468. 1: (words: Array[0..4] of word);
  469. {$ifdef FPC_LITTLE_ENDIAN}
  470. 2: (cards: Array[0..1] of cardinal; w: word);
  471. {$else not FPC_LITTLE_ENDIAN}
  472. 2: (w:word; cards: Array[0..1] of cardinal);
  473. {$endif not FPC_LITTLE_ENDIAN}
  474. end;
  475. const
  476. maxDigits = 17;
  477. function Real80bitToStr(var e : TSplit80bitReal;var ext : extended) : string;
  478. var
  479. Temp : string;
  480. new : TSplit80bitReal;
  481. fraczero, expmaximal, sign, outside_double : boolean;
  482. exp : smallint;
  483. d : double;
  484. i : longint;
  485. mantval : qword;
  486. begin
  487. if ppufile.change_endian then
  488. begin
  489. for i:=0 to 9 do
  490. new.bytes[i]:=e.bytes[9-i];
  491. e:=new;
  492. end;
  493. if sizeof(ext)=10 then
  494. begin
  495. ext:=pextended(@e)^;
  496. str(ext,result);
  497. exit;
  498. end;
  499. { extended, format (MSB): 1 Sign bit, 15 bit exponent, 64 bit mantissa }
  500. sign := (e.w and $8000) <> 0;
  501. expMaximal := (e.w and $7fff) = 32767;
  502. exp:=(e.w and $7fff) - 16383 - 63;
  503. fraczero := (e.cards[0] = 0) and
  504. ((e.cards[1] and $7fffffff) = 0);
  505. {$ifdef FPC_LITTLE_ENDIAN}
  506. mantval := qword(e.cards[0]) or (qword(e.cards[1]) shl 32);
  507. {$else not FPC_LITTLE_ENDIAN}
  508. mantval := (qword(e.cards[0]) shl 32) or qword(e.cards[1]);
  509. {$endif not FPC_LITTLE_ENDIAN}
  510. if expMaximal then
  511. if fraczero then
  512. if sign then
  513. temp := '-Inf'
  514. else temp := '+Inf'
  515. else temp := 'Nan'
  516. else
  517. begin
  518. d:=double(mantval);
  519. if sign then
  520. d:=-d;
  521. outside_double:=false;
  522. Try
  523. if exp > 0 then
  524. begin
  525. for i:=1 to exp do
  526. d:=d *2.0;
  527. end
  528. else if exp < 0 then
  529. begin
  530. for i:=1 to -exp do
  531. d:=d /2.0;
  532. end;
  533. Except
  534. outside_double:=true;
  535. end;
  536. if (mantval<>0) and (d=0.0) then
  537. outside_double:=true;
  538. if outside_double then
  539. begin
  540. Temp:='Extended value outside double bound';
  541. ext:=0.0;
  542. end
  543. else
  544. begin
  545. ext:=d;
  546. system.str(d,temp);
  547. end;
  548. end;
  549. result:=temp;
  550. end;
  551. {$POP}
  552. const has_errors : boolean = false;
  553. has_warnings : boolean = false;
  554. has_more_infos : boolean = false;
  555. procedure SetHasErrors;
  556. begin
  557. has_errors:=true;
  558. end;
  559. Procedure WriteError(const S : string);
  560. Begin
  561. system.Writeln(StdErr, S);
  562. SetHasErrors;
  563. End;
  564. procedure StrAppend(var st : string; const st2 : string);
  565. begin
  566. st:=st+st2;
  567. end;
  568. procedure tppudumpfile.RaiseAssertion(Code: Longint);
  569. begin
  570. WriteError('Internal Error ' + ToStr(Code));
  571. inherited RaiseAssertion(Code);
  572. end;
  573. Procedure WriteWarning(const S : string);
  574. var
  575. ss: string;
  576. Begin
  577. ss:='!! Warning: ' + S;
  578. if nostdout then
  579. system.Writeln(StdErr, ss)
  580. else
  581. system.Writeln(ss);
  582. has_warnings:=true;
  583. End;
  584. procedure Write(const s: string);
  585. begin
  586. if nostdout then exit;
  587. system.write(s);
  588. end;
  589. procedure Write(const params: array of const);
  590. var
  591. i: integer;
  592. { Last vtType define in rtl/inc/objpash.inc }
  593. const
  594. max_vttype = vtUnicodeString;
  595. begin
  596. if nostdout then exit;
  597. for i:=Low(params) to High(params) do
  598. { All vtType in
  599. vtInteger = 0;
  600. vtBoolean = 1;
  601. vtChar = 2;
  602. vtExtended = 3;
  603. vtString = 4;
  604. vtPointer = 5;
  605. vtPChar = 6;
  606. vtObject = 7;
  607. vtClass = 8;
  608. vtWideChar = 9;
  609. vtPWideChar = 10;
  610. vtAnsiString32 = 11; called vtAnsiString in objpas unit
  611. vtCurrency = 12;
  612. vtVariant = 13;
  613. vtInterface = 14;
  614. vtWideString = 15;
  615. vtInt64 = 16;
  616. vtQWord = 17;
  617. vtUnicodeString = 18;
  618. // vtAnsiString16 = 19; not yet used
  619. // vtAnsiString64 = 20; not yet used
  620. }
  621. with TVarRec(params[i]) do
  622. case VType of
  623. vtInteger: system.write(VInteger);
  624. vtBoolean: system.write(VBoolean);
  625. vtChar: system.write(VChar);
  626. vtExtended: system.write(VExtended^);
  627. vtString: system.write(VString^);
  628. vtPointer:
  629. begin
  630. { Not sure the display will be correct
  631. if sizeof pointer is not native }
  632. WriteWarning('Pointer constant');
  633. end;
  634. vtPChar: system.write(VPChar);
  635. vtObject:
  636. begin
  637. { Not sure the display will be correct
  638. if sizeof pointer is not native }
  639. WriteWarning('Object constant');
  640. end;
  641. vtClass:
  642. begin
  643. { Not sure the display will be correct
  644. if sizeof pointer is not native }
  645. WriteWarning('Class constant');
  646. end;
  647. vtWideChar: system.write(VWideChar);
  648. vtPWideChar:
  649. begin
  650. WriteWarning('PWideChar constant');
  651. end;
  652. vtAnsiString: system.write(ansistring(VAnsiString));
  653. vtCurrency : system.write(VCurrency^);
  654. vtVariant :
  655. begin
  656. { Not sure the display will be correct
  657. if sizeof pointer is not native }
  658. WriteWarning('Variant constant');
  659. end;
  660. vtInterface :
  661. begin
  662. { Not sure the display will be correct
  663. if sizeof pointer is not native }
  664. WriteWarning('Interface constant');
  665. end;
  666. vtWideString : system.write(widestring(VWideString));
  667. vtInt64: system.write(VInt64^);
  668. vtQWord: system.write(VQWord^);
  669. vtUnicodeString : system.write(unicodestring(VUnicodeString));
  670. else
  671. begin
  672. system.writeln;
  673. system.writeln('Unsupported var type: ', VType);
  674. Halt(10);
  675. end;
  676. end;
  677. end;
  678. procedure Writeln(const s: string = '');
  679. begin
  680. if nostdout then exit;
  681. system.writeln(s);
  682. end;
  683. procedure Writeln(const params: array of const);
  684. begin
  685. if nostdout then exit;
  686. Write(params);
  687. system.writeln;
  688. end;
  689. Procedure HasMoreInfos;
  690. begin
  691. Writeln('!! Entry has more information stored');
  692. has_more_infos:=true;
  693. end;
  694. function Unknown(const st : string; val :longint) : string;
  695. Begin
  696. Unknown:='<!! Unknown'+st+' value '+tostr(val)+'>';
  697. SetHasErrors;
  698. end;
  699. function ToStr(w:longint):String;
  700. begin
  701. Str(w,ToStr);
  702. end;
  703. Function Target2Str(w:longint):string;
  704. begin
  705. if w<=ord(high(tsystem)) then
  706. Target2Str:=Targets[tsystem(w)]
  707. else
  708. Target2Str:=Unknown('target',w);
  709. end;
  710. Function Cpu2Str(w:longint):string;
  711. begin
  712. if w<=ord(high(tsystemcpu)) then
  713. begin
  714. cpu:=tsystemcpu(w);
  715. Cpu2Str:=CpuTxt[cpu];
  716. end
  717. else
  718. Cpu2Str:=Unknown('cpu',w);
  719. end;
  720. Function Varspez2Str(w:longint):string;
  721. const
  722. { in symconst unit
  723. tvarspez = (vs_value,vs_const,vs_var,vs_out,vs_constref); }
  724. varspezstr : array[tvarspez] of string[8]=('Value','Const','Var','Out','ConstRef','Final');
  725. begin
  726. if w<=ord(high(varspezstr)) then
  727. Varspez2Str:=varspezstr[tvarspez(w)]
  728. else
  729. Varspez2Str:=Unknown('varspez',w);
  730. end;
  731. Function VarRegable2Str(w:longint):string;
  732. { tvarregable type is defined in symconst unit }
  733. const
  734. varregableStr : array[tvarregable] of string[6]=('None','IntReg','FPUReg','MMReg','Addr');
  735. begin
  736. if w<=ord(high(varregablestr)) then
  737. Varregable2Str:=varregablestr[tvarregable(w)]
  738. else
  739. Varregable2Str:=Unknown('regable',w);
  740. end;
  741. Function Visibility2Str(w:longint):string;
  742. const
  743. { tvisibility type is defined in symconst unit }
  744. visibilityName : array[tvisibility] of string[16] = (
  745. 'hidden','strict private','private','strict protected','protected',
  746. 'public','published','<none>'
  747. );
  748. begin
  749. if w<=ord(high(visibilityName)) then
  750. result:=visibilityName[tvisibility(w)]
  751. else
  752. result:=Unknown('visibility',w);
  753. end;
  754. Function IntfEntryType2Str(w:longint):string;
  755. const
  756. { tinterfaceentrytype type is defined in symconst unit }
  757. Name : array[tinterfaceentrytype] of string = (
  758. 'standard','virtual method result','static method result','field value','virtual method class',
  759. 'static method class','field value class'
  760. );
  761. begin
  762. if w<=ord(high(Name)) then
  763. result:=Name[tinterfaceentrytype(w)]
  764. else
  765. result:=Unknown('entry type',w);
  766. end;
  767. function PPUFlags2Str(flags:dword):string;
  768. type
  769. tflagopt=record
  770. mask : dword;
  771. str : string[30];
  772. end;
  773. const
  774. flagopts=8;
  775. flagopt : array[1..flagopts] of tflagopt=(
  776. (mask: $4 ;str:'big_endian'),
  777. // (mask: $10 ;str:'browser'),
  778. (mask: $20 ;str:'in_library'),
  779. (mask: $40 ;str:'smart_linked'),
  780. (mask: $80 ;str:'static_linked'),
  781. (mask: $100 ;str:'shared_linked'),
  782. (mask: $400 ;str:'no_link'),
  783. (mask: $1000 ;str:'little_endian'),
  784. (mask: $8000 ;str:'fpu_emulation_on')
  785. );
  786. var
  787. i : longint;
  788. ntflags : dword;
  789. first : boolean;
  790. s : string;
  791. begin
  792. s:='';
  793. ntflags:=flags;
  794. if flags<>0 then
  795. begin
  796. first:=true;
  797. for i:=1to flagopts do
  798. if (flags and flagopt[i].mask)<>0 then
  799. begin
  800. if first then
  801. first:=false
  802. else
  803. s:=s+', ';
  804. s:=s+flagopt[i].str;
  805. ntflags:=ntflags and (not flagopt[i].mask);
  806. end;
  807. end
  808. else
  809. s:='none';
  810. if ntflags<>0 then
  811. begin
  812. s:=s+' unknown '+hexstr(ntflags,8);
  813. SetHasErrors;
  814. end;
  815. PPUFlags2Str:=s;
  816. end;
  817. Function L0(l:longint):string;
  818. {
  819. return the string of value l, if l<10 then insert a zero, so
  820. the string is always at least 2 chars '01','02',etc
  821. }
  822. var
  823. s : string;
  824. begin
  825. Str(l,s);
  826. if l<10 then
  827. s:='0'+s;
  828. L0:=s;
  829. end;
  830. function filetimestring( t : longint) : string;
  831. {
  832. convert dos datetime t to a string YY/MM/DD HH:MM:SS
  833. }
  834. var
  835. DT : TDateTime;
  836. hsec : word;
  837. Year,Month,Day: Word;
  838. hour,min,sec : word;
  839. begin
  840. if t=-1 then
  841. begin
  842. Result := 'Not Found';
  843. SetHasErrors;
  844. exit;
  845. end;
  846. DT := FileDateToDateTime(t);
  847. DecodeTime(DT,hour,min,sec,hsec);
  848. DecodeDate(DT,year,month,day);
  849. Result := L0(Year)+'/'+L0(Month)+'/'+L0(Day)+' '+L0(Hour)+':'+L0(min)+':'+L0(sec);
  850. end;
  851. {****************************************************************************
  852. Read Routines
  853. ****************************************************************************}
  854. function readsymstr(ppufile: tppufile): ansistring;
  855. begin
  856. if not(mf_symansistr in CurUnit.ModuleFlags) then
  857. result:=ppufile.getstring
  858. else
  859. result:=ppufile.getansistring;
  860. end;
  861. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;forward;
  862. procedure readrecsymtableoptions;
  863. var
  864. usefieldalignment : shortint;
  865. begin
  866. if ppufile.readentry<>ibrecsymtableoptions then
  867. begin
  868. SetHasErrors;
  869. exit;
  870. end;
  871. writeln([space,' recordalignment: ',shortint(ppufile.getbyte)]);
  872. usefieldalignment:=shortint(ppufile.getbyte);
  873. writeln([space,' usefieldalignment: ',usefieldalignment]);
  874. writeln([space,' recordalignmin: ',shortint(ppufile.getbyte)]);
  875. if (usefieldalignment=C_alignment) then
  876. writeln([space,' fieldalignment: ',shortint(ppufile.getbyte)]);
  877. readmanagementoperatoroptions(space,'Fields have MOPs');
  878. end;
  879. function readsymtableoptions(const s: string) : tsymtableoptions;
  880. type
  881. tsymtblopt=record
  882. mask : tsymtableoption;
  883. str : string[30];
  884. end;
  885. const
  886. symtblopts=ord(high(tsymtableoption)) + 1;
  887. symtblopt : array[1..symtblopts] of tsymtblopt=(
  888. (mask:sto_has_helper; str:'Has helper'),
  889. (mask:sto_has_generic; str:'Has generic'),
  890. (mask:sto_has_operator; str:'Has operator'),
  891. (mask:sto_needs_init_final;str:'Needs init final table'),
  892. (mask:sto_has_non_trivial_init;str:'Has non trivial init')
  893. );
  894. var
  895. options : tsymtableoptions;
  896. first : boolean;
  897. i : integer;
  898. begin
  899. if ppufile.readentry<>ibsymtableoptions then
  900. begin
  901. SetHasErrors;
  902. exit;
  903. end;
  904. ppufile.getset(tppuset1(options));
  905. if space<>'' then
  906. writeln([space,'------ ',s,' ------']);
  907. write([space,'Symtable options: ']);
  908. if options<>[] then
  909. begin
  910. first:=true;
  911. for i:=1 to symtblopts do
  912. if (symtblopt[i].mask in options) then
  913. begin
  914. if first then
  915. first:=false
  916. else
  917. write(', ');
  918. write(symtblopt[i].str);
  919. end;
  920. end
  921. else
  922. write('none');
  923. writeln;
  924. readsymtableoptions:=options;
  925. end;
  926. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef); forward;
  927. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil); forward;
  928. procedure readsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  929. var
  930. stored_symtable_options : tsymtableoptions;
  931. begin
  932. stored_symtable_options:=current_symtable_options;
  933. current_symtable_options:=readsymtableoptions(s);
  934. readdefinitions(s, ParentDef);
  935. readsymbols(s, ParentDef);
  936. current_symtable_options:=stored_symtable_options;
  937. end;
  938. procedure readrecordsymtable(const s: string; ParentDef: TPpuContainerDef = nil);
  939. begin
  940. readrecsymtableoptions;
  941. readsymtable(s, ParentDef);
  942. end;
  943. Procedure ReadLinkContainer(const prefix:string);
  944. {
  945. Read a serie of strings and write to the screen starting every line
  946. with prefix
  947. }
  948. function maskstr(m:longint):string;
  949. { link options are in globtype unit
  950. const
  951. link_none = $0;
  952. link_always = $1;
  953. link_static = $2;
  954. link_smart = $4;
  955. link_shared = $8; }
  956. var
  957. s : string;
  958. begin
  959. s:='';
  960. if (m and link_always)<>0 then
  961. s:=s+'always ';
  962. if (m and link_static)<>0 then
  963. s:=s+'static ';
  964. if (m and link_smart)<>0 then
  965. s:=s+'smart ';
  966. if (m and link_shared)<>0 then
  967. s:=s+'shared ';
  968. maskstr:=s;
  969. end;
  970. var
  971. s : string;
  972. m : longint;
  973. begin
  974. while not ppufile.endofentry do
  975. begin
  976. s:=ppufile.getstring;
  977. m:=ppufile.getlongint;
  978. WriteLn([prefix,s,' (',maskstr(m),')']);
  979. end;
  980. end;
  981. Procedure ReadContainer(const prefix:string);
  982. {
  983. Read a series of strings and write to the screen starting every line
  984. with prefix
  985. }
  986. begin
  987. while not ppufile.endofentry do
  988. WriteLn([prefix,ppufile.getstring]);
  989. end;
  990. procedure ReadLoadUnit;
  991. var
  992. ucrc,uintfcrc, indcrc : cardinal;
  993. un: TPpuUnitDef;
  994. begin
  995. while not ppufile.EndOfEntry do
  996. begin
  997. un:=TPpuUnitDef.Create(CurUnit.UsedUnits);
  998. un.Name:=ppufile.getstring;
  999. write(['Uses unit: ',un.Name]);
  1000. ucrc:=cardinal(ppufile.getlongint);
  1001. uintfcrc:=cardinal(ppufile.getlongint);
  1002. indcrc:=cardinal(ppufile.getlongint);
  1003. writeln([' (Crc: ',hexstr(ucrc,8),', IntfcCrc: ',hexstr(uintfcrc,8),', IndCrc: ',hexstr(indcrc,8),')']);
  1004. un.Crc:=ucrc;
  1005. un.IntfCrc:=uintfcrc;
  1006. end;
  1007. end;
  1008. Procedure ReadDerefmap;
  1009. var
  1010. i,mapsize : longint;
  1011. s: string;
  1012. begin
  1013. mapsize:=ppufile.getlongint;
  1014. writeln(['DerefMapsize: ',mapsize]);
  1015. SetLength(CurUnit.RefUnits, mapsize);
  1016. for i:=0 to mapsize-1 do
  1017. begin
  1018. s:=ppufile.getstring;
  1019. writeln(['DerefMap[',i,'] = ',s]);
  1020. CurUnit.RefUnits[i]:=LowerCase(s);
  1021. end;
  1022. end;
  1023. Procedure ReadImportSymbols;
  1024. var
  1025. extlibname : string;
  1026. j,
  1027. extsymcnt : longint;
  1028. extsymname : string;
  1029. extsymmangledname : string;
  1030. extsymordnr : longint;
  1031. extsymisvar : boolean;
  1032. begin
  1033. while not ppufile.endofentry do
  1034. begin
  1035. extlibname:=ppufile.getstring;
  1036. extsymcnt:=ppufile.getlongint;
  1037. writeln(['External Library: ',extlibname,' (',extsymcnt,' imports)']);
  1038. for j:=0 to extsymcnt-1 do
  1039. begin
  1040. extsymname:=ppufile.getstring;
  1041. extsymmangledname:=ppufile.getstring;
  1042. extsymordnr:=ppufile.getlongint;
  1043. extsymisvar:=ppufile.getbyte<>0;
  1044. writeln([' ',extsymname,' as ',extsymmangledname,
  1045. '(OrdNr: ',extsymordnr,' IsVar: ',extsymisvar,')']);
  1046. end;
  1047. end;
  1048. end;
  1049. Procedure ReadDerefdata;
  1050. begin
  1051. derefdatalen:=ppufile.entrysize;
  1052. if derefdatalen=0 then
  1053. begin
  1054. Writeln(['No Derefdata length=0']);
  1055. derefdata:=nil;
  1056. exit;
  1057. end;
  1058. Writeln(['Derefdata length: ',derefdatalen]);
  1059. derefdata:=allocmem(derefdatalen);
  1060. ppufile.getdata(derefdata^,derefdatalen);
  1061. end;
  1062. Procedure FreeDerefdata;
  1063. begin
  1064. if assigned(derefdata) then
  1065. begin
  1066. FreeMem(derefdata);
  1067. derefdata:=nil;
  1068. derefdatalen:=0;
  1069. end;
  1070. end;
  1071. Procedure ReadWpoFileInfo;
  1072. begin
  1073. Writeln(['Compiled with input whole-program optimisation from ',ppufile.getstring,' ',filetimestring(ppufile.getlongint)]);
  1074. end;
  1075. Procedure ReadAsmSymbols;
  1076. const
  1077. unitasmlisttype: array[tunitasmlisttype] of string[6]=(
  1078. 'PUBLIC',
  1079. 'EXTERN'
  1080. );
  1081. type
  1082. { Copied from aasmbase.pas }
  1083. TAsmsymbind=(
  1084. AB_NONE,AB_EXTERNAL,AB_COMMON,AB_LOCAL,AB_GLOBAL,AB_WEAK_EXTERNAL,
  1085. { global in the current program/library, but not visible outside it }
  1086. AB_PRIVATE_EXTERN,AB_LAZY,AB_IMPORT,
  1087. { a symbol that's internal to the compiler and used as a temp }
  1088. AB_TEMP,
  1089. { a global symbol that points to another global symbol and is only used
  1090. to allow indirect loading in case of packages and indirect imports }
  1091. AB_INDIRECT,AB_EXTERNAL_INDIRECT);
  1092. TAsmsymtype=(
  1093. AT_NONE,AT_FUNCTION,AT_DATA,AT_SECTION,AT_LABEL,
  1094. {
  1095. the address of this code label is taken somewhere in the code
  1096. so it must be taken care of it when creating pic
  1097. }
  1098. AT_ADDR,
  1099. { Label for debug or other non-program information }
  1100. AT_METADATA,
  1101. { label for data that must always be accessed indirectly, because it
  1102. is handled explcitely in the system unit or (e.g. RTTI and threadvar
  1103. tables) -- never seen in an assembler/assembler writer, always
  1104. changed to AT_DATA }
  1105. AT_DATA_FORCEINDIRECT,
  1106. { don't generate an implicit indirect symbol as that might be provided
  1107. by other means (e.g. the typed const builder) to ensure a correct
  1108. section name }
  1109. AT_DATA_NOINDIRECT,
  1110. { Thread-local symbol (ELF targets) }
  1111. AT_TLS,
  1112. { GNU indirect function (ELF targets) }
  1113. AT_GNU_IFUNC
  1114. );
  1115. var
  1116. s,
  1117. bindstr,
  1118. typestr : string;
  1119. i : longint;
  1120. t: tunitasmlisttype;
  1121. begin
  1122. writeln([space,'Assembler Symbols']);
  1123. writeln([space,'-----------------']);
  1124. t:=tunitasmlisttype(ppufile.getbyte);
  1125. if (t>=Low(tunitasmlisttype)) and (t<=High(tunitasmlisttype)) then
  1126. typestr:=unitasmlisttype[t]
  1127. else
  1128. typestr:='UNKNOWN';
  1129. writeln([space,'Type: ',typestr]);
  1130. writeln([space,'Count: ',ppufile.getlongint]);
  1131. i:=0;
  1132. while (not ppufile.endofentry) and (not ppufile.error) do
  1133. begin
  1134. s:=ppufile.getstring;
  1135. case tasmsymbind(ppufile.getbyte) of
  1136. AB_EXTERNAL :
  1137. bindstr:='External';
  1138. AB_COMMON :
  1139. bindstr:='Common';
  1140. AB_LOCAL :
  1141. bindstr:='Local';
  1142. AB_GLOBAL :
  1143. bindstr:='Global';
  1144. AB_WEAK_EXTERNAL :
  1145. bindstr:='Weak external';
  1146. AB_PRIVATE_EXTERN :
  1147. bindstr:='Private extern';
  1148. AB_LAZY :
  1149. bindstr:='Lazy';
  1150. AB_IMPORT :
  1151. bindstr:='Import';
  1152. AB_TEMP :
  1153. bindstr:='Temp';
  1154. AB_INDIRECT :
  1155. bindstr:='Indirect';
  1156. AB_EXTERNAL_INDIRECT :
  1157. bindstr:='Indirect external';
  1158. else
  1159. begin
  1160. bindstr:='<Error !!>';
  1161. SetHasErrors;
  1162. end;
  1163. end;
  1164. case tasmsymtype(ppufile.getbyte) of
  1165. AT_FUNCTION :
  1166. typestr:='Function';
  1167. AT_DATA :
  1168. typestr:='Data';
  1169. AT_SECTION :
  1170. typestr:='Section';
  1171. AT_LABEL :
  1172. typestr:='Label';
  1173. AT_ADDR :
  1174. typestr:='Label (with address taken)';
  1175. AT_METADATA :
  1176. typestr:='Metadata';
  1177. { this shouldn't appear in a PPU }
  1178. AT_DATA_FORCEINDIRECT :
  1179. typestr:='Data (ForceIndirect)';
  1180. { this shouldn't appear in a PPU }
  1181. AT_DATA_NOINDIRECT:
  1182. typestr:='Data (NoIndirect)';
  1183. AT_TLS :
  1184. typestr:='TLS';
  1185. AT_GNU_IFUNC :
  1186. typestr:='GNU IFUNC';
  1187. else
  1188. begin
  1189. typestr:='<Error !!>';
  1190. SetHasErrors;
  1191. end;
  1192. end;
  1193. Writeln([space,' ',i,' : ',s,' [',bindstr,',',typestr,']']);
  1194. inc(i);
  1195. end;
  1196. writeln([space]);
  1197. end;
  1198. function getexprint:Tconstexprint;
  1199. begin
  1200. getexprint.overflow:=false;
  1201. getexprint.signed:=ppufile.getboolean;
  1202. getexprint.svalue:=ppufile.getint64;
  1203. end;
  1204. Procedure ReadPosInfo(Def: TPpuDef = nil);
  1205. var
  1206. info : byte;
  1207. fileindex,line,column : longint;
  1208. begin
  1209. with ppufile do
  1210. begin
  1211. fileindex:=0;
  1212. line:=0;
  1213. column:=0;
  1214. {
  1215. info byte layout in bits:
  1216. 0-1 - amount of bytes for fileindex
  1217. 2-3 - amount of bytes for line
  1218. 4-5 - amount of bytes for column
  1219. }
  1220. info:=getbyte;
  1221. case (info and $03) of
  1222. 0 : fileindex:=getbyte;
  1223. 1 : fileindex:=getword;
  1224. 2 : fileindex:=(getbyte shl 16) or getword;
  1225. 3 : fileindex:=getlongint;
  1226. end;
  1227. case ((info shr 2) and $03) of
  1228. 0 : line:=getbyte;
  1229. 1 : line:=getword;
  1230. 2 : line:=(getbyte shl 16) or getword;
  1231. 3 : line:=getlongint;
  1232. end;
  1233. case ((info shr 4) and $03) of
  1234. 0 : column:=getbyte;
  1235. 1 : column:=getword;
  1236. 2 : column:=(getbyte shl 16) or getword;
  1237. 3 : column:=getlongint;
  1238. end;
  1239. Writeln([fileindex,' (',line,',',column,')']);
  1240. if Def <> nil then
  1241. begin
  1242. Def.FilePos.FileIndex:=fileindex;
  1243. Def.FilePos.Line:=line;
  1244. Def.FilePos.Col:=column;
  1245. end;
  1246. end;
  1247. end;
  1248. procedure readderef(const derefspace: string; Ref: TPpuRef = nil);
  1249. var
  1250. b : tdereftype;
  1251. first : boolean;
  1252. idx : longint;
  1253. i,n : byte;
  1254. pdata : pbyte;
  1255. begin
  1256. if not assigned(derefdata) then
  1257. exit;
  1258. first:=true;
  1259. idx:=ppufile.getlongint;
  1260. if idx = -1 then
  1261. begin
  1262. writeln('Nil');
  1263. exit;
  1264. end;
  1265. if (idx>derefdatalen) then
  1266. begin
  1267. WriteError('!! Error: Deref idx '+IntToStr(idx)+' > '+IntToStr(derefdatalen));
  1268. exit;
  1269. end;
  1270. write([derefspace,'(',idx,') ']);
  1271. pdata:=@derefdata[idx];
  1272. i:=0;
  1273. n:=pdata[i];
  1274. inc(i);
  1275. if n<1 then
  1276. begin
  1277. WriteError('!! Error: Deref len < 1');
  1278. exit;
  1279. end;
  1280. while (i<=n) do
  1281. begin
  1282. if not first then
  1283. write(', ')
  1284. else
  1285. first:=false;
  1286. b:=tdereftype(pdata[i]);
  1287. inc(i);
  1288. case b of
  1289. deref_nil :
  1290. write('Nil');
  1291. deref_symid :
  1292. begin
  1293. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  1294. inc(i,4);
  1295. write(['SymId ',idx]);
  1296. if Ref <> nil then
  1297. Ref.Id:=idx;
  1298. end;
  1299. deref_defid :
  1300. begin
  1301. idx:=pdata[i] shl 24 or pdata[i+1] shl 16 or pdata[i+2] shl 8 or pdata[i+3];
  1302. inc(i,4);
  1303. write(['DefId ',idx]);
  1304. if Ref <> nil then
  1305. Ref.Id:=idx;
  1306. end;
  1307. deref_unit :
  1308. begin
  1309. idx:=pdata[i] shl 8 or pdata[i+1];
  1310. inc(i,2);
  1311. write(['Unit ',idx]);
  1312. if Ref <> nil then
  1313. Ref.UnitIndex:=idx;
  1314. end;
  1315. else
  1316. begin
  1317. WriteError('!! unsupported dereftyp: '+IntToStr(ord(b)));
  1318. break;
  1319. end;
  1320. end;
  1321. end;
  1322. writeln;
  1323. end;
  1324. Procedure ReadUnitImportSyms;
  1325. var
  1326. c,i : longint;
  1327. begin
  1328. writeln([space,'Imported Symbols']);
  1329. writeln([space,'----------------']);
  1330. c:=ppufile.getlongint;
  1331. for i:=0 to c-1 do
  1332. readderef(space);
  1333. writeln([space]);
  1334. end;
  1335. procedure readpropaccesslist(const s:string; Ref: TPpuRef = nil);
  1336. { type tsltype is in symconst unit }
  1337. const
  1338. slstr : array[tsltype] of string[12] = (
  1339. '',
  1340. 'load',
  1341. 'call',
  1342. 'subscript',
  1343. 'vec',
  1344. 'typeconv',
  1345. 'absolutetype'
  1346. );
  1347. var
  1348. sl : tsltype;
  1349. begin
  1350. readderef('',Ref);
  1351. repeat
  1352. sl:=tsltype(ppufile.getbyte);
  1353. if sl=sl_none then
  1354. break;
  1355. write([s,'(',slstr[sl],') ']);
  1356. case sl of
  1357. sl_none : ;
  1358. sl_call,
  1359. sl_load,
  1360. sl_subscript :
  1361. if (Ref <> nil) and (Ref.IsNull) then
  1362. begin
  1363. readderef('',Ref);
  1364. Ref.IsSymId:=True;
  1365. end
  1366. else
  1367. readderef('');
  1368. sl_absolutetype,
  1369. sl_typeconv :
  1370. readderef('');
  1371. sl_vec :
  1372. begin
  1373. writeln([ppufile.getlongint]);
  1374. readderef('');
  1375. end;
  1376. end;
  1377. until false;
  1378. end;
  1379. (*
  1380. talignmentinfo = packed record
  1381. procalign,
  1382. loopalign,
  1383. jumpalign,
  1384. constalignmin,
  1385. constalignmax,
  1386. varalignmin,
  1387. varalignmax,
  1388. localalignmin,
  1389. localalignmax,
  1390. recordalignmin,
  1391. recordalignmax,
  1392. maxCrecordalign : longint;
  1393. end;
  1394. tsettings = packed record
  1395. alignment : talignmentinfo;
  1396. globalswitches : tglobalswitches;
  1397. moduleswitches : tmoduleswitches;
  1398. localswitches : tlocalswitches;
  1399. modeswitches : tmodeswitches;
  1400. optimizerswitches : toptimizerswitches;
  1401. { generate information necessary to perform these wpo's during a subsequent compilation }
  1402. genwpoptimizerswitches: twpoptimizerswitches;
  1403. { perform these wpo's using information generated during a previous compilation }
  1404. dowpoptimizerswitches: twpoptimizerswitches;
  1405. debugswitches : tdebugswitches;
  1406. { 0: old behaviour for sets <=256 elements
  1407. >0: round to this size }
  1408. setalloc,
  1409. packenum : shortint;
  1410. packrecords : shortint;
  1411. maxfpuregisters : shortint;
  1412. cputype,
  1413. optimizecputype : tcputype;
  1414. fputype : tfputype;
  1415. asmmode : tasmmode;
  1416. interfacetype : tinterfacetypes;
  1417. defproccall : tproccalloption;
  1418. sourcecodepage : tcodepagestring;
  1419. minfpconstprec : tfloattype;
  1420. disabledircache : boolean;
  1421. { CPU targets with microcontroller support can add a controller specific unit }
  1422. controllertype : tcontrollertype;
  1423. { WARNING: this pointer cannot be written as such in record token }
  1424. pmessage : pmessagestaterecord;
  1425. end;
  1426. *)
  1427. procedure readprocinfooptions(space : string);
  1428. (*
  1429. tprocinfoflag=(
  1430. { procedure has at least one assembler block }
  1431. pi_has_assembler_block,
  1432. { procedure does a call }
  1433. pi_do_call,
  1434. { procedure has a try statement = no register optimization }
  1435. pi_uses_exceptions,
  1436. { procedure is declared as @var(assembler), don't optimize}
  1437. pi_is_assembler,
  1438. { procedure contains data which needs to be finalized }
  1439. pi_needs_implicit_finally,
  1440. { procedure has the implicit try..finally generated }
  1441. pi_has_implicit_finally,
  1442. { procedure uses fpu}
  1443. pi_uses_fpu,
  1444. { procedure uses GOT for PIC code }
  1445. pi_needs_got,
  1446. { references var/proc/type/const in static symtable,
  1447. i.e. not allowed for inlining from other units }
  1448. pi_uses_static_symtable,
  1449. { set if the procedure has to push parameters onto the stack }
  1450. pi_has_stackparameter,
  1451. { set if the procedure has at least one label }
  1452. pi_has_label,
  1453. { calls itself recursive }
  1454. pi_is_recursive,
  1455. { stack frame optimization not possible (only on x86 probably) }
  1456. pi_needs_stackframe,
  1457. { set if the procedure has at least one register saved on the stack }
  1458. pi_has_saved_regs,
  1459. { dfa was generated for this proc }
  1460. pi_dfaavailable,
  1461. { subroutine contains interprocedural used labels }
  1462. pi_has_interproclabel,
  1463. { subroutine contains interprocedural gotos }
  1464. pi_has_global_goto
  1465. ); *)
  1466. type
  1467. tprocinfoopt=record
  1468. mask : tprocinfoflag;
  1469. str : string[81];
  1470. end;
  1471. const
  1472. procinfoopts=ord(high(tprocinfoflag)) - ord(low(tprocinfoflag));
  1473. procinfoopt : array[0..procinfoopts] of tprocinfoopt=(
  1474. (mask:pi_has_assembler_block;
  1475. str:' has at least one assembler block'),
  1476. (mask:pi_do_call;
  1477. str:' does a call'),
  1478. (mask:pi_uses_exceptions;
  1479. str:' has a try statement = no register optimization '),
  1480. (mask:pi_is_assembler;
  1481. str:' is declared as @var(assembler), don''t optimize'),
  1482. (mask:pi_needs_implicit_finally;
  1483. str:' contains data which needs to be finalized '),
  1484. (mask:pi_has_implicit_finally;
  1485. str:' has the implicit try..finally generated '),
  1486. (mask:pi_uses_fpu;
  1487. str:' uses fpu'),
  1488. (mask:pi_needs_got;
  1489. str:' uses GOT for PIC code '),
  1490. (mask:pi_uses_static_symtable;
  1491. str:' references var/proc/type/const in static symtable'),
  1492. (mask:pi_has_stackparameter;
  1493. str:' set if the procedure has to push parameters onto the stack '),
  1494. (mask:pi_has_label;
  1495. str:' set if the procedure has at least one label '),
  1496. (mask:pi_is_recursive;
  1497. str:' calls itself recursive '),
  1498. (mask:pi_needs_stackframe;
  1499. str:' stack frame optimization not possible (only on x86 probably) '),
  1500. (mask:pi_has_saved_regs;
  1501. str:' set if the procedure has at least one register saved on the stack '),
  1502. (mask:pi_dfaavailable;
  1503. str:' dfa was generated for this proc '),
  1504. (mask:pi_has_interproclabel;
  1505. str:' subroutine contains interprocedural used labels '),
  1506. (mask:pi_has_unwind_info;
  1507. str:' unwinding info was generated for this proc '),
  1508. (mask:pi_has_global_goto;
  1509. str:' subroutine contains interprocedural goto '),
  1510. (mask:pi_has_inherited;
  1511. str:' subroutine contains inherited call '),
  1512. (mask:pi_has_nested_exit;
  1513. str:' subroutine contains a nested subroutine which calls the exit of the current one '),
  1514. (mask:pi_has_stack_allocs;
  1515. str:' allocates memory on stack, so stack may be unbalanced on exit '),
  1516. (mask:pi_estimatestacksize;
  1517. str:' stack size is estimated before subroutine is compiled '),
  1518. (mask:pi_calls_c_varargs;
  1519. str:' calls function with C-style varargs '),
  1520. (mask:pi_has_open_array_parameter;
  1521. str:' has open array parameter '),
  1522. (mask:pi_uses_threadvar;
  1523. str:' uses threadvars '),
  1524. (mask:pi_has_except_table_data;
  1525. str:' has except table data '),
  1526. (mask:pi_needs_tls;
  1527. str:' uses TLS data pointer '),
  1528. (mask:pi_uses_get_frame;
  1529. str:' uses get_frame'),
  1530. (mask:pi_uses_ymm;
  1531. str:' uses ymm register (x86 only)')
  1532. );
  1533. var
  1534. procinfooptions : tprocinfoflags;
  1535. i : longint;
  1536. first : boolean;
  1537. begin
  1538. ppufile.getset(tppuset4(procinfooptions));
  1539. if procinfooptions<>[] then
  1540. begin
  1541. first:=true;
  1542. for i:=0 to procinfoopts do
  1543. if (procinfoopt[i].mask in procinfooptions) then
  1544. begin
  1545. if first then
  1546. first:=false
  1547. else
  1548. write(', ');
  1549. write(procinfoopt[i].str);
  1550. end;
  1551. end;
  1552. writeln;
  1553. end;
  1554. procedure readsymoptions(space : string; Def: TPpuDef = nil);
  1555. type
  1556. tsymopt=record
  1557. mask : tsymoption;
  1558. str : string[30];
  1559. end;
  1560. const
  1561. symopts=ord(high(tsymoption)) - ord(low(tsymoption));
  1562. { sp_none = 0 corresponds to nothing }
  1563. symopt : array[1..symopts] of tsymopt=(
  1564. (mask:sp_static; str:'Static'),
  1565. (mask:sp_hint_deprecated; str:'Hint Deprecated'),
  1566. (mask:sp_hint_platform; str:'Hint Platform'),
  1567. (mask:sp_hint_library; str:'Hint Library'),
  1568. (mask:sp_hint_unimplemented; str:'Hint Unimplemented'),
  1569. (mask:sp_hint_experimental; str:'Hint Experimental'),
  1570. (mask:sp_has_overloaded; str:'Has overloaded'),
  1571. (mask:sp_internal; str:'Internal'),
  1572. (mask:sp_implicitrename; str:'Implicit Rename'),
  1573. (mask:sp_generic_para; str:'Generic Parameter'),
  1574. (mask:sp_has_deprecated_msg; str:'Has Deprecated Message'),
  1575. (mask:sp_generic_dummy; str:'Generic Dummy'),
  1576. (mask:sp_explicitrename; str:'Explicit Rename'),
  1577. (mask:sp_generic_const; str:'Generic Constant Parameter')
  1578. );
  1579. var
  1580. symoptions : tsymoptions;
  1581. i : longint;
  1582. first : boolean;
  1583. begin
  1584. ppufile.getset(tppuset2(symoptions));
  1585. if symoptions<>[] then
  1586. begin
  1587. if Def <> nil then
  1588. if sp_internal in symoptions then
  1589. Def.Visibility:=dvHidden;
  1590. first:=true;
  1591. for i:=1to symopts do
  1592. if (symopt[i].mask in symoptions) then
  1593. begin
  1594. if first then
  1595. first:=false
  1596. else
  1597. write(', ');
  1598. write(symopt[i].str);
  1599. end;
  1600. end;
  1601. writeln;
  1602. if sp_has_deprecated_msg in symoptions then
  1603. writeln([space,'Deprecated : ', ppufile.getstring]);
  1604. end;
  1605. procedure readvisibility(Def: TPpuDef = nil);
  1606. var
  1607. i: byte;
  1608. begin
  1609. i:=ppufile.getbyte;
  1610. if Def <> nil then
  1611. case tvisibility(i) of
  1612. vis_public: Def.Visibility:=dvPublic;
  1613. vis_published: Def.Visibility:=dvPublished;
  1614. vis_protected, vis_strictprotected: Def.Visibility:=dvProtected;
  1615. else Def.Visibility:=dvPrivate;
  1616. end;
  1617. writeln(Visibility2Str(i));
  1618. end;
  1619. procedure readattrs(def: TPpuDef);
  1620. var
  1621. i,cnt,paras: longint;
  1622. begin
  1623. cnt:=ppufile.getlongint;
  1624. if cnt>0 then
  1625. begin
  1626. writeln([space,' Attributes : ']);
  1627. space:=' '+space;
  1628. if assigned(def) then
  1629. SetLength(def.Attrs,cnt);
  1630. for i:=0 to cnt-1 do
  1631. begin
  1632. writeln([space,'** Custom Attribute ',i,' **']);
  1633. write ([space,' Type symbol : ']);
  1634. if assigned(def) then
  1635. begin
  1636. def.Attrs[i].TypeSym:=TPpuRef.Create;
  1637. readderef('',def.Attrs[i].TypeSym);
  1638. end
  1639. else
  1640. readderef('');
  1641. write ([space,' Type constructor : ']);
  1642. if assigned(def) then
  1643. begin
  1644. def.Attrs[i].TypeConstr:=TPpuRef.Create;
  1645. readderef('',def.Attrs[i].TypeConstr);
  1646. end
  1647. else
  1648. readderef('');
  1649. paras:=ppufile.getlongint;
  1650. writeln([space,' Parameters : ',paras]);
  1651. if assigned(def) then
  1652. def.Attrs[i].ParaCount:=paras;
  1653. end;
  1654. delete(space,1,4);
  1655. end;
  1656. end;
  1657. procedure readnodetree; forward;
  1658. procedure readattrparas(def: TPpuDef);
  1659. var
  1660. attr,para: LongInt;
  1661. begin
  1662. if Length(def.Attrs) > 0 then
  1663. writeln([space,' Attr Paras : ']);
  1664. space:=' '+space;
  1665. for attr:=0 to High(def.Attrs) do
  1666. begin
  1667. writeln([space,'** Custom Attribute ',attr,' Arguments **']);
  1668. space:=' '+space;
  1669. for para:=0 to def.Attrs[attr].ParaCount-1 do
  1670. begin
  1671. readnodetree;
  1672. end;
  1673. delete(space,1,4);
  1674. end;
  1675. delete(space,1,4);
  1676. end;
  1677. procedure readdefsubentries(def: TPpuDef);
  1678. begin
  1679. space:=' '+space;
  1680. readattrparas(def);
  1681. delete(space,1,4);
  1682. end;
  1683. procedure readsymsubentries(def: TPpuDef);
  1684. begin
  1685. readattrparas(def);
  1686. end;
  1687. procedure readcommonsym(const s:string; Def: TPpuDef = nil);
  1688. var
  1689. i: integer;
  1690. n: ansistring;
  1691. begin
  1692. n:=readsymstr(ppufile);
  1693. if Def <> nil then
  1694. Def.Name:=n;
  1695. i:=ppufile.getlongint;
  1696. if Def <> nil then
  1697. Def.SetSymId(i);
  1698. writeln([space,'** Symbol Id ',i,' **']);
  1699. writeln([space,s,n]);
  1700. write ([space,' File Pos : ']);
  1701. readposinfo(Def);
  1702. write ([space,' Visibility : ']);
  1703. readvisibility(Def);
  1704. write ([space,' SymOptions : ']);
  1705. readsymoptions(space+' ',Def);
  1706. readattrs(Def);
  1707. end;
  1708. procedure readcgpara(const space:string);
  1709. { this is originally in cgbase.pas }
  1710. type
  1711. TCGLoc=(LOC_INVALID, LOC_VOID, LOC_CONSTANT, LOC_JUMP, LOC_FLAGS,
  1712. LOC_REGISTER, LOC_CREGISTER, LOC_FPUREGISTER, LOC_CFPUREGISTER,
  1713. LOC_MMXREGISTER, LOC_CMMXREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  1714. LOC_SUBSETREG, LOC_CSUBSETREG, LOC_SUBSETREF, LOC_CSUBSETREF,
  1715. LOC_CREFERENCE, LOC_REFERENCE);
  1716. const
  1717. tcgloc2str : array[TCGLoc] of string[12] = (
  1718. 'LOC_INVALID', 'LOC_VOID', 'LOC_CONST', 'LOC_JUMP', 'LOC_FLAGS',
  1719. 'LOC_REG', 'LOC_CREG', 'LOC_FPUREG', 'LOC_CFPUREG',
  1720. 'LOC_MMXREG', 'LOC_CMMXREG', 'LOC_MMREG', 'LOC_CMMREG',
  1721. 'LOC_SSETREG', 'LOC_CSSETREG', 'LOC_SSETREF', 'LOC_CSSETREF',
  1722. 'LOC_CREF', 'LOC_REF');
  1723. var
  1724. i: byte;
  1725. ii: longint;
  1726. np: byte;
  1727. loc: tcgloc;
  1728. begin
  1729. i:=ppufile.getbyte;
  1730. writeln([space,' Alignment : ',i]);
  1731. i:=ppufile.getbyte;
  1732. writeln([space,' Size : ',i]);
  1733. ii:=ppufile.getaint;
  1734. writeln([space,' IntSize : ',ii]);
  1735. readderef(space+' ');
  1736. np:=ppufile.getbyte;
  1737. writeln([space,' NumParaloc : ',np]);
  1738. while np > 0 do
  1739. begin
  1740. i:=ppufile.getbyte;
  1741. writeln([space,' Paraloc Size : ',i]);
  1742. loc:=tcgloc(ppufile.getbyte);
  1743. if loc > high(tcgloc) then
  1744. begin
  1745. WriteError('!! Location is out of range! '+IntToStr(ord(loc)));
  1746. loc:=LOC_INVALID;
  1747. end;
  1748. writeln([space,' Paraloc Loc : (',ord(loc),') ',tcgloc2str[loc]]);
  1749. case loc of
  1750. LOC_REFERENCE:
  1751. begin
  1752. writeln([space,' RegIndex : $',hexstr(ppufile.getdword,8)]);
  1753. writeln([space,' Offset : ',ppufile.getaint]);
  1754. end;
  1755. LOC_FPUREGISTER,
  1756. LOC_CFPUREGISTER,
  1757. LOC_MMREGISTER,
  1758. LOC_CMMREGISTER,
  1759. LOC_REGISTER,
  1760. LOC_CREGISTER :
  1761. begin
  1762. writeln([space,' ShiftVal : ',ppufile.getbyte]);
  1763. writeln([space,' Register : $',hexstr(ppufile.getdword,8)]);
  1764. end;
  1765. LOC_VOID:
  1766. begin end
  1767. else
  1768. WriteError('!! Invalid location error')
  1769. end;
  1770. dec(np);
  1771. end;
  1772. end;
  1773. procedure displaytokenbuffer(tokenbuf : pbyte;tokenbufsize : longint);
  1774. type
  1775. ptoken=^ttoken;
  1776. pmsgstate =^tmsgstate;
  1777. var
  1778. tbi : longint;
  1779. state : tmsgstate;
  1780. prev_settings, new_settings : Tsettings;
  1781. nb, msgvalue, mesgnb : longint;
  1782. function readtoken: ttoken;
  1783. var
  1784. b,b2 : byte;
  1785. begin
  1786. b:=tokenbuf[tbi];
  1787. inc(tbi);
  1788. if (b and $80)<>0 then
  1789. begin
  1790. b2:=tokenbuf[tbi];
  1791. inc(tbi);
  1792. result:=ttoken(((b and $7f) shl 8) or b2);
  1793. end
  1794. else
  1795. result:=ttoken(b);
  1796. end;
  1797. function gettokenbufdword : dword;
  1798. var
  1799. var32 : dword;
  1800. begin
  1801. var32:=unaligned(pdword(@tokenbuf[tbi])^);
  1802. inc(tbi,sizeof(dword));
  1803. if ppufile.change_endian then
  1804. var32:=swapendian(var32);
  1805. result:=var32;
  1806. end;
  1807. function gettokenbufword : word;
  1808. var
  1809. var16 : word;
  1810. begin
  1811. var16:=unaligned(pword(@tokenbuf[tbi])^);
  1812. inc(tbi,sizeof(word));
  1813. if ppufile.change_endian then
  1814. var16:=swapendian(var16);
  1815. result:=var16;
  1816. end;
  1817. function gettokenbuflongint : longint;
  1818. var
  1819. var32 : longint;
  1820. begin
  1821. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1822. inc(tbi,sizeof(longint));
  1823. if ppufile.change_endian then
  1824. var32:=swapendian(var32);
  1825. result:=var32;
  1826. end;
  1827. function gettokenbufshortint : shortint;
  1828. var
  1829. var8 : shortint;
  1830. begin
  1831. var8:=pshortint(@tokenbuf[tbi])^;
  1832. inc(tbi,sizeof(shortint));
  1833. result:=var8;
  1834. end;
  1835. procedure tokenreadset(var b;size : longint);
  1836. var
  1837. i : longint;
  1838. begin
  1839. move(tokenbuf[tbi],b,size);
  1840. inc(tbi,size);
  1841. if ppufile.change_endian then
  1842. for i:=0 to size-1 do
  1843. Pbyte(@b)[i]:=reverse_byte(Pbyte(@b)[i]);
  1844. end;
  1845. function gettokenbufbyte : byte;
  1846. begin
  1847. result:=pbyte(@tokenbuf[tbi])^;
  1848. inc(tbi);
  1849. end;
  1850. function tokenreadenum(size : longint) : longword;
  1851. begin
  1852. if size=1 then
  1853. result:=gettokenbufbyte
  1854. else if size=2 then
  1855. result:=gettokenbufword
  1856. else if size=4 then
  1857. result:=gettokenbufdword;
  1858. end;
  1859. function gettokenbufsizeint : int64;
  1860. var
  1861. var64 : int64;
  1862. var32 : longint;
  1863. var16 : smallint;
  1864. begin
  1865. if CpuAddrBitSize[cpu]=64 then
  1866. begin
  1867. var64:=unaligned(pint64(@tokenbuf[tbi])^);
  1868. inc(tbi,sizeof(int64));
  1869. if ppufile.change_endian then
  1870. var64:=swapendian(var64);
  1871. result:=var64;
  1872. end
  1873. else if CpuAddrBitSize[cpu]=32 then
  1874. begin
  1875. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1876. inc(tbi,sizeof(longint));
  1877. if ppufile.change_endian then
  1878. var32:=swapendian(var32);
  1879. result:=var32;
  1880. end
  1881. else if CpuAddrBitSize[cpu]=16 then
  1882. begin
  1883. { ASizeInt is still a longint, see globtype.pas unit }
  1884. var32:=unaligned(plongint(@tokenbuf[tbi])^);
  1885. inc(tbi,sizeof(longint));
  1886. if ppufile.change_endian then
  1887. var32:=swapendian(var32);
  1888. result:=var32;
  1889. end
  1890. else
  1891. begin
  1892. WriteError('Wrong CpuAddrBitSize');
  1893. result:=0;
  1894. end;
  1895. end;
  1896. procedure tokenreadsettings(var asettings : tsettings; expected_size : asizeint);
  1897. { This procedure
  1898. needs to be changed whenever
  1899. globals.tsettings type is changed,
  1900. the problem is that no error will appear
  1901. before tests with generics are tested. PM }
  1902. var
  1903. startpos, endpos : longword;
  1904. begin
  1905. { WARNING all those fields need to be in the correct
  1906. order otherwise cross_endian PPU reading will fail }
  1907. startpos:=tbi;
  1908. with asettings do
  1909. begin
  1910. alignment.procalign:=gettokenbuflongint;
  1911. alignment.loopalign:=gettokenbuflongint;
  1912. alignment.jumpalign:=gettokenbuflongint;
  1913. alignment.jumpalignskipmax:=gettokenbuflongint;
  1914. alignment.coalescealign:=gettokenbuflongint;
  1915. alignment.coalescealignskipmax:=gettokenbuflongint;
  1916. alignment.constalignmin:=gettokenbuflongint;
  1917. alignment.constalignmax:=gettokenbuflongint;
  1918. alignment.varalignmin:=gettokenbuflongint;
  1919. alignment.varalignmax:=gettokenbuflongint;
  1920. alignment.localalignmin:=gettokenbuflongint;
  1921. alignment.localalignmax:=gettokenbuflongint;
  1922. alignment.recordalignmin:=gettokenbuflongint;
  1923. alignment.recordalignmax:=gettokenbuflongint;
  1924. alignment.maxCrecordalign:=gettokenbuflongint;
  1925. tokenreadset(globalswitches,sizeof(globalswitches));
  1926. tokenreadset(targetswitches,sizeof(targetswitches));
  1927. tokenreadset(moduleswitches,sizeof(moduleswitches));
  1928. tokenreadset(localswitches,sizeof(localswitches));
  1929. tokenreadset(modeswitches,sizeof(modeswitches));
  1930. tokenreadset(optimizerswitches,sizeof(optimizerswitches));
  1931. tokenreadset(genwpoptimizerswitches,sizeof(genwpoptimizerswitches));
  1932. tokenreadset(dowpoptimizerswitches,sizeof(dowpoptimizerswitches));
  1933. tokenreadset(debugswitches,sizeof(debugswitches));
  1934. { 0: old behaviour for sets <=256 elements
  1935. >0: round to this size }
  1936. setalloc:=gettokenbufshortint;
  1937. packenum:=gettokenbufshortint;
  1938. packrecords:=gettokenbufshortint;
  1939. maxfpuregisters:=gettokenbufshortint;
  1940. cputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  1941. optimizecputype:=tcputype(tokenreadenum(sizeof(tcputype)));
  1942. fputype:=tfputype(tokenreadenum(sizeof(tfputype)));
  1943. asmmode:=tasmmode(tokenreadenum(sizeof(tasmmode)));
  1944. interfacetype:=tinterfacetypes(tokenreadenum(sizeof(tinterfacetypes)));
  1945. defproccall:=tproccalloption(tokenreadenum(sizeof(tproccalloption)));
  1946. { tstringencoding is word type,
  1947. thus this should be OK here }
  1948. sourcecodepage:=tstringEncoding(gettokenbufword);
  1949. minfpconstprec:=tfloattype(tokenreadenum(sizeof(tfloattype)));
  1950. disabledircache:=boolean(gettokenbufbyte);
  1951. tlsmodel:=ttlsmodel(tokenreadenum(sizeof(ttlsmodel)));
  1952. { TH: Since the field was conditional originally, it was not stored in PPUs. }
  1953. { While adding ControllerSupport constant, I decided not to store ct_none }
  1954. { on targets not supporting controllers, but this might be changed here and }
  1955. { in tokenwritesettings in the future to unify the PPU structure and handling }
  1956. { of this field in the compiler. }
  1957. {$PUSH}
  1958. {$WARN 6018 OFF} (* Unreachable code due to compile time evaluation *)
  1959. if CpuHasController[cpu] then
  1960. controllertype:=tcontrollertype(tokenreadenum(sizeof(tcontrollertype)))
  1961. else
  1962. ControllerType:=ct_none;
  1963. {$POP}
  1964. endpos:=tbi;
  1965. if endpos-startpos<>expected_size then
  1966. Writeln(['Wrong size of Settings read-in: ',expected_size,' expected, but got ',endpos-startpos]);
  1967. end;
  1968. end;
  1969. procedure dump_new_settings;
  1970. (* tsettings = record
  1971. alignment : talignmentinfo;
  1972. globalswitches : tglobalswitches;
  1973. targetswitches : ttargetswitches;
  1974. moduleswitches : tmoduleswitches;
  1975. localswitches : tlocalswitches;
  1976. modeswitches : tmodeswitches;
  1977. optimizerswitches : toptimizerswitches;
  1978. { generate information necessary to perform these wpo's during a subsequent compilation }
  1979. genwpoptimizerswitches: twpoptimizerswitches;
  1980. { perform these wpo's using information generated during a previous compilation }
  1981. dowpoptimizerswitches: twpoptimizerswitches;
  1982. debugswitches : tdebugswitches;
  1983. { 0: old behaviour for sets <=256 elements
  1984. >0: round to this size }
  1985. setalloc,
  1986. packenum : shortint;
  1987. packrecords : shortint;
  1988. maxfpuregisters : shortint;
  1989. cputype,
  1990. optimizecputype,
  1991. asmcputype : tcputype;
  1992. fputype : tfputype;
  1993. asmmode : tasmmode;
  1994. interfacetype : tinterfacetypes;
  1995. defproccall : tproccalloption;
  1996. sourcecodepage : tstringencoding;
  1997. minfpconstprec : tfloattype;
  1998. disabledircache : boolean;
  1999. tlsmodel : ttlsmodel;
  2000. {$if defined(i8086)}
  2001. x86memorymodel : tx86memorymodel;
  2002. {$endif defined(i8086)}
  2003. {$if defined(ARM)}
  2004. instructionset : tinstructionset;
  2005. {$endif defined(ARM)}
  2006. {$if defined(LLVM) and not defined(GENERIC_CPU)}
  2007. llvmversion: tllvmversion;
  2008. {$endif defined(LLVM) and not defined(GENERIC_CPU)}
  2009. { CPU targets with microcontroller support can add a controller specific unit }
  2010. controllertype : tcontrollertype;
  2011. { WARNING: this pointer cannot be written as such in record token }
  2012. pmessage : pmessagestaterecord;
  2013. end; *)
  2014. const
  2015. targetswitchname : array[ttargetswitch] of string[30] =
  2016. { global target-specific switches }
  2017. ('Target None', {ts_none}
  2018. { generate code that results in smaller TOCs than normal (AIX) }
  2019. 'Small TOC', {ts_small_toc}
  2020. { for the JVM target: generate integer array initializations via string
  2021. constants in order to reduce the generated code size (Java routines
  2022. are limited to 64kb of bytecode) }
  2023. 'JVM compact int array init', {ts_compact_int_array_init}
  2024. { for the JVM target: intialize enum fields in constructors with the
  2025. enum class instance corresponding to ordinal value 0 (not done by
  2026. default because this initialization can only be performed after the
  2027. inherited constructors have run, and if they call a virtual method
  2028. of the current class, then this virtual method may already have
  2029. initialized that field with another value and the constructor
  2030. initialization will result in data loss }
  2031. 'JVM enum field init', {ts_jvm_enum_field_init}
  2032. { when automatically generating getters/setters for properties, use
  2033. these strings as prefixes for the generated getters/setter names }
  2034. 'Auto getter prefix', {ts_auto_getter_prefix}
  2035. 'Auto setter prefix', {ts_auto_setter_predix}
  2036. 'Thumb interworking', {ts_thumb_interworking,}
  2037. { lowercase the first character of routine names, used to generate
  2038. names that are compliant with Java coding standards from code
  2039. written according to Delphi coding standards }
  2040. 'LowerCase proc start', {ts_lowercase_proc_start,}
  2041. { initialise local variables on the JVM target so you won't get
  2042. accidental uses of uninitialised values }
  2043. 'Init locals', {ts_init_locals}
  2044. { emit a CLD instruction before using the x86 string instructions }
  2045. 'Emit CLD instruction', {ts_cld}
  2046. { increment BP before pushing it in the function prologue and decrement
  2047. it after popping it in the function epilogue, iff the function is
  2048. going to terminate with a far ret. Thus, the BP value pushed on the
  2049. stack becomes odd if the function is far and even if the function is
  2050. near. This allows walking the BP chain on the stack and e.g.
  2051. obtaining a stack trace even if the program uses a mixture of near
  2052. and far calls. This is also required for Win16 real mode, because it
  2053. allows Windows to move code segments around (in order to defragment
  2054. memory) and then walk through the stacks of all running programs and
  2055. update the segment values of the segment that has moved. }
  2056. 'Use odd BP for far procs' {ts_x86_far_procs_push_odd_bp}
  2057. );
  2058. moduleswitchname : array[tmoduleswitch] of string[40] =
  2059. ('Module None', {cs_modulenone,}
  2060. { parser }
  2061. 'Floating Point Emulation',{ cs_fp_emulation}
  2062. 'Extended syntax', {cs_extsyntax}
  2063. 'Open string', {cs_openstring}
  2064. { support }
  2065. 'Goto allowed', {cs_support_goto}
  2066. 'Macro support', {cs_support_macro}
  2067. 'C operator support', {cs_support_c_operators}
  2068. { generation }
  2069. 'Profile', {cs_profile}
  2070. 'Debug information', {cs_debuginfo}
  2071. 'Compilation of System unit', {cs_compilesystem}
  2072. 'Line information', {cs_lineinfo}
  2073. 'Implicit exceptions', {cs_implicit_exceptions}
  2074. 'Explicit CodePage', {cs_explicit_codepage}
  2075. 'System CodePage', {cs_system_codepage}
  2076. { linking }
  2077. 'Create smart units', {cs_create_smart}
  2078. 'Create dynamic', {cs_create_dynamic}
  2079. 'Create PIC code', {cs_create_pic}
  2080. { browser switches are back }
  2081. 'Browser', {cs_browser}
  2082. 'Local Browser', {cs_local_browser}
  2083. { target specific }
  2084. 'Executable Stack', {cs_executable_stack}
  2085. { i8086 specific }
  2086. 'Huge code', {cs_huge_code}
  2087. 'Win16 smart callbacks', {cs_win16_smartcallbacks}
  2088. { Record usage of checkpointer experimental feature }
  2089. 'CheckPointer used', {cs_checkpointer_called}
  2090. 'Supports LLVM Link-Time Optimization' {cs_lto}
  2091. );
  2092. globalswitchname : array[tglobalswitch] of string[50] =
  2093. ('Global None',{cs_globalnone}
  2094. { parameter switches }
  2095. 'Check unit name', {cs_check_unit_name}
  2096. 'Constructor name', {cs_constructor_name}
  2097. 'Support exceptions',{cs_support_exceptions}
  2098. 'Support Objective-C pas',{ cs_support_c_objectivepas}
  2099. 'Transparent file names', {cs_transparent_file_names}
  2100. { units }
  2101. 'Load Objpas Unit', {cs_load_objpas_unit}
  2102. 'Load GPC unit', {cs_load_gpc_unit}
  2103. 'Load FPCKylix unit', {cs_load_fpcylix_unit}
  2104. 'Support Vectors', {cs_support_vectors}
  2105. { debuginfo }
  2106. 'Use HeapTRc unit', {cs_use_heaptrc}
  2107. 'Use line information', {cs_use_lineinfo}
  2108. 'Use GDB Valgrind', {cs_gdb_valgrind}
  2109. 'No regalloc', {cs_no_regalloc}
  2110. 'Stabs preserve cases', {cs_stabs_preservecase}
  2111. { assembling }
  2112. 'Leave assembler file', {cs_asm_leave}
  2113. 'Use external assembler', {cs_asm_extern}
  2114. 'Use pipes to call assembler', {cs_asm_pipe}
  2115. 'Add source infos into assembler files', {cs_asm_source}
  2116. 'Add register allocation into assembler files', {cs_asm_regalloc}
  2117. 'Add temporary allocation into assmebler files', {cs_asm_tempalloc}
  2118. 'Add node information into assembler files', {cs_asm_nodes}
  2119. 'Adapt assembler call to GNU version <= 2.25', {cs_asm_pre_binutils_2_25}
  2120. { linking }
  2121. 'Skip linking stage', {cs_link_nolink}
  2122. 'Link static', {cs_link_static}
  2123. 'Link smart', {cs_link_smart}
  2124. 'Link shared', {cs_link_shared}
  2125. 'Link deffile', {cs_link_deffile}
  2126. 'Strip after linking', {cs_link_strip}
  2127. 'Use linker static flag',{cs_link_staticflag}
  2128. 'Link on target OS',{cs_link_on_target}
  2129. 'Use external linker', {cs_link_extern}
  2130. 'Link opt vtable', {cs_link_opt_vtable}
  2131. 'Link opt used sections', {cs_link_opt_used_sections}
  2132. 'Link debug to separate file',{cs_link_separate_dbg_file}
  2133. 'Create linker map', {cs_link_map}
  2134. 'Link to pthread', {cs_link_pthread}
  2135. 'Link no default lib order', {cs_link_no_default_lib_order}
  2136. 'Link using native linker', {cs_link_native}
  2137. 'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
  2138. 'Link using vlink', {cs_link_vlink}
  2139. 'Link-Time Optimization disabled for system unit', {cs_lto_nosystem}
  2140. 'Assemble on target OS', {cs_asemble_on_target}
  2141. 'Use a memory model to support >2GB static data on 64 Bit target' {cs_large}
  2142. );
  2143. localswitchname : array[tlocalswitch] of string[50] =
  2144. { Switches which can be changed locally }
  2145. ('Local None', {cs_localnone}
  2146. { codegen }
  2147. 'Check overflow', {cs_check_overflow}
  2148. 'Check range', {cs_check_range}
  2149. 'Check object error', {cs_check_object}
  2150. 'Check I/O error', {cs_check_io}
  2151. 'Check stack', {cs_check_stack}
  2152. 'Check pointer', {cs_checkpointer}
  2153. 'Check ordinal size', {cs_check_ordinal_size}
  2154. 'Generate stackframes', {cs_generate_stackframes}
  2155. 'Do assertions', {cs_do_assertion}
  2156. 'Generate RTTI', {cs_generate_rtti}
  2157. 'Full boolean evaluaion', {cs_full_boolean_eval}
  2158. 'Typed constant are writable', {cs_typed_const_writable}
  2159. 'Allow calcuation on enum types', {cs_allow_enum_calc}
  2160. 'Do inline', {cs_do_inline}
  2161. 'Add FWAIT instruction for FPU 8087', {cs_fpu_fwait}
  2162. 'IEEE errors', {cs_ieee_errors}
  2163. 'Check low address loading', {cs_check_low_addr_load}
  2164. 'Imported data', {cs_imported_data}
  2165. 'Excess precision', {cs_excessprecision}
  2166. 'Check fpu exceptions', {cs_check_fpu_exceptions}
  2167. 'Check all case coverage', {cs_check_all_case_coverage}
  2168. { mmx }
  2169. 'Allow MMX instructions', {cs_mmx}
  2170. 'Use MMX saturation', {cs_mmx_saturation}
  2171. { parser }
  2172. 'Use typed addresses', {cs_typed_addresses}
  2173. 'Use strict var strings', {cs_strict_var_strings}
  2174. 'Use reference counted strings', {cs_refcountedstrings}
  2175. 'Use bit-packing', {cs_bitpacking}
  2176. 'Use var property setter', {cs_varpropsetter}
  2177. 'Use scoped enums',{cs_scopedenums}
  2178. 'Use pointer math', {cs_pointermath}
  2179. { macpas specific}
  2180. 'MACPAS exteranl variable', {cs_external_var}
  2181. 'MACPAS externally visible', {cs_externally_visible}
  2182. { jvm specific }
  2183. 'JVM check var copyout', {cs_check_var_copyout}
  2184. 'Zero based strings', {cs_zerobasedstrings}
  2185. { i8086 specific }
  2186. 'i8086 force FAR calls', {cs_force_far_calls}
  2187. 'i8086 huge pointer arithmetic', {cs_hugeptr_arithmetic_normalization}
  2188. 'i8086 huge pointer comparison' {cs_hugeptr_comparison_normalization}
  2189. );
  2190. { Switches which can be changed by a mode (fpc,tp7,delphi) }
  2191. modeswitchname : array[tmodeswitch] of string[50] =
  2192. ('m_none',
  2193. { generic }
  2194. 'm_fpc','m_objfpc','m_delphi','m_tp7','m_mac','m_iso','m_extpas',
  2195. {$ifdef gpc_mode}'m_gpc',{$endif}
  2196. { more specific }
  2197. 'm_class', { delphi class model }
  2198. 'm_objpas', { load objpas unit }
  2199. 'm_result', { result in functions }
  2200. 'm_string_pchar', { pchar 2 string conversion }
  2201. 'm_cvar_support', { cvar variable directive }
  2202. 'm_nested_comment', { nested comments }
  2203. 'm_tp_procvar', { tp style procvars (no @ needed) }
  2204. 'm_mac_procvar', { macpas style procvars }
  2205. 'm_repeat_forward', { repeating forward declarations is needed }
  2206. 'm_pointer_2_procedure', { allows the assignement of pointers to
  2207. procedure variables }
  2208. 'm_autoderef', { does auto dereferencing of struct. vars }
  2209. 'm_initfinal', { initialization/finalization for units }
  2210. 'm_default_ansistring', { ansistring turned on by default }
  2211. 'm_out', { support the calling convention OUT }
  2212. 'm_default_para', { support default parameters }
  2213. 'm_hintdirective', { support hint directives }
  2214. 'm_duplicate_names', { allow locals/paras to have duplicate names of globals }
  2215. 'm_property', { allow properties }
  2216. 'm_default_inline', { allow inline proc directive }
  2217. 'm_except', { allow exception-related keywords }
  2218. 'm_objectivec1', { support interfacing with Objective-C (1.0) }
  2219. 'm_objectivec2', { support interfacing with Objective-C (2.0) }
  2220. 'm_nested_procvars', { support nested procedural variables }
  2221. 'm_non_local_goto', { support non local gotos (like iso pascal) }
  2222. 'm_advanced_records', { advanced record syntax with visibility sections, methods and properties }
  2223. 'm_isolike_unary_minus', { unary minus like in iso pascal: same precedence level as binary minus/plus }
  2224. 'm_systemcodepage', { use system codepage as compiler codepage by default, emit ansistrings with system codepage }
  2225. 'm_final_fields', { allows declaring fields as "final", which means they must be initialised
  2226. in the (class) constructor and are constant from then on (same as final
  2227. fields in Java) }
  2228. 'm_default_unicodestring', { makes the default string type in $h+ mode unicodestring rather than
  2229. ansistring; similarly, char becomes unicodechar rather than ansichar }
  2230. 'm_type_helpers', { allows the declaration of "type helper" for all supported types
  2231. (primitive types, records, classes, interfaces) }
  2232. 'm_blocks', { support for http://en.wikipedia.org/wiki/Blocks_(C_language_extension) }
  2233. 'm_isolike_io', { I/O as it required by an ISO compatible compiler }
  2234. 'm_isolike_program_para',{ program parameters as it required by an ISO compatible compiler }
  2235. 'm_isolike_mod', { mod operation as it is required by an iso compatible compiler }
  2236. 'm_array_operators', { use Delphi compatible array operators instead of custom ones ("+") }
  2237. 'm_multi_helpers', { helpers can appear in multiple scopes simultaneously }
  2238. 'm_array2dynarray', { regular arrays can be implicitly converted to dynamic arrays }
  2239. 'm_prefixed_attributes' { enable attributes that are defined before the type they belong to }
  2240. );
  2241. { optimizer }
  2242. optimizerswitchname : array[toptimizerswitch] of string[50] =
  2243. ('cs_opt_none',
  2244. 'cs_opt_level1',
  2245. 'cs_opt_level2',
  2246. 'cs_opt_level3',
  2247. 'cs_opt_level4',
  2248. 'cs_opt_regvar',
  2249. 'cs_opt_uncertain',
  2250. 'cs_opt_size',
  2251. 'cs_opt_stackframe',
  2252. 'cs_opt_peephole',
  2253. 'cs_opt_loopunroll',
  2254. 'cs_opt_tailrecursion',
  2255. 'cs_opt_nodecse',
  2256. 'cs_opt_nodedfa',
  2257. 'cs_opt_loopstrength',
  2258. 'cs_opt_scheduler',
  2259. 'cs_opt_autoinline',
  2260. 'cs_useebp',
  2261. 'cs_userbp',
  2262. 'cs_opt_reorder_fields',
  2263. 'cs_opt_fastmath',
  2264. { Allow removing expressions whose result is not used, even when this
  2265. can change program behaviour (range check errors disappear',
  2266. access violations due to invalid pointer derefences disappear, ...).
  2267. Note: it does not (and must not) remove expressions that have
  2268. explicit side-effects, only implicit side-effects (like the ones
  2269. mentioned before) can disappear.
  2270. }
  2271. 'cs_opt_dead_values',
  2272. { compiler checks for empty procedures/methods and removes calls to them if possible }
  2273. 'cs_opt_remove_empty_proc',
  2274. 'cs_opt_constant_propagate',
  2275. 'cs_opt_dead_store_eliminate',
  2276. 'cs_opt_forcenostackframe',
  2277. 'cs_opt_use_load_modify_store',
  2278. 'cs_opt_unused_para'
  2279. );
  2280. var
  2281. globalswitch : tglobalswitch;
  2282. targetswitch : ttargetswitch;
  2283. moduleswitch : tmoduleswitch;
  2284. localswitch : tlocalswitch;
  2285. modeswitch : tmodeswitch;
  2286. optimizerswitch : toptimizerswitch;
  2287. globalswitches : tglobalswitches;
  2288. targetswitches : ttargetswitches;
  2289. moduleswitches : tmoduleswitches;
  2290. localswitches : tlocalswitches;
  2291. modeswitches : tmodeswitches;
  2292. optimizerswitches : toptimizerswitches;
  2293. begin
  2294. {alignment : talignmentinfo;}
  2295. {talignmentinfo = packed record}
  2296. writeln('Procedure alignment: '+tostr(new_settings.alignment.procalign));
  2297. writeln('Loop alignment: '+tostr(new_settings.alignment.loopalign));
  2298. { alignment for labels after unconditional jumps, this must be a power of two }
  2299. writeln('Jump alignment: '+tostr(new_settings.alignment.jumpalign));
  2300. { max. alignment for labels after unconditional jumps:
  2301. the compiler tries to align jumpalign, however, to do so it inserts at maximum jumpalignskipmax bytes or uses
  2302. the next smaller power of two of jumpalign }
  2303. writeln('Jump skip max alignment: '+tostr(new_settings.alignment.jumpalignskipmax));
  2304. { alignment for labels where two flows of the program flow coalesce, this must be a power of two }
  2305. writeln('Coalescence alignment: '+tostr(new_settings.alignment.coalescealign));
  2306. { max. alignment for labels where two flows of the program flow coalesce
  2307. the compiler tries to align to coalescealign, however, to do so it inserts at maximum coalescealignskipmax bytes or uses
  2308. the next smaller power of two of coalescealign }
  2309. writeln('Coalescence skip max alignment: '+tostr(new_settings.alignment.coalescealignskipmax));
  2310. writeln('Const min alignment: '+tostr(new_settings.alignment.constalignmin));
  2311. writeln('Const max alignment: '+tostr(new_settings.alignment.constalignmax));
  2312. writeln('Var min alignment: '+tostr(new_settings.alignment.varalignmin));
  2313. writeln('Var max alignment: '+tostr(new_settings.alignment.varalignmax));
  2314. writeln('Local min alignment: '+tostr(new_settings.alignment.localalignmin));
  2315. writeln('Local max alignment: '+tostr(new_settings.alignment.localalignmax));
  2316. writeln('Min record alignment: '+tostr(new_settings.alignment.recordalignmin));
  2317. writeln('Max record alignment: '+tostr(new_settings.alignment.recordalignmax));
  2318. writeln('Max C record alignment: '+tostr(new_settings.alignment.maxCrecordalign));
  2319. globalswitches:=new_settings.globalswitches;
  2320. for globalswitch:=low(tglobalswitch) to high(tglobalswitch) do
  2321. if globalswitch in globalswitches then
  2322. begin
  2323. writeln('global switch: '+globalswitchname[globalswitch]);
  2324. exclude(globalswitches,globalswitch);
  2325. end;
  2326. if (globalswitches <> []) then
  2327. writeln('Unknown global switch');
  2328. targetswitches:=new_settings.targetswitches;
  2329. for targetswitch:=low(ttargetswitch) to high(ttargetswitch) do
  2330. if targetswitch in targetswitches then
  2331. begin
  2332. writeln('target switch: '+targetswitchname[targetswitch]);
  2333. exclude(targetswitches,targetswitch);
  2334. end;
  2335. if (targetswitches <> []) then
  2336. writeln('Unknown target switch');
  2337. moduleswitches:=new_settings.moduleswitches;
  2338. for moduleswitch:=low(tmoduleswitch) to high(tmoduleswitch) do
  2339. if moduleswitch in moduleswitches then
  2340. begin
  2341. writeln('module switch: '+moduleswitchname[moduleswitch]);
  2342. exclude(moduleswitches,moduleswitch);
  2343. end;
  2344. if (moduleswitches <> []) then
  2345. writeln('Unknown module switch');
  2346. localswitches:=new_settings.localswitches;
  2347. for localswitch:=low(tlocalswitch) to high(tlocalswitch) do
  2348. if localswitch in localswitches then
  2349. begin
  2350. writeln('local switch: '+localswitchname[localswitch]);
  2351. exclude(localswitches,localswitch);
  2352. end;
  2353. if (localswitches <> []) then
  2354. writeln('Unknown local switch');
  2355. modeswitches:=new_settings.modeswitches;
  2356. for modeswitch:=low(tmodeswitch) to high(tmodeswitch) do
  2357. if modeswitch in modeswitches then
  2358. begin
  2359. writeln(['mode switch: ',modeswitchname[modeswitch]]);
  2360. exclude(modeswitches,modeswitch);
  2361. end;
  2362. if (modeswitches <> []) then
  2363. writeln('Unknown mode switch');
  2364. optimizerswitches:=new_settings.optimizerswitches;
  2365. for optimizerswitch:=low(toptimizerswitch) to high(toptimizerswitch) do
  2366. if optimizerswitch in optimizerswitches then
  2367. begin
  2368. writeln(['optimizer switch: ',optimizerswitchname[optimizerswitch]]);
  2369. exclude(optimizerswitches,optimizerswitch);
  2370. end;
  2371. if (optimizerswitches <> []) then
  2372. writeln('Unknown optimizer switch');
  2373. writeln(['Set allocation size ',new_settings.setalloc]);
  2374. writeln(['Pack enums ',new_settings.packenum]);
  2375. writeln(['Pack records ',new_settings.packrecords]);
  2376. writeln(['Max FPU registers ',new_settings.maxfpuregisters]);
  2377. writeln(['CPU type ',new_settings.cputype]);
  2378. writeln(['CPU optimize type ',new_settings.optimizecputype]);
  2379. writeln(['FPU type ',new_settings.fputype]);
  2380. writeln(['ASM mode ',new_settings.asmmode]);
  2381. end;
  2382. var
  2383. linestr,genstr : string;
  2384. token : ttoken;
  2385. copy_size, stbi, last_col, new_col : longint;
  2386. last_line,new_line : dword;
  2387. len : sizeint;
  2388. wstring : widestring;
  2389. astring : ansistring;
  2390. begin
  2391. tbi:=0;
  2392. last_line:=0;
  2393. last_col:=0;
  2394. linestr:='';
  2395. genstr:='';
  2396. fillchar(new_settings,sizeof(new_settings),#0);
  2397. fillchar(prev_settings,sizeof(prev_settings),#0);
  2398. write([space,' Tokens: ']);
  2399. while tbi<tokenbufsize do
  2400. begin
  2401. token:=readtoken;
  2402. if token<>_GENERICSPECIALTOKEN then
  2403. begin
  2404. if token <= high(ttoken) then
  2405. begin
  2406. write(arraytokeninfo[token].str);
  2407. if not (token in [_CWCHAR, _CWSTRING, _CSTRING, _CCHAR,
  2408. _INTCONST,_REALNUMBER, _ID]) then
  2409. StrAppend(linestr,lowercase(arraytokeninfo[token].str));
  2410. end
  2411. else
  2412. begin
  2413. HasMoreInfos;
  2414. write('Error in Token List');
  2415. break;
  2416. end;
  2417. {idtoken:=}readtoken;
  2418. end;
  2419. case token of
  2420. _CWCHAR,
  2421. _CWSTRING :
  2422. begin
  2423. len:=gettokenbufsizeint;
  2424. setlength(wstring,len);
  2425. move(tokenbuf[tbi],wstring[1],len*2);
  2426. write([' ''',wstring,'''']);
  2427. StrAppend(linestr,' ''');
  2428. StrAppend(linestr,wstring);
  2429. StrAppend(linestr,'''');
  2430. inc(tbi,len*2);
  2431. end;
  2432. _CSTRING:
  2433. begin
  2434. len:=gettokenbufsizeint;
  2435. setlength(astring,len);
  2436. if len>0 then
  2437. move(tokenbuf[tbi],astring[1],len);
  2438. write([' ''',astring,'''']);
  2439. StrAppend(linestr,' ''');
  2440. StrAppend(linestr,astring);
  2441. StrAppend(linestr,'''');
  2442. inc(tbi,len);
  2443. end;
  2444. _CCHAR:
  2445. begin
  2446. write([' ''',unaligned(pshortstring(@tokenbuf[tbi])^),'''']);
  2447. StrAppend(linestr,' ''');
  2448. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2449. StrAppend(linestr,'''');
  2450. inc(tbi,tokenbuf[tbi]+1);
  2451. end;
  2452. _INTCONST,
  2453. _REALNUMBER :
  2454. begin
  2455. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2456. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2457. inc(tbi,tokenbuf[tbi]+1);
  2458. end;
  2459. _ID :
  2460. begin
  2461. write([' ',unaligned(pshortstring(@tokenbuf[tbi])^)]);
  2462. StrAppend(linestr,unaligned(pshortstring(@tokenbuf[tbi])^));
  2463. inc(tbi,tokenbuf[tbi]+1);
  2464. end;
  2465. _GENERICSPECIALTOKEN:
  2466. begin
  2467. { Short version of column change,
  2468. byte or $80 used }
  2469. if (tokenbuf[tbi] and $80)<>0 then
  2470. begin
  2471. new_col:=tokenbuf[tbi] and $7f;
  2472. write(['Col: ',new_col]);
  2473. if length(linestr)<new_col-1 then
  2474. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2475. inc(tbi);
  2476. last_col:=new_col;
  2477. end
  2478. else
  2479. case tspecialgenerictoken(tokenbuf[tbi]) of
  2480. ST_LOADSETTINGS:
  2481. begin
  2482. inc(tbi);
  2483. write([space,'Settings: ']);
  2484. fillchar(new_settings,sizeof(new_settings),#0);
  2485. { This does not load pmessage pointer }
  2486. new_settings.pmessage:=nil;
  2487. { TSettings size depends in target...
  2488. We first read the size of the copied part }
  2489. { Still not cross endian ready :( }
  2490. copy_size:=gettokenbufsizeint;
  2491. stbi:=tbi;
  2492. tokenreadsettings(new_settings, copy_size);
  2493. tbi:=stbi+copy_size;
  2494. if CompareByte(new_settings,prev_settings,sizeof(new_settings))<>0 then
  2495. begin
  2496. dump_new_settings;
  2497. writeln;
  2498. end
  2499. else
  2500. begin
  2501. writeln('Unchanged');
  2502. end;
  2503. prev_settings:=new_settings;
  2504. end;
  2505. ST_LOADMESSAGES:
  2506. begin
  2507. inc(tbi);
  2508. mesgnb:=tokenbuf[tbi];
  2509. writeln([space,mesgnb,' messages: ']);
  2510. inc(tbi);
  2511. for nb:=1 to mesgnb do
  2512. begin
  2513. msgvalue:=gettokenbufsizeint;
  2514. //inc(tbi,sizeof(sizeint));
  2515. state:=tmsgstate(gettokenbufsizeint);
  2516. writeln(['#',msgvalue,' ',state]);
  2517. end;
  2518. end;
  2519. ST_LINE:
  2520. begin
  2521. inc(tbi);
  2522. new_line:=gettokenbufdword;
  2523. if (new_line<>last_line) then
  2524. begin
  2525. StrAppend(genstr,linestr+LineEnding);
  2526. linestr:='';
  2527. end;
  2528. writeln(['Line: ',new_line]);
  2529. last_line:=new_line;
  2530. end;
  2531. ST_COLUMN:
  2532. begin
  2533. inc(tbi);
  2534. new_col:=gettokenbufword;
  2535. write(['Col: ',new_col]);
  2536. if length(linestr)<new_col - 1 then
  2537. StrAppend(linestr,StringOfChar(' ',new_col - 1 - length(linestr)));
  2538. last_col:=new_col;
  2539. end;
  2540. ST_FILEINDEX:
  2541. begin
  2542. inc(tbi);
  2543. StrAppend(genstr,linestr+LineEnding);
  2544. linestr:='';
  2545. write(['File: ',gettokenbufword]);
  2546. end;
  2547. else
  2548. begin
  2549. HasMoreInfos;
  2550. write('Error in Token List');
  2551. break;
  2552. end;
  2553. end;
  2554. end;
  2555. else ; { empty else to avoid warning }
  2556. end;
  2557. if tbi<tokenbufsize then
  2558. write(',');
  2559. end;
  2560. writeln;
  2561. StrAppend(genstr,linestr);
  2562. writeln(['##',genstr,'##']);
  2563. end;
  2564. procedure readcommondef(const s:string; out defoptions: tdefoptions; Def: TPpuDef = nil);
  2565. type
  2566. tdefopt=record
  2567. mask : tdefoption;
  2568. str : string[30];
  2569. end;
  2570. tdefstateinfo=record
  2571. mask : tdefstate;
  2572. str : string[30];
  2573. end;
  2574. tgenconstrflag=record
  2575. mask : tgenericconstraintflag;
  2576. str : string[30];
  2577. end;
  2578. const
  2579. defopt : array[1..ord(high(tdefoption))] of tdefopt=(
  2580. (mask:df_unique; str:'Unique Type'),
  2581. (mask:df_generic; str:'Generic'),
  2582. (mask:df_specialization; str:'Specialization'),
  2583. (mask:df_copied_def; str:'Copied Typedef'),
  2584. (mask:df_genconstraint; str:'Generic Constraint'),
  2585. { this should never happen for defs stored to a ppu file }
  2586. (mask:df_not_registered_no_free; str:'Unregistered/No free (invalid)'),
  2587. (mask:df_llvm_no_struct_packing; str:'LLVM unpacked struct'),
  2588. (mask:df_internal; str:'Internal'),
  2589. (mask:df_has_global_ref; str:'Has Global Ref'),
  2590. (mask:df_has_generic_fields; str:'Has generic fields')
  2591. );
  2592. defstate : array[1..ord(high(tdefstate))] of tdefstateinfo=(
  2593. (mask:ds_vmt_written; str:'VMT Written'),
  2594. (mask:ds_rtti_table_used; str:'RTTITable Used'),
  2595. (mask:ds_init_table_used; str:'InitTable Used'),
  2596. (mask:ds_rtti_table_written; str:'RTTITable Written'),
  2597. (mask:ds_init_table_written; str:'InitTable Written'),
  2598. (mask:ds_dwarf_dbg_info_used; str:'Dwarf DbgInfo Used'),
  2599. (mask:ds_dwarf_dbg_info_written;str:'Dwarf DbgInfo Written')
  2600. );
  2601. genconstrflag : array[1..ord(high(tgenericconstraintflag))] of tgenconstrflag=(
  2602. (mask:gcf_constructor; str:'Constructor'),
  2603. (mask:gcf_class; str:'Class'),
  2604. (mask:gcf_record; str:'Record')
  2605. );
  2606. var
  2607. defstates : tdefstates;
  2608. i, nb, len : longint;
  2609. first : boolean;
  2610. min_size, tokenbufsize : longint;
  2611. tokenbuf : pbyte;
  2612. genconstr : tgenericconstraintflags;
  2613. begin
  2614. i:=ppufile.getlongint;
  2615. if Def <> nil then
  2616. Def.Id:=i;
  2617. writeln([space,'** Definition Id ',i,' **']);
  2618. writeln([space,s]);
  2619. write ([space,' Type symbol : ']);
  2620. if Def <> nil then
  2621. readderef('', Def.Ref)
  2622. else
  2623. readderef('');
  2624. write ([space,' DefOptions : ']);
  2625. ppufile.getset(tppuset2(defoptions));
  2626. if defoptions<>[] then
  2627. begin
  2628. first:=true;
  2629. for i:=1to high(defopt) do
  2630. if (defopt[i].mask in defoptions) then
  2631. begin
  2632. if first then
  2633. first:=false
  2634. else
  2635. write(', ');
  2636. write(defopt[i].str);
  2637. end;
  2638. end;
  2639. writeln;
  2640. write ([space,' DefStates : ']);
  2641. ppufile.getset(tppuset1(defstates));
  2642. if defstates<>[] then
  2643. begin
  2644. first:=true;
  2645. for i:=1 to high(defstate) do
  2646. if (defstate[i].mask in defstates) then
  2647. begin
  2648. if first then
  2649. first:=false
  2650. else
  2651. write(', ');
  2652. write(defstate[i].str);
  2653. end;
  2654. end;
  2655. writeln;
  2656. if df_genconstraint in defoptions then
  2657. begin
  2658. ppufile.getset(tppuset1(genconstr));
  2659. write ([space,' GenConstraints : ']);
  2660. if genconstr<>[] then
  2661. begin
  2662. first:=true;
  2663. for i:=1 to high(genconstrflag) do
  2664. if (genconstrflag[i].mask in genconstr) then
  2665. begin
  2666. if first then
  2667. first:=false
  2668. else
  2669. write(', ');
  2670. write(genconstrflag[i].str);
  2671. end;
  2672. end;
  2673. writeln;
  2674. len:=ppufile.getlongint;
  2675. if len>0 then
  2676. begin
  2677. space:=' '+space;
  2678. writeln([space,'------ constraint defs begin ------']);
  2679. for i:=0 to len-1 do
  2680. begin
  2681. writeln([space,'------ constraint def ',i,' ------']);
  2682. readderef(space);
  2683. end;
  2684. writeln([space,'------ constraint defs end ------']);
  2685. delete(space,1,4);
  2686. end;
  2687. end;
  2688. if [df_generic,df_specialization]*defoptions<>[] then
  2689. begin
  2690. nb:=ppufile.getlongint;
  2691. writeln([space,'has ',nb,' parameters']);
  2692. if nb>0 then
  2693. begin
  2694. for i:=0 to nb-1 do
  2695. begin
  2696. writeln([space,'parameter ',i,': ',ppufile.getstring]);
  2697. readderef(space);
  2698. end;
  2699. end;
  2700. end;
  2701. if df_generic in defoptions then
  2702. begin
  2703. tokenbufsize:=ppufile.getlongint;
  2704. writeln([space,' Tokenbuffer size : ',tokenbufsize]);
  2705. tokenbuf:=allocmem(tokenbufsize);
  2706. ppufile.getdata(tokenbuf^,tokenbufsize);
  2707. displaytokenbuffer(tokenbuf,tokenbufsize);
  2708. freemem(tokenbuf);
  2709. end;
  2710. if df_specialization in defoptions then
  2711. begin
  2712. write ([space,' Orig. GenericDef : ']);
  2713. readderef('');
  2714. end;
  2715. space:=space+' ';
  2716. readattrs(def);
  2717. delete(space,1,4);
  2718. current_defoptions:=defoptions;
  2719. end;
  2720. { Read abstract procdef and return if inline procdef }
  2721. { type tproccalloption is in globtype unit }
  2722. { type tproctypeoption is in globtype unit }
  2723. { type tprocoption is in globtype unit }
  2724. procedure read_abstract_proc_def(var proccalloption:tproccalloption;var procoptions:tprocoptions; ProcDef: TPpuProcDef);
  2725. type
  2726. tproccallopt=record
  2727. mask : tproccalloption;
  2728. str : string[30];
  2729. end;
  2730. tproctypeopt=record
  2731. mask : tproctypeoption;
  2732. str : string[30];
  2733. end;
  2734. tprocopt=record
  2735. mask : tprocoption;
  2736. str : string[34];
  2737. end;
  2738. const
  2739. {proccalloptionStr is also in globtype unit }
  2740. proctypeopt : array[1..ord(high(tproctypeoption))] of tproctypeopt=(
  2741. (mask:potype_proginit; str:'ProgInit'),
  2742. (mask:potype_unitinit; str:'UnitInit'),
  2743. (mask:potype_unitfinalize; str:'UnitFinalize'),
  2744. (mask:potype_constructor; str:'Constructor'),
  2745. (mask:potype_destructor; str:'Destructor'),
  2746. (mask:potype_operator; str:'Operator'),
  2747. (mask:potype_procedure; str:'Procedure'),
  2748. (mask:potype_function; str:'Function'),
  2749. (mask:potype_class_constructor; str:'Class Constructor'),
  2750. (mask:potype_class_destructor; str:'Class Destructor'),
  2751. { Dispinterface property accessors }
  2752. (mask:potype_propgetter; str:'Property Getter'),
  2753. (mask:potype_propsetter; str:'Property Setter'),
  2754. (mask:potype_exceptfilter; str:'SEH filter'),
  2755. (mask:potype_mainstub; str:'main stub'),
  2756. (mask:potype_pkgstub; str:'package stub'),
  2757. (mask:potype_libmainstub; str:'library main stub')
  2758. );
  2759. procopt : array[1..ord(high(tprocoption))] of tprocopt=(
  2760. (mask:po_classmethod; str:'ClassMethod'),
  2761. (mask:po_virtualmethod; str:'VirtualMethod'),
  2762. (mask:po_abstractmethod; str:'AbstractMethod'),
  2763. (mask:po_finalmethod; str:'FinalMethod'),
  2764. (mask:po_staticmethod; str:'StaticMethod'),
  2765. (mask:po_overridingmethod;str:'OverridingMethod'),
  2766. (mask:po_methodpointer; str:'MethodPointer'),
  2767. (mask:po_interrupt; str:'Interrupt'),
  2768. (mask:po_iocheck; str:'IOCheck'),
  2769. (mask:po_assembler; str:'Assembler'),
  2770. (mask:po_msgstr; str:'MsgStr'),
  2771. (mask:po_msgint; str:'MsgInt'),
  2772. (mask:po_exports; str:'Exports'),
  2773. (mask:po_external; str:'External'),
  2774. (mask:po_overload; str:'Overload'),
  2775. (mask:po_varargs; str:'VarArgs'),
  2776. (mask:po_internconst; str:'InternConst'),
  2777. (mask:po_addressonly; str:'AddressOnly'),
  2778. (mask:po_public; str:'Public'),
  2779. (mask:po_hascallingconvention;str:'HasCallingConvention'),
  2780. (mask:po_reintroduce; str:'ReIntroduce'),
  2781. (mask:po_explicitparaloc; str:'ExplicitParaloc'),
  2782. (mask:po_nostackframe; str:'NoStackFrame'),
  2783. (mask:po_has_mangledname; str:'HasMangledName'),
  2784. (mask:po_has_public_name; str:'HasPublicName'),
  2785. (mask:po_forward; str:'Forward'),
  2786. (mask:po_global; str:'Global'),
  2787. (mask:po_syscall; str:'Syscall'),
  2788. (mask:po_syscall_legacy; str:'SyscallLegacy'),
  2789. (mask:po_syscall_basenone;str:'SyscallBaseNone'),
  2790. (mask:po_syscall_basefirst;str:'SyscallBaseFirst'),
  2791. (mask:po_syscall_baselast;str:'SyscallBaseLast'),
  2792. (mask:po_syscall_basereg; str:'SyscallBaseReg'),
  2793. (mask:po_syscall_has_libsym; str:'Has LibSym'),
  2794. (mask:po_syscall_has_importnr; str:'Uses ImportNr'),
  2795. (mask:po_inline; str:'Inline'),
  2796. (mask:po_compilerproc; str:'CompilerProc'),
  2797. (mask:po_has_importdll; str:'HasImportDLL'),
  2798. (mask:po_has_importname; str:'HasImportName'),
  2799. (mask:po_kylixlocal; str:'KylixLocal'),
  2800. (mask:po_dispid; str:'DispId'),
  2801. (mask:po_weakexternal; str:'WeakExternal'),
  2802. (mask:po_objc; str:'ObjC'),
  2803. (mask:po_enumerator_movenext; str:'EnumeratorMoveNext'),
  2804. (mask:po_optional; str: 'Optional'),
  2805. (mask:po_delphi_nested_cc;str: 'Delphi-style nested frameptr'),
  2806. (mask:po_java_nonvirtual; str: 'Java non-virtual method'),
  2807. (mask:po_ignore_for_overload_resolution;str: 'Ignored for overload resolution'),
  2808. (mask:po_rtlproc; str: 'RTL procedure'),
  2809. (mask:po_auto_raised_visibility; str: 'Visibility raised by compiler'),
  2810. (mask:po_far; str: 'Far'),
  2811. (mask:po_hasnearfarcallmodel; str: 'Near/Far explicit'),
  2812. (mask:po_noreturn; str: 'No return'),
  2813. (mask:po_is_function_ref; str: 'Function reference'),
  2814. (mask:po_is_block; str: 'C "Block"'),
  2815. (mask:po_is_auto_getter; str: 'Automatically generated getter'),
  2816. (mask:po_is_auto_setter; str: 'Automatically generated setter'),
  2817. (mask:po_noinline; str: 'Never inline'),
  2818. (mask:po_variadic; str: 'C VarArgs with array-of-const para'),
  2819. (mask:po_objc_related_result_type; str: 'Objective-C related result type')
  2820. );
  2821. var
  2822. proctypeoption : tproctypeoption;
  2823. i : longint;
  2824. first : boolean;
  2825. begin
  2826. write([space,' Return type : ']);
  2827. readderef('', ProcDef.ReturnType);
  2828. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2829. case proctypeoption of
  2830. potype_function: Include(ProcDef.Options, poFunction);
  2831. potype_procedure: Include(ProcDef.Options, poProcedure);
  2832. potype_constructor: Include(ProcDef.Options, poConstructor);
  2833. potype_destructor: Include(ProcDef.Options, poDestructor);
  2834. potype_operator: Include(ProcDef.Options, poOperator);
  2835. end;
  2836. write([space,' TypeOption : ']);
  2837. first:=true;
  2838. for i:=1 to high(proctypeopt) do
  2839. if (proctypeopt[i].mask=proctypeoption) then
  2840. begin
  2841. if first then
  2842. first:=false
  2843. else
  2844. write(', ');
  2845. write(proctypeopt[i].str);
  2846. end;
  2847. writeln;
  2848. proccalloption:=tproccalloption(ppufile.getbyte);
  2849. writeln([space,' CallOption : ',proccalloptionStr[proccalloption]]);
  2850. ppufile.getset(tppuset8(procoptions));
  2851. if procoptions<>[] then
  2852. begin
  2853. if po_classmethod in procoptions then Include(ProcDef.Options, poClassMethod);
  2854. if po_virtualmethod in procoptions then Include(ProcDef.Options, poVirtual);
  2855. if po_abstractmethod in procoptions then Include(ProcDef.Options, poAbstract);
  2856. if po_overridingmethod in procoptions then Include(ProcDef.Options, poOverriding);
  2857. if po_overload in procoptions then Include(ProcDef.Options, poOverload);
  2858. if po_inline in procoptions then Include(ProcDef.Options, poInline);
  2859. if (po_methodpointer in procoptions) and (ProcDef.DefType = dtProcType) then
  2860. TPpuProcTypeDef(ProcDef).MethodPtr:=True;
  2861. write([space,' Options : ']);
  2862. first:=true;
  2863. for i:=1 to high(procopt) do
  2864. if (procopt[i].mask in procoptions) then
  2865. begin
  2866. if first then
  2867. first:=false
  2868. else
  2869. write(', ');
  2870. write(procopt[i].str);
  2871. end;
  2872. writeln;
  2873. end;
  2874. if (po_explicitparaloc in procoptions) then
  2875. begin
  2876. readcgpara(space);
  2877. end;
  2878. end;
  2879. { type tvaroption is in unit symconst }
  2880. { register variable }
  2881. { type tvarregable is in unit symconst }
  2882. procedure readabstractvarsym(const s:string;var varoptions:tvaroptions; VarDef: TPpuVarDef = nil);
  2883. type
  2884. tvaropt=record
  2885. mask : tvaroption;
  2886. str : string[30];
  2887. end;
  2888. const
  2889. varopt : array[1..ord(high(tvaroption))] of tvaropt=(
  2890. (mask:vo_is_external; str:'External'),
  2891. (mask:vo_is_dll_var; str:'DLLVar'),
  2892. (mask:vo_is_thread_var; str:'ThreadVar'),
  2893. (mask:vo_has_local_copy; str:'HasLocalCopy'),
  2894. (mask:vo_is_const; str:'Constant'),
  2895. (mask:vo_is_public; str:'Public'),
  2896. (mask:vo_is_high_para; str:'HighValue'),
  2897. (mask:vo_is_funcret; str:'Funcret'),
  2898. (mask:vo_is_self; str:'Self'),
  2899. (mask:vo_is_vmt; str:'VMT'),
  2900. (mask:vo_is_result; str:'Result'),
  2901. (mask:vo_is_parentfp; str:'ParentFP'),
  2902. (mask:vo_is_loop_counter; str:'LoopCounter'),
  2903. (mask:vo_is_hidden_para; str:'Hidden'),
  2904. (mask:vo_has_explicit_paraloc;str:'ExplicitParaloc'),
  2905. (mask:vo_is_syscall_lib; str:'SysCallLib'),
  2906. (mask:vo_has_mangledname; str:'HasMangledName'),
  2907. (mask:vo_is_typed_const; str:'TypedConst'),
  2908. (mask:vo_is_range_check; str:'RangeCheckSwitch'),
  2909. (mask:vo_is_overflow_check; str:'OverflowCheckSwitch'),
  2910. (mask:vo_is_typinfo_para; str:'TypeInfo'),
  2911. (mask:vo_is_msgsel;str:'MsgSel'),
  2912. (mask:vo_is_weak_external;str:'WeakExternal'),
  2913. (mask:vo_is_first_field;str:'IsFirstField'),
  2914. (mask:vo_volatile; str:'Volatile'),
  2915. (mask:vo_has_section; str:'HasSection'),
  2916. (mask:vo_force_finalize; str:'ForceFinalize'),
  2917. (mask:vo_is_default_var; str:'DefaultIntrinsicVar'),
  2918. (mask:vo_is_far; str:'IsFar'),
  2919. (mask:vo_has_global_ref; str:'HasGlobalRef')
  2920. );
  2921. type
  2922. tvaraccessdesc=record
  2923. mask: tvarsymaccessflag;
  2924. str: string[30];
  2925. end;
  2926. const
  2927. varaccessstr : array[ord(low(tvarsymaccessflag))..ord(high(tvarsymaccessflag))] of tvaraccessdesc=(
  2928. (mask: vsa_addr_taken; str:'Address taken'),
  2929. (mask: vsa_different_scope; str:'Accessed from different scope')
  2930. );
  2931. var
  2932. i : longint;
  2933. accessflag: tvarsymaccessflag;
  2934. varsymaccessflags: tvarsymaccessflags;
  2935. first : boolean;
  2936. begin
  2937. readcommonsym(s, VarDef);
  2938. i:=ppufile.getbyte;
  2939. if (VarDef <> nil) and (VarDef.DefType = dtParam) then
  2940. with TPpuParamDef(VarDef) do
  2941. case tvarspez(i) of
  2942. vs_value: Spez:=psValue;
  2943. vs_var: Spez:=psVar;
  2944. vs_out: Spez:=psOut;
  2945. vs_const: Spez:=psConst;
  2946. vs_constref: Spez:=psConstRef;
  2947. end;
  2948. writeln([space,' Spez : ',Varspez2Str(i)]);
  2949. writeln([space,' Regable : ',Varregable2Str(ppufile.getbyte)]);
  2950. ppufile.getset(tppuset1(varsymaccessflags));
  2951. write([space, ' Access Flags : ']);
  2952. first:=true;
  2953. for i:=low(varaccessstr) to high(varaccessstr) do
  2954. begin
  2955. if varaccessstr[i].mask in varsymaccessflags then
  2956. begin
  2957. if first then
  2958. first:=false
  2959. else
  2960. write([', ']);
  2961. write([varaccessstr[i].str]);
  2962. end
  2963. end;
  2964. writeln;
  2965. write ([space,' Var Type : ']);
  2966. if VarDef <> nil then
  2967. readderef('',VarDef.VarType)
  2968. else
  2969. readderef('');
  2970. ppufile.getset(tppuset4(varoptions));
  2971. if varoptions<>[] then
  2972. begin
  2973. if (VarDef <> nil) and (VarDef.DefType = dtParam) and (vo_is_hidden_para in varoptions) then
  2974. TPpuParamDef(VarDef).Spez:=psHidden;
  2975. write([space,' Options : ']);
  2976. first:=true;
  2977. for i:=1 to high(varopt) do
  2978. if (varopt[i].mask in varoptions) then
  2979. begin
  2980. if first then
  2981. first:=false
  2982. else
  2983. write(', ');
  2984. write(varopt[i].str);
  2985. end;
  2986. writeln;
  2987. end;
  2988. end;
  2989. procedure readobjectdefoptions(ObjDef: TPpuObjectDef = nil);
  2990. type
  2991. tsymopt=record
  2992. mask : tobjectoption;
  2993. str : string[30];
  2994. end;
  2995. const
  2996. symopt : array[1..ord(high(tobjectoption))] of tsymopt=(
  2997. (mask:oo_is_forward; str:'IsForward'),
  2998. (mask:oo_is_abstract; str:'IsAbstract'),
  2999. (mask:oo_is_sealed; str:'IsSealed'),
  3000. (mask:oo_has_virtual; str:'HasVirtual'),
  3001. (mask:oo_has_private; str:'HasPrivate'),
  3002. (mask:oo_has_protected; str:'HasProtected'),
  3003. (mask:oo_has_strictprivate; str:'HasStrictPrivate'),
  3004. (mask:oo_has_strictprotected;str:'HasStrictProtected'),
  3005. (mask:oo_has_constructor; str:'HasConstructor'),
  3006. (mask:oo_has_destructor; str:'HasDestructor'),
  3007. (mask:oo_has_vmt; str:'HasVMT'),
  3008. (mask:oo_has_msgstr; str:'HasMsgStr'),
  3009. (mask:oo_has_msgint; str:'HasMsgInt'),
  3010. (mask:oo_can_have_published; str:'CanHavePublished'),
  3011. (mask:oo_has_default_property;str:'HasDefaultProperty'),
  3012. (mask:oo_has_valid_guid; str:'HasValidGUID'),
  3013. (mask:oo_has_enumerator_movenext; str:'HasEnumeratorMoveNext'),
  3014. (mask:oo_has_enumerator_current; str:'HasEnumeratorCurrent'),
  3015. (mask:oo_is_external; str:'External'),
  3016. (mask:oo_is_formal; str:'Formal'),
  3017. (mask:oo_is_classhelper; str:'Class Helper/Category'),
  3018. (mask:oo_has_class_constructor; str:'HasClassConstructor'),
  3019. (mask:oo_has_class_destructor; str:'HasClassDestructor'),
  3020. (mask:oo_is_enum_class; str:'JvmEnumClass'),
  3021. (mask:oo_has_new_destructor; str:'HasNewDestructor')
  3022. );
  3023. var
  3024. i : longint;
  3025. first : boolean;
  3026. begin
  3027. ppufile.getset(tppuset4(current_objectoptions));
  3028. if current_objectoptions<>[] then
  3029. begin
  3030. if ObjDef <> nil then
  3031. begin
  3032. if oo_is_abstract in current_objectoptions then
  3033. Include(ObjDef.Options, ooIsAbstract);
  3034. end;
  3035. first:=true;
  3036. for i:=1 to high(symopt) do
  3037. if (symopt[i].mask in current_objectoptions) then
  3038. begin
  3039. if first then
  3040. first:=false
  3041. else
  3042. write(', ');
  3043. write(symopt[i].str);
  3044. end;
  3045. end;
  3046. writeln;
  3047. end;
  3048. procedure readprocimploptions(const space: string; out implprocoptions: timplprocoptions);
  3049. type
  3050. tpiopt=record
  3051. mask : timplprocoption;
  3052. str : string[30];
  3053. end;
  3054. const
  3055. piopt : array[low(timplprocoption)..high(timplprocoption)] of tpiopt=(
  3056. (mask:pio_empty; str:'IsEmpty'),
  3057. (mask:pio_has_inlininginfo; str:'HasInliningInfo'),
  3058. (mask:pio_inline_not_possible; str:'InlineNotPossible'),
  3059. (mask:pio_nested_access; str:'NestedAccess'),
  3060. (mask:pio_thunk; str:'Thunk'),
  3061. (mask:pio_fastmath; str:'FastMath'),
  3062. (mask:pio_inline_forbidden; str:'InlineForbidden')
  3063. );
  3064. var
  3065. i: timplprocoption;
  3066. first: boolean;
  3067. begin
  3068. ppufile.getset(tppuset1(implprocoptions));
  3069. if implprocoptions<>[] then
  3070. begin
  3071. first:=true;
  3072. write([space,' Options : ']);
  3073. for i:=low(piopt) to high(piopt) do
  3074. begin
  3075. if i in implprocoptions then
  3076. begin
  3077. if first then
  3078. first:=false
  3079. else
  3080. write(', ');
  3081. write(piopt[i].str);
  3082. end;
  3083. end;
  3084. writeln;
  3085. end;
  3086. end;
  3087. procedure readarraydefoptions(ArrayDef: TPpuArrayDef);
  3088. { type tarraydefoption is in unit symconst }
  3089. const
  3090. symopt : array[tarraydefoption] of string = (
  3091. { ado_IsConvertedPointer } 'ConvertedPointer',
  3092. { ado_IsDynamicArray } 'IsDynamicArray',
  3093. { ado_IsVariant } 'IsVariant',
  3094. { ado_IsConstructor } 'IsConstructor',
  3095. { ado_IsArrayOfConst } 'ArrayOfConst',
  3096. { ado_IsConstString } 'ConstString',
  3097. { ado_IsBitPacked } 'BitPacked',
  3098. { ado_IsVector } 'Vector',
  3099. { ado_IsGeneric } 'Generic'
  3100. );
  3101. var
  3102. symoptions: tarraydefoptions;
  3103. i: tarraydefoption;
  3104. first: boolean;
  3105. begin
  3106. ppufile.getset(tppuset2(symoptions));
  3107. if symoptions<>[] then
  3108. begin
  3109. if ado_IsDynamicArray in symoptions then Include(ArrayDef.Options, aoDynamic);
  3110. first:=true;
  3111. for i:=Low(symopt) to high(symopt) do
  3112. if (i in symoptions) then
  3113. begin
  3114. if first then
  3115. first:=false
  3116. else
  3117. write(', ');
  3118. write(symopt[i]);
  3119. end;
  3120. end;
  3121. writeln;
  3122. end;
  3123. (* options for properties
  3124. tpropertyoption=(ppo_none,
  3125. ppo_indexed,
  3126. ppo_defaultproperty,
  3127. ppo_stored,
  3128. ppo_hasparameters,
  3129. ppo_implements,
  3130. ppo_enumerator_current,
  3131. ppo_overrides,
  3132. ppo_dispid_write { no longer used }
  3133. );
  3134. tpropertyoptions=set of tpropertyoption;
  3135. *)
  3136. function readpropertyoptions:tpropertyoptions;
  3137. { type tarraydefoption is in unit symconst }
  3138. type
  3139. tpropopt=record
  3140. mask : tpropertyoption;
  3141. str : string[30];
  3142. end;
  3143. const
  3144. symopt : array[1..ord(high(tpropertyoption))] of tpropopt=(
  3145. (mask:ppo_indexed;str:'indexed'),
  3146. (mask:ppo_defaultproperty;str:'default'),
  3147. (mask:ppo_stored;str:'stored'),
  3148. (mask:ppo_hasparameters;str:'has parameters'),
  3149. (mask:ppo_implements;str:'implements'),
  3150. (mask:ppo_enumerator_current;str:'enumerator current'),
  3151. (mask:ppo_overrides;str:'overrides'),
  3152. (mask:ppo_dispid_write;str:'dispid write') { no longer used }
  3153. );
  3154. var
  3155. i : longint;
  3156. first : boolean;
  3157. begin
  3158. ppufile.getset(tppuset2(result));
  3159. if result<>[] then
  3160. begin
  3161. first:=true;
  3162. for i:=1 to high(symopt) do
  3163. if (symopt[i].mask in result) then
  3164. begin
  3165. if first then
  3166. first:=false
  3167. else
  3168. write(', ');
  3169. write(symopt[i].str);
  3170. end;
  3171. end;
  3172. writeln;
  3173. end;
  3174. function readmanagementoperatoroptions(const space : string;const name : string):tmanagementoperators;
  3175. { type is in unit symconst }
  3176. { Management operator options
  3177. tmanagementoperator=(
  3178. mop_none,
  3179. mop_initialize,
  3180. mop_finalize,
  3181. mop_addref,
  3182. mop_copy);
  3183. }
  3184. type
  3185. tmopopt=record
  3186. mask : tmanagementoperator;
  3187. str : string[10];
  3188. end;
  3189. const
  3190. managementoperatoropt : array[1..ord(high(tmanagementoperator))] of tmopopt=(
  3191. (mask:mop_initialize;str:'initialize'),
  3192. (mask:mop_finalize;str:'finalize'),
  3193. (mask:mop_addref;str:'addref'),
  3194. (mask:mop_copy;str:'copy')
  3195. );
  3196. var
  3197. i : longint;
  3198. first : boolean;
  3199. begin
  3200. ppufile.getset(tppuset1(result));
  3201. if result<>[] then
  3202. begin
  3203. first:=true;
  3204. for i:=1 to high(managementoperatoropt) do
  3205. if (managementoperatoropt[i].mask in result) then
  3206. begin
  3207. if first then
  3208. begin
  3209. write(space);
  3210. write(name);
  3211. write(': ');
  3212. first:=false;
  3213. end
  3214. else
  3215. write(', ');
  3216. write(managementoperatoropt[i].str);
  3217. end;
  3218. if not first then
  3219. writeln;
  3220. end;
  3221. end;
  3222. procedure readnodetree;
  3223. var
  3224. l : longint;
  3225. p : pointer;
  3226. begin
  3227. with ppufile do
  3228. begin
  3229. if space<>'' then
  3230. Writeln([space,'------ nodetree ------']);
  3231. if readentry=ibnodetree then
  3232. begin
  3233. l:=entrysize;
  3234. Writeln([space,'Tree size : ',l]);
  3235. { Read data to prevent error that entry is not completly read }
  3236. getmem(p,l);
  3237. getdata(p^,l);
  3238. freemem(p);
  3239. end
  3240. else
  3241. begin
  3242. WriteError('!! ibnodetree not found');
  3243. end;
  3244. end;
  3245. end;
  3246. procedure ReadCreatedObjTypes;
  3247. var
  3248. i,j,
  3249. len,
  3250. bssize: longint;
  3251. bs: pbyte;
  3252. begin
  3253. if ppufile.readentry<>ibcreatedobjtypes then
  3254. begin
  3255. WriteError('!! ibcreatedobjtypes entry not found');
  3256. ppufile.skipdata(ppufile.entrysize);
  3257. exit
  3258. end;
  3259. writeln;
  3260. writeln([space,'WPO info']);
  3261. writeln([space,'--------']);
  3262. len:=ppufile.getlongint;
  3263. writeln([space,'** Instantiated Object/Class types: ',len,' **']);
  3264. space:=space+' ';
  3265. for i:=0 to len-1 do
  3266. readderef(space);
  3267. setlength(space,length(space)-2);
  3268. len:=ppufile.getlongint;
  3269. writeln([space,'** Instantiated ClassRef types: ',len,' **']);
  3270. space:=space+' ';
  3271. for i:=0 to len-1 do
  3272. readderef(space);
  3273. setlength(space,length(space)-2);
  3274. len:=ppufile.getlongint;
  3275. writeln([space,'** Possibly instantiated ClassRef types : ',len,' **']);
  3276. space:=space+' ';
  3277. for i:=0 to len-1 do
  3278. readderef(space);
  3279. setlength(space,length(space)-2);
  3280. len:=ppufile.getlongint;
  3281. writeln([space,'** Class types with called virtual methods info : ',len,' **']);
  3282. space:=space+' ';
  3283. for i:=0 to len-1 do
  3284. begin
  3285. write([space,'Class def : ']);
  3286. readderef('');
  3287. write([space+' ','Called vmtentries : ']);
  3288. bssize:=ppufile.getlongint;
  3289. getmem(bs,bssize);
  3290. ppufile.readdata(bs^,bssize);
  3291. for j:=0 to bssize*8-1 do
  3292. if (((bs+j shr 3)^ shr (j and 7)) and 1) <> 0 then
  3293. write([j,', ']);
  3294. writeln;
  3295. freemem(bs);
  3296. end;
  3297. setlength(space,length(space)-2);
  3298. end;
  3299. {****************************************************************************
  3300. Read Symbols Part
  3301. ****************************************************************************}
  3302. procedure readsymbols(const s:string; ParentDef: TPpuContainerDef = nil);
  3303. function _finddef(symdef: TPpuDef): TPpuDef;
  3304. begin
  3305. Result:=nil;
  3306. if symdef.Ref.IsCurUnit then
  3307. begin;
  3308. Result:=CurUnit.FindById(symdef.Ref.Id);
  3309. if (Result <> nil) and (Result.Ref.Id = symdef.Id) then
  3310. begin
  3311. Result.Name:=symdef.Name;
  3312. Result.FilePos:=symdef.FilePos;
  3313. end
  3314. else
  3315. Result:=nil;
  3316. end;
  3317. end;
  3318. type
  3319. pguid = ^tguid;
  3320. tguid = packed record
  3321. D1: LongWord;
  3322. D2: Word;
  3323. D3: Word;
  3324. D4: array[0..7] of Byte;
  3325. end;
  3326. var
  3327. b : byte;
  3328. pc : pchar;
  3329. ch : dword;
  3330. startnewline : boolean;
  3331. i,j,len : longint;
  3332. prettyname, ss : ansistring;
  3333. ws: widestring;
  3334. guid : tguid;
  3335. realvalue : ppureal;
  3336. doublevalue : double;
  3337. singlevalue : single;
  3338. realstr : shortstring;
  3339. extended : TSplit80bitReal;
  3340. pw : pcompilerwidestring;
  3341. varoptions : tvaroptions;
  3342. propoptions : tpropertyoptions;
  3343. iexp: Tconstexprint;
  3344. def: TPpuDef;
  3345. constdef: TPpuConstDef absolute def;
  3346. begin
  3347. with ppufile do
  3348. begin
  3349. if space<>'' then
  3350. Writeln([space,'------ ',s,' ------']);
  3351. if readentry=ibstartsyms then
  3352. begin
  3353. Writeln([space,'Symtable count: ',getlongint]);
  3354. end
  3355. else
  3356. Writeln('!! ibstartsym not found');
  3357. repeat
  3358. def:=nil;
  3359. b:=readentry;
  3360. case b of
  3361. ibunitsym :
  3362. readcommonsym('Unit symbol ');
  3363. ibnamespacesym :
  3364. begin
  3365. readcommonsym('NameSpace symbol ');
  3366. write([space,' Hidden Unit : ']);
  3367. readderef('');
  3368. end;
  3369. iblabelsym :
  3370. readcommonsym('Label symbol ');
  3371. ibtypesym :
  3372. begin
  3373. def:=TPpuTypeRef.Create(nil);
  3374. readcommonsym('Type symbol ',def);
  3375. write([space,' Result Type : ']);
  3376. readderef('', def.Ref);
  3377. if _finddef(def) = nil then
  3378. def.Parent:=ParentDef;
  3379. prettyname:=getansistring;
  3380. if prettyname<>'' then
  3381. begin
  3382. write([space,' Pretty Name : ']);
  3383. Writeln(prettyname);
  3384. end;
  3385. end;
  3386. ibprocsym :
  3387. begin
  3388. def:=TPpuDef.Create(nil);
  3389. readcommonsym('Procedure symbol ', def);
  3390. len:=ppufile.getword;
  3391. for i:=1 to len do
  3392. begin
  3393. write([space,' Definition : ']);
  3394. readderef('', def.Ref);
  3395. _finddef(def);
  3396. end;
  3397. end;
  3398. ibconstsym :
  3399. begin
  3400. constdef:=TPpuConstDef.Create(ParentDef);
  3401. readcommonsym('Constant symbol ',constdef);
  3402. b:=getbyte;
  3403. case tconsttyp(b) of
  3404. constord :
  3405. begin
  3406. write ([space,' OrdinalType : ']);
  3407. readderef('',constdef.TypeRef);
  3408. iexp:=getexprint;
  3409. constdef.ConstType:=ctInt;
  3410. constdef.VInt:=iexp.svalue;
  3411. writeln([space,' Value : ',constexp.tostr(iexp)]);
  3412. end;
  3413. constpointer :
  3414. begin
  3415. write ([space,' PointerType : ']);
  3416. readderef('',constdef.TypeRef);
  3417. constdef.ConstType:=ctInt;
  3418. constdef.VInt:=int64(getptruint);
  3419. writeln([space,' Value : ',constdef.VInt])
  3420. end;
  3421. conststring,
  3422. constresourcestring :
  3423. begin
  3424. write ([space,' StringType : ']);
  3425. readderef('',constdef.TypeRef);
  3426. len:=getlongint;
  3427. getmem(pc,len+1);
  3428. getdata(pc^,len);
  3429. (pc+len)^:= #0;
  3430. writeln([space,' Length : ',len]);
  3431. writeln([space,' Value : "',pc,'"']);
  3432. constdef.ConstType:=ctStr;
  3433. SetString(constdef.VStr, pc, len);
  3434. constdef.VStr:=UTF8Encode(constdef.VStr);
  3435. freemem(pc,len+1);
  3436. end;
  3437. constreal :
  3438. begin
  3439. constdef.ConstType:=ctFloat;
  3440. write ([space,' RealType : ']);
  3441. readderef('',constdef.TypeRef);
  3442. write([space,' Value : ']);
  3443. if entryleft=sizeof(ppureal) then
  3444. begin
  3445. realvalue:=getrealsize(sizeof(ppureal));
  3446. constdef.VFloat:=realvalue;
  3447. system.str(realvalue,realstr);
  3448. writeln([realstr]);
  3449. end
  3450. else if entryleft=sizeof(double) then
  3451. begin
  3452. doublevalue:=getrealsize(sizeof(double));
  3453. constdef.VFloat:=doublevalue;
  3454. system.str(doublevalue,realstr);
  3455. writeln([realstr]);
  3456. end
  3457. else if entryleft=sizeof(single) then
  3458. begin
  3459. singlevalue:=getrealsize(sizeof(single));
  3460. constdef.VFloat:=singlevalue;
  3461. system.str(singlevalue,realstr);
  3462. writeln([realstr]);
  3463. end
  3464. else if entryleft=10 then
  3465. begin
  3466. getdata(extended,entryleft);
  3467. ss:=Real80bitToStr(extended,constdef.VFloat);
  3468. writeln(ss);
  3469. end
  3470. else
  3471. begin
  3472. realvalue:=0.0;
  3473. WriteError('Error reading real value');
  3474. end;
  3475. end;
  3476. constset :
  3477. begin
  3478. constdef.ConstType:=ctSet;
  3479. write ([space,' Set Type : ']);
  3480. readderef('',constdef.TypeRef);
  3481. for i:=1to 4 do
  3482. begin
  3483. write ([space,' Value : ']);
  3484. for j:=1to 8 do
  3485. begin
  3486. if j>1 then
  3487. write(',');
  3488. b:=getbyte;
  3489. write(hexstr(b,2));
  3490. constdef.VSet[i*j-1]:=b;
  3491. end;
  3492. writeln;
  3493. end;
  3494. end;
  3495. constnil:
  3496. begin
  3497. write([space,' NIL pointer :']);
  3498. readderef('',constdef.TypeRef);
  3499. constdef.ConstType:=ctPtr;
  3500. constdef.VInt:=0;
  3501. end;
  3502. constwstring :
  3503. begin
  3504. initwidestring(pw);
  3505. setlengthwidestring(pw,getlongint);
  3506. if widecharsize=2 then
  3507. { don't use getdata, because the compilerwidechars may have to
  3508. be byteswapped
  3509. }
  3510. begin
  3511. for i:=0 to pw^.len-1 do
  3512. pw^.data[i]:=ppufile.getword;
  3513. SetString(ws, PWideChar(pw^.data), pw^.len);
  3514. constdef.VStr:=UTF8Encode(ws);
  3515. constdef.ConstType:=ctStr;
  3516. end
  3517. else if widecharsize=4 then
  3518. begin
  3519. for i:=0 to pw^.len-1 do
  3520. pw^.data[i]:=cardinal(ppufile.getlongint);
  3521. end
  3522. else
  3523. begin
  3524. WriteError('Unsupported tcompilerwidechar size');
  3525. end;
  3526. Write([space,'Wide string type']);
  3527. startnewline:=true;
  3528. for i:=0 to pw^.len-1 do
  3529. begin
  3530. if startnewline then
  3531. begin
  3532. writeln;
  3533. write(space);
  3534. startnewline:=false;
  3535. end;
  3536. ch:=pw^.data[i];
  3537. if widecharsize=2 then
  3538. write(hexstr(ch,4))
  3539. else
  3540. write(hexstr(ch,8));
  3541. if ((i + 1) mod 8)= 0 then
  3542. startnewline:=true
  3543. else
  3544. if i <> pw^.len-1 then
  3545. write(', ');
  3546. end;
  3547. donewidestring(pw);
  3548. Writeln;
  3549. end;
  3550. constguid:
  3551. begin
  3552. write ([space,' IntfType : ']);
  3553. readderef('',constdef.TypeRef);
  3554. getdata(guid,sizeof(guid));
  3555. write ([space,' IID String: {',hexstr(guid.d1,8),'-',hexstr(guid.d2,4),'-',hexstr(guid.d3,4),'-']);
  3556. for i:=0 to 7 do
  3557. begin
  3558. write(hexstr(guid.d4[i],2));
  3559. if i=1 then write('-');
  3560. end;
  3561. writeln('}');
  3562. end
  3563. else
  3564. Writeln (['!! Invalid unit format : Invalid const type encountered: ',b]);
  3565. end;
  3566. end;
  3567. ibabsolutevarsym :
  3568. begin
  3569. def:=TPpuVarDef.Create(ParentDef);
  3570. readabstractvarsym('Absolute variable symbol ',varoptions,TPpuVarDef(def));
  3571. Write ([space,' Relocated to ']);
  3572. b:=getbyte;
  3573. case absolutetyp(b) of
  3574. tovar :
  3575. readpropaccesslist(space+' Sym : ');
  3576. toasm :
  3577. Writeln(['Assembler name : ',getstring]);
  3578. toaddr :
  3579. begin
  3580. Write(['Address : ',getpuint]);
  3581. if tsystemcpu(ppufile.header.common.cpu)=cpu_i386 then
  3582. Write([' (Far: ',getbyte<>0,')']);
  3583. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  3584. if getbyte<>0 then
  3585. Write([' (Far: TRUE, Segment=',getaword,')'])
  3586. else
  3587. Write([' (Far: FALSE)']);
  3588. Writeln;
  3589. end;
  3590. else
  3591. Writeln (['!! Invalid unit format : Invalid absolute type encountered: ',b]);
  3592. end;
  3593. end;
  3594. ibfieldvarsym :
  3595. begin
  3596. def:=TPpuFieldDef.Create(ParentDef);
  3597. readabstractvarsym('Field Variable symbol ',varoptions,TPpuVarDef(def));
  3598. writeln([space,' Address : ',getasizeint]);
  3599. if vo_has_mangledname in varoptions then
  3600. writeln([space,' Mangled name : ',getstring]);
  3601. end;
  3602. ibstaticvarsym :
  3603. begin
  3604. def:=TPpuVarDef.Create(ParentDef);
  3605. readabstractvarsym('Global Variable symbol ',varoptions,TPpuVarDef(def));
  3606. write ([space,' DefaultConst : ']);
  3607. readderef('');
  3608. if (vo_has_mangledname in varoptions) then
  3609. writeln([space,'Mangledname : ',readsymstr(ppufile)]);
  3610. if vo_has_section in varoptions then
  3611. writeln(['Section name:',ppufile.getansistring]);
  3612. write ([space,' FieldVarSymDeref: ']);
  3613. readderef('');
  3614. end;
  3615. iblocalvarsym :
  3616. begin
  3617. readabstractvarsym('Local Variable symbol ',varoptions);
  3618. write ([space,' DefaultConst : ']);
  3619. readderef('');
  3620. end;
  3621. ibparavarsym :
  3622. begin
  3623. def:=TPpuParamDef.Create(ParentDef);
  3624. readabstractvarsym('Parameter Variable symbol ',varoptions,TPpuVarDef(def));
  3625. write ([space,' DefaultConst : ']);
  3626. readderef('',TPpuParamDef(def).DefaultValue);
  3627. writeln([space,' ParaNr : ',getword]);
  3628. writeln([space,' Univ : ',getboolean]);
  3629. writeln([space,' VarState : ',getbyte]);
  3630. writeln([space,' Refs : ',getbyte]);
  3631. if (vo_has_explicit_paraloc in varoptions) then
  3632. begin
  3633. readcgpara(space+' ');
  3634. end;
  3635. end;
  3636. ibenumsym :
  3637. begin
  3638. def:=TPpuConstDef.Create(nil);
  3639. readcommonsym('Enumeration symbol ',def);
  3640. write ([space,' Definition : ']);
  3641. readderef('');
  3642. TPpuConstDef(def).ConstType:=ctInt;
  3643. TPpuConstDef(def).VInt:=getlongint;
  3644. writeln([space,' Value : ',TPpuConstDef(def).VInt]);
  3645. if (ParentDef <> nil) and (ParentDef.DefType = dtEnum) then
  3646. def.Parent:=ParentDef;
  3647. end;
  3648. ibsyssym :
  3649. begin
  3650. readcommonsym('Internal system symbol ');
  3651. writeln([space,' Internal Nr : ',getlongint]);
  3652. end;
  3653. ibmacrosym :
  3654. begin
  3655. readcommonsym('Macro symbol ');
  3656. writeln([space,' Defined: ',getboolean]);
  3657. writeln([space,' Compiler var: ',getboolean]);
  3658. len:=getlongint;
  3659. writeln([space,' Value length: ',len]);
  3660. if len > 0 then
  3661. begin
  3662. getmem(pc,len+1);
  3663. getdata(pc^,len);
  3664. (pc+len)^:= #0;
  3665. writeln([space,' Value: "',pc,'"']);
  3666. freemem(pc,len+1);
  3667. end;
  3668. end;
  3669. ibpropertysym :
  3670. begin
  3671. def:=TPpuPropDef.Create(ParentDef);
  3672. readcommonsym('Property ',def);
  3673. write ([space,' Prop Options : ']);
  3674. propoptions:=readpropertyoptions;
  3675. if ppo_overrides in propoptions then
  3676. begin
  3677. write ([space,' OverrideProp : ']);
  3678. readderef('');
  3679. end;
  3680. if ppo_defaultproperty in propoptions then
  3681. Include(TPpuPropDef(def).Options, poDefault);
  3682. write ([space,' Prop Type : ']);
  3683. readderef('',TPpuPropDef(def).PropType);
  3684. writeln([space,' Index : ',getlongint]);
  3685. writeln([space,' Default : ',getlongint]);
  3686. write ([space,' Index Type : ']);
  3687. readderef('');
  3688. { palt_none }
  3689. write ([space,' Noneaccess : ']);
  3690. readpropaccesslist('');
  3691. write ([space,' Readaccess : ']);
  3692. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Getter);
  3693. write ([space,' Writeaccess : ']);
  3694. readpropaccesslist(space+' Sym: ',TPpuPropDef(def).Setter);
  3695. write ([space,' Storedaccess : ']);
  3696. readpropaccesslist(space+' Sym: ');
  3697. if [ppo_hasparameters,ppo_overrides]*propoptions=[ppo_hasparameters] then
  3698. begin
  3699. space:=' '+space;
  3700. readsymtable('parast',TPpuPropDef(def));
  3701. delete(space,1,4);
  3702. end;
  3703. end;
  3704. iberror :
  3705. begin
  3706. WriteError('!! Error in PPU');
  3707. exit;
  3708. end;
  3709. ibendsyms :
  3710. break;
  3711. else
  3712. begin
  3713. WriteError('!! Skipping unsupported PPU Entry in Symbols: '+IntToStr(b));
  3714. end;
  3715. end;
  3716. if assigned(def) then
  3717. readsymsubentries(def);
  3718. if (def <> nil) and (def.Parent = nil) then
  3719. def.Free;
  3720. if not EndOfEntry then
  3721. HasMoreInfos;
  3722. until false;
  3723. end;
  3724. end;
  3725. {****************************************************************************
  3726. Read defintions Part
  3727. ****************************************************************************}
  3728. procedure readdefinitions(const s:string; ParentDef: TPpuContainerDef);
  3729. { type tordtype is in symconst unit }
  3730. {
  3731. uvoid,
  3732. u8bit,u16bit,u32bit,u64bit,u128bit,
  3733. s8bit,s16bit,s32bit,s64bit,s128bit,
  3734. bool8bit,bool16bit,bool32bit,bool64bit,
  3735. uchar,uwidechar,scurrency,customint
  3736. ); }
  3737. { type tobjecttyp is in symconst unit }
  3738. { type tvarianttype is in symconst unit }
  3739. { type thelpertype is in symconst unit }
  3740. var
  3741. b : byte;
  3742. otb : byte; { Object Type byte, needed later again }
  3743. l,j,tokenbufsize : longint;
  3744. tokenbuf : pbyte;
  3745. calloption : tproccalloption;
  3746. procoptions : tprocoptions;
  3747. implprocoptions: timplprocoptions;
  3748. defoptions: tdefoptions;
  3749. iexpr: Tconstexprint;
  3750. def: TPpuDef;
  3751. objdef: TPpuObjectDef absolute def;
  3752. arrdef: TPpuArrayDef absolute def;
  3753. enumdef: TPpuEnumDef absolute def;
  3754. setdef: TPpuSetDef absolute def;
  3755. orddef: TPpuOrdDef absolute def;
  3756. floatdef: TPpuFloatDef absolute def;
  3757. strdef: TPpuStringDef absolute def;
  3758. filedef: TPpuFileDef absolute def;
  3759. begin
  3760. with ppufile do
  3761. begin
  3762. if space<>'' then
  3763. Writeln([space,'------ ',s,' ------']);
  3764. if readentry<>ibstartdefs then
  3765. Writeln('!! ibstartdefs not found');
  3766. repeat
  3767. def:=nil;
  3768. b:=readentry;
  3769. case b of
  3770. ibpointerdef :
  3771. begin
  3772. def:=TPpuPointerDef.Create(ParentDef);
  3773. readcommondef('Pointer definition',defoptions,def);
  3774. write ([space,' Pointed Type : ']);
  3775. readderef('',TPpuPointerDef(def).Ptr);
  3776. writeln([space,' Has Pointer Math : ',(getbyte<>0)]);
  3777. if tsystemcpu(ppufile.header.common.cpu) in [cpu_i8086,cpu_i386,cpu_x86_64] then
  3778. begin
  3779. write([space,' X86 Pointer Type : ']);
  3780. b:=getbyte;
  3781. case tx86pointertyp(b) of
  3782. x86pt_near: writeln('Near');
  3783. x86pt_near_cs: writeln('Near ''CS''');
  3784. x86pt_near_ds: writeln('Near ''DS''');
  3785. x86pt_near_ss: writeln('Near ''SS''');
  3786. x86pt_near_es: writeln('Near ''ES''');
  3787. x86pt_near_fs: writeln('Near ''FS''');
  3788. x86pt_near_gs: writeln('Near ''GS''');
  3789. x86pt_far: writeln('Far');
  3790. x86pt_huge: writeln('Huge');
  3791. else
  3792. WriteWarning('Invalid x86 pointer type: ' + IntToStr(b));
  3793. end;
  3794. end;
  3795. end;
  3796. iborddef :
  3797. begin
  3798. orddef:=TPpuOrdDef.Create(ParentDef);
  3799. readcommondef('Ordinal definition',defoptions,orddef);
  3800. write ([space,' Base type : ']);
  3801. b:=getbyte;
  3802. case tordtype(b) of
  3803. uvoid:
  3804. begin
  3805. writeln('uvoid');
  3806. orddef.OrdType:=otVoid;
  3807. end;
  3808. u8bit:
  3809. begin
  3810. writeln('u8bit');
  3811. orddef.OrdType:=otUInt;
  3812. orddef.Size:=1;
  3813. end;
  3814. u16bit:
  3815. begin
  3816. writeln('u16bit');
  3817. orddef.OrdType:=otUInt;
  3818. orddef.Size:=2;
  3819. end;
  3820. u32bit:
  3821. begin
  3822. writeln('u32bit');
  3823. orddef.OrdType:=otUInt;
  3824. orddef.Size:=4;
  3825. end;
  3826. u64bit:
  3827. begin
  3828. writeln('u64bit');
  3829. orddef.OrdType:=otUInt;
  3830. orddef.Size:=8;
  3831. end;
  3832. u128bit:
  3833. begin
  3834. writeln('u128bit');
  3835. orddef.OrdType:=otUInt;
  3836. orddef.Size:=16;
  3837. end;
  3838. s8bit:
  3839. begin
  3840. writeln('s8bit');
  3841. orddef.OrdType:=otSInt;
  3842. orddef.Size:=1;
  3843. end;
  3844. s16bit:
  3845. begin
  3846. writeln('s16bit');
  3847. orddef.OrdType:=otSInt;
  3848. orddef.Size:=2;
  3849. end;
  3850. s32bit:
  3851. begin
  3852. writeln('s32bit');
  3853. orddef.OrdType:=otSInt;
  3854. orddef.Size:=4;
  3855. end;
  3856. s64bit:
  3857. begin
  3858. writeln('s64bit');
  3859. orddef.OrdType:=otSInt;
  3860. orddef.Size:=8;
  3861. end;
  3862. s128bit:
  3863. begin
  3864. writeln('s128bit');
  3865. orddef.OrdType:=otSInt;
  3866. orddef.Size:=16;
  3867. end;
  3868. pasbool1:
  3869. begin
  3870. writeln('pasbool1');
  3871. orddef.OrdType:=otPasBool;
  3872. orddef.Size:=1;
  3873. end;
  3874. pasbool8:
  3875. begin
  3876. writeln('pasbool8');
  3877. orddef.OrdType:=otPasBool;
  3878. orddef.Size:=1;
  3879. end;
  3880. pasbool16:
  3881. begin
  3882. writeln('pasbool16');
  3883. orddef.OrdType:=otPasBool;
  3884. orddef.Size:=2;
  3885. end;
  3886. pasbool32:
  3887. begin
  3888. writeln('pasbool32');
  3889. orddef.OrdType:=otPasBool;
  3890. orddef.Size:=4;
  3891. end;
  3892. pasbool64:
  3893. begin
  3894. writeln('pasbool64');
  3895. orddef.OrdType:=otPasBool;
  3896. orddef.Size:=8;
  3897. end;
  3898. bool8bit:
  3899. begin
  3900. writeln('bool8bit');
  3901. orddef.OrdType:=otBool;
  3902. orddef.Size:=1;
  3903. end;
  3904. bool16bit:
  3905. begin
  3906. writeln('bool16bit');
  3907. orddef.OrdType:=otBool;
  3908. orddef.Size:=2;
  3909. end;
  3910. bool32bit:
  3911. begin
  3912. writeln('bool32bit');
  3913. orddef.OrdType:=otBool;
  3914. orddef.Size:=4;
  3915. end;
  3916. bool64bit:
  3917. begin
  3918. writeln('bool64bit');
  3919. orddef.OrdType:=otBool;
  3920. orddef.Size:=8;
  3921. end;
  3922. uchar:
  3923. begin
  3924. writeln('uchar');
  3925. orddef.OrdType:=otChar;
  3926. orddef.Size:=1;
  3927. end;
  3928. uwidechar:
  3929. begin
  3930. writeln('uwidechar');
  3931. orddef.OrdType:=otChar;
  3932. orddef.Size:=2;
  3933. end;
  3934. scurrency:
  3935. begin
  3936. writeln('scurrency');
  3937. orddef.OrdType:=otCurrency;
  3938. orddef.Size:=8;
  3939. end;
  3940. customint:
  3941. begin
  3942. writeln('customint');
  3943. orddef.OrdType:=otSint;
  3944. orddef.Size:=sizeof(ASizeInt);
  3945. end
  3946. else
  3947. WriteWarning('Invalid base type: ' + IntToStr(b));
  3948. end;
  3949. iexpr:=getexprint;
  3950. orddef.RangeLow:=iexpr.svalue;
  3951. write([space,' Range : ',constexp.tostr(iexpr)]);
  3952. iexpr:=getexprint;
  3953. orddef.RangeHigh:=iexpr.svalue;
  3954. writeln([' to ',constexp.tostr(iexpr)]);
  3955. end;
  3956. ibfloatdef :
  3957. begin
  3958. floatdef:=TPpuFloatDef.Create(ParentDef);
  3959. readcommondef('Float definition',defoptions,floatdef);
  3960. write ([space,' Float type : ']);
  3961. b:=getbyte;
  3962. case b of
  3963. ftSingle:
  3964. begin
  3965. writeln('Single');
  3966. floatdef.FloatType:=pftSingle;
  3967. end;
  3968. ftDouble:
  3969. begin
  3970. writeln('Double');
  3971. floatdef.FloatType:=pftDouble;
  3972. end;
  3973. ftExtended:
  3974. begin
  3975. writeln('Extended');
  3976. floatdef.FloatType:=pftExtended;
  3977. end;
  3978. ftComp:
  3979. begin
  3980. writeln('Comp');
  3981. floatdef.FloatType:=pftComp;
  3982. end;
  3983. ftCurr:
  3984. begin
  3985. writeln('Currency');
  3986. floatdef.FloatType:=pftCurrency;
  3987. end;
  3988. ftFloat128:
  3989. begin
  3990. writeln('Float128');
  3991. floatdef.FloatType:=pftFloat128;
  3992. end;
  3993. else
  3994. WriteWarning('Invalid float type: ' + IntToStr(b));
  3995. end;
  3996. end;
  3997. ibarraydef :
  3998. begin
  3999. arrdef:=TPpuArrayDef.Create(ParentDef);
  4000. readcommondef('Array definition',defoptions,arrdef);
  4001. write ([space,' Element type : ']);
  4002. readderef('',arrdef.ElType);
  4003. write ([space,' Range Type : ']);
  4004. readderef('',arrdef.RangeType);
  4005. arrdef.RangeLow:=getasizeint;
  4006. arrdef.RangeHigh:=getasizeint;
  4007. writeln([space,' Range : ',arrdef.RangeLow,' to ',arrdef.RangeHigh]);
  4008. write ([space,' Options : ']);
  4009. readarraydefoptions(arrdef);
  4010. if tsystemcpu(ppufile.header.common.cpu)=cpu_i8086 then
  4011. writeln([space,' Huge : ',(getbyte<>0)]);
  4012. readsymtable('symbols', arrdef);
  4013. end;
  4014. ibprocdef :
  4015. begin
  4016. def:=TPpuProcDef.Create(ParentDef);
  4017. readcommondef('Procedure definition',defoptions,def);
  4018. read_abstract_proc_def(calloption,procoptions,TPpuProcDef(def));
  4019. if (po_has_mangledname in procoptions) then
  4020. writeln([space,' Mangled name : ',readsymstr(ppufile)]);
  4021. writeln([space,' Number : ',getword]);
  4022. writeln([space,' Level : ',getbyte]);
  4023. write ([space,' Class : ']);
  4024. readderef('');
  4025. write ([space,' Procsym : ']);
  4026. readderef('', def.Ref);
  4027. write ([space,' File Pos : ']);
  4028. readposinfo(def);
  4029. write ([space,' Visibility : ']);
  4030. readvisibility(def);
  4031. write ([space,' SymOptions : ']);
  4032. readsymoptions(space+' ');
  4033. if (po_has_importdll in procoptions) then
  4034. writeln([space,' Import DLL : ',getstring]);
  4035. if (po_has_importname in procoptions) then
  4036. writeln([space,' Import Name : ',getstring]);
  4037. writeln([space,' Import Nr : ',getword]);
  4038. if (po_msgint in procoptions) then
  4039. writeln([space,' MsgInt : ',getlongint]);
  4040. if (po_msgstr in procoptions) then
  4041. writeln([space,' MsgStr : ',getstring]);
  4042. if (po_dispid in procoptions) then
  4043. writeln([space,' DispID: ',ppufile.getlongint]);
  4044. readprocimploptions(space,implprocoptions);
  4045. if (pio_has_inlininginfo in implprocoptions) then
  4046. begin
  4047. write ([space,' FuncretSym : ']);
  4048. readderef('');
  4049. readprocinfooptions(space);
  4050. end;
  4051. b:=ppufile.getbyte;
  4052. if b<>0 then
  4053. begin
  4054. write ([space,' Alias names : ']);
  4055. for j:=1 to b do
  4056. begin
  4057. write(ppufile.getstring);
  4058. if j<b then
  4059. write(', ');
  4060. end;
  4061. writeln;
  4062. end;
  4063. tokenbufsize:=ppufile.getlongint;
  4064. if tokenbufsize<>0 then
  4065. begin
  4066. space:=space + ' ';
  4067. write ([space,'Declaration token buffer : size = ',tokenbufsize]);
  4068. tokenbuf:=allocmem(tokenbufsize);
  4069. ppufile.getdata(tokenbuf^,tokenbufsize);
  4070. displaytokenbuffer(tokenbuf,tokenbufsize);
  4071. freemem(tokenbuf);
  4072. delete(space,1,4);
  4073. end;
  4074. if po_syscall_has_libsym in procoptions then
  4075. begin
  4076. { library symbol for AmigaOS/MorphOS/AROS }
  4077. write ([space,' Library symbol : ']);
  4078. readderef('');
  4079. end;
  4080. if not EndOfEntry then
  4081. HasMoreInfos;
  4082. space:=' '+space;
  4083. { parast }
  4084. readsymtable('parast', TPpuProcDef(def));
  4085. { localst }
  4086. if (pio_has_inlininginfo in implprocoptions) then
  4087. readsymtable('inline localst')
  4088. else if (df_generic in defoptions) then
  4089. readsymtable('generic localst');
  4090. if (pio_has_inlininginfo in implprocoptions) then
  4091. readnodetree;
  4092. delete(space,1,4);
  4093. end;
  4094. ibprocvardef :
  4095. begin
  4096. def:=TPpuProcTypeDef.Create(ParentDef);
  4097. readcommondef('Procedural type (ProcVar) definition',defoptions,def);
  4098. read_abstract_proc_def(calloption,procoptions, TPpuProcDef(def));
  4099. writeln([space,' Symtable level :',ppufile.getbyte]);
  4100. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4101. readderef('');
  4102. if not EndOfEntry then
  4103. HasMoreInfos;
  4104. space:=' '+space;
  4105. { parast }
  4106. readsymtable('parast',TPpuProcDef(def));
  4107. delete(space,1,4);
  4108. end;
  4109. ibshortstringdef :
  4110. begin
  4111. strdef:=TPpuStringDef.Create(ParentDef);
  4112. strdef.StrType:=stShort;
  4113. readcommondef('ShortString definition',defoptions,strdef);
  4114. strdef.Len:=getbyte;
  4115. writeln([space,' Length : ',strdef.Len]);
  4116. end;
  4117. ibwidestringdef :
  4118. begin
  4119. strdef:=TPpuStringDef.Create(ParentDef);
  4120. strdef.StrType:=stWide;
  4121. readcommondef('WideString definition',defoptions,strdef);
  4122. strdef.Len:=getasizeint;
  4123. writeln([space,' Length : ',strdef.Len]);
  4124. end;
  4125. ibunicodestringdef :
  4126. begin
  4127. strdef:=TPpuStringDef.Create(ParentDef);
  4128. strdef.StrType:=stUnicode;
  4129. readcommondef('UnicodeString definition',defoptions,strdef);
  4130. strdef.Len:=getasizeint;
  4131. writeln([space,' Length : ',strdef.Len]);
  4132. writeln([space,' Encoding : ',getword]);
  4133. end;
  4134. ibansistringdef :
  4135. begin
  4136. strdef:=TPpuStringDef.Create(ParentDef);
  4137. strdef.StrType:=stAnsi;
  4138. readcommondef('AnsiString definition',defoptions,strdef);
  4139. strdef.Len:=getasizeint;
  4140. writeln([space,' Length : ',strdef.Len]);
  4141. writeln([space,' Encoding : ',getword]);
  4142. end;
  4143. iblongstringdef :
  4144. begin
  4145. strdef:=TPpuStringDef.Create(ParentDef);
  4146. strdef.StrType:=stLong;
  4147. readcommondef('Longstring definition',defoptions,strdef);
  4148. strdef.Len:=getasizeint;
  4149. writeln([space,' Length : ',strdef.Len]);
  4150. end;
  4151. ibrecorddef :
  4152. begin
  4153. objdef:=TPpuRecordDef.Create(ParentDef);
  4154. readcommondef('Record definition',defoptions, objdef);
  4155. def.Name:=getstring;
  4156. writeln([space,' Name of Record : ',objdef.Name]);
  4157. writeln([space,' Import lib/pkg : ',getstring]);
  4158. write ([space,' Options : ']);
  4159. readobjectdefoptions(objdef);
  4160. if (df_copied_def in defoptions) then
  4161. begin
  4162. Include(TPpuRecordDef(def).Options, ooCopied);
  4163. write([space,' Copied from : ']);
  4164. readderef('',objdef.Ancestor);
  4165. end
  4166. else
  4167. begin
  4168. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4169. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4170. writeln([space,' PadAlign : ',shortint(getbyte)]);
  4171. writeln([space,'UseFieldAlignment : ',shortint(getbyte)]);
  4172. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4173. objdef.Size:=getasizeint;
  4174. writeln([space,' DataSize : ',objdef.Size]);
  4175. writeln([space,' PaddingSize : ',getword]);
  4176. readmanagementoperatoroptions(space,'Management operators');
  4177. end;
  4178. {read the record definitions and symbols}
  4179. if not(df_copied_def in current_defoptions) then
  4180. begin
  4181. space:=' '+space;
  4182. readrecordsymtable('fields',TPpuRecordDef(def));
  4183. Delete(space,1,4);
  4184. end;
  4185. if not EndOfEntry then
  4186. HasMoreInfos;
  4187. end;
  4188. ibobjectdef :
  4189. begin
  4190. objdef:=TPpuObjectDef.Create(ParentDef);
  4191. readcommondef('Object/Class definition',defoptions,objdef);
  4192. objdef.Name:=getstring;
  4193. writeln([space,' Name of Class : ',objdef.Name]);
  4194. writeln([space,' Import lib/pkg : ',getstring]);
  4195. write ([space,' Options : ']);
  4196. readobjectdefoptions(objdef);
  4197. otb:=getbyte;
  4198. write ([space,' Type : ']);
  4199. case tobjecttyp(otb) of
  4200. odt_class : writeln('class');
  4201. odt_object : writeln('object');
  4202. odt_interfacecom : writeln('interfacecom');
  4203. odt_interfacecorba : writeln('interfacecorba');
  4204. odt_cppclass : writeln('cppclass');
  4205. odt_dispinterface : writeln('dispinterface');
  4206. odt_objcclass : writeln('objcclass');
  4207. odt_objcprotocol : writeln('objcprotocol');
  4208. odt_helper : writeln('helper');
  4209. odt_objccategory : writeln('objccategory');
  4210. odt_javaclass : writeln('Java class');
  4211. odt_interfacejava : writeln('Java interface');
  4212. else WriteWarning('Invalid object type: ' + IntToStr(b));
  4213. end;
  4214. case tobjecttyp(otb) of
  4215. odt_class, odt_cppclass, odt_objcclass, odt_javaclass:
  4216. objdef.ObjType:=otClass;
  4217. odt_object:
  4218. objdef.ObjType:=otObject;
  4219. odt_interfacecom, odt_interfacecorba, odt_interfacejava, odt_dispinterface:
  4220. objdef.ObjType:=otInterface;
  4221. odt_helper:
  4222. objdef.ObjType:=otHelper;
  4223. end;
  4224. b:=getbyte;
  4225. write ([space,' Helper Type : ']);
  4226. case thelpertype(b) of
  4227. ht_none : writeln('none');
  4228. ht_class : writeln('class helper');
  4229. ht_record : writeln('record helper');
  4230. ht_type : writeln('type helper');
  4231. else WriteWarning('Invalid helper type: ' + IntToStr(b));
  4232. end;
  4233. writeln([space,' External name : ',getstring]);
  4234. objdef.Size:=getasizeint;
  4235. writeln([space,' DataSize : ',objdef.Size]);
  4236. writeln([space,' PaddingSize : ',getword]);
  4237. writeln([space,' FieldAlign : ',shortint(getbyte)]);
  4238. writeln([space,' RecordAlign : ',shortint(getbyte)]);
  4239. writeln([space,' RecordAlignMin : ',shortint(getbyte)]);
  4240. write ([space, ' VmtField : ']);
  4241. readderef('',nil);
  4242. write ([space, ' Ancestor Class : ']);
  4243. readderef('',objdef.Ancestor);
  4244. if tobjecttyp(otb) in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  4245. begin
  4246. { IIDGUID }
  4247. for j:=1to 16 do
  4248. getbyte;
  4249. objdef.IID:=getstring;
  4250. writeln([space,' IID String : ',objdef.IID]);
  4251. end;
  4252. l:=getlongint;
  4253. if l > 0 then
  4254. objdef.Options:=objdef.Options + [ooAbstractMethods];
  4255. writeln([space,' Abstract methods : ',l]);
  4256. if tobjecttyp(otb)=odt_helper then
  4257. begin
  4258. write([space,' Helper parent : ']);
  4259. readderef('',objdef.HelperParent);
  4260. end;
  4261. l:=getlongint;
  4262. writeln([space,' VMT entries: ',l]);
  4263. for j:=1 to l do
  4264. begin
  4265. write([space,' ']);
  4266. readderef('');
  4267. write([space,' Visibility: ']);
  4268. readvisibility;
  4269. end;
  4270. if tobjecttyp(otb) in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  4271. begin
  4272. l:=getlongint;
  4273. writeln([space,' Impl Intf Count : ',l]);
  4274. for j:=1 to l do
  4275. begin
  4276. write ([space,' - Definition : ']);
  4277. readderef('');
  4278. write ([space,' - Getter Def : ']);
  4279. readderef('');
  4280. writeln([space,' IOffset : ',getlongint]);
  4281. writeln([space,' Entry type : ',IntfEntryType2Str(getbyte)]);
  4282. end;
  4283. end;
  4284. if df_copied_def in current_defoptions then
  4285. begin
  4286. Include(objdef.Options, ooCopied);
  4287. writeln(' Copy of def: ');
  4288. readderef('',objdef.Ancestor);
  4289. end
  4290. else
  4291. begin
  4292. {read the record definitions and symbols}
  4293. space:=' '+space;
  4294. readrecordsymtable('fields',objdef);
  4295. Delete(space,1,4);
  4296. end;
  4297. if not EndOfEntry then
  4298. HasMoreInfos;
  4299. end;
  4300. ibfiledef :
  4301. begin
  4302. filedef:=TPpuFileDef.Create(ParentDef);
  4303. ReadCommonDef('File definition',defoptions,filedef);
  4304. write ([space,' Type : ']);
  4305. case getbyte of
  4306. 0 : begin
  4307. writeln('Text');
  4308. filedef.FileType:=ftText;
  4309. end;
  4310. 1 : begin
  4311. writeln('Typed');
  4312. filedef.FileType:=ftTyped;
  4313. write ([space,' File of Type : ']);
  4314. readderef('',filedef.TypeRef);
  4315. end;
  4316. 2 : begin
  4317. writeln('Untyped');
  4318. filedef.FileType:=ftUntyped;
  4319. end;
  4320. end;
  4321. end;
  4322. ibformaldef :
  4323. begin
  4324. def:=TPpuFormalDef.Create(ParentDef);
  4325. readcommondef('Generic definition (void-typ)',defoptions,def);
  4326. TPpuFormalDef(def).IsTyped:=(getbyte<>0);
  4327. writeln([space,' Is Typed : ',TPpuFormalDef(def).IsTyped]);
  4328. end;
  4329. ibundefineddef :
  4330. begin
  4331. def:=TPpuUndefinedDef.Create(ParentDef);
  4332. readcommondef('Undefined definition (generic parameter)',defoptions,def);
  4333. end;
  4334. ibenumdef :
  4335. begin
  4336. enumdef:=TPpuEnumDef.Create(ParentDef);
  4337. readcommondef('Enumeration type definition',defoptions,enumdef);
  4338. enumdef.ElLow:=getaint;
  4339. writeln([space,' Smallest element : ',enumdef.ElLow]);
  4340. enumdef.ElHigh:=getaint;
  4341. writeln([space,' Largest element : ',enumdef.ElHigh]);
  4342. enumdef.Size:=byte(getaint);
  4343. writeln([space,' Size : ',enumdef.Size]);
  4344. if df_copied_def in defoptions then
  4345. begin
  4346. write([space,'Base enumeration type : ']);
  4347. readderef('',enumdef.CopyFrom);
  4348. end
  4349. else
  4350. begin
  4351. space:=' '+space;
  4352. readsymtable('elements',enumdef);
  4353. delete(space,1,4);
  4354. end;
  4355. if tsystemcpu(ppufile.header.common.cpu)=cpu_jvm then
  4356. begin
  4357. write([space,' Class def : ']);
  4358. readderef('');
  4359. end;
  4360. end;
  4361. ibclassrefdef :
  4362. begin
  4363. def:=TPpuClassRefDef.Create(ParentDef);
  4364. readcommondef('Class reference definition',defoptions,def);
  4365. write ([space,' Pointed Type : ']);
  4366. readderef('',TPpuClassRefDef(def).ClassRef);
  4367. end;
  4368. ibsetdef :
  4369. begin
  4370. setdef:=TPpuSetDef.Create(ParentDef);
  4371. readcommondef('Set definition',defoptions,setdef);
  4372. write ([space,' Element type : ']);
  4373. readderef('',setdef.ElType);
  4374. setdef.Size:=getasizeint;
  4375. writeln([space,' Size : ',setdef.Size]);
  4376. setdef.SetBase:=getasizeint;
  4377. writeln([space,' Set Base : ',setdef.SetBase]);
  4378. setdef.SetMax:=getasizeint;
  4379. writeln([space,' Set Max : ',setdef.SetMax]);
  4380. end;
  4381. ibvariantdef :
  4382. begin
  4383. def:=TPpuVariantDef.Create(ParentDef);
  4384. readcommondef('Variant definition',defoptions,def);
  4385. write ([space,' Varianttype : ']);
  4386. b:=getbyte;
  4387. case tvarianttype(b) of
  4388. vt_normalvariant :
  4389. writeln('Normal');
  4390. vt_olevariant :
  4391. begin
  4392. TPpuVariantDef(def).IsOLE:=True;
  4393. writeln('OLE');
  4394. end
  4395. else
  4396. WriteWarning('Invalid varianttype: ' + IntToStr(b));
  4397. end;
  4398. end;
  4399. iberror :
  4400. begin
  4401. WriteError('!! Error in PPU');
  4402. exit;
  4403. end;
  4404. ibenddefs :
  4405. break;
  4406. else
  4407. begin
  4408. WriteError('!! Skipping unsupported PPU Entry in definitions: '+IntToStr(b));
  4409. end;
  4410. end;
  4411. if assigned(def) then
  4412. readdefsubentries(def);
  4413. if (def <> nil) and (def.Parent = nil) then
  4414. def.Free;
  4415. if not EndOfEntry then
  4416. HasMoreInfos;
  4417. until false;
  4418. end;
  4419. end;
  4420. procedure readmoduleoptions(space : string);
  4421. type
  4422. { tmoduleoption type is in unit fmodule }
  4423. tmoduleoption = (mo_none,
  4424. mo_hint_deprecated,
  4425. mo_hint_platform,
  4426. mo_hint_library,
  4427. mo_hint_unimplemented,
  4428. mo_hint_experimental,
  4429. mo_has_deprecated_msg
  4430. );
  4431. tmoduleoptions = set of tmoduleoption;
  4432. tmoduleopt=record
  4433. mask : tmoduleoption;
  4434. str : string[30];
  4435. end;
  4436. const
  4437. moduleopts=ord(high(tmoduleoption));
  4438. moduleopt : array[1..moduleopts] of tmoduleopt=(
  4439. (mask:mo_hint_deprecated; str:'Hint Deprecated'),
  4440. (mask:mo_hint_platform; str:'Hint Platform'),
  4441. (mask:mo_hint_library; str:'Hint Library'),
  4442. (mask:mo_hint_unimplemented; str:'Hint Unimplemented'),
  4443. (mask:mo_hint_experimental; str:'Hint Experimental'),
  4444. (mask:mo_has_deprecated_msg; str:'Has Deprecated Message')
  4445. );
  4446. var
  4447. moduleoptions : tmoduleoptions;
  4448. i : longint;
  4449. first : boolean;
  4450. begin
  4451. ppufile.getset(tppuset1(moduleoptions));
  4452. if moduleoptions<>[] then
  4453. begin
  4454. first:=true;
  4455. for i:=1to moduleopts do
  4456. if (moduleopt[i].mask in moduleoptions) then
  4457. begin
  4458. if first then
  4459. first:=false
  4460. else
  4461. write(', ');
  4462. write(moduleopt[i].str);
  4463. end;
  4464. end;
  4465. writeln;
  4466. if mo_has_deprecated_msg in moduleoptions then
  4467. writeln([space,'Deprecated : ', ppufile.getstring]);
  4468. end;
  4469. {****************************************************************************
  4470. Read General Part
  4471. ****************************************************************************}
  4472. procedure readinterface(silent : boolean);
  4473. var
  4474. b : byte;
  4475. sourcenumber, i : longint;
  4476. feature : tfeature;
  4477. features : tfeatures;
  4478. s : string;
  4479. begin
  4480. with ppufile do
  4481. begin
  4482. repeat
  4483. b:=readentry;
  4484. case b of
  4485. ibmodulename :
  4486. begin
  4487. CurUnit.Name:=getstring;
  4488. if not silent then
  4489. Writeln(['Module Name: ',CurUnit.Name]);
  4490. end;
  4491. ibfeatures :
  4492. begin
  4493. getset(tppuset4(features));
  4494. Writeln('Features: ');
  4495. for feature:=low(tfeatures) to high(tfeature) do
  4496. if feature in features then
  4497. begin
  4498. str(feature,s);
  4499. s:=copy(s,3,255);
  4500. writeln([s]);
  4501. end;
  4502. end;
  4503. ibmoduleoptions:
  4504. if not silent then
  4505. readmoduleoptions(' ');
  4506. ibsourcefiles :
  4507. begin
  4508. sourcenumber:=1;
  4509. if not silent then
  4510. while not EndOfEntry do
  4511. begin
  4512. with TPpuSrcFile.Create(CurUnit.SourceFiles) do begin
  4513. Name:=getstring;
  4514. i:=getlongint;
  4515. try
  4516. if i >= 0 then
  4517. FileTime:=FileDateToDateTime(i);
  4518. Writeln(['Source file ',sourcenumber,' : ',Name,' ',filetimestring(i)]);
  4519. except
  4520. end;
  4521. end;
  4522. inc(sourcenumber);
  4523. end;
  4524. end;
  4525. {$IFDEF MACRO_DIFF_HINT}
  4526. ibusedmacros :
  4527. begin
  4528. if not silent then
  4529. while not EndOfEntry do
  4530. begin
  4531. Write('Conditional ',getstring);
  4532. if getboolean then
  4533. write(' defined at startup')
  4534. else
  4535. write(' not defined at startup');
  4536. if getboolean then
  4537. writeln(' was used')
  4538. else
  4539. writeln;
  4540. end;
  4541. end;
  4542. {$ENDIF}
  4543. ibloadunit :
  4544. if not silent then
  4545. ReadLoadUnit;
  4546. iblinkunitofiles :
  4547. if not silent then
  4548. ReadLinkContainer('Link unit object file: ');
  4549. iblinkunitstaticlibs :
  4550. if not silent then
  4551. ReadLinkContainer('Link unit static lib: ');
  4552. iblinkunitsharedlibs :
  4553. if not silent then
  4554. ReadLinkContainer('Link unit shared lib: ');
  4555. iblinkotherofiles :
  4556. if not silent then
  4557. ReadLinkContainer('Link other object file: ');
  4558. iblinkotherstaticlibs :
  4559. if not silent then
  4560. ReadLinkContainer('Link other static lib: ');
  4561. iblinkothersharedlibs :
  4562. if not silent then
  4563. ReadLinkContainer('Link other shared lib: ');
  4564. iblinkotherframeworks:
  4565. if not silent then
  4566. ReadLinkContainer('Link framework: ');
  4567. ibjvmnamespace:
  4568. Writeln('JVM name space: '+getString);
  4569. ibmainname:
  4570. if not silent then
  4571. Writeln(['Specified main program symbol name: ',getstring]);
  4572. ibImportSymbols :
  4573. if not silent then
  4574. ReadImportSymbols;
  4575. ibderefdata :
  4576. ReadDerefData;
  4577. ibderefmap :
  4578. ReadDerefMap;
  4579. ibwpofile :
  4580. if not silent then
  4581. ReadWpoFileInfo;
  4582. ibresources :
  4583. if not silent then
  4584. ReadContainer('Resource file: ');
  4585. iborderedsymbols:
  4586. if not silent then
  4587. ReadContainer('Ordered symbol: ');
  4588. iberror :
  4589. begin
  4590. WriteError('Error in PPU');
  4591. exit;
  4592. end;
  4593. ibendinterface :
  4594. break;
  4595. else
  4596. begin
  4597. WriteError('!! Skipping unsupported PPU Entry in General Part: '+IntToStr(b));
  4598. end;
  4599. end;
  4600. until false;
  4601. end;
  4602. end;
  4603. {****************************************************************************
  4604. Read Implementation Part
  4605. ****************************************************************************}
  4606. procedure readimplementation;
  4607. var
  4608. b : byte;
  4609. begin
  4610. with ppufile do
  4611. begin
  4612. repeat
  4613. b:=readentry;
  4614. case b of
  4615. ibasmsymbols :
  4616. ReadAsmSymbols;
  4617. ibloadunit :
  4618. ReadLoadUnit;
  4619. ibunitimportsyms :
  4620. ReadUnitImportSyms;
  4621. iberror :
  4622. begin
  4623. WriteError('Error in PPU');
  4624. exit;
  4625. end;
  4626. ibendimplementation :
  4627. break;
  4628. else
  4629. begin
  4630. WriteError('!! Skipping unsupported PPU Entry in Implementation: '+IntToStr(b));
  4631. end;
  4632. end;
  4633. until false;
  4634. end;
  4635. end;
  4636. function parseextraheader(module: TPpuModuleDef; ppufile: tppufile): boolean;
  4637. var
  4638. b: byte;
  4639. begin
  4640. result:=false;
  4641. b:=ppufile.readentry;
  4642. if b<>ibextraheader then
  4643. exit;
  4644. CurUnit.LongVersion:=cardinal(ppufile.getlongint);
  4645. Writeln(['LongVersion: ',CurUnit.LongVersion]);
  4646. ppufile.getset(tppuset4(CurUnit.ModuleFlags));
  4647. result:=ppufile.EndOfEntry and (CurUnit.LongVersion=CurrentPPULongVersion);
  4648. if mf_symansistr in CurUnit.ModuleFlags then
  4649. SymAnsiStr:=true;
  4650. end;
  4651. procedure dofile (filename : string);
  4652. begin
  4653. { reset }
  4654. space:='';
  4655. { fix filename }
  4656. if pos('.',filename)=0 then
  4657. filename:=filename+'.ppu';
  4658. ppufile:=tppudumpfile.create(filename);
  4659. if not ppufile.openfile then
  4660. begin
  4661. WriteError('IO-Error when opening : '+filename+', Skipping');
  4662. exit;
  4663. end;
  4664. { PPU File is open, check for PPU Id }
  4665. if not ppufile.CheckPPUID then
  4666. begin
  4667. WriteError(Filename+' : Not a valid PPU file, Skipping');
  4668. exit;
  4669. end;
  4670. { Check PPU Version }
  4671. ppuversion:=ppufile.getversion;
  4672. Writeln(['Analyzing ',filename,' (v',PPUVersion,')']);
  4673. if not SkipVersionCheck and (PPUVersion <> CurrentPPUVersion) then
  4674. begin
  4675. WriteError(Format('Unsupported PPU version %d. Expecting PPU version %d.', [PPUVersion, CurrentPPUVersion]));
  4676. exit;
  4677. end;
  4678. CurUnit:=TPpuModuleDef.Create(UnitList);
  4679. CurUnit.Version:=ppuversion;
  4680. if not parseextraheader(CurUnit, ppufile) then
  4681. begin
  4682. WriteError(Format('Unsupported PPU sub-version %d. Expecting PPU sub-version %d.', [CurUnit.LongVersion, CurrentPPULongVersion]));
  4683. end;
  4684. { Write PPU Header Information }
  4685. if (verbose and v_header)<>0 then
  4686. begin
  4687. Writeln;
  4688. Writeln('Header');
  4689. Writeln('-------');
  4690. with ppufile.header do
  4691. begin
  4692. Writeln(['Compiler version : ',ppufile.header.common.compiler shr 14,'.',
  4693. (ppufile.header.common.compiler shr 7) and $7f,'.',
  4694. ppufile.header.common.compiler and $7f]);
  4695. WriteLn(['Target processor : ',Cpu2Str(common.cpu)]);
  4696. WriteLn(['Target operating system : ',Target2Str(common.target)]);
  4697. Writeln(['Unit flags : ',PPUFlags2Str(common.flags)]);
  4698. Writeln(['FileSize (w/o header) : ',common.size]);
  4699. Writeln(['Checksum : ',hexstr(checksum,8)]);
  4700. Writeln(['Interface Checksum : ',hexstr(interface_checksum,8)]);
  4701. Writeln(['Indirect Checksum : ',hexstr(indirect_checksum,8)]);
  4702. Writeln(['Definitions stored : ',tostr(deflistsize)]);
  4703. Writeln(['Symbols stored : ',tostr(symlistsize)]);
  4704. end;
  4705. end;
  4706. with ppufile.header do
  4707. begin
  4708. CurUnit.Crc:=checksum;
  4709. CurUnit.IntfCrc:=interface_checksum;
  4710. CurUnit.TargetCPU:=Cpu2Str(common.cpu);
  4711. CurUnit.TargetOS:=Target2Str(common.target);
  4712. end;
  4713. {read the general stuff}
  4714. if (verbose and v_interface)<>0 then
  4715. begin
  4716. Writeln;
  4717. Writeln('Interface section');
  4718. Writeln('------------------');
  4719. readinterface(false);
  4720. end
  4721. { We need derefdata from Interface }
  4722. else if verbose and (v_defs or v_syms or v_implementation)<>0 then
  4723. readinterface(true)
  4724. else
  4725. ppufile.skipuntilentry(ibendinterface);
  4726. Writeln;
  4727. Writeln('Interface symtable');
  4728. Writeln('----------------------');
  4729. readsymtableoptions('interface');
  4730. {read the definitions}
  4731. if (verbose and v_defs)<>0 then
  4732. begin
  4733. Writeln;
  4734. Writeln('Interface definitions');
  4735. Writeln('----------------------');
  4736. readdefinitions('interface', CurUnit);
  4737. end
  4738. else
  4739. ppufile.skipuntilentry(ibenddefs);
  4740. {read the symbols}
  4741. if (verbose and v_syms)<>0 then
  4742. begin
  4743. Writeln;
  4744. Writeln('Interface Symbols');
  4745. Writeln('------------------');
  4746. readsymbols('interface',CurUnit);
  4747. end
  4748. else
  4749. ppufile.skipuntilentry(ibendsyms);
  4750. {read the macro symbols}
  4751. if (verbose and v_syms)<>0 then
  4752. begin
  4753. Writeln;
  4754. Writeln('Interface Macro Symbols');
  4755. Writeln('-----------------------');
  4756. end;
  4757. if ppufile.readentry<>ibexportedmacros then
  4758. begin
  4759. WriteError('!! Error in PPU');
  4760. exit;
  4761. end;
  4762. if ppufile.getboolean then
  4763. begin
  4764. readsymtableoptions('interface macro');
  4765. {skip the definition section for macros (since they are never used) }
  4766. ppufile.skipuntilentry(ibenddefs);
  4767. {read the macro symbols}
  4768. if (verbose and v_syms)<>0 then
  4769. readsymbols('interface macro')
  4770. else
  4771. ppufile.skipuntilentry(ibendsyms);
  4772. end
  4773. else
  4774. Writeln('(no exported macros)');
  4775. {read the implementation stuff}
  4776. if (verbose and v_implementation)<>0 then
  4777. begin
  4778. Writeln;
  4779. Writeln('Implementation section');
  4780. Writeln('-----------------------');
  4781. readimplementation;
  4782. end
  4783. else
  4784. ppufile.skipuntilentry(ibendimplementation);
  4785. {read the static symtable}
  4786. Writeln;
  4787. Writeln('Implementation symtable');
  4788. Writeln('----------------------');
  4789. readsymtableoptions('implementation');
  4790. if (mf_local_symtable in CurUnit.ModuleFlags) then
  4791. begin
  4792. if (verbose and v_defs)<>0 then
  4793. begin
  4794. Writeln;
  4795. Writeln('Static definitions');
  4796. Writeln('----------------------');
  4797. readdefinitions('implementation', nil);
  4798. end
  4799. else
  4800. ppufile.skipuntilentry(ibenddefs);
  4801. {read the symbols}
  4802. if (verbose and v_syms)<>0 then
  4803. begin
  4804. Writeln;
  4805. Writeln('Static Symbols');
  4806. Writeln('------------------');
  4807. readsymbols('implementation');
  4808. end
  4809. else
  4810. ppufile.skipuntilentry(ibendsyms);
  4811. end;
  4812. ReadCreatedObjTypes;
  4813. FreeDerefdata;
  4814. {shutdown ppufile}
  4815. ppufile.closefile;
  4816. ppufile.free;
  4817. Writeln;
  4818. end;
  4819. procedure WriteLogo;
  4820. begin
  4821. writeln(Title+' Version '+version_string);
  4822. writeln(Copyright);
  4823. writeln;
  4824. end;
  4825. procedure help;
  4826. begin
  4827. WriteLogo;
  4828. writeln('usage: ppudump [options] <filename1> <filename2>...');
  4829. writeln;
  4830. writeln('[options] can be:');
  4831. writeln(' -F<format> Set output format to <format>');
  4832. writeln(' t - text format (default)');
  4833. writeln(' j - JSON format');
  4834. writeln(' x - XML format');
  4835. writeln(' -M Exit with ExitCode=2 if more information is available');
  4836. writeln(' -S Skip PPU version check. May lead to reading errors');
  4837. writeln(' -V<verbose> Set verbosity to <verbose>');
  4838. writeln(' H - Show header info');
  4839. writeln(' I - Show interface');
  4840. writeln(' M - Show implementation');
  4841. writeln(' S - Show interface symbols');
  4842. writeln(' D - Show interface definitions');
  4843. writeln(' A - Show all');
  4844. writeln(' -h, -? This helpscreen');
  4845. halt;
  4846. end;
  4847. var
  4848. startpara,
  4849. nrfile,i : longint;
  4850. para : string;
  4851. const
  4852. error_on_more : boolean = false;
  4853. begin
  4854. if paramcount<1 then
  4855. help;
  4856. { turn verbose on by default }
  4857. verbose:=v_all;
  4858. { read options }
  4859. startpara:=1;
  4860. while copy(paramstr(startpara),1,1)='-' do
  4861. begin
  4862. para:=paramstr(startpara);
  4863. case upcase(para[2]) of
  4864. 'F' : begin
  4865. FreeAndNil(pout);
  4866. if Length(para) > 2 then
  4867. case upcase(para[3]) of
  4868. 'T':
  4869. nostdout:=False;
  4870. 'J':
  4871. begin
  4872. nostdout:=True;
  4873. pout:=TPpuJsonOutput.Create(StdOutputHandle);
  4874. end;
  4875. 'X':
  4876. begin
  4877. nostdout:=True;
  4878. pout:=TPpuXmlOutput.Create(StdOutputHandle);
  4879. end;
  4880. else
  4881. begin
  4882. WriteError('Invalid output format: ' + para[3]);
  4883. Halt(1);
  4884. end;
  4885. end;
  4886. end;
  4887. 'M' : error_on_more:=true;
  4888. 'S' : SkipVersionCheck:=True;
  4889. 'V' : begin
  4890. verbose:=0;
  4891. for i:=3 to length(para) do
  4892. case upcase(para[i]) of
  4893. 'H' : verbose:=verbose or v_header;
  4894. 'I' : verbose:=verbose or v_interface;
  4895. 'M' : verbose:=verbose or v_implementation;
  4896. 'D' : verbose:=verbose or v_defs;
  4897. 'S' : verbose:=verbose or v_syms;
  4898. 'A' : verbose:=verbose or v_all;
  4899. end;
  4900. end;
  4901. 'H' : help;
  4902. '?' : help;
  4903. else
  4904. begin
  4905. WriteError('Invalid option: ' + para);
  4906. Halt(1);
  4907. end;
  4908. end;
  4909. inc(startpara);
  4910. end;
  4911. if not nostdout then
  4912. WriteLogo;
  4913. UnitList:=TPpuContainerDef.Create(nil);
  4914. try
  4915. UnitList.ItemsName:='';
  4916. { process files }
  4917. for nrfile:=startpara to paramcount do
  4918. dofile (paramstr(nrfile));
  4919. if not has_errors and (pout <> nil) then
  4920. begin
  4921. pout.Init;
  4922. UnitList.Write(pout);
  4923. pout.Done;
  4924. end;
  4925. finally
  4926. UnitList.Free;
  4927. pout.Free;
  4928. end;
  4929. if has_errors then
  4930. Halt(1);
  4931. if error_on_more and
  4932. (has_more_infos or has_warnings) then
  4933. Halt(2);
  4934. end.