()
| 112 | |
| 113 | |
| 114 | def main(): |
| 115 | args = parser.parse_args() |
| 116 | print(f"Called with: {args}") |
| 117 | # If we don't have the html folder already... |
| 118 | if not os.path.exists(os.path.join(args.inputfolder, ARCHIVE_NAME)): |
| 119 | try: |
| 120 | download_asm_doc_archive(args.downloadfolder) |
| 121 | except IOError as e: |
| 122 | print("Error when downloading archive:") |
| 123 | print(e) |
| 124 | sys.exit(1) |
| 125 | instructions = parse_html(args.inputfolder) |
| 126 | instructions.sort(key=lambda b: b.name) |
| 127 | all_inst = set() |
| 128 | for inst in instructions: |
| 129 | if not all_inst.isdisjoint(inst.names): |
| 130 | print(f"Overlap in instruction names: {inst.names.intersection(all_inst)} for {inst.name}") |
| 131 | all_inst = all_inst.union(inst.names) |
| 132 | print(f"Writing {len(instructions)} instructions") |
| 133 | with open(args.outputpath, 'w') as f: |
| 134 | f.write(""" |
| 135 | import type {AssemblyInstructionInfo} from '../../../types/assembly-docs.interfaces.js'; |
| 136 | |
| 137 | export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined { |
| 138 | if (!opcode) return; |
| 139 | switch (opcode.toUpperCase()) { |
| 140 | """.lstrip()) |
| 141 | for inst in instructions: |
| 142 | for name in sorted(inst.names): |
| 143 | f.write(f' case "{name}":\n') |
| 144 | f.write(' return {}'.format(json.dumps({ |
| 145 | "tooltip": inst.tooltip, |
| 146 | "html": inst.body, |
| 147 | "url": get_url_for_instruction(inst) |
| 148 | }, indent=16, separators=(',', ': '), sort_keys=True))[:-1] + ' };\n\n') |
| 149 | f.write(""" |
| 150 | } |
| 151 | } |
| 152 | """) |
| 153 | |
| 154 | |
| 155 | if __name__ == '__main__': |
no test coverage detected