# 常量定义 from __future__ import annotations DEFAULT_INPUT_FILE: str = 'test.vp' DEFAULT_OUTPUT_FILE: str = 'test.ll' SLICE_THRESHOLD: int = 50 SLICE_LEVEL_DEFAULT: int = 3 SLICE_LEVELS: dict[int | str, str] = { 0: 'no_optimize', 1: 'conservative', 2: 'moderate', 3: 'aggressive', 's': 'size', } DEFAULT_COMPILE_COMMAND: str = 'gcc' DEFAULT_COMPILE_FLAGS: str = '' DEFAULT_METADATA: dict[str, str] = { 'PROJECT_NAME': 'TransPyC Project', 'AUTHOR': 'TransPyC Team', 'VERSION': '1.0.0', 'DESCRIPTION': 'Auto-generated LLVM IR file', 'COPYRIGHT_YEAR': '2026', 'COPYRIGHT_HOLDER': 'Galactic Vorpal Software Development Studio (e.g. GVSDS Inc.)' } # 调用点热点统计(--hotspot-sites)默认白名单:内存/字符串族被调函数基名 # (基名 = 去掉 16 位 sha1 模块前缀后的名字,如 "23499a69276862b2.strcmp" -> "strcmp") DEFAULT_HOTSPOT_CALLEES: tuple[str, ...] = ( 'strcmp', 'strncmp', 'strchr', 'strlen', 'strstr', 'memcpy', 'memset', 'memmove', 'strcpy', 'strcat', ) ERROR_MESSAGES: dict[str, str] = { 'MISSING_ARGS': 'Missing required arguments -f and/or -o', 'UNKNOWN_ARG': 'Unknown argument', 'UNSUPPORTED_TYPE': 'Unsupported file type', 'FAILED_PARSE': 'Failed to parse file', 'COMPILE_FAILED': 'Compilation or execution failed' } HELP_MESSAGE: str = ''' Usage: python TransPyC.py -f InputFile -o OutputFile [-wh header_files] [-debug DebugFile] [-cc compile_command] [-cflags CompileFlags] [-run] [-args RunArgs] [-h HelperFiles] [--hotspot-sites [SitesFile]] [--hotspot-callees a,b,c] [--hotspot-sites-all] -h: Specify helper files (C or Python) to help identify structs, functions, variables, and ptrs --hotspot-sites: 统计各调用点真实运行次数(Ctrl+C 退出时写入 SitesFile,默认 hotspot_sites.txt, 按计数降序),并为每个函数定义加计时器:自身耗时 self、包含式耗时 inc 与进入次数, 按 self 降序写入同目录 hotspot_time.txt(行为 `<函数名> <进入次数>`); 单位 tick(x86_64 上为序列化的 lfence; rdtsc 计数)。self 已扣除本函数内被插桩 子调用的 inc,但**不含未插桩的被调方**(间接调用、strcmp/memcpy 等无定义的外部 函数、深度溢出跳过的调用),这些仍计入调用者的 self --hotspot-callees: --hotspot-sites 的白名单被调函数基名(逗号分隔,默认内存/字符串族) --hotspot-sites-all: --hotspot-sites 对全部直接 call 点插桩(忽略白名单,体积/开销大) ''' mode: str = "strict"