76 lines
2.6 KiB
Python
76 lines
2.6 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_add(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
|
|
|
|
en_input = instruction["inputs"].get("en")
|
|
en_scl = (
|
|
get_scl_representation(en_input, network_id, scl_map, access_map)
|
|
if en_input
|
|
else "TRUE"
|
|
)
|
|
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 en_scl is None or in1_scl is None or in2_scl is None:
|
|
return False
|
|
|
|
target_scl = get_target_scl_name(
|
|
instruction, "out", network_id, default_to_temp=True
|
|
)
|
|
if target_scl is None:
|
|
print(f"Error: Sin destino ADD {instr_uid}")
|
|
instruction["scl"] = f"// ERROR: Add {instr_uid} sin destino"
|
|
instruction["type"] += "_error"
|
|
return True
|
|
|
|
# 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 es necesario
|
|
op1 = f"({op1})" if " " in op1 and not op1.startswith("(") else op1
|
|
op2 = f"({op2})" if " " in op2 and not op2.startswith("(") else op2
|
|
|
|
scl_core = f"{target_scl} := {op1} + {op2};"
|
|
scl_final = (
|
|
f"IF {en_scl} THEN\n {scl_core}\nEND_IF;" if en_scl != "TRUE" else scl_core
|
|
)
|
|
|
|
instruction["scl"] = scl_final
|
|
instruction["type"] = instr_type + SCL_SUFFIX
|
|
map_key_out = (network_id, instr_uid, "out")
|
|
scl_map[map_key_out] = target_scl
|
|
map_key_eno = (network_id, instr_uid, "eno")
|
|
scl_map[map_key_eno] = en_scl
|
|
return True
|
|
|
|
# --- Function code ends ---
|
|
|
|
# --- Processor Information Function ---
|
|
def get_processor_info():
|
|
"""Devuelve la información para el procesador Add."""
|
|
return {'type_name': 'add', 'processor_func': process_add, 'priority': 4}
|