ppudump.pp 164 KB

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