summaryrefslogtreecommitdiff
path: root/willow/tools/willowc/include/sourcemanager.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'willow/tools/willowc/include/sourcemanager.hpp')
-rw-r--r--willow/tools/willowc/include/sourcemanager.hpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/willow/tools/willowc/include/sourcemanager.hpp b/willow/tools/willowc/include/sourcemanager.hpp
index a526e48..25d4128 100644
--- a/willow/tools/willowc/include/sourcemanager.hpp
+++ b/willow/tools/willowc/include/sourcemanager.hpp
@@ -1,24 +1,59 @@
#ifndef WILLOWC_INCLUDE_SOURCEMANAGER_HPP
#define WILLOWC_INCLUDE_SOURCEMANAGER_HPP
-#include <filesystem>
#include <memory>
#include <string>
+#include <unordered_map>
+#include <map>
#include <vector>
+#include <optional>
+
+#include <willow/IR/Location.h>
namespace willowc {
using FileID = std::uint32_t;
+class LineCache {
+public:
+private:
+ std::unordered_map<std::size_t, std::size_t> cache_;
+};
+
class SourceManager {
+public:
struct File {
std::string path;
+ // TODO: remove this, but find something better than using the abs path
+ std::string display_path;
std::unique_ptr<char[]> buf;
+ size_t size;
+
+ willow::Location getLoc(std::size_t offset);
+ std::map<std::size_t, uint32_t> linecache_;
+
+ File(std::string path, std::string display_path, std::unique_ptr<char[]> buf,
+ size_t size)
+ : path(std::move(path)), display_path(std::move(display_path)),
+ buf(std::move(buf)), size(size), linecache_{{{0, 1}}} {}
};
-public:
+
std::optional<FileID> addFile(std::string_view path);
+ std::optional<FileID> addStdIn();
+ std::optional<FileID> getFileID(const std::string& path);
+ std::string_view getBuf(FileID file) const {
+ const File &f = file_table.at(file);
+ return std::string_view(f.buf.get(), f.size);
+ }
+ File &getFile(FileID id) { return file_table.at(id); }
+
+ const std::vector<File>& files() const { return file_table; }
+ std::vector<File>& files() { return file_table; }
+
+ size_t numFiles() { return file_table.size(); }
private:
std::vector<File> file_table;
+ std::unordered_map<std::string, FileID> ids;
};
} // namespace willowc