2026-07-10 10:38:57 +02:00

46 lines
2.4 KiB
Python

from ScEpTIC.AST.elements.instructions.other_operations import CallOperation
from ScEpTIC.AST.transformations.base.instructions.custom_log import CustomLog, CustomLogDump
from ScEpTIC.AST.transformations.base.instructions.printf import Printf
from ScEpTIC.AST.transformations.base.instructions.enter_mcu_lpm import EnterMCULPM
from ScEpTIC.AST.transformations.base.instructions.increment_custom_metric import IncrementCustomMetric
from ScEpTIC.AST.transformations.base.instructions.simulate_clock_cycles import SimulateClockCycles
from ScEpTIC.AST.transformations.base.instructions.print_vm_dump import PrintVMDump
from ScEpTIC.AST.transformations.base.instructions.interrupts import InterruptsEnable, InterruptsDisable, InterruptsEnableFiring, InterruptsDisableFiring
from ScEpTIC.AST.transformations.base.instructions.timers import TimerStart, TimerStop, TimerSetPeriod
def apply_transformation(functions, vmstate, f_declarations):
"""
:param functions: ScEpTIC AST functions
:param vmstate: vmstate
"""
config = vmstate.config.ast_transformations.base
function_map = {
config.simulate_clock_cycles_function_name: SimulateClockCycles,
config.increment_custom_metric_function_name: IncrementCustomMetric,
config.enter_mcu_lpm_function_name: EnterMCULPM,
config.print_dump_function_name: PrintVMDump,
config.interrupts_enable_firing_function_name: InterruptsEnableFiring,
config.interrupts_disable_firing_function_name: InterruptsDisableFiring,
config.interrupts_enable_function_name: InterruptsEnable,
config.interrupts_disable_function_name: InterruptsDisable,
config.timer_start_function_name: TimerStart,
config.timer_stop_function_name: TimerStop,
config.timer_set_period_function_name: TimerSetPeriod,
config.printf_function_name: Printf,
config.custom_log_function_name: CustomLog,
config.custom_log_dump_function_name: CustomLogDump,
}
for f_name, function in functions.items():
for n, instruction in enumerate(function.body):
if isinstance(instruction, CallOperation):
if instruction.name in function_map.keys():
op = function_map[instruction.name](instruction)
function.body[n] = op
for f_name in function_map.keys():
if f_name in f_declarations:
del f_declarations[f_name]