object-introspection/oi/OILibraryImpl.h

90 lines
2.2 KiB
C
Raw Permalink Normal View History

2022-12-19 14:37:51 +00:00
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
2023-08-16 20:40:36 +01:00
#include <oi/oi.h>
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
#include <filesystem>
#include <map>
#include <span>
#include <unordered_set>
#include <utility>
#include "oi/CodeGen.h"
#include "oi/Features.h"
2023-04-26 16:20:53 +01:00
#include "oi/OICompiler.h"
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
namespace oi::detail {
2022-12-19 14:37:51 +00:00
class OILibraryImpl {
2023-08-16 20:40:36 +01:00
private:
class LocalTextSegment {
public:
LocalTextSegment() = default;
LocalTextSegment(size_t size);
~LocalTextSegment();
LocalTextSegment(const LocalTextSegment&) = delete;
LocalTextSegment& operator=(const LocalTextSegment&) = delete;
LocalTextSegment(LocalTextSegment&& that) {
std::swap(this->data_, that.data_);
}
LocalTextSegment& operator=(LocalTextSegment&& that) {
std::swap(this->data_, that.data_);
return *this;
}
std::span<uint8_t> data() {
return data_;
}
void release() {
data_ = {};
}
private:
std::span<uint8_t> data_;
};
class MemoryFile {
public:
MemoryFile(const char* name);
~MemoryFile();
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
std::filesystem::path path();
private:
int fd_ = -1;
};
public:
OILibraryImpl(void* atomicHole,
std::unordered_set<oi::Feature> fs,
GeneratorOptions opts);
std::pair<void*, const exporters::inst::Inst&> init();
2022-12-19 14:37:51 +00:00
private:
2023-08-16 20:40:36 +01:00
void* atomicHole_;
std::map<Feature, bool> requestedFeatures_;
GeneratorOptions opts_;
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
oi::detail::OICompiler::Config compilerConfig_{};
oi::detail::OICodeGen::Config generatorConfig_{};
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
LocalTextSegment textSeg;
2022-12-19 14:37:51 +00:00
2023-08-16 20:40:36 +01:00
void processConfigFile();
std::pair<void*, const exporters::inst::Inst&> compileCode();
2022-12-19 14:37:51 +00:00
};
2023-08-16 20:40:36 +01:00
} // namespace oi::detail