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

Function write_script

etc/scripts/docenizers/docenizer-avr.py:139–160  ·  view source on GitHub ↗
(filename, instructions)

Source from the content-addressed store, hash-verified

137
138
139def write_script(filename, instructions):
140 log_message(f"writing to {filename}...")
141 with open(filename, "w") as script:
142 script.write("import type {AssemblyInstructionInfo} from '../../../types/assembly-docs.interfaces.js';\n")
143 script.write("\n")
144 script.write("export function getAsmOpcode(opcode: string | undefined): AssemblyInstructionInfo | undefined {\n")
145 script.write(" if (!opcode) return;\n")
146 script.write(" switch (opcode.toUpperCase()) {\n")
147 for inst in instructions.values():
148 script.write(f" case \"{inst.mnemonic}\":\n")
149 if inst.mnemonic_2:
150 script.write(f" case \"{inst.mnemonic_2}\":\n")
151 script.write(" return {\n")
152 html = f"{16 * ' '}\"html\": \"<p>"
153 html += inst.description.replace("\n\n", "</p><p>")
154 html += "</p>\",\n"
155 script.write(html)
156 script.write(f"{16 * ' '}\"tooltip\": \"{inst.name}\",\n")
157 script.write(f"{16 * ' '}\"url\": \"{FILE}#page={inst.page}\",\n")
158 script.write(12 * " " + "};\n\n")
159 script.write(" }\n}")
160 log_message(f"wrote {len(instructions)} opcodes to asm-docs-avr.ts")
161
162
163def log_message(msg):

Callers 1

mainFunction · 0.70

Calls 1

log_messageFunction · 0.85

Tested by

no test coverage detected