24 lines
963 B
TypeScript
24 lines
963 B
TypeScript
|
import { u8 } from "./etc";
|
||
|
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) {
|
||
|
const hex_code = instruction[0].toString(16).toUpperCase().padStart(2, "0");
|
||
|
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;
|
||
|
}
|