Clean up the source manager

This commit is contained in:
Sameer Rahmani 2023-08-12 20:54:07 +01:00
parent 9d894b662b
commit 6cfe47b6d6
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
6 changed files with 16 additions and 10 deletions

View File

@ -20,6 +20,8 @@ target_sources(serene PRIVATE
commands/commands.cpp commands/commands.cpp
jit/jit.cpp jit/jit.cpp
reader.cpp
source_mgr.cpp
errors.cpp errors.cpp
ast.cpp ast.cpp
namespace.cpp namespace.cpp

View File

@ -59,6 +59,10 @@ class LLJIT;
class LLLazyJIT; class LLLazyJIT;
} // namespace llvm::orc } // namespace llvm::orc
namespace serene {
class Namespace;
} // namespace serene
#define MAIN_PROCESS_JD_NAME "*main*" #define MAIN_PROCESS_JD_NAME "*main*"
#define JIT_LOG(...) \ #define JIT_LOG(...) \
DEBUG_WITH_TYPE("JIT", llvm::dbgs() << "[JIT]: " << __VA_ARGS__ << "\n"); DEBUG_WITH_TYPE("JIT", llvm::dbgs() << "[JIT]: " << __VA_ARGS__ << "\n");

View File

@ -327,16 +327,16 @@ ast::MaybeNode Reader::readList() {
bool list_terminated = false; bool list_terminated = false;
do { do {
const auto *c = nextChar(true); const auto *ch = nextChar(true);
if (isEndOfBuffer(c)) { if (isEndOfBuffer(ch)) {
advance(true); advance(true);
advance(); advance();
list->location.end = getCurrentLocation(); list->location.end = getCurrentLocation();
return errors::make(errors::Type::EOFWhileScaningAList, list->location); return errors::make(errors::Type::EOFWhileScaningAList, list->location);
} }
switch (*c) { switch (*ch) {
case ')': case ')':
advance(true); advance(true);
advance(); advance();

View File

@ -112,10 +112,10 @@ public:
/// Parses the given `input` string and returns a `Result<ast>` /// Parses the given `input` string and returns a `Result<ast>`
/// which may contains an AST or an `llvm::Error` /// which may contains an AST or an `llvm::Error`
ast::MaybeAst read(llvm::StringRef input, llvm::StringRef ns, ast::MaybeAst read(jit::JIT &engine, llvm::StringRef input, llvm::StringRef ns,
std::optional<llvm::StringRef> filename);
ast::MaybeAst read(llvm::MemoryBufferRef input, llvm::StringRef ns,
std::optional<llvm::StringRef> filename); std::optional<llvm::StringRef> filename);
ast::MaybeAst read(jit::JIT &engine, llvm::MemoryBufferRef input,
llvm::StringRef ns, std::optional<llvm::StringRef> filename);
} // namespace serene } // namespace serene
#endif #endif

View File

@ -94,7 +94,7 @@ MaybeNS SourceMgr::readNamespace(jit::JIT &engine, std::string name,
if (bufferId == 0) { if (bufferId == 0) {
auto msg = llvm::formatv("Couldn't add namespace '{0}'", name).str(); auto msg = llvm::formatv("Couldn't add namespace '{0}'", name).str();
return errors::make(errors::Type; : NSAddToSMError, importLoc, msg); return errors::make(errors::Type::NSAddToSMError, importLoc, msg);
} }
// Since we moved the buffer to be added as the source storage we // Since we moved the buffer to be added as the source storage we
@ -102,7 +102,7 @@ MaybeNS SourceMgr::readNamespace(jit::JIT &engine, std::string name,
const auto *buf = getMemoryBuffer(bufferId); const auto *buf = getMemoryBuffer(bufferId);
// Read the content of the buffer by passing it the reader // Read the content of the buffer by passing it the reader
auto maybeAst = read(jit, buf->getBuffer(), name, auto maybeAst = read(engine, buf->getBuffer(), name,
std::optional(llvm::StringRef(importedFile))); std::optional(llvm::StringRef(importedFile)));
if (!maybeAst) { if (!maybeAst) {
@ -123,7 +123,7 @@ MaybeNS SourceMgr::readNamespace(jit::JIT &engine, std::string name,
}; };
unsigned SourceMgr::AddNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> f, unsigned SourceMgr::AddNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> f,
LocationRange includeLoc) { const LocationRange &includeLoc) {
SrcBuffer nb; SrcBuffer nb;
nb.buffer = std::move(f); nb.buffer = std::move(f);
nb.importLoc = includeLoc; nb.importLoc = includeLoc;

View File

@ -174,7 +174,7 @@ public:
/// Add a new source buffer to this source manager. This takes ownership of /// Add a new source buffer to this source manager. This takes ownership of
/// the memory buffer. /// the memory buffer.
unsigned AddNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> f, unsigned AddNewSourceBuffer(std::unique_ptr<llvm::MemoryBuffer> f,
LocationRange includeLoc); const LocationRange &includeLoc);
/// Lookup for a file containing the namespace definition of with given /// Lookup for a file containing the namespace definition of with given
/// namespace name \p name. In case that the file exists, it returns an /// namespace name \p name. In case that the file exists, it returns an