75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
from .processor_utils import get_scl_representation, format_variable_name,get_target_scl_name
|
|
|
|
|
|
# TODO: Import necessary functions from processor_utils
|
|
# Example: from .processor_utils import get_scl_representation, format_variable_name
|
|
# Or: import processors.processor_utils as utils
|
|
|
|
# TODO: Define constants if needed (e.g., SCL_SUFFIX) or import them
|
|
SCL_SUFFIX = "_scl"
|
|
|
|
# --- Function code starts ---
|
|
def process_eq(instruction, network_id, scl_map, access_map, data):
|
|
instr_uid = instruction["instruction_uid"]
|
|
instr_type = instruction["type"]
|
|
if instr_type.endswith(SCL_SUFFIX) or "_error" in instr_type:
|
|
return False
|
|
|
|
in1_info = instruction["inputs"].get("in1")
|
|
in2_info = instruction["inputs"].get("in2")
|
|
in1_scl = get_scl_representation(in1_info, network_id, scl_map, access_map)
|
|
in2_scl = get_scl_representation(in2_info, network_id, scl_map, access_map)
|
|
|
|
if in1_scl is None or in2_scl is None:
|
|
return False # Dependencias no listas
|
|
|
|
# Formatear operandos si son variables
|
|
op1 = (
|
|
format_variable_name(in1_scl)
|
|
if in1_info and in1_info.get("type") == "variable"
|
|
else in1_scl
|
|
)
|
|
op2 = (
|
|
format_variable_name(in2_scl)
|
|
if in2_info and in2_info.get("type") == "variable"
|
|
else in2_scl
|
|
)
|
|
|
|
# Añadir paréntesis si los operandos contienen espacios (poco probable después de formatear)
|
|
op1 = f"({op1})" if " " in op1 and not op1.startswith("(") else op1
|
|
op2 = f"({op2})" if " " in op2 and not op2.startswith("(") else op2
|
|
|
|
comparison_scl = f"{op1} = {op2}"
|
|
|
|
# Guardar el resultado booleano de la comparación en el mapa SCL para la salida 'out'
|
|
map_key_out = (network_id, instr_uid, "out")
|
|
scl_map[map_key_out] = comparison_scl
|
|
|
|
# Procesar la entrada 'pre' (RLO anterior) para determinar ENO
|
|
pre_input = instruction["inputs"].get("pre")
|
|
pre_scl = (
|
|
"TRUE"
|
|
if pre_input is None
|
|
else get_scl_representation(pre_input, network_id, scl_map, access_map)
|
|
)
|
|
if pre_scl is None:
|
|
return False # Dependencia 'pre' no lista
|
|
|
|
# Guardar el estado de 'pre' como ENO
|
|
map_key_eno = (network_id, instr_uid, "eno")
|
|
scl_map[map_key_eno] = pre_scl
|
|
|
|
# El SCL generado es solo un comentario indicando la condición,
|
|
# ya que la lógica se propaga a través de scl_map['out']
|
|
instruction["scl"] = f"// Comparison Eq {instr_uid}: {comparison_scl}"
|
|
instruction["type"] = instr_type + SCL_SUFFIX
|
|
return True
|
|
|
|
# --- Function code ends ---
|
|
|
|
# --- Processor Information Function ---
|
|
def get_processor_info():
|
|
"""Devuelve la información para el comparador de igualdad (EQ)."""
|
|
return {'type_name': 'eq', 'processor_func': process_eq, 'priority': 2}
|