1# coding=utf-8 2# 3# Copyright (c) 2025 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16from dataclasses import dataclass 17from typing import TYPE_CHECKING, ClassVar 18 19from taihe.driver.backend import Backend, BackendConfig 20 21if TYPE_CHECKING: 22 from taihe.driver.contexts import CompilerInstance 23 24 25@dataclass 26class AniBridgeBackendConfig(BackendConfig): 27 NAME = "ani-bridge" 28 DEPS: ClassVar = ["cpp-user"] 29 30 def construct(self, instance: "CompilerInstance") -> Backend: 31 from taihe.codegen.ani.gen_ani import ANICodeGenerator 32 from taihe.codegen.ani.gen_sts import STSCodeGenerator 33 34 # TODO: unify {ANI,STS}CodeGenerator 35 class AniBridgeBackendImpl(Backend): 36 def __init__(self, ci: "CompilerInstance"): 37 super().__init__(ci) 38 self._ci = ci 39 40 def generate(self): 41 om = self._ci.output_manager 42 am = self._ci.analysis_manager 43 pg = self._ci.package_group 44 ANICodeGenerator(om, am).generate(pg) 45 STSCodeGenerator(om, am).generate(pg) 46 47 return AniBridgeBackendImpl(instance)