2024-02-16 08:44:20 +00:00
|
|
|
import { format_hex, u8 } from "./etc";
|
2024-02-16 05:17:23 +00:00
|
|
|
import { Instruction, InstructionSet } from "./instructionSet";
|
|
|
|
|
|
|
|
export function generate_isa(iset: InstructionSet): string {
|
|
|
|
const instructions: Array<[u8, Instruction]> = [];
|
|
|
|
for (const kv of iset.instructions.entries()) {
|
|
|
|
instructions.push(kv);
|
|
|
|
}
|
|
|
|
let output_string = "INSTRUCTIONS\n";
|
|
|
|
let max_instr_name_len = 0;
|
|
|
|
for (const instruction of instructions) {
|
|
|
|
const short_description = instruction[1].name;
|
|
|
|
max_instr_name_len = Math.max(max_instr_name_len, short_description.length);
|
|
|
|
}
|
|
|
|
for (const instruction of instructions) {
|
2024-02-16 08:44:20 +00:00
|
|
|
const hex_code = format_hex(instruction[0]);
|
2024-02-16 05:17:23 +00:00
|
|
|
const short_description = instruction[1].name.padEnd(max_instr_name_len, " ");
|
|
|
|
const parameter_count = instruction[1].params.length;
|
|
|
|
const description = instruction[1].desc;
|
|
|
|
output_string += `0x${hex_code}: ${short_description} - ${parameter_count} Parameter - ${description}\n`;
|
|
|
|
}
|
|
|
|
return output_string;
|
|
|
|
}
|