为匹配白名单的直接 call 点插桩 internal i64 __fhs_site_<K>(call 前 +1),计数天然包含循环内放大的真实执行次数,可把热点定位到具体调用点。 新增 --hotspot-callees 覆盖白名单、--hotspot-sites-all 全量;按去 16 位 sha1 前缀后的基名匹配。Ctrl+C 落盘独立文件 hotspot_sites.txt(# sites 分段,含调用方/被调方/计数/源码位置),按计数降序;不破坏既有 hotspot.txt 格式。 在 AST->IR 生成期由 _HotspotSiteBuilder 为每条新生成的 call 指令轻量挂载 _src_file/_src_line,插桩时作为可选尾字段输出;取不到则留空不伪造。开关关闭时改用原生 ir.IRBuilder,零影响。
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
# 常量定义
|
||
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]
|
||
[-func-hotspot HotFile] [--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
|
||
-func-hotspot: 统计各函数调用次数,Ctrl+C 退出时写入 HotFile(每行 "函数名 计数")
|
||
--hotspot-sites: 统计各调用点真实运行次数,Ctrl+C 退出时写入 SitesFile(默认 hotspot_sites.txt,
|
||
按计数降序;可独立于 -func-hotspot 使用)
|
||
--hotspot-callees: --hotspot-sites 的白名单被调函数基名(逗号分隔,默认内存/字符串族)
|
||
--hotspot-sites-all: --hotspot-sites 对全部直接 call 点插桩(忽略白名单,体积/开销大)
|
||
'''
|
||
|
||
mode: str = "strict"
|