diff --git a/lib/core/Handles/HandlesAsyncFunctions.py b/lib/core/Handles/HandlesAsyncFunctions.py index 949247b..b475404 100644 --- a/lib/core/Handles/HandlesAsyncFunctions.py +++ b/lib/core/Handles/HandlesAsyncFunctions.py @@ -146,6 +146,7 @@ class AsyncFunctionHandle(BaseHandle): frame_ty: ir.IdentifiedStructType = ir.IdentifiedStructType(Gen.module, f'Coro_{name}') frame_ty.set_body(*fields) Gen._coro_frame_types[name] = frame_ty + Gen.structs[f'Coro_{name}'] = frame_ty Gen._coro_local_vars[name] = local_names return frame_ty diff --git a/lib/core/LLVMCG/StructGen.py b/lib/core/LLVMCG/StructGen.py index f6eb280..a705710 100644 --- a/lib/core/LLVMCG/StructGen.py +++ b/lib/core/LLVMCG/StructGen.py @@ -168,6 +168,18 @@ class StructGenMixin: else: struct_defs.append(f'{sname_ir} = type {{ {elems} }}') struct_names.add(sname) + # 协程帧结构体兜底(M1):帧注册进 Gen.structs 时上面已输出; + # 未注册(被 _generate_structs 清空)时这里补齐定义,避免 + # getelementptr base element must be sized。 + coro_frames: dict = getattr(self, '_coro_frame_types', None) or {} + for _cf_name, _cf_ty in coro_frames.items(): + if _cf_name in struct_names: + continue + if isinstance(_cf_ty, ir.IdentifiedStructType) and _cf_ty.elements: + _cf_sname: str = _cf_ty.name + _cf_ir: str = f'%"{_cf_sname}"' if (_cf_sname[0].isdigit() or "." in _cf_sname) else f'%{_cf_sname}' + struct_defs.append(f'{_cf_ir} = type {{ {", ".join(str(e) for e in _cf_ty.elements)} }}') + struct_names.add(_cf_sname) if struct_defs: lines: list[str] = ir_text.split('\n') # 预计算全部 "= type" 定义行前缀(一次性),用 str.startswith(tuple)