#!/usr/bin/env python
import instructions
import sys

def write_defines():
    classes = {
        'ARITH': 0,
        'BRANCH': 1,
        'MEM': 2,
        'MISC': 3,
    }
    with open(sys.argv[1], 'w') as defines:
        defines.write("`define INSTR_NOP 32'b11111100000000000000000000000000\n")
        for k, v in classes.items():
            defines.write("`define CLASS_{0}\t2'h{1:x}\n".format(k.upper(), v))
        for name, instr_def in instructions.instructions.items():
            defines.write("`define OPCODE_{0}\t4'h{1:x}\n".format(name.upper(),
                instr_def['opcode']))
        for name, val in instructions.alu_opcodes.items():
            defines.write("`define ALU_OPC_{0}\t5'b{1:05b}\n".format(name.upper(),
                                                                     val))

if __name__ == '__main__':
    write_defines()
