MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / main

Function main

etc/scripts/docenizers/docenizer-python.py:114–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

112
113
114def 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("""
135import type {AssemblyInstructionInfo} from '../../../types/assembly-docs.interfaces.js';
136
137export 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
155if __name__ == '__main__':

Callers 1

Calls 6

exitMethod · 0.80
sortMethod · 0.80
download_asm_doc_archiveFunction · 0.70
parse_htmlFunction · 0.70
get_url_for_instructionFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected