// Part of the Concrete Compiler Project, under the BSD3 License with Zama // Exceptions. See // https://github.com/zama-ai/concrete-compiler-internal/blob/main/LICENSE.txt // for license information. #include "concretelang/Conversion/Tools.h" mlir::LogicalResult insertForwardDeclaration(mlir::Operation *op, mlir::RewriterBase &rewriter, llvm::StringRef funcName, mlir::FunctionType funcType) { // Looking for the `funcName` Operation auto module = mlir::SymbolTable::getNearestSymbolTable(op); auto opFunc = mlir::dyn_cast_or_null( mlir::SymbolTable::lookupSymbolIn(module, funcName)); if (!opFunc) { // Insert the forward declaration of the funcName mlir::OpBuilder::InsertionGuard guard(rewriter); rewriter.setInsertionPointToStart(&module->getRegion(0).front()); opFunc = rewriter.create(rewriter.getUnknownLoc(), funcName, funcType); opFunc.setPrivate(); } else { // Check if the `funcName` is well a private function if (!opFunc.isPrivate()) { op->emitError() << "the function \"" << funcName << "\" conflicts with the concrete C API, please rename"; return mlir::failure(); } } assert(mlir::SymbolTable::lookupSymbolIn(module, funcName) ->template hasTrait()); return mlir::success(); }