Files
TransPyC/lib/constants/config.py
T
TermiNexus fc5a6134ca feat(hotspot)!: 下线 --func-hotspot 并为 --hotspot-sites 增加每函数计时器
移除 --func-hotspot 全链路(CLI 解析与绑定、Config argparse 与注入、Translator 属性、LlvmGenerator 收口与透传、BaseGen 专属实现、Phase2Translator 透传、帮助文本);全仓已无 FuncHotspot/func-hotspot 残留引用。

通用截断逻辑保留并改名为 _InstallHotspotTruncate,供 --hotspot-sites 使用(分别清空 hotspot_sites.txt 与 hotspot_time.txt);ctor 注册改为直接新建并接收处理器列表(sites 与 time 两个处理器在同一 ctor 内注册)。

--hotspot-sites 现附带每函数计时:入口读一次 @llvm.readcyclecounter() 存起始 tick,在函数所有 ret 之前再读一次并累加差值到 internal i64 __fhs_ftime_N,同时 __fhs_ftime_enter_N 记录进入次数;单位为 tick(x86_64 即 CPU 周期),语义为 inclusive(包含内层调用)。

计时结果按耗时降序写入同目录 hotspot_time.txt(# time <module_sha1> 分段 + 函数名/累计 tick/进入次数),不改变 hotspot_sites.txt 的既有格式与字段。不传 --hotspot-sites 时零影响。
2026-09-14 13:10:06 +08:00

57 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 常量定义
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,
按计数降序),并为每个函数定义加计时器(累计耗时与进入次数按耗时降序写入同目录
hotspot_time.txt;耗时单位为 tick = @llvm.readcyclecounter() 计数)
--hotspot-callees: --hotspot-sites 的白名单被调函数基名(逗号分隔,默认内存/字符串族)
--hotspot-sites-all: --hotspot-sites 对全部直接 call 点插桩(忽略白名单,体积/开销大)
'''
mode: str = "strict"