Beispiel #1
0
def _assemble_expression(parts):
	if not isinstance(parts, list):
		return parts

	node = nodes.BinaryOperator()
	node.left = _assemble_expression(parts[-3])

	node.type = parts[-2]
	assert isinstance(node.type, int)

	node.right = _assemble_expression(parts[-1])

	i = len(parts) - 4

	while i > 0:
		operator = parts[i]
		component = parts[i - 1]

		upper_node = nodes.BinaryOperator()
		upper_node.right = node
		upper_node.left = _assemble_expression(component)

		upper_node.type = operator

		node = upper_node

		i -= 2

	return node
Beispiel #2
0
def _build_binary_expression(state, addr, instruction):
    operator = nodes.BinaryOperator()
    opcode = instruction.opcode

    if opcode == ins.POW.opcode:
        operator.type = nodes.BinaryOperator.T_POW
    else:
        map_index = opcode - ins.ADDVN.opcode
        map_index %= 5
        map_index += ins.ADDVN.opcode

        operator.type = _BINARY_OPERATOR_MAP[map_index]

    assert (ins.ADDVN.opcode <= opcode <= ins.POW.opcode)
    assert instruction.B_type == ins.T_VAR

    # VN
    if opcode < ins.ADDNV.opcode:
        operator.left = _build_slot(state, addr, instruction.B)
        operator.right = _build_numeric_constant(state, instruction.CD)

    # NV
    elif opcode < ins.ADDVV.opcode:
        operator.right = _build_slot(state, addr, instruction.B)
        operator.left = _build_numeric_constant(state, instruction.CD)

    # VV
    else:
        assert instruction.CD_type == ins.T_VAR
        operator.left = _build_slot(state, addr, instruction.B)
        operator.right = _build_slot(state, addr, instruction.CD)

    return operator
Beispiel #3
0
def _build_concat_expression(state, addr, instruction):
    operator = nodes.BinaryOperator()
    operator.type = nodes.BinaryOperator.T_CONCAT

    slot = instruction.B

    operator.left = _build_slot(state, addr, slot)
    operator.right = _build_slot(state, addr, slot + 1)

    slot += 2

    while slot <= instruction.CD:
        upper_operator = nodes.BinaryOperator()
        upper_operator.left = operator
        upper_operator.right = _build_slot(state, addr, slot)
        upper_operator.type = nodes.BinaryOperator.T_CONCAT

        operator = upper_operator

        slot += 1

    return operator
Beispiel #4
0
def _build_comparison_expression(state, addr, instruction):
    operator = nodes.BinaryOperator()

    operator.left = _build_slot(state, addr, instruction.A)

    opcode = instruction.opcode

    if opcode == ins.ISEQS.opcode or opcode == ins.ISNES.opcode:
        operator.right = _build_string_constant(state, instruction.CD)
    elif opcode == ins.ISEQN.opcode or opcode == ins.ISNEN.opcode:
        operator.right = _build_numeric_constant(state, instruction.CD)
    elif opcode == ins.ISEQP.opcode or opcode == ins.ISNEP.opcode:
        operator.right = _build_primitive(state, instruction.CD)
    else:
        operator.right = _build_slot(state, addr, instruction.CD)

    operator.type = _COMPARISON_MAP[instruction.opcode]
    assert operator.type is not None

    return operator