# 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)
    opcode_field = build_bitfield(31, 26, _opcode_of('call'))

    if (isinstance(args[0], Number) or
        (isinstance(args[0], Id) and args[0].id in defines)
        ):
        # Number or defined constant
        #
        num = _define_or_const(args[0], defines, 26)
        return AssembledInstruction(
                op=opcode_field | build_bitfield(25, 0, num))
    elif isinstance(args[0], Id):
        label = args[0].id

        if label in symtab:
            # Relocation: place the label value into the
            # destination field, and specify a relocation for the
            # label's segment.
            #
            segment, addr = symtab[label]
            return AssembledInstruction(
                    op= opcode_field |
                        build_bitfield(25, 0, addr / 4),
                    reloc_req=(RelocType.CALL, segment))
        else:
            # Import symbol: leave the destination field empty
            # and specify an import symbol in the assembled
            # instruction.
            #
            return AssembledInstruction(
                    op=opcode_field,

# 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)

    opcode_field = build_bitfield(31, 26, _opcode_of('call'))

    if (isinstance(args[0], Number) or
        (isinstance(args[0], Id) and args[0].id in defines)
        ):
        # Number or defined constant
        #
        num = _define_or_const(args[0], defines, 26)
        return AssembledInstruction(
                op=opcode_field | build_bitfield(25, 0, num))
    elif isinstance(args[0], Id):
        label = args[0].id

        if label in symtab:
            # Relocation: place the label value into the
            # destination field, and specify a relocation for the
            # label's segment.
            #
            segment, addr = symtab[label]
            return AssembledInstruction(
                    op= opcode_field |
                        build_bitfield(25, 0, addr / 4),
                    reloc_req=(RelocType.CALL, segment))
        else:
            # Import symbol: leave the destination field empty
            # and specify an import symbol in the assembled
            # instruction.
            #
            return AssembledInstruction(
                    op=opcode_field,

                    import_req=(ImportType.CALL, label))