| 137 | |
| 138 | |
| 139 | def 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 | |
| 163 | def log_message(msg): |