import os
import shutil

from imc_utils.build_config.cortex_m33 import BuildConfigM33
from imc_utils.build_config.test_env import TestEnv

WORKSPACE_ROOT = "/home/ybkim/workspace/imc/imc_freertos_app_m33"
NVM_RESET_BIN = f"{WORKSPACE_ROOT}/imc/utils/nvm_reset.elf"
OPENOCD_SCRIPT = f"{WORKSPACE_ROOT}/imc_freertos_app_m33.cfg"
BUILD_DIR = f"{WORKSPACE_ROOT}/build"

config = BuildConfigM33()
config.bench_name = "vFFT"
config.insert_compiler_checkpoints = True
config.enable_extension = True
config.use_checkpoint_pass_counter = False
config.checkpoint_pass_count = 1000
config.use_checkpoint_voltage_check = True
config.bench_infinite_loop = True
config.split_loop = True
config.loop_pass_count = 30
config.enable_static_loop_pass_count = False
config.enable_adaptive_loop_pass_count = False
config.max_loop_ids = 20
config.bench_repeat_count = config.bench_repeat_count_small[config.bench_name]
config.print_stats = True
config.custom_unroll = False
config.enable_dynamic_checkpoint = True

config.duplication_ratio = 50

env = TestEnv(WORKSPACE_ROOT, NVM_RESET_BIN, OPENOCD_SCRIPT)

if os.path.exists(BUILD_DIR):
    shutil.rmtree(BUILD_DIR)

os.mkdir(BUILD_DIR)

env.build_binary(config, BUILD_DIR)