#!/usr/bin/env python3
# Generate instructions opcode list.
#
# (c) Mit authors 2018-2020
#
# The package is distributed under the MIT/X11 License.
#
# THIS PROGRAM IS PROVIDED AS IS, WITH NO WARRANTY. USE IS AT THE USER’S
# RISK.

from spec import Instructions, ExtraInstructions, MitErrorCode
from code_util import Code, copyright_banner, enum_to_c


GENERATOR_PROGRAM = 'gen-opcodes'
PURPOSE = 'Instruction opcodes.'
COPYRIGHT_YEARS = '2018-2020'


max_instruction = max([i.opcode for i in Instructions])
code = copyright_banner(GENERATOR_PROGRAM, PURPOSE, COPYRIGHT_YEARS)
code.append(f'''
#ifndef MIT_OPCODES_H
#define MIT_OPCODES_H


''')
code.append('')
code.extend(enum_to_c(Instructions, lambda i: i.opcode))
code.append('')
code.extend(enum_to_c(ExtraInstructions, lambda i: i.opcode))
code.append('')
code.extend(enum_to_c(MitErrorCode))
code.append('')
code.append('#endif')

print(code)
