feat(tpc): includes 只认项目配置;ASan 改为显式链接 clang64 运行库
includes 目录不再回退仓库硬编码 TransPyCRoot/includes:Phase2Translator 新增 PROJECT_INCLUDE_DIRS(INCLUDE_DIRS 置空以兼容旧引用),Config.py 从 project.vpj 的 includes 同步;HandlesImports 的模块搜索、TypeAnnotationResolver._builtins_include_dirs 一律只读项目目录。 ASan:mingw64 clang 没有 x86_64-w64-windows-gnu 目标的 ASan runtime,新增 _FindAsanRuntimeDir 定位 clang64 运行库并按 -l: 显式链接(asan_dynamic-x86_64.dll.a + runtime_thunk),定位失败即报错退出。HandlesExprFormat:i32 不再写 'l' 长度修饰符(LP64 下 printf 会按 64 位读实参)。
This commit is contained in:
1 parent
ab3873b038
commit
cc2f5d34eb
122 files changed
+89
-31
No files matched your search
+12
-10
@@ -147,16 +147,16 @@ def main() -> None:
|
||||
parser.add_argument('--run', action='store_true', help='编译成功后立即执行生成的可执行文件')
|
||||
parser.add_argument('--rebuild-includes', action='store_true', help='删除 includes.binary 预编译缓存并重新编译所有 includes')
|
||||
parser.add_argument('--clear-cache', action='store_true', help='清除 .transpyc_cache 全局缓存(.vpi/.stub.ll/.doc.json)')
|
||||
parser.add_argument('--asan', action='store_true', help='ASan 模式:对全部 .ll 做 opt -passes=asan 插桩并链接 -fsanitize=address(需 clang64 环境)')
|
||||
parser.add_argument('--asan', action='store_true', help='ASan 模式:对全部 .ll 做 opt -passes=asan 插桩,并显式链接 clang64 的 ASan 运行库(mingw64 的 clang 没有 x86_64-w64-windows-gnu 目标的 ASan runtime,不能用 -fsanitize=address)')
|
||||
parser.add_argument('--nowarn-register', action='store_true', help='抑制"外部函数返回类型未登记"类 WARN 输出(透传给自举编译的 TransPyV.exe)')
|
||||
|
||||
args: argparse.Namespace = parser.parse_args()
|
||||
|
||||
# ASan 模式(--asan):直接经 args 传给 Phase2Translator(compile_ll_to_obj
|
||||
# 先 opt -passes=asan 插桩,链接追加 -fsanitize=address)。不再用 TPC_ASAN
|
||||
# 环境变量透传——环境变量在 worker 子进程/外部调用链下不可靠。
|
||||
# 先 opt -passes=asan 插桩,链接显式 -l: clang64 的 libclang_rt.asan_dynamic*)。
|
||||
# 不再用 TPC_ASAN 环境变量透传——环境变量在 worker 子进程/外部调用链下不可靠。
|
||||
if args.asan:
|
||||
_vlog().info('ASan 模式已启用(opt -passes=asan + -fsanitize=address)', 'asan')
|
||||
_vlog().info('ASan 模式已启用(opt -passes=asan + clang64 libclang_rt.asan_dynamic*)', 'asan')
|
||||
|
||||
project_file: str | None = args.project
|
||||
if not project_file:
|
||||
@@ -184,6 +184,13 @@ def main() -> None:
|
||||
cc_flags: list[str] = resolved.get('compiler', {}).get('flags', ['-filetype=obj'])
|
||||
slice_level: int = resolved.get('options', {}).get('slice_level', 3)
|
||||
project_include_dirs: list[str] = resolved.get('includes', [])
|
||||
# includes 只认项目配置:同步到 Phase2Translator.PROJECT_INCLUDE_DIRS,
|
||||
# 供 builtins.vp 扫描等静态路径在 phase1/2 全程使用(禁止仓库硬编码回退)
|
||||
try:
|
||||
from lib.Projectrans.Phase2Translator import Phase2Translator
|
||||
Phase2Translator.PROJECT_INCLUDE_DIRS = [os.path.abspath(d) for d in project_include_dirs if os.path.isdir(os.path.join(project_dir, d)) or os.path.isdir(d)]
|
||||
except Exception:
|
||||
pass
|
||||
target_triple: str | None = resolved.get('target', {}).get('triple')
|
||||
target_datalayout: str | None = resolved.get('target', {}).get('datalayout')
|
||||
|
||||
@@ -250,11 +257,6 @@ def main() -> None:
|
||||
_vlog().error("阶段一需要指定源目录,不支持文件列表")
|
||||
sys.exit(1)
|
||||
all_include_dirs: list[str] = list(project_include_dirs) if project_include_dirs else []
|
||||
for d in Phase2Translator.INCLUDE_DIRS:
|
||||
if os.path.isdir(d):
|
||||
d = os.path.abspath(d)
|
||||
if d not in [os.path.abspath(x) for x in all_include_dirs]:
|
||||
all_include_dirs.append(d)
|
||||
gen: Phase1Generator = Phase1Generator(src, temp_dir, include_dirs=all_include_dirs, target_triple=target_triple, target_datalayout=target_datalayout)
|
||||
gen.run()
|
||||
save_sha1_map(temp_dir, gen.sha1_map)
|
||||
@@ -286,7 +288,7 @@ def main() -> None:
|
||||
force_recompile_includes: bool = bool(resolved.get('options', {}).get('force_recompile_includes', False))
|
||||
if args.rebuild_includes:
|
||||
force_recompile_includes = True
|
||||
all_inc_dirs: list[str] = list(project_include_dirs) + list(Phase2Translator.INCLUDE_DIRS)
|
||||
all_inc_dirs: list[str] = list(project_include_dirs)
|
||||
seen_dirs: set[str] = set()
|
||||
for inc_dir in all_inc_dirs:
|
||||
abs_inc: str = os.path.abspath(inc_dir)
|
||||
|
||||
Reference in new issue
Block a user