LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
Loading...
Searching...
No Matches
IncludeHelper.h
Go to the documentation of this file.
1
//===-- IncludeHelper.h -----------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLZK Project, under the Apache License v2.0.
4
// See LICENSE.txt for license information.
5
// Copyright 2025 Veridise Inc.
6
// SPDX-License-Identifier: Apache-2.0
7
//
8
//===----------------------------------------------------------------------===//
9
10
#pragma once
11
12
#include <mlir/IR/BuiltinOps.h>
13
#include <mlir/IR/OwningOpRef.h>
14
#include <mlir/Support/LLVM.h>
15
#include <mlir/Support/LogicalResult.h>
16
17
#include <llvm/ADT/SmallString.h>
18
#include <llvm/Support/Path.h>
19
#include <llvm/Support/SourceMgr.h>
20
21
namespace
llzk
{
22
23
class
GlobalSourceMgr
{
24
std::vector<std::string> includeDirectories;
25
26
public
:
27
static
GlobalSourceMgr
&
get
() {
28
static
GlobalSourceMgr
theInstance;
29
return
theInstance;
30
}
31
32
mlir::LogicalResult
setup
(
const
std::vector<std::string> &includeDirs) {
33
includeDirectories = includeDirs;
34
return
mlir::success();
35
}
36
37
// Adapted from mlir::SourceMgr::OpenIncludeFile() because SourceMgr is
38
// not a mature, usable component of MLIR.
39
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
40
openIncludeFile
(
const
mlir::StringRef filename, std::string &resolvedFile) {
41
auto
result = llvm::MemoryBuffer::getFile(filename);
42
43
llvm::SmallString<64> pathBuffer(filename);
44
// If the file didn't exist directly, see if it's in an include path.
45
for
(
unsigned
i = 0, e = includeDirectories.size(); i != e && !result; ++i) {
46
pathBuffer = includeDirectories[i];
47
llvm::sys::path::append(pathBuffer, filename);
48
result = llvm::MemoryBuffer::getFile(pathBuffer);
49
}
50
51
if
(result) {
52
resolvedFile =
static_cast<
std::string
>
(pathBuffer);
53
}
54
55
return
result;
56
}
57
};
58
59
}
// namespace llzk
llzk::GlobalSourceMgr
Definition
IncludeHelper.h:23
llzk::GlobalSourceMgr::get
static GlobalSourceMgr & get()
Definition
IncludeHelper.h:27
llzk::GlobalSourceMgr::setup
mlir::LogicalResult setup(const std::vector< std::string > &includeDirs)
Definition
IncludeHelper.h:32
llzk::GlobalSourceMgr::openIncludeFile
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > openIncludeFile(const mlir::StringRef filename, std::string &resolvedFile)
Definition
IncludeHelper.h:40
llzk
Definition
AnalysisPassEnums.cpp:19
include
llzk
Dialect
Include
Util
IncludeHelper.h
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.