# Path: luz_asm_sim/lib/asmlib/asm_common_types.py

# 
# Path: luz_asm_sim/lib/commonlib/portability.py
# def is_int_type(obj):
#     if sys.hexversion > 0x03000000:
#         return isinstance(obj, int)
#     else:
#         return isinstance(obj, int) or isinstance(obj, long)
# 
# Path: luz_asm_sim/lib/asmlib/asmparser.py
# class ParseError(Exception): pass
# class AsmParser(object):
#     def __init__(self, yacctab='parsetab'):
#     def parse(self, text):
#     def _lex_error_func(self, msg):
#     def p_asm_file(self, p):
#     def p_asm_line_1(self, p):
#     def p_asm_line_2(self, p):
#     def p_empty_line(self, p):
#     def p_directive_1(self, p):
#     def p_directive_2(self, p):
#     def p_instruction_1(self, p):
#     def p_instruction_2(self, p):
#     def p_label_def(self, p):
#     def p_arguments_opt(self, p):
#     def p_arguments_1(self, p):
#     def p_arguments_2(self, p):
#     def p_argument_1(self, p):
#     def p_argument_2(self, p):
#     def p_argument_3(self, p):
#     def p_argument_4(self, p):
#     def p_argument_5(self, p):
#     def p_number(self, p):
#     def p_error(self, p):


import re
from .asm_common_types import ImportType, RelocType
from ..commonlib.utils import (
    extract_bitfield, num_fits_in_nbits, build_bitfield)
from ..commonlib.luz_opcodes import *
from ..commonlib.portability import is_int_type
from .asmparser import (
    AsmParser, Id, Number, String, MemRef)
        raise InstructionError('Invalid register: %s' % str(arg))


def _const(arg, maxbits=16):
    """ Constructor for numeric constants.
        Expected: a Number, that is expected to fit into maxbits
        bits. This number can either be signed or unsigned - this
        is to be controlled by the assembly programmer.

        Otherwise, InstructionError is raised.

        The number is returned as an integer.
    """
    if not (isinstance(arg, Number) and is_int_type(arg.val)):
        raise InstructionError('Invalid number argument: %s' % arg)

    num = arg.val

    if (    (num > 0 and num_fits_in_nbits(num, maxbits)) or
            num_fits_in_nbits(num, maxbits, signed=True)):
        return num
    else:
        raise InstructionError("Constant %s won't fit in %s bits" % (num, maxbits))


def _memref(arg, defines):
    """ Constructor for memory reference arguments.

        Returns the pair: reg, offset
    """

# Path: luz_asm_sim/lib/asmlib/asm_common_types.py

# 
# Path: luz_asm_sim/lib/commonlib/portability.py
# def is_int_type(obj):
#     if sys.hexversion > 0x03000000:
#         return isinstance(obj, int)
#     else:
#         return isinstance(obj, int) or isinstance(obj, long)
# 
# Path: luz_asm_sim/lib/asmlib/asmparser.py
# class ParseError(Exception): pass
# class AsmParser(object):
#     def __init__(self, yacctab='parsetab'):
#     def parse(self, text):
#     def _lex_error_func(self, msg):
#     def p_asm_file(self, p):
#     def p_asm_line_1(self, p):
#     def p_asm_line_2(self, p):
#     def p_empty_line(self, p):
#     def p_directive_1(self, p):
#     def p_directive_2(self, p):
#     def p_instruction_1(self, p):
#     def p_instruction_2(self, p):
#     def p_label_def(self, p):
#     def p_arguments_opt(self, p):
#     def p_arguments_1(self, p):
#     def p_arguments_2(self, p):
#     def p_argument_1(self, p):
#     def p_argument_2(self, p):
#     def p_argument_3(self, p):
#     def p_argument_4(self, p):
#     def p_argument_5(self, p):
#     def p_number(self, p):
#     def p_error(self, p):


# Path: luz_asm_sim/lib/asmlib/asm_instructions.py
import re
from .asm_common_types import ImportType, RelocType
from ..commonlib.utils import (
    extract_bitfield, num_fits_in_nbits, build_bitfield)
from ..commonlib.luz_opcodes import *
from ..commonlib.portability import is_int_type
from .asmparser import (
    AsmParser, Id, Number, String, MemRef)

        raise InstructionError('Invalid register: %s' % str(arg))


def _const(arg, maxbits=16):
    """ Constructor for numeric constants.
        Expected: a Number, that is expected to fit into maxbits
        bits. This number can either be signed or unsigned - this
        is to be controlled by the assembly programmer.

        Otherwise, InstructionError is raised.

        The number is returned as an integer.
    """
    if not (isinstance(arg, Number) and is_int_type(arg.val)):
        raise InstructionError('Invalid number argument: %s' % arg)

    num = arg.val

    if (    (num > 0 and num_fits_in_nbits(num, maxbits)) or
            num_fits_in_nbits(num, maxbits, signed=True)):
        return num
    else:
        raise InstructionError("Constant %s won't fit in %s bits" % (num, maxbits))


def _memref(arg, defines):
    """ Constructor for memory reference arguments.

        Returns the pair: reg, offset
    """

    if not isinstance(arg, MemRef):