Add basic namespace loader template funections to the jit
This commit is contained in:
parent
1e8c820fb6
commit
b66e92fb1f
|
@ -109,7 +109,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
If you need help or you just want to hangout, you can find us at:
|
||||
|
||||
- *IRC*: *#serene-lang* on the libera chat server
|
||||
|
||||
- *Matrix Network*: https://matrix.to/#/#serene:matrix.org?via=matrix.org&via=gitter.im
|
||||
|
||||
- *MailingList*: https://www.freelists.org/list/serene
|
||||
|
|
|
@ -88,6 +88,8 @@ public:
|
|||
/// Setup the load path for namespace lookups
|
||||
void setLoadPaths(std::vector<std::string> &dirs) { loadPaths.swap(dirs); };
|
||||
|
||||
/// Return the load paths for namespaces
|
||||
std::vector<std::string> &getLoadPaths() { return loadPaths; };
|
||||
// JIT JITDylib related functions ---
|
||||
|
||||
// TODO: For Dylib related functions, make sure that the namespace in questoin
|
||||
|
|
|
@ -28,8 +28,9 @@
|
|||
#ifndef SERENE_JIT_HALLEY_H
|
||||
#define SERENE_JIT_HALLEY_H
|
||||
|
||||
#include "serene/context.h" // for Serene...
|
||||
#include "serene/export.h" // for SERENE...
|
||||
#include "serene/context.h" // for Serene...
|
||||
#include "serene/export.h" // for SERENE...
|
||||
#include "serene/fs.h"
|
||||
#include "serene/types/types.h" // for Intern...
|
||||
|
||||
#include <llvm/ADT/SmallVector.h> // for SmallV...
|
||||
|
@ -136,6 +137,11 @@ public:
|
|||
Halley(std::unique_ptr<SereneContext> ctx,
|
||||
llvm::orc::JITTargetMachineBuilder &&jtmb, llvm::DataLayout &&dl);
|
||||
|
||||
/// Initialize the engine by loading required libraries and shared libs
|
||||
/// like the `serene.core` and other namespaces
|
||||
llvm::Error initialize();
|
||||
llvm::Error loadNamespace(std::string &nsName);
|
||||
|
||||
static MaybeEngine make(std::unique_ptr<SereneContext> sereneCtxPtr,
|
||||
llvm::orc::JITTargetMachineBuilder &&jtmb);
|
||||
|
||||
|
@ -194,6 +200,14 @@ public:
|
|||
|
||||
llvm::Error loadModule(const char *nsName, const char *file);
|
||||
void dumpToObjectFile(llvm::StringRef filename);
|
||||
|
||||
/// This function loads the namespace by the given `nsName` from the file
|
||||
/// in the given `path`. It assumes that the `path` exists.
|
||||
llvm::Error loadNamespaceFrom(fs::NSFileType type_, llvm::StringRef nsName,
|
||||
llvm::StringRef path);
|
||||
|
||||
template <fs::NSFileType fileType>
|
||||
llvm::Error loadNamespaceFrom(llvm::StringRef nsName, llvm::StringRef path);
|
||||
};
|
||||
|
||||
MaybeEngine makeHalleyJIT(std::unique_ptr<SereneContext> ctx);
|
||||
|
|
|
@ -25,6 +25,7 @@ endif()
|
|||
add_library(serene
|
||||
serene.cpp
|
||||
context.cpp
|
||||
fs.cpp
|
||||
|
||||
jit/halley.cpp)
|
||||
|
||||
|
|
|
@ -470,6 +470,107 @@ llvm::Error Halley::loadModule(const char *nsName, const char *file) {
|
|||
};
|
||||
// /TODO
|
||||
|
||||
// TODO: [error] Remove this function when we implemented
|
||||
// the error subsystem
|
||||
llvm::Error NotImplemented(llvm::StringRef s) {
|
||||
return llvm::make_error<llvm::StringError>("Not Implemented: " + s);
|
||||
};
|
||||
// /TODO
|
||||
|
||||
template <>
|
||||
llvm::Error
|
||||
Halley::loadNamespaceFrom<fs::NSFileType::Source>(llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
(void)nsName;
|
||||
(void)path;
|
||||
return NotImplemented("loadNamespaceFrom<source>");
|
||||
};
|
||||
|
||||
template <>
|
||||
llvm::Error
|
||||
Halley::loadNamespaceFrom<fs::NSFileType::TextIR>(llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
(void)nsName;
|
||||
(void)path;
|
||||
|
||||
return NotImplemented("loadNamespaceFrom<TextIR>");
|
||||
};
|
||||
|
||||
template <>
|
||||
llvm::Error
|
||||
Halley::loadNamespaceFrom<fs::NSFileType::BinaryIR>(llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
(void)nsName;
|
||||
(void)path;
|
||||
return NotImplemented("loadNamespaceFrom<binary>");
|
||||
};
|
||||
|
||||
template <>
|
||||
llvm::Error
|
||||
Halley::loadNamespaceFrom<fs::NSFileType::ObjectFile>(llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
(void)nsName;
|
||||
(void)path;
|
||||
return NotImplemented("loadNamespaceFrom<object>");
|
||||
};
|
||||
|
||||
template <>
|
||||
llvm::Error
|
||||
Halley::loadNamespaceFrom<fs::NSFileType::StaticLib>(llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
(void)nsName;
|
||||
(void)path;
|
||||
return NotImplemented("loadNamespaceFrom<static>");
|
||||
};
|
||||
|
||||
template <>
|
||||
llvm::Error
|
||||
Halley::loadNamespaceFrom<fs::NSFileType::SharedLib>(llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
(void)nsName;
|
||||
(void)path;
|
||||
return NotImplemented("loadNamespaceFrom<shared>");
|
||||
};
|
||||
|
||||
llvm::Error Halley::loadNamespaceFrom(fs::NSFileType type_,
|
||||
llvm::StringRef nsName,
|
||||
llvm::StringRef path) {
|
||||
switch (type_) {
|
||||
case fs::NSFileType::Source:
|
||||
return loadNamespaceFrom<fs::NSFileType::Source>(nsName, path);
|
||||
case fs::NSFileType::TextIR:
|
||||
return loadNamespaceFrom<fs::NSFileType::TextIR>(nsName, path);
|
||||
case fs::NSFileType::BinaryIR:
|
||||
return loadNamespaceFrom<fs::NSFileType::BinaryIR>(nsName, path);
|
||||
case fs::NSFileType::ObjectFile:
|
||||
return loadNamespaceFrom<fs::NSFileType::ObjectFile>(nsName, path);
|
||||
case fs::NSFileType::StaticLib:
|
||||
case fs::NSFileType::SharedLib:
|
||||
return loadNamespaceFrom<fs::NSFileType::StaticLib>(nsName, path);
|
||||
};
|
||||
};
|
||||
|
||||
llvm::Error Halley::loadNamespace(std::string &nsName) {
|
||||
for (auto &path : ctx->getLoadPaths()) {
|
||||
std::string nsFileName = fs::namespaceToPath(nsName);
|
||||
(void)path;
|
||||
for (int i = 0; i <= (int)fs::NSFileType::SharedLib; i++) {
|
||||
if (fs::exists(nsFileName + fs::extensionFor((fs::NSFileType)i))) {
|
||||
// fs::NSFileType type_ = ;
|
||||
return loadNamespaceFrom((fs::NSFileType)i, nsName,
|
||||
nsFileName +
|
||||
fs::extensionFor((fs::NSFileType)i));
|
||||
}
|
||||
}
|
||||
}
|
||||
return llvm::Error::success();
|
||||
};
|
||||
|
||||
llvm::Error Halley::initialize() {
|
||||
(void)ctx;
|
||||
return llvm::Error::success();
|
||||
};
|
||||
|
||||
MaybeEngine makeHalleyJIT(std::unique_ptr<SereneContext> ctx) {
|
||||
llvm::orc::JITTargetMachineBuilder jtmb(ctx->triple);
|
||||
auto maybeJIT = Halley::make(std::move(ctx), std::move(jtmb));
|
||||
|
|
|
@ -68,6 +68,7 @@ void applySereneCLOptions(serene::jit::Engine &engine) {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: [engine] Should we move this to the engine itself?
|
||||
auto &ctx = engine.getContext();
|
||||
ctx.setLoadPaths(options->loadPaths);
|
||||
|
||||
|
|
Loading…
Reference in New Issue