-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathasm_documentation.ts
55 lines (48 loc) · 1.72 KB
/
asm_documentation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {asmData} from "@server/completion/data/types"
function formatOperands(operands: Record<string, number | string>): string {
return Object.entries(operands)
.map(([_, value]) => value.toString())
.join(" ")
}
export function generateAsmDoc(word: string): string | null {
const data = asmData()
const upperWord = word.toUpperCase()
const instruction = data.instructions.find(i => i.mnemonic === upperWord)
if (instruction) {
const stackInfo = instruction.doc.stack ? `- Stack: \`${instruction.doc.stack}\`` : ""
const gas = instruction.doc.gas.length > 0 ? instruction.doc.gas : `unknown`
return [
"```",
`${instruction.mnemonic} (${instruction.doc.category})`,
"```",
stackInfo,
`- Gas: \`${gas}\``,
"",
instruction.doc.description,
"",
instruction.doc.fift_examples.length > 0 ? "**Examples:**" : "",
...instruction.doc.fift_examples.map(
ex => `\`\`\`\n${ex.fift}\n\`\`\`\n${ex.description}`,
),
].join("\n")
}
const alias = data.aliases.find(a => a.mnemonic === upperWord)
if (alias) {
const stackInfo = alias.doc_stack ? `- Stack: \`${alias.doc_stack}\`` : ""
const operandsStr = formatOperands(alias.operands)
return [
"```",
alias.mnemonic,
"```",
`- Alias of: \`${operandsStr} ${alias.alias_of}\`\n`,
stackInfo,
"",
alias.description ?? "",
"",
alias.doc_fift ? `Fift: ${alias.doc_fift}` : "",
]
.filter(Boolean)
.join("\n")
}
return null
}