Subversion Repositories Kolibri OS

Rev

Rev 8976 | Rev 8980 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. import re
  2. import os
  3. import argparse
  4. import sys
  5.  
  6. # Parameters
  7. # Path to doxygen folder to make doxygen files in: -o <path>
  8. doxygen_src_path = 'docs/doxygen'
  9. # Remove generated doxygen files: --clean
  10. clean_generated_stuff = False
  11. # Dump all defined symbols: --dump
  12. dump_symbols = False
  13. # Print symbol stats: --stats
  14. print_stats = False
  15. # Do not write warnings file: --nowarn
  16. enable_warnings = True
  17.  
  18. # Constants
  19. link_root = "http://websvn.kolibrios.org/filedetails.php?repname=Kolibri+OS&path=/kernel/trunk"
  20.  
  21. # fasm keywords
  22. keywords = [
  23.         # Generic keywords
  24.         "align",
  25.         "equ",
  26.         "org",
  27.         "while",
  28.         "load",
  29.         "store",
  30.         "times",
  31.         "repeat",
  32.         "virtual",
  33.         "display",
  34.         "err",
  35.         "assert",
  36.         "if",
  37.         # Instructions
  38.         "aaa",
  39.         "aad",
  40.         "aam",
  41.         "aas",
  42.         "adc",
  43.         "adcx",
  44.         "add",
  45.         "addpd",
  46.         "addps",
  47.         "addsd",
  48.         "addss",
  49.         "addsubpd",
  50.         "addsubps",
  51.         "adox",
  52.         "aesdec",
  53.         "aesdeclast",
  54.         "aesenc",
  55.         "aesenclast",
  56.         "aesimc",
  57.         "aeskeygenassist",
  58.         "and",
  59.         "andn",
  60.         "andnpd",
  61.         "andnps",
  62.         "andpd",
  63.         "andps",
  64.         "arpl",
  65.         "bextr",
  66.         "blendpd",
  67.         "blendps",
  68.         "blendvpd",
  69.         "blendvps",
  70.         "blsi",
  71.         "blsmsk",
  72.         "blsr",
  73.         "bndcl",
  74.         "bndcn",
  75.         "bndcu",
  76.         "bndldx",
  77.         "bndmk",
  78.         "bndmov",
  79.         "bndstx",
  80.         "bound",
  81.         "bsf",
  82.         "bsr",
  83.         "bswap",
  84.         "bt",
  85.         "btc",
  86.         "btr",
  87.         "bts",
  88.         "bzhi",
  89.         "call",
  90.         "cbw",
  91.         "cdq",
  92.         "cdqe",
  93.         "clac",
  94.         "clc",
  95.         "cld",
  96.         "cldemote",
  97.         "clflush",
  98.         "clflushopt",
  99.         "cli",
  100.         "clts",
  101.         "clwb",
  102.         "cmc",
  103.         "cmova",
  104.         "cmovae",
  105.         "cmovb",
  106.         "cmovbe",
  107.         "cmovc",
  108.         "cmove",
  109.         "cmovg",
  110.         "cmovge",
  111.         "cmovl",
  112.         "cmovle",
  113.         "cmovna",
  114.         "cmovnae",
  115.         "cmovnb",
  116.         "cmovnbe",
  117.         "cmovnc",
  118.         "cmovne",
  119.         "cmovng",
  120.         "cmovnge",
  121.         "cmovnl",
  122.         "cmovnle",
  123.         "cmovno",
  124.         "cmovnp",
  125.         "cmovns",
  126.         "cmovnz",
  127.         "cmovo",
  128.         "cmovp",
  129.         "cmovpe",
  130.         "cmovpo",
  131.         "cmovs",
  132.         "cmovz",
  133.         "cmp",
  134.         "cmppd",
  135.         "cmpps",
  136.         "cmps",
  137.         "cmpsb",
  138.         "cmpsd",
  139.         "cmpsd",
  140.         "cmpsq",
  141.         "cmpss",
  142.         "cmpsw",
  143.         "cmpxchg",
  144.         "cmpxchg16b",
  145.         "cmpxchg8b",
  146.         "comisd",
  147.         "comiss",
  148.         "cpuid",
  149.         "cqo",
  150.         "crc32",
  151.         "cvtdq2pd",
  152.         "cvtdq2ps",
  153.         "cvtpd2dq",
  154.         "cvtpd2pi",
  155.         "cvtpd2ps",
  156.         "cvtpi2pd",
  157.         "cvtpi2ps",
  158.         "cvtps2dq",
  159.         "cvtps2pd",
  160.         "cvtps2pi",
  161.         "cvtsd2si",
  162.         "cvtsd2ss",
  163.         "cvtsi2sd",
  164.         "cvtsi2ss",
  165.         "cvtss2sd",
  166.         "cvtss2si",
  167.         "cvttpd2dq",
  168.         "cvttpd2pi",
  169.         "cvttps2dq",
  170.         "cvttps2pi",
  171.         "cvttsd2si",
  172.         "cvttss2si",
  173.         "cwd",
  174.         "cwde",
  175.         "daa",
  176.         "das",
  177.         "dec",
  178.         "div",
  179.         "divpd",
  180.         "divps",
  181.         "divsd",
  182.         "divss",
  183.         "dppd",
  184.         "dpps",
  185.         "emms",
  186.         "enter",
  187.         "extractps",
  188.         "f2xm1",
  189.         "fabs",
  190.         "fadd",
  191.         "faddp",
  192.         "fbld",
  193.         "fbstp",
  194.         "fchs",
  195.         "fclex",
  196.         "fcmova",
  197.         "fcmovae",
  198.         "fcmovb",
  199.         "fcmovbe",
  200.         "fcmovc",
  201.         "fcmove",
  202.         "fcmovg",
  203.         "fcmovge",
  204.         "fcmovl",
  205.         "fcmovle",
  206.         "fcmovna",
  207.         "fcmovnae",
  208.         "fcmovnb",
  209.         "fcmovnbe",
  210.         "fcmovnc",
  211.         "fcmovne",
  212.         "fcmovng",
  213.         "fcmovnge",
  214.         "fcmovnl",
  215.         "fcmovnle",
  216.         "fcmovno",
  217.         "fcmovnp",
  218.         "fcmovns",
  219.         "fcmovnz",
  220.         "fcmovo",
  221.         "fcmovp",
  222.         "fcmovpe",
  223.         "fcmovpo",
  224.         "fcmovs",
  225.         "fcmovz",
  226.         "fcom",
  227.         "fcomi",
  228.         "fcomip",
  229.         "fcomp",
  230.         "fcompp",
  231.         "fcos",
  232.         "fdecstp",
  233.         "fdiv",
  234.         "fdivp",
  235.         "fdivr",
  236.         "fdivrp",
  237.         "ffree",
  238.         "fiadd",
  239.         "ficom",
  240.         "ficomp",
  241.         "fidiv",
  242.         "fidivr",
  243.         "fild",
  244.         "fimul",
  245.         "fincstp",
  246.         "finit",
  247.         "fist",
  248.         "fistp",
  249.         "fisttp",
  250.         "fisub",
  251.         "fisubr",
  252.         "fld",
  253.         "fld1",
  254.         "fldcw",
  255.         "fldenv",
  256.         "fldl2e",
  257.         "fldl2t",
  258.         "fldlg2",
  259.         "fldln2",
  260.         "fldpi",
  261.         "fldz",
  262.         "fmul",
  263.         "fmulp",
  264.         "fnclex",
  265.         "fninit",
  266.         "fnop",
  267.         "fnsave",
  268.         "fnstcw",
  269.         "fnstenv",
  270.         "fnstsw",
  271.         "fpatan",
  272.         "fprem",
  273.         "fprem1",
  274.         "fptan",
  275.         "frndint",
  276.         "frstor",
  277.         "fsave",
  278.         "fscale",
  279.         "fsin",
  280.         "fsincos",
  281.         "fsqrt",
  282.         "fst",
  283.         "fstcw",
  284.         "fstenv",
  285.         "fstp",
  286.         "fstsw",
  287.         "fsub",
  288.         "fsubp",
  289.         "fsubr",
  290.         "fsubrp",
  291.         "ftst",
  292.         "fucom",
  293.         "fucomi",
  294.         "fucomip",
  295.         "fucomp",
  296.         "fucompp",
  297.         "fwait",
  298.         "fxam",
  299.         "fxch",
  300.         "fxrstor",
  301.         "fxsave",
  302.         "fxtract",
  303.         "fyl2x",
  304.         "fyl2xp1",
  305.         "gf2p8affineinvqb",
  306.         "gf2p8affineqb",
  307.         "gf2p8mulb",
  308.         "haddpd",
  309.         "haddps",
  310.         "hlt",
  311.         "hsubpd",
  312.         "hsubps",
  313.         "idiv",
  314.         "imul",
  315.         "in",
  316.         "inc",
  317.         "ins",
  318.         "insb",
  319.         "insd",
  320.         "insertps",
  321.         "insw",
  322.         "int",
  323.         "int1",
  324.         "int3",
  325.         "into",
  326.         "invd",
  327.         "invlpg",
  328.         "invpcid",
  329.         "iret",
  330.         "iretd",
  331.         "jmp",
  332.         "ja",
  333.         "jae",
  334.         "jb",
  335.         "jbe",
  336.         "jc",
  337.         "jcxz",
  338.         "jecxz",
  339.         "je",
  340.         "jg",
  341.         "jge",
  342.         "jl",
  343.         "jle",
  344.         "jna",
  345.         "jnae",
  346.         "jnb",
  347.         "jnbe",
  348.         "jnc",
  349.         "jne",
  350.         "jng",
  351.         "jnge",
  352.         "jnl",
  353.         "jnle",
  354.         "jno",
  355.         "jnp",
  356.         "jns",
  357.         "jnz",
  358.         "jo",
  359.         "jp",
  360.         "jpe",
  361.         "jpo",
  362.         "js",
  363.         "jz",
  364.         "kaddb",
  365.         "kaddd",
  366.         "kaddq",
  367.         "kaddw",
  368.         "kandb",
  369.         "kandd",
  370.         "kandnb",
  371.         "kandnd",
  372.         "kandnq",
  373.         "kandnw",
  374.         "kandq",
  375.         "kandw",
  376.         "kmovb",
  377.         "kmovd",
  378.         "kmovq",
  379.         "kmovw",
  380.         "knotb",
  381.         "knotd",
  382.         "knotq",
  383.         "knotw",
  384.         "korb",
  385.         "kord",
  386.         "korq",
  387.         "kortestb",
  388.         "kortestd",
  389.         "kortestq",
  390.         "kortestw",
  391.         "korw",
  392.         "kshiftlb",
  393.         "kshiftld",
  394.         "kshiftlq",
  395.         "kshiftlw",
  396.         "kshiftrb",
  397.         "kshiftrd",
  398.         "kshiftrq",
  399.         "kshiftrw",
  400.         "ktestb",
  401.         "ktestd",
  402.         "ktestq",
  403.         "ktestw",
  404.         "kunpckbw",
  405.         "kunpckdq",
  406.         "kunpckwd",
  407.         "kxnorb",
  408.         "kxnord",
  409.         "kxnorq",
  410.         "kxnorw",
  411.         "kxorb",
  412.         "kxord",
  413.         "kxorq",
  414.         "kxorw",
  415.         "lahf",
  416.         "lar",
  417.         "lddqu",
  418.         "ldmxcsr",
  419.         "lds",
  420.         "lea",
  421.         "leave",
  422.         "les",
  423.         "lfence",
  424.         "lfs",
  425.         "lgdt",
  426.         "lgs",
  427.         "lidt",
  428.         "lldt",
  429.         "lmsw",
  430.         "lock",
  431.         "lods",
  432.         "lodsb",
  433.         "lodsd",
  434.         "lodsq",
  435.         "lodsw",
  436.         "loop",
  437.         "loopa",
  438.         "loopae",
  439.         "loopb",
  440.         "loopbe",
  441.         "loopc",
  442.         "loope",
  443.         "loopg",
  444.         "loopge",
  445.         "loopl",
  446.         "loople",
  447.         "loopna",
  448.         "loopnae",
  449.         "loopnb",
  450.         "loopnbe",
  451.         "loopnc",
  452.         "loopne",
  453.         "loopng",
  454.         "loopnge",
  455.         "loopnl",
  456.         "loopnle",
  457.         "loopno",
  458.         "loopnp",
  459.         "loopns",
  460.         "loopnz",
  461.         "loopo",
  462.         "loopp",
  463.         "looppe",
  464.         "looppo",
  465.         "loops",
  466.         "loopz",
  467.         "lsl",
  468.         "lss",
  469.         "ltr",
  470.         "lzcnt",
  471.         "maskmovdqu",
  472.         "maskmovq",
  473.         "maxpd",
  474.         "maxps",
  475.         "maxsd",
  476.         "maxss",
  477.         "mfence",
  478.         "minpd",
  479.         "minps",
  480.         "minsd",
  481.         "minss",
  482.         "monitor",
  483.         "mov",
  484.         "movapd",
  485.         "movaps",
  486.         "movbe",
  487.         "movd",
  488.         "movddup",
  489.         "movdir64b",
  490.         "movdiri",
  491.         "movdq2q",
  492.         "movdqa",
  493.         "movdqu",
  494.         "movhlps",
  495.         "movhpd",
  496.         "movhps",
  497.         "movlhps",
  498.         "movlpd",
  499.         "movlps",
  500.         "movmskpd",
  501.         "movmskps",
  502.         "movntdq",
  503.         "movntdqa",
  504.         "movnti",
  505.         "movntpd",
  506.         "movntps",
  507.         "movntq",
  508.         "movq",
  509.         "movq",
  510.         "movq2dq",
  511.         "movs",
  512.         "movsb",
  513.         "movsd",
  514.         "movsd",
  515.         "movshdup",
  516.         "movsldup",
  517.         "movsq",
  518.         "movss",
  519.         "movsw",
  520.         "movsx",
  521.         "movsxd",
  522.         "movupd",
  523.         "movups",
  524.         "movzx",
  525.         "mpsadbw",
  526.         "mul",
  527.         "mulpd",
  528.         "mulps",
  529.         "mulsd",
  530.         "mulss",
  531.         "mulx",
  532.         "mwait",
  533.         "neg",
  534.         "nop",
  535.         "not",
  536.         "or",
  537.         "orpd",
  538.         "orps",
  539.         "out",
  540.         "outs",
  541.         "outsb",
  542.         "outsd",
  543.         "outsw",
  544.         "pabsb",
  545.         "pabsd",
  546.         "pabsq",
  547.         "pabsw",
  548.         "packssdw",
  549.         "packsswb",
  550.         "packusdw",
  551.         "packuswb",
  552.         "paddb",
  553.         "paddd",
  554.         "paddq",
  555.         "paddsb",
  556.         "paddsw",
  557.         "paddusb",
  558.         "paddusw",
  559.         "paddw",
  560.         "palignr",
  561.         "pand",
  562.         "pandn",
  563.         "pause",
  564.         "pavgb",
  565.         "pavgw",
  566.         "pblendvb",
  567.         "pblendw",
  568.         "pclmulqdq",
  569.         "pcmpeqb",
  570.         "pcmpeqd",
  571.         "pcmpeqq",
  572.         "pcmpeqw",
  573.         "pcmpestri",
  574.         "pcmpestrm",
  575.         "pcmpgtb",
  576.         "pcmpgtd",
  577.         "pcmpgtq",
  578.         "pcmpgtw",
  579.         "pcmpistri",
  580.         "pcmpistrm",
  581.         "pdep",
  582.         "pext",
  583.         "pextrb",
  584.         "pextrd",
  585.         "pextrq",
  586.         "pextrw",
  587.         "phaddd",
  588.         "phaddsw",
  589.         "phaddw",
  590.         "phminposuw",
  591.         "phsubd",
  592.         "phsubsw",
  593.         "phsubw",
  594.         "pinsrb",
  595.         "pinsrd",
  596.         "pinsrq",
  597.         "pinsrw",
  598.         "pmaddubsw",
  599.         "pmaddwd",
  600.         "pmaxsb",
  601.         "pmaxsd",
  602.         "pmaxsq",
  603.         "pmaxsw",
  604.         "pmaxub",
  605.         "pmaxud",
  606.         "pmaxuq",
  607.         "pmaxuw",
  608.         "pminsb",
  609.         "pminsd",
  610.         "pminsq",
  611.         "pminsw",
  612.         "pminub",
  613.         "pminud",
  614.         "pminuq",
  615.         "pminuw",
  616.         "pmovmskb",
  617.         "pmovsx",
  618.         "pmovzx",
  619.         "pmuldq",
  620.         "pmulhrsw",
  621.         "pmulhuw",
  622.         "pmulhw",
  623.         "pmulld",
  624.         "pmullq",
  625.         "pmullw",
  626.         "pmuludq",
  627.         "pop",
  628.         "popa",
  629.         "popad",
  630.         "popcnt",
  631.         "popf",
  632.         "popfd",
  633.         "popfq",
  634.         "por",
  635.         "prefetchw",
  636.         "prefetchh",
  637.         "psadbw",
  638.         "pshufb",
  639.         "pshufd",
  640.         "pshufhw",
  641.         "pshuflw",
  642.         "pshufw",
  643.         "psignb",
  644.         "psignd",
  645.         "psignw",
  646.         "pslld",
  647.         "pslldq",
  648.         "psllq",
  649.         "psllw",
  650.         "psrad",
  651.         "psraq",
  652.         "psraw",
  653.         "psrld",
  654.         "psrldq",
  655.         "psrlq",
  656.         "psrlw",
  657.         "psubb",
  658.         "psubd",
  659.         "psubq",
  660.         "psubsb",
  661.         "psubsw",
  662.         "psubusb",
  663.         "psubusw",
  664.         "psubw",
  665.         "ptest",
  666.         "ptwrite",
  667.         "punpckhbw",
  668.         "punpckhdq",
  669.         "punpckhqdq",
  670.         "punpckhwd",
  671.         "punpcklbw",
  672.         "punpckldq",
  673.         "punpcklqdq",
  674.         "punpcklwd",
  675.         "push",
  676.         "pushw",
  677.         "pushd",
  678.         "pusha",
  679.         "pushad",
  680.         "pushf",
  681.         "pushfd",
  682.         "pushfq",
  683.         "pxor",
  684.         "rcl",
  685.         "rcpps",
  686.         "rcpss",
  687.         "rcr",
  688.         "rdfsbase",
  689.         "rdgsbase",
  690.         "rdmsr",
  691.         "rdpid",
  692.         "rdpkru",
  693.         "rdpmc",
  694.         "rdrand",
  695.         "rdseed",
  696.         "rdtsc",
  697.         "rdtscp",
  698.         "rep",
  699.         "repe",
  700.         "repne",
  701.         "repnz",
  702.         "repz",
  703.         "ret",
  704.         "rol",
  705.         "ror",
  706.         "rorx",
  707.         "roundpd",
  708.         "roundps",
  709.         "roundsd",
  710.         "roundss",
  711.         "rsm",
  712.         "rsqrtps",
  713.         "rsqrtss",
  714.         "sahf",
  715.         "sal",
  716.         "sar",
  717.         "sarx",
  718.         "sbb",
  719.         "scas",
  720.         "scasb",
  721.         "scasd",
  722.         "scasw",
  723.         "seta",
  724.         "setae",
  725.         "setb",
  726.         "setbe",
  727.         "setc",
  728.         "sete",
  729.         "setg",
  730.         "setge",
  731.         "setl",
  732.         "setle",
  733.         "setna",
  734.         "setnae",
  735.         "setnb",
  736.         "setnbe",
  737.         "setnc",
  738.         "setne",
  739.         "setng",
  740.         "setnge",
  741.         "setnl",
  742.         "setnle",
  743.         "setno",
  744.         "setnp",
  745.         "setns",
  746.         "setnz",
  747.         "seto",
  748.         "setp",
  749.         "setpe",
  750.         "setpo",
  751.         "sets",
  752.         "setz",
  753.         "sfence",
  754.         "sgdt",
  755.         "sha1msg1",
  756.         "sha1msg2",
  757.         "sha1nexte",
  758.         "sha1rnds4",
  759.         "sha256msg1",
  760.         "sha256msg2",
  761.         "sha256rnds2",
  762.         "shl",
  763.         "shld",
  764.         "shlx",
  765.         "shr",
  766.         "shrd",
  767.         "shrx",
  768.         "shufpd",
  769.         "shufps",
  770.         "sidt",
  771.         "sldt",
  772.         "smsw",
  773.         "sqrtpd",
  774.         "sqrtps",
  775.         "sqrtsd",
  776.         "sqrtss",
  777.         "stac",
  778.         "stc",
  779.         "std",
  780.         "sti",
  781.         "stmxcsr",
  782.         "stos",
  783.         "stosb",
  784.         "stosd",
  785.         "stosq",
  786.         "stosw",
  787.         "str",
  788.         "sub",
  789.         "subpd",
  790.         "subps",
  791.         "subsd",
  792.         "subss",
  793.         "swapgs",
  794.         "syscall",
  795.         "sysenter",
  796.         "sysexit",
  797.         "sysret",
  798.         "test",
  799.         "tpause",
  800.         "tzcnt",
  801.         "ucomisd",
  802.         "ucomiss",
  803.         "ud",
  804.         "umonitor",
  805.         "umwait",
  806.         "unpckhpd",
  807.         "unpckhps",
  808.         "unpcklpd",
  809.         "unpcklps",
  810.         "valignd",
  811.         "valignq",
  812.         "vblendmpd",
  813.         "vblendmps",
  814.         "vbroadcast",
  815.         "vcompresspd",
  816.         "vcompressps",
  817.         "vcvtpd2qq",
  818.         "vcvtpd2udq",
  819.         "vcvtpd2uqq",
  820.         "vcvtph2ps",
  821.         "vcvtps2ph",
  822.         "vcvtps2qq",
  823.         "vcvtps2udq",
  824.         "vcvtps2uqq",
  825.         "vcvtqq2pd",
  826.         "vcvtqq2ps",
  827.         "vcvtsd2usi",
  828.         "vcvtss2usi",
  829.         "vcvttpd2qq",
  830.         "vcvttpd2udq",
  831.         "vcvttpd2uqq",
  832.         "vcvttps2qq",
  833.         "vcvttps2udq",
  834.         "vcvttps2uqq",
  835.         "vcvttsd2usi",
  836.         "vcvttss2usi",
  837.         "vcvtudq2pd",
  838.         "vcvtudq2ps",
  839.         "vcvtuqq2pd",
  840.         "vcvtuqq2ps",
  841.         "vcvtusi2sd",
  842.         "vcvtusi2ss",
  843.         "vdbpsadbw",
  844.         "verr",
  845.         "verw",
  846.         "vexpandpd",
  847.         "vexpandps",
  848.         "vextractf128",
  849.         "vextractf32x4",
  850.         "vextractf32x8",
  851.         "vextractf64x2",
  852.         "vextractf64x4",
  853.         "vextracti128",
  854.         "vextracti32x4",
  855.         "vextracti32x8",
  856.         "vextracti64x2",
  857.         "vextracti64x4",
  858.         "vfixupimmpd",
  859.         "vfixupimmps",
  860.         "vfixupimmsd",
  861.         "vfixupimmss",
  862.         "vfmadd132pd",
  863.         "vfmadd132ps",
  864.         "vfmadd132sd",
  865.         "vfmadd132ss",
  866.         "vfmadd213pd",
  867.         "vfmadd213ps",
  868.         "vfmadd213sd",
  869.         "vfmadd213ss",
  870.         "vfmadd231pd",
  871.         "vfmadd231ps",
  872.         "vfmadd231sd",
  873.         "vfmadd231ss",
  874.         "vfmaddsub132pd",
  875.         "vfmaddsub132ps",
  876.         "vfmaddsub213pd",
  877.         "vfmaddsub213ps",
  878.         "vfmaddsub231pd",
  879.         "vfmaddsub231ps",
  880.         "vfmsub132pd",
  881.         "vfmsub132ps",
  882.         "vfmsub132sd",
  883.         "vfmsub132ss",
  884.         "vfmsub213pd",
  885.         "vfmsub213ps",
  886.         "vfmsub213sd",
  887.         "vfmsub213ss",
  888.         "vfmsub231pd",
  889.         "vfmsub231ps",
  890.         "vfmsub231sd",
  891.         "vfmsub231ss",
  892.         "vfmsubadd132pd",
  893.         "vfmsubadd132ps",
  894.         "vfmsubadd213pd",
  895.         "vfmsubadd213ps",
  896.         "vfmsubadd231pd",
  897.         "vfmsubadd231ps",
  898.         "vfnmadd132pd",
  899.         "vfnmadd132ps",
  900.         "vfnmadd132sd",
  901.         "vfnmadd132ss",
  902.         "vfnmadd213pd",
  903.         "vfnmadd213ps",
  904.         "vfnmadd213sd",
  905.         "vfnmadd213ss",
  906.         "vfnmadd231pd",
  907.         "vfnmadd231ps",
  908.         "vfnmadd231sd",
  909.         "vfnmadd231ss",
  910.         "vfnmsub132pd",
  911.         "vfnmsub132ps",
  912.         "vfnmsub132sd",
  913.         "vfnmsub132ss",
  914.         "vfnmsub213pd",
  915.         "vfnmsub213ps",
  916.         "vfnmsub213sd",
  917.         "vfnmsub213ss",
  918.         "vfnmsub231pd",
  919.         "vfnmsub231ps",
  920.         "vfnmsub231sd",
  921.         "vfnmsub231ss",
  922.         "vfpclasspd",
  923.         "vfpclassps",
  924.         "vfpclasssd",
  925.         "vfpclassss",
  926.         "vgatherdpd",
  927.         "vgatherdpd",
  928.         "vgatherdps",
  929.         "vgatherdps",
  930.         "vgatherqpd",
  931.         "vgatherqpd",
  932.         "vgatherqps",
  933.         "vgatherqps",
  934.         "vgetexppd",
  935.         "vgetexpps",
  936.         "vgetexpsd",
  937.         "vgetexpss",
  938.         "vgetmantpd",
  939.         "vgetmantps",
  940.         "vgetmantsd",
  941.         "vgetmantss",
  942.         "vinsertf128",
  943.         "vinsertf32x4",
  944.         "vinsertf32x8",
  945.         "vinsertf64x2",
  946.         "vinsertf64x4",
  947.         "vinserti128",
  948.         "vinserti32x4",
  949.         "vinserti32x8",
  950.         "vinserti64x2",
  951.         "vinserti64x4",
  952.         "vmaskmov",
  953.         "vmovdqa32",
  954.         "vmovdqa64",
  955.         "vmovdqu16",
  956.         "vmovdqu32",
  957.         "vmovdqu64",
  958.         "vmovdqu8",
  959.         "vpblendd",
  960.         "vpblendmb",
  961.         "vpblendmd",
  962.         "vpblendmq",
  963.         "vpblendmw",
  964.         "vpbroadcast",
  965.         "vpbroadcastb",
  966.         "vpbroadcastd",
  967.         "vpbroadcastm",
  968.         "vpbroadcastq",
  969.         "vpbroadcastw",
  970.         "vpcmpb",
  971.         "vpcmpd",
  972.         "vpcmpq",
  973.         "vpcmpub",
  974.         "vpcmpud",
  975.         "vpcmpuq",
  976.         "vpcmpuw",
  977.         "vpcmpw",
  978.         "vpcompressd",
  979.         "vpcompressq",
  980.         "vpconflictd",
  981.         "vpconflictq",
  982.         "vperm2f128",
  983.         "vperm2i128",
  984.         "vpermb",
  985.         "vpermd",
  986.         "vpermi2b",
  987.         "vpermi2d",
  988.         "vpermi2pd",
  989.         "vpermi2ps",
  990.         "vpermi2q",
  991.         "vpermi2w",
  992.         "vpermilpd",
  993.         "vpermilps",
  994.         "vpermpd",
  995.         "vpermps",
  996.         "vpermq",
  997.         "vpermt2b",
  998.         "vpermt2d",
  999.         "vpermt2pd",
  1000.         "vpermt2ps",
  1001.         "vpermt2q",
  1002.         "vpermt2w",
  1003.         "vpermw",
  1004.         "vpexpandd",
  1005.         "vpexpandq",
  1006.         "vpgatherdd",
  1007.         "vpgatherdd",
  1008.         "vpgatherdq",
  1009.         "vpgatherdq",
  1010.         "vpgatherqd",
  1011.         "vpgatherqd",
  1012.         "vpgatherqq",
  1013.         "vpgatherqq",
  1014.         "vplzcntd",
  1015.         "vplzcntq",
  1016.         "vpmadd52huq",
  1017.         "vpmadd52luq",
  1018.         "vpmaskmov",
  1019.         "vpmovb2m",
  1020.         "vpmovd2m",
  1021.         "vpmovdb",
  1022.         "vpmovdw",
  1023.         "vpmovm2b",
  1024.         "vpmovm2d",
  1025.         "vpmovm2q",
  1026.         "vpmovm2w",
  1027.         "vpmovq2m",
  1028.         "vpmovqb",
  1029.         "vpmovqd",
  1030.         "vpmovqw",
  1031.         "vpmovsdb",
  1032.         "vpmovsdw",
  1033.         "vpmovsqb",
  1034.         "vpmovsqd",
  1035.         "vpmovsqw",
  1036.         "vpmovswb",
  1037.         "vpmovusdb",
  1038.         "vpmovusdw",
  1039.         "vpmovusqb",
  1040.         "vpmovusqd",
  1041.         "vpmovusqw",
  1042.         "vpmovuswb",
  1043.         "vpmovw2m",
  1044.         "vpmovwb",
  1045.         "vpmultishiftqb",
  1046.         "vprold",
  1047.         "vprolq",
  1048.         "vprolvd",
  1049.         "vprolvq",
  1050.         "vprord",
  1051.         "vprorq",
  1052.         "vprorvd",
  1053.         "vprorvq",
  1054.         "vpscatterdd",
  1055.         "vpscatterdq",
  1056.         "vpscatterqd",
  1057.         "vpscatterqq",
  1058.         "vpsllvd",
  1059.         "vpsllvq",
  1060.         "vpsllvw",
  1061.         "vpsravd",
  1062.         "vpsravq",
  1063.         "vpsravw",
  1064.         "vpsrlvd",
  1065.         "vpsrlvq",
  1066.         "vpsrlvw",
  1067.         "vpternlogd",
  1068.         "vpternlogq",
  1069.         "vptestmb",
  1070.         "vptestmd",
  1071.         "vptestmq",
  1072.         "vptestmw",
  1073.         "vptestnmb",
  1074.         "vptestnmd",
  1075.         "vptestnmq",
  1076.         "vptestnmw",
  1077.         "vrangepd",
  1078.         "vrangeps",
  1079.         "vrangesd",
  1080.         "vrangess",
  1081.         "vrcp14pd",
  1082.         "vrcp14ps",
  1083.         "vrcp14sd",
  1084.         "vrcp14ss",
  1085.         "vreducepd",
  1086.         "vreduceps",
  1087.         "vreducesd",
  1088.         "vreducess",
  1089.         "vrndscalepd",
  1090.         "vrndscaleps",
  1091.         "vrndscalesd",
  1092.         "vrndscaless",
  1093.         "vrsqrt14pd",
  1094.         "vrsqrt14ps",
  1095.         "vrsqrt14sd",
  1096.         "vrsqrt14ss",
  1097.         "vscalefpd",
  1098.         "vscalefps",
  1099.         "vscalefsd",
  1100.         "vscalefss",
  1101.         "vscatterdpd",
  1102.         "vscatterdps",
  1103.         "vscatterqpd",
  1104.         "vscatterqps",
  1105.         "vshuff32x4",
  1106.         "vshuff64x2",
  1107.         "vshufi32x4",
  1108.         "vshufi64x2",
  1109.         "vtestpd",
  1110.         "vtestps",
  1111.         "vzeroall",
  1112.         "vzeroupper",
  1113.         "wait",
  1114.         "wbinvd",
  1115.         "wrfsbase",
  1116.         "wrgsbase",
  1117.         "wrmsr",
  1118.         "wrpkru",
  1119.         "xabort",
  1120.         "xacquire",
  1121.         "xadd",
  1122.         "xbegin",
  1123.         "xchg",
  1124.         "xend",
  1125.         "xgetbv",
  1126.         "xlat",
  1127.         "xlatb",
  1128.         "xor",
  1129.         "xorpd",
  1130.         "xorps",
  1131.         "xrelease",
  1132.         "xrstor",
  1133.         "xrstors",
  1134.         "xsave",
  1135.         "xsavec",
  1136.         "xsaveopt",
  1137.         "xsaves",
  1138.         "xsetbv",
  1139.         "xtest"
  1140. ]
  1141.  
  1142. fasm_types = [
  1143.         "db", "rb",
  1144.         "dw", "rw",
  1145.         "dd", "rd",
  1146.         "dp", "rp",
  1147.         "df", "rf",
  1148.         "dq", "rq",
  1149.         "dt", "rt",
  1150.         "du",
  1151. ]
  1152.  
  1153. # Dict where an identifier is assicoated with a string
  1154. # The string contains characters specifying flags
  1155. # Available flags:
  1156. #  k - Keyword
  1157. #  m - Macro name
  1158. #  t - fasm data Type name (db, rq, etc.)
  1159. #  s - Struct type name
  1160. #  e - equated constant (name equ value)
  1161. #  = - set constants (name = value)
  1162. ID_KIND_KEYWORD = 'k'
  1163. ID_KIND_MACRO_NAME = 'm'
  1164. ID_KIND_FASM_TYPE = 't'
  1165. ID_KIND_STRUCT_NAME = 's'
  1166. ID_KIND_EQUATED_CONSTANT = 'e'
  1167. ID_KIND_SET_CONSTANT = '='
  1168. id2kind = {}
  1169.  
  1170. # Add kind flag to identifier in id2kind
  1171. def id_add_kind(identifier, kind):
  1172.         if identifier not in id2kind:
  1173.                 id2kind[identifier] = ''
  1174.         id2kind[identifier] += kind
  1175.  
  1176. # Remove kind flag of identifier in id2kind
  1177. def id_remove_kind(identifier, kind):
  1178.         if identifier in id2kind:
  1179.                 if kind in id2kind[identifier]:
  1180.                         id2kind[identifier] = id2kind[identifier].replace(kind, '')
  1181.  
  1182. # Get kind of an identifier
  1183. def id_get_kind(identifier):
  1184.         if identifier in id2kind:
  1185.                 return id2kind[identifier]
  1186.         else:
  1187.                 return ''
  1188.  
  1189. for keyword in keywords:
  1190.         id_add_kind(keyword, ID_KIND_KEYWORD)
  1191.  
  1192. for fasm_type in fasm_types:
  1193.         id_add_kind(fasm_type, ID_KIND_FASM_TYPE)
  1194.  
  1195. # Warning list
  1196. warnings = ""
  1197.  
  1198. # Parse arguments
  1199. parser = argparse.ArgumentParser()
  1200. parser.add_argument("-o", help="Doxygen output folder")
  1201. parser.add_argument("--clean", help="Remove generated files", action="store_true")
  1202. parser.add_argument("--dump", help="Dump all defined symbols", action="store_true")
  1203. parser.add_argument("--stats", help="Print symbol stats", action="store_true")
  1204. parser.add_argument("--nowarn", help="Do not write warnings file", action="store_true")
  1205. parser.add_argument("--noemit", help="Do not emit doxygen files (for testing)", action="store_true")
  1206. args = parser.parse_args()
  1207. doxygen_src_path = args.o if args.o else 'docs/doxygen'
  1208. clean_generated_stuff = args.clean
  1209. dump_symbols = args.dump
  1210. print_stats = args.stats
  1211. enable_warnings = not args.nowarn
  1212. noemit = args.noemit
  1213.  
  1214. # Variables, functions, labels, macros, structure types
  1215. elements = []
  1216.  
  1217. class LegacyAsmReader:
  1218.         def __init__(self, file):
  1219.                 self.file = file
  1220.                 self.lines = open(file, "r", encoding="utf-8").readlines()
  1221.                 self.line_idx = 0
  1222.                 self.i = 0
  1223.  
  1224.         def curr(self):
  1225.                 try: return self.lines[self.line_idx][self.i]
  1226.                 except: return ''
  1227.  
  1228.         def step(self):
  1229.                 c = self.curr()
  1230.                 self.i += 1
  1231.                 # Wrap the line if '\\' followed by whitespaces and/or comment
  1232.                 while self.curr() == '\\':
  1233.                         i_of_backslash = self.i
  1234.                         self.i += 1
  1235.                         while self.curr().isspace():
  1236.                                 self.i += 1
  1237.                         if self.curr() == ';' or self.curr() == '':
  1238.                                 self.line_idx += 1
  1239.                                 self.i = 0
  1240.                         else:
  1241.                                 # There's something other than a comment after the backslash
  1242.                                 # So don't interpret the backslash as a line wrap
  1243.                                 self.i = i_of_backslash
  1244.                                 break
  1245.                 return c
  1246.  
  1247.         def nextline(self):
  1248.                 c = self.curr()
  1249.                 while c != '':
  1250.                         c = self.step()
  1251.                 self.line_idx += 1
  1252.                 self.i = 0
  1253.  
  1254.         def no_lines(self):
  1255.                 if self.line_idx >= len(self.lines):
  1256.                         return True
  1257.                 return False
  1258.  
  1259.         def location(self):    
  1260.                 return f"{self.file}:{self.line_idx + 1}"
  1261.  
  1262.         def skip_spaces(self):
  1263.                 while self.curr().isspace():
  1264.                         self.step()
  1265.  
  1266. class AsmReaderRecognizingStrings(LegacyAsmReader):
  1267.         def __init__(self, file):
  1268.                 super().__init__(file)
  1269.                 self.in_string = None
  1270.                 self.should_recognize_strings = True
  1271.  
  1272.         def step(self):
  1273.                 c = super().step()
  1274.                 if self.should_recognize_strings and (c == '"' or c == "'"):
  1275.                         # If just now we was at the double or single quotation mark
  1276.                         # and we aren't in a string yet
  1277.                         # then say "we are in a string openned with this quotation mark now"
  1278.                         if self.in_string == None:
  1279.                                 self.in_string = c
  1280.                         # If just now we was at the double or single quotation mark
  1281.                         # and we are in the string entered with the same quotation mark
  1282.                         # then say "we aren't in a string anymore"
  1283.                         elif self.in_string == c:
  1284.                                 self.in_string = None
  1285.                 return c
  1286.  
  1287. class AsmReaderReadingComments(AsmReaderRecognizingStrings):
  1288.         def __init__(self, file):
  1289.                 super().__init__(file)
  1290.                 self.status = dict()
  1291.                 self.status_reset()
  1292.                 self.comment = ''
  1293.  
  1294.         def status_reset(self):
  1295.                 # If the line has non-comment code
  1296.                 self.status_has_code = False
  1297.                 # If the line has a comment at the end
  1298.                 self.status_has_comment = False
  1299.                 # Let it recognize strings further, we are definitely out of a comment
  1300.                 self.should_recognize_strings = True
  1301.  
  1302.         def status_set_has_comment(self):
  1303.                 self.status_has_comment = True
  1304.                 # Don't let it recognize strings cause we are in a comment now
  1305.                 self.should_recognize_strings = False
  1306.  
  1307.         def status_set_has_code(self):
  1308.                 self.status_has_code = True
  1309.  
  1310.         def update_status(self):
  1311.                 # If we aren't in a comment and we aren't in a string - say we are now in a comment if ';' met
  1312.                 if not self.status_has_comment and not self.in_string and self.curr() == ';':
  1313.                         self.status_set_has_comment()
  1314.                 # Else if we are in a comment - collect the comment
  1315.                 elif self.status_has_comment:
  1316.                         self.comment += self.curr()
  1317.                 # Else if there's some non-whitespace character out of a comment
  1318.                 # then the line has code
  1319.                 elif not self.status_has_comment and not self.curr().isspace():
  1320.                         self.status_set_has_code()
  1321.  
  1322.         def step(self):
  1323.                 # Get to the next character
  1324.                 c = super().step()
  1325.                 # Update status of the line according to the next character
  1326.                 self.update_status()
  1327.                 return c
  1328.  
  1329.         def nextline(self):
  1330.                 super().nextline()
  1331.                 # If the line we leave was not a comment-only line
  1332.                 # then forget the collected comment
  1333.                 # Otherwise the collected comment should be complemented by comment from next line in step()
  1334.                 if self.status_has_code:
  1335.                         self.comment = ''
  1336.                 # Reset the line status (now it's the status of the new line)
  1337.                 self.status_reset()
  1338.                 # Set new status for this line according to the first character in the line
  1339.                 self.update_status()
  1340.  
  1341. class AsmReaderFetchingIdentifiers(AsmReaderReadingComments):
  1342.         def __init__(self, file):
  1343.                 super().__init__(file)
  1344.  
  1345.         def fetch_identifier(self):
  1346.                 self.skip_spaces()
  1347.                 result = ''
  1348.                 while is_id(self.curr()):
  1349.                         result += self.step()
  1350.                 return result
  1351.  
  1352. class AsmReader(AsmReaderFetchingIdentifiers):
  1353.         def __init__(self, file):
  1354.                 super().__init__(file)
  1355.  
  1356. created_files = []
  1357.  
  1358. class AsmElement:
  1359.         def __init__(self, location, name, comment):
  1360.                 self.location = location
  1361.                 self.file = self.location.split(':')[0].replace('\\', '/')
  1362.                 self.line = self.location.split(':')[1]
  1363.                 self.name = name
  1364.                 self.comment = comment
  1365.  
  1366.         def dump(self):
  1367.                 print(f"{self.comment}")
  1368.                 print(f"{self.location}: {self.name}")
  1369.  
  1370.         def emit(self, dest, doxycomment = '', declaration = ''):
  1371.                 # Do not emit anything if the symbol is marked as hidden in its comment
  1372.                 if '@dont_give_a_doxygen' in self.comment:
  1373.                         return
  1374.  
  1375.                 global warnings
  1376.                 # Redefine default declaration
  1377.                 if declaration == '':
  1378.                         declaration = f'#define {self.name}'
  1379.                 # Check doxycomment
  1380.                 if not doxycomment.endswith('\n'):
  1381.                         doxycomment += '\n'
  1382.                 if doxycomment.split('@brief ')[1][0].islower():
  1383.                         warnings += f"{self.location}: Brief comment starting from lowercase\n"
  1384.                 # Build contents to emit
  1385.                 contents = ''
  1386.                 contents += '/**\n'
  1387.                 contents += doxycomment
  1388.                 contents += (f"@par Source\n" +
  1389.                              f"<a href='{link_root}/{self.file}#line-{self.line}'>{self.file}:{self.line}</a>\n")
  1390.                 contents += '*/\n'
  1391.                 contents += declaration
  1392.                 contents += '\n\n'
  1393.                 # Get path to file to emit this
  1394.                 full_path = dest + '/' + self.file
  1395.                 # Remove the file on first access if it was created by previous generation
  1396.                 if full_path not in created_files:
  1397.                         if os.path.isfile(full_path):
  1398.                                 os.remove(full_path)
  1399.                         created_files.append(full_path)
  1400.                 # Create directories need for the file
  1401.                 os.makedirs(os.path.dirname(full_path), exist_ok=True)
  1402.                 f = open(full_path, "a")
  1403.                 contents = ''.join([i if ord(i) < 128 else '?' for i in contents])
  1404.                 f.write(contents)
  1405.                 f.close()
  1406.  
  1407. class AsmVariable(AsmElement):
  1408.         def __init__(self, location, name, comment, type, init):
  1409.                 super().__init__(location, name, comment)
  1410.                 self.type = type
  1411.                 self.init = init
  1412.  
  1413.         def dump(self):
  1414.                 super().dump()
  1415.                 print(f"Variable")
  1416.  
  1417.         def emit(self, dest):
  1418.                 # Build doxycomment specific for the variable
  1419.                 doxycomment = ''
  1420.                 doxycomment += self.comment
  1421.                 if '@brief' not in doxycomment:
  1422.                         doxycomment = '@brief ' + doxycomment
  1423.                 doxycomment += (f"@par Initial value\n" +
  1424.                                 f"{self.init}\n")
  1425.                 # Build the declaration
  1426.                 name = self.name.replace(".", "_")
  1427.                 var_type = self.type.replace(".", "_")
  1428.                 declaration = f"{var_type} {name};"
  1429.                 # Emit this
  1430.                 super().emit(dest, doxycomment, declaration)
  1431.  
  1432. class AsmFunction(AsmElement):
  1433.         def __init__(self, location, name, comment, calling_convention, args, used_regs):
  1434.                 super().__init__(location, name, comment)
  1435.                 self.calling_convention = calling_convention
  1436.                 self.args = args
  1437.                 self.used_regs = used_regs
  1438.  
  1439.         def dump(self):
  1440.                 super().dump()
  1441.                 print(f"Function")
  1442.  
  1443.         def emit(self, dest):
  1444.                 # Build doxycomment specific for the variable
  1445.                 doxycomment = ''
  1446.                 doxycomment += self.comment
  1447.                 if '@brief' not in doxycomment:
  1448.                         doxycomment = '@brief ' + doxycomment
  1449.                 # Build the arg list for declaration
  1450.                 arg_list = '('
  1451.                 if len(self.args) > 0:
  1452.                         argc = 0
  1453.                         for arg in self.args:
  1454.                                 if argc != 0:
  1455.                                         arg_list += ", "
  1456.                                 arg_list += f"{arg[1]} {arg[0]}"
  1457.                                 argc += 1
  1458.                 arg_list += ')'
  1459.                 # Build the declaration
  1460.                 name = self.name.replace(".", "_")
  1461.                 declaration = f"void {name}{arg_list};"
  1462.                 # Emit this
  1463.                 super().emit(dest, doxycomment, declaration)
  1464.  
  1465. class AsmLabel(AsmElement):
  1466.         def __init__(self, location, name, comment):
  1467.                 super().__init__(location, name, comment)
  1468.  
  1469.         def dump(self):
  1470.                 super().dump()
  1471.                 print(f"Label")
  1472.  
  1473.         def emit(self, dest):
  1474.                 # Build doxycomment specific for the variable
  1475.                 doxycomment = ''
  1476.                 doxycomment += self.comment
  1477.                 if '@brief' not in doxycomment:
  1478.                         doxycomment = '@brief ' + doxycomment
  1479.                 # Build the declaration
  1480.                 name = self.name.replace(".", "_")
  1481.                 declaration = f"label {name};"
  1482.                 # Emit this
  1483.                 super().emit(dest, doxycomment, declaration)
  1484.  
  1485. class AsmMacro(AsmElement):
  1486.         def __init__(self, location, name, comment, args):
  1487.                 super().__init__(location, name, comment)
  1488.                 self.args = args
  1489.  
  1490.         def dump(self):
  1491.                 super().dump()
  1492.                 print(f"Macro")
  1493.                 print(f"Parameters: {self.args}")
  1494.  
  1495.         def emit(self, dest):
  1496.                 # Construct arg list without '['s, ']'s and '*'s
  1497.                 args = [arg for arg in self.args if arg not in "[]*"]
  1498.                 # Construct C-like arg list
  1499.                 arg_list = ""
  1500.                 if len(args) > 0:
  1501.                         arg_list += '('
  1502.                         argc = 0
  1503.                         for arg in args:
  1504.                                 if argc != 0:
  1505.                                         arg_list += ", "
  1506.                                 arg_list += arg
  1507.                                 argc += 1
  1508.                         arg_list += ')'
  1509.                 # Build doxycomment
  1510.                 doxycomment = ''
  1511.                 doxycomment += self.comment
  1512.                 if '@brief' not in doxycomment:
  1513.                         doxycomment = '@brief ' + doxycomment
  1514.                 # Build declaration
  1515.                 declaration = f"#define {self.name}{arg_list}"
  1516.                 # Emit this
  1517.                 super().emit(dest, doxycomment, declaration)
  1518.  
  1519. class AsmStruct(AsmElement):
  1520.         def __init__(self, location, name, comment, members):
  1521.                 super().__init__(location, name, comment)
  1522.                 self.members = members
  1523.  
  1524.         def dump(self):
  1525.                 super().dump()
  1526.                 print(f"Struct")
  1527.  
  1528.         def emit(self, dest):
  1529.                 # Build doxycomment
  1530.                 doxycomment = ''
  1531.                 doxycomment += self.comment
  1532.                 if '@brief' not in doxycomment:
  1533.                         doxycomment = '@brief ' + doxycomment
  1534.                 doxycomment += '\n'
  1535.                 # Build declaration
  1536.                 declaration = f"struct {self.name}" + " {\n"
  1537.                 for member in self.members:
  1538.                         if type(member) == AsmVariable:
  1539.                                 declaration += f'\t{member.type} {member.name}; /**< {member.comment} */\n'
  1540.                 declaration += '};'
  1541.                 # Emit this
  1542.                 super().emit(dest, doxycomment, declaration)
  1543.  
  1544. class AsmUnion(AsmElement):
  1545.         def __init__(self, location, name, comment, members):
  1546.                 super().__init__(location, name, comment)
  1547.                 self.members = members
  1548.  
  1549.         def dump(self):
  1550.                 super().dump()
  1551.                 print(f"Union")
  1552.  
  1553.         def emit(self, dest):
  1554.                 # Build doxycomment
  1555.                 doxycomment = ''
  1556.                 doxycomment += self.comment
  1557.                 if '@brief' not in doxycomment:
  1558.                         doxycomment = '@brief ' + doxycomment
  1559.                 # Build declaration
  1560.                 declaration = f"union {self.name}" + " {};"
  1561.                 # Emit this
  1562.                 super().emit(dest, doxycomment, declaration)
  1563.  
  1564. class VariableNameIsMacroName:
  1565.         def __init__(self, name):
  1566.                 self.name = name
  1567.  
  1568. def is_id(c):
  1569.         return c.isprintable() and c not in "+-/*=<>()[]{};:,|&~#`'\" \n\r\t\v"
  1570.  
  1571. def is_starts_as_id(s):
  1572.         return not s[0].isdigit()
  1573.  
  1574. def parse_after_macro(r):
  1575.         location = r.location()
  1576.  
  1577.         # Skip spaces after the "macro" keyword
  1578.         r.skip_spaces()
  1579.         # Read macro name
  1580.         name = ""
  1581.         while is_id(r.curr()) or r.curr() == '#':
  1582.                 name += r.step()
  1583.         # Skip spaces after macro name
  1584.         r.skip_spaces()
  1585.         # Find all arguments
  1586.         args = []
  1587.         arg = ''
  1588.         while r.curr() and r.curr() != ';' and r.curr() != '{':
  1589.                 # Collect identifier
  1590.                 if is_id(r.curr()):
  1591.                         arg += r.step()
  1592.                 # Save the collected identifier
  1593.                 elif r.curr() == ',':
  1594.                         args.append(arg)
  1595.                         arg = ''
  1596.                         r.step()
  1597.                 # Just push the '['
  1598.                 elif r.curr() == '[':
  1599.                         args.append(r.step())
  1600.                 # Just push the identifier and get ']' ready to be pushed on next comma
  1601.                 elif r.curr() == ']':
  1602.                         args.append(arg)
  1603.                         arg = r.step()
  1604.                 # Just push the identifier and get '*' ready to be pushed on next comma
  1605.                 elif r.curr() == '*':
  1606.                         args.append(arg)
  1607.                         arg = r.step()
  1608.                 # Just skip whitespaces
  1609.                 elif r.curr().isspace():
  1610.                         r.step()
  1611.                 # Something unexpected
  1612.                 else:
  1613.                         raise Exception(f"Unexpected symbol '{r.curr()}' at index #{r.i} " +
  1614.                                         f"in the macro declaration at {location} " +
  1615.                                         f"(line: {r.lines[r.line_idx]})\n''")
  1616.         # Append the last argument
  1617.         if arg != '':
  1618.                 args.append(arg)
  1619.         # Skip t spaces after the argument list
  1620.         r.skip_spaces()
  1621.         # Get a comment if it is: read till the end of the line and get the comment from the reader
  1622.         while r.curr() != '':
  1623.                 r.step()
  1624.         comment = r.comment
  1625.         # Find end of the macro
  1626.         prev = ''
  1627.         while True:
  1628.                 if r.curr() == '}' and prev != '\\':
  1629.                         break
  1630.                 elif r.curr() == '':
  1631.                         prev = ''
  1632.                         r.nextline()
  1633.                         continue
  1634.                 prev = r.step()
  1635.         # Build the output
  1636.         return AsmMacro(location, name, comment, args)
  1637.  
  1638. def parse_variable(r, first_word = None):
  1639.         global warnings
  1640.         location = r.location()
  1641.  
  1642.         # Skip spaces before variable name
  1643.         r.skip_spaces()
  1644.         # Get variable name
  1645.         name = ""
  1646.         # Read it if it was not supplied
  1647.         if first_word == None:
  1648.                 while is_id(r.curr()):
  1649.                         name += r.step()
  1650.         # Or use the supplied one instead
  1651.         else:
  1652.                 name = first_word
  1653.         # Check the name
  1654.         # If it's 0 len, that means threr's something else than an identifier at the beginning
  1655.         if len(name) == 0:
  1656.                 return None
  1657.         # If it starts from digit or othervice illegally it's illegal
  1658.         if not is_starts_as_id(name):
  1659.                 return None
  1660.         # Get kind of the identifier from id2kind table
  1661.         kind = id_get_kind(name)
  1662.         # If it's a keyword, that's not a variable declaration
  1663.         if ID_KIND_KEYWORD in kind:
  1664.                 return None
  1665.         # If it's a macro name, that's not a variable declaration
  1666.         if ID_KIND_MACRO_NAME in kind:
  1667.                 return VariableNameIsMacroName(name)
  1668.         # If it's a datatype or a structure name that's not a variable declaration: that's just a data
  1669.         # don't document just a data for now
  1670.         if ID_KIND_STRUCT_NAME in kind or ID_KIND_FASM_TYPE in kind:
  1671.                 return None
  1672.         # Skip spaces before type name
  1673.         r.skip_spaces()
  1674.         # Read type name
  1675.         var_type = ""
  1676.         while is_id(r.curr()):
  1677.                 var_type += r.step()
  1678.         # Check the type name
  1679.         if len(var_type) == 0:
  1680.                 # If there's no type identifier after the name
  1681.                 # maybe the name is something meaningful for the next parser
  1682.                 # return it
  1683.                 return name
  1684.         # If it starts from digit or othervice illegally it's illegal
  1685.         if not is_starts_as_id(var_type):
  1686.                 return None
  1687.         # Get kind of type identifier
  1688.         type_kind = id_get_kind(var_type)
  1689.         # If it's a keyword, that's not a variable declaration
  1690.         # return the two words of the lexical structure
  1691.         if ID_KIND_KEYWORD in type_kind:
  1692.                 return (name, var_type)
  1693.         # Skip spaces before the value
  1694.         r.skip_spaces()
  1695.         # Read the value until the comment or end of the line
  1696.         value = ""
  1697.         while r.curr() != ';' and r.curr() != '' and r.curr() != '\n':
  1698.                 value += r.step()
  1699.         # Skip spaces after the value
  1700.         r.skip_spaces()
  1701.         # Read till end of the line to get a comment from the reader
  1702.         while r.curr() != '':
  1703.                 r.step()
  1704.         # Build the result
  1705.         return AsmVariable(location, name, r.comment, var_type, value)
  1706.  
  1707. def parse_after_struct(r, as_union = True):
  1708.         global warnings
  1709.         location = r.location()
  1710.  
  1711.         # Skip spaces after "struct" keyword
  1712.         r.skip_spaces()
  1713.         # Read struct name
  1714.         name = ""
  1715.         while is_id(r.curr()):
  1716.                 name += r.step()
  1717.         # Read till end of the line and get the comment from the reader
  1718.         while r.curr() != '':
  1719.                 r.step()
  1720.         comment = r.comment
  1721.         # Get to the next line to parse struct members
  1722.         r.nextline()
  1723.         # Parse struct members
  1724.         members = []
  1725.         while True:
  1726.                 r.skip_spaces()
  1727.                 var = parse_variable(r)
  1728.                 if type(var) == AsmVariable:
  1729.                         members.append(var)
  1730.                 elif type(var) == str:
  1731.                         if var == 'union':
  1732.                                 # Parse the union as a struct
  1733.                                 union = parse_after_struct(r, as_union = True)
  1734.                                 members.append(union)
  1735.                                 # Skip the ends of the union
  1736.                                 r.nextline()
  1737.                         elif r.curr() == ':':
  1738.                                 warnings += f"{r.location()}: Skept the label in the struct\n"
  1739.                         else:
  1740.                                 raise Exception(f"Garbage in struct member at {location} (got '{var}' identifier)")
  1741.                 elif type(var) == VariableNameIsMacroName:
  1742.                         if var.name == 'ends':
  1743.                                 break
  1744.                 r.nextline()
  1745.         # Return the result
  1746.         if as_union:
  1747.                 return AsmStruct(location, name, comment, members)
  1748.         else:
  1749.                 return AsmUnion(location, name, comment, members)
  1750.  
  1751. def parse_after_proc(r):
  1752.         # Get proc name
  1753.         name = r.fetch_identifier()
  1754.         # Next identifier after the proc name
  1755.         identifier = r.fetch_identifier()
  1756.         # Check if the id is 'stdcall' or 'c' (calling convention specifier)
  1757.         # and if so - save the convention and lookup the next identifier
  1758.         calling_convention = ''
  1759.         if identifier == 'stdcall' or identifier == 'c':
  1760.                 calling_convention = identifier
  1761.                 # If next is a comma, just skip it
  1762.                 if r.curr() == ',':
  1763.                         r.step()
  1764.                 # Read the next identifier
  1765.                 identifier = r.fetch_identifier()
  1766.         # Check if the id is 'uses' (used register list specifier)
  1767.         # and if so save the used register list
  1768.         used_regs = []
  1769.         if identifier == 'uses':
  1770.                 # Read the registers
  1771.                 while True:
  1772.                         reg_name = r.fetch_identifier()
  1773.                         if reg_name != '':
  1774.                                 used_regs.append(reg_name)
  1775.                         else:
  1776.                                 break
  1777.                 # If next is a comma, just skip it
  1778.                 if r.curr() == ',':
  1779.                         r.step()
  1780.                 # Read the next identifier
  1781.                 identifier = r.fetch_identifier()
  1782.         # Check if there are argument identifiers
  1783.         args = []
  1784.         while identifier != '':
  1785.                 arg_name = identifier
  1786.                 arg_type = 'arg_t'
  1787.                 # Skip spaces after argument name
  1788.                 r.skip_spaces()
  1789.                 # If there's a ':' after the name - the next identifier is type
  1790.                 if r.curr() == ':':
  1791.                         r.step()
  1792.                         arg_type = r.fetch_identifier()
  1793.                 # If there's a comma - there's one more argument
  1794.                 # else no arguments anymore
  1795.                 if r.curr() == ',':
  1796.                         r.step()
  1797.                         identifier = r.fetch_identifier()
  1798.                 else:
  1799.                         identifier = ''
  1800.                 args.append((arg_name, arg_type))
  1801.         # Get to the end of the line and get a comment from the reader
  1802.         while r.curr() != '':
  1803.                 r.step()
  1804.         comment = r.comment
  1805.         # Build the element
  1806.         return AsmFunction(r.location(), name, comment, calling_convention, args, used_regs)
  1807.  
  1808. def get_declarations(asm_file_contents, asm_file_name):
  1809.         r = AsmReader(asm_file_name)
  1810.  
  1811.         while not r.no_lines():
  1812.                 # Skip leading spaces
  1813.                 r.skip_spaces()
  1814.                 # Skip the line if it's starting with a comment
  1815.                 if r.curr() == ';':
  1816.                         r.nextline()
  1817.                         continue
  1818.                 # Get first word
  1819.                 first_word = ""
  1820.                 while is_id(r.curr()):
  1821.                         first_word += r.step()
  1822.                 # Match macro declaration
  1823.                 if first_word == "macro":
  1824.                         macro = parse_after_macro(r)
  1825.                         elements.append(macro)
  1826.                         id_add_kind(macro.name, ID_KIND_MACRO_NAME)
  1827.                 # Match structure declaration
  1828.                 elif first_word == "struct":
  1829.                         struct = parse_after_struct(r)
  1830.                         elements.append(struct)
  1831.                         id_add_kind(struct.name, ID_KIND_STRUCT_NAME)
  1832.                 # Match function definition
  1833.                 elif first_word == "proc":
  1834.                         proc = parse_after_proc(r)
  1835.                         elements.append(proc)
  1836.                 elif first_word == 'format':
  1837.                         # Skip the format directive
  1838.                         pass
  1839.                 elif first_word == 'include':
  1840.                         # Skip the include directive
  1841.                         pass
  1842.                 elif first_word == 'if':
  1843.                         # Skip the conditional directive
  1844.                         pass
  1845.                 elif first_word == 'repeat':
  1846.                         # Skip the repeat directive
  1847.                         pass
  1848.                 elif first_word == 'purge':
  1849.                         while True:
  1850.                                 # Skip spaces after the 'purge' keyword or after the comma what separated the previous macro name
  1851.                                 r.skip_spaces()
  1852.                                 # Get the purged macro name
  1853.                                 name = ''
  1854.                                 while is_id(r.curr()):
  1855.                                         name += r.step()
  1856.                                 # Remove the purged macro from the macro names list
  1857.                                 try:
  1858.                                         id_remove_kind(name, ID_KIND_MACRO_NAME)
  1859.                                 except:
  1860.                                         pass
  1861.                                 # Skip spaces after the name
  1862.                                 r.skip_spaces()
  1863.                                 # If it's comma (',') after then that's not the last purged macro, continue purging
  1864.                                 if r.curr() == ',':
  1865.                                         r.step()
  1866.                                         continue
  1867.                                 # Here we purged all the macros should be purged
  1868.                                 break
  1869.                 # Match label or a variable
  1870.                 elif len(first_word) != 0:
  1871.                         # Skip spaces after the identifier
  1872.                         r.skip_spaces()
  1873.                         # Match a variable
  1874.                         var = parse_variable(r, first_word)
  1875.                         if type(var) == AsmVariable:
  1876.                                 elements.append(var)
  1877.                         # If it wasn't a variable but there was an identifier
  1878.                         # Maybe that's a label and the identifier is the label name
  1879.                         # The parse_variable returns the first found or supplied identifier
  1880.                         # In this case it returns the first_word which is supplied
  1881.                         # If it didn't match a type identifier after the word
  1882.                         elif type(var) == str:
  1883.                                 name = var
  1884.                                 # Match label beginning (':' after name)
  1885.                                 if r.curr() == ':':
  1886.                                         # Get to the end of the line and get the coment from the reader
  1887.                                         while r.curr() != '':
  1888.                                                 r.step()
  1889.                                         comment = r.comment
  1890.                                         # Only handle non-local labels
  1891.                                         if name[0] != '.' and name != "@@" and name != "$Revision":
  1892.                                                 elements.append(AsmLabel(r.location(), name, comment))
  1893.                                 elif r.curr() == '=':
  1894.                                         # Save the identifier as a set constant
  1895.                                         id_add_kind(first_word, ID_KIND_SET_CONSTANT)
  1896.                         elif type(var) == tuple:
  1897.                                 (word_one, word_two) = var
  1898.                                 if word_two == 'equ':
  1899.                                         # Save the identifier as an equated constant
  1900.                                         id_add_kind(word_one, ID_KIND_EQUATED_CONSTANT)
  1901.                 r.nextline()
  1902.  
  1903. def it_neds_to_be_parsed(source_file):
  1904.         dest = doxygen_src_path + '/' + source_file
  1905.         # If there's no the doxygen file it should be compiled to
  1906.         # then yes, we should compile it to doxygen
  1907.         if not os.path.isfile(dest):
  1908.                 return True
  1909.         source_change_time = os.path.getmtime(source_file)
  1910.         dest_change_file = os.path.getmtime(dest)
  1911.         # If the source is newer than the doxygen it was compiled to
  1912.         # then the source should be recompiled (existing doxygen is old)
  1913.         if source_change_time > dest_change_file:
  1914.                 return True
  1915.         return False
  1916.  
  1917. def handle_file(handled_files, asm_file_name, subdir = "."):
  1918.         # Canonicalize the file path and get it relative to cwd
  1919.         cwd = os.path.abspath(os.path.dirname(sys.argv[0]))
  1920.         asm_file_name = os.path.realpath(asm_file_name)
  1921.         asm_file_name = asm_file_name[len(cwd) + 1:]
  1922.         # If it's lang.inc - skip it
  1923.         if asm_file_name == 'lang.inc':
  1924.                 return
  1925.         # If the file was handled in this execution before - skip it
  1926.         if asm_file_name in handled_files:
  1927.                 return
  1928.         # Say that the file was handled in this execution
  1929.         handled_files.append(asm_file_name)
  1930.         # Check if the file should be parsed (if it was modified or wasn't parsed yet)
  1931.         should_get_declarations = True
  1932.         if not it_neds_to_be_parsed(asm_file_name):
  1933.                 print(f"Skipping {asm_file_name} (already newest)")
  1934.                 should_get_declarations = False
  1935.         else:
  1936.                 print(f"Handling {asm_file_name}")
  1937.         # Read the source
  1938.         asm_file_contents = open(asm_file_name, "r", encoding="utf-8").read()
  1939.         # Find includes, fix their paths and handle em recoursively
  1940.         includes = re.findall(r'^include (["\'])(.*)\1', asm_file_contents, flags=re.MULTILINE)
  1941.         for include in includes:
  1942.                 include = include[1].replace('\\', '/');
  1943.                 full_path = subdir + '/' + include;
  1944.                 # If the path isn't valid, maybe that's not relative path
  1945.                 if not os.path.isfile(full_path):
  1946.                         full_path = include
  1947.                 new_subdir = full_path.rsplit('/', 1)[0]
  1948.                 handle_file(handled_files, full_path, new_subdir)
  1949.         # Only collect declarations from the file if it wasn't parsed before
  1950.         if should_get_declarations and not clean_generated_stuff:
  1951.                 get_declarations(asm_file_contents, asm_file_name)
  1952.  
  1953. kernel_files = []
  1954.  
  1955. handle_file(kernel_files, "./kernel.asm");
  1956.  
  1957. if dump_symbols:
  1958.         for asm_element in elements:
  1959.                 asm_element.dump()
  1960.  
  1961. if print_stats:
  1962.         print("--stats is not nimplmented")
  1963.  
  1964. if clean_generated_stuff:
  1965.         kernel_files_set = set(kernel_files)
  1966.         for file in kernel_files:
  1967.                 doxygen_file = f"{doxygen_src_path}/{file}"
  1968.                 if (os.path.isfile(doxygen_file)):
  1969.                         print(f"Removing {file}... ", end = '')
  1970.                         os.remove(doxygen_file)
  1971.                         print("Done.")
  1972. elif not noemit:
  1973.         print(f"Writing doumented sources to {doxygen_src_path}")
  1974.  
  1975.         i = 0
  1976.         for element in elements:
  1977.                 print(f"[{i + 1}/{len(elements)}] Emitting {element.name} from {element.location}")
  1978.                 element.emit(doxygen_src_path)
  1979.                 i += 1
  1980.  
  1981. if enable_warnings:
  1982.         open('asmxygen.txt', "w", encoding = "utf-8").write(warnings)
  1983.