1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LIBLLVMBACKEND_COMPILER_INTERFACE_H 17 #define LIBLLVMBACKEND_COMPILER_INTERFACE_H 18 19 #include <string> 20 #include <vector> 21 22 #include "utils/expected.h" 23 24 namespace ark::compiler { 25 class Graph; 26 } // namespace ark::compiler 27 28 namespace ark::llvmbackend { 29 30 struct CompiledCode { 31 const uint8_t *code; 32 size_t size; 33 }; 34 35 struct CompilerInterface { 36 CompilerInterface() = default; 37 virtual ~CompilerInterface() = default; 38 39 virtual Expected<bool, std::string> TryAddGraph(ark::compiler::Graph *graph) = 0; 40 virtual void FinishCompile() = 0; 41 virtual bool HasCompiledCode() = 0; 42 virtual bool IsIrFailed() = 0; 43 44 CompilerInterface(const CompilerInterface &) = delete; 45 void operator=(const CompilerInterface &) = delete; 46 CompilerInterface(CompilerInterface &&) = delete; 47 CompilerInterface &operator=(CompilerInterface &&) = delete; 48 }; 49 50 struct IrtocCompilerInterface : public CompilerInterface { 51 IrtocCompilerInterface() = default; 52 ~IrtocCompilerInterface() override = default; 53 54 virtual void WriteObjectFile(std::string_view output) = 0; 55 virtual CompiledCode GetCompiledCode(std::string_view functionName) = 0; 56 virtual size_t GetObjectFileSize() = 0; 57 virtual bool IsEmpty() = 0; 58 59 IrtocCompilerInterface(const IrtocCompilerInterface &) = delete; 60 void operator=(const IrtocCompilerInterface &) = delete; 61 IrtocCompilerInterface(IrtocCompilerInterface &&) = delete; 62 IrtocCompilerInterface &operator=(IrtocCompilerInterface &&) = delete; 63 }; 64 65 } // namespace ark::llvmbackend 66 67 #endif // LIBLLVMBACKEND_COMPILER_INTERFACE_H 68