| SRCS = \ | SRCS = \ | ||||
| src/BXParser.cc src/build.cc src/compdb.cc src/CompileStep.cc src/DepNode.cc \ | |||||
| src/globals.cc src/LinkStep.cc src/logger.cc src/parallel.cc src/sys.cc \ | |||||
| src/toolchain.cc src/main.cc | |||||
| lib/BXParser.cc lib/build.cc lib/compdb.cc lib/CompileStep.cc lib/DepNode.cc \ | |||||
| lib/globals.cc lib/LinkStep.cc lib/logger.cc lib/parallel.cc lib/sys.cc \ | |||||
| lib/toolchain.cc cmd/main.cc | |||||
| HDRS = \ | HDRS = \ | ||||
| src/BXParser.h src/build.h src/compdb.h src/CompileStep.h src/DepNode.h \ | |||||
| src/globals.h src/LinkStep.h src/logger.h src/parallel.h src/sys.h \ | |||||
| src/toolchain.h src/bufio.h | |||||
| lib/BXParser.h lib/build.h lib/compdb.h lib/CompileStep.h lib/DepNode.h \ | |||||
| lib/globals.h lib/LinkStep.h lib/logger.h lib/parallel.h lib/sys.h \ | |||||
| lib/toolchain.h lib/bufio.h | |||||
| BUILD = build | BUILD = build | ||||
| OBJS = $(patsubst %,$(BUILD)/%.o,$(SRCS)) | OBJS = $(patsubst %,$(BUILD)/%.o,$(SRCS)) | ||||
| CFLAGS = -std=c++14 -Wall -Wextra -Wno-unused-parameter -O3 -g | CFLAGS = -std=c++14 -Wall -Wextra -Wno-unused-parameter -O3 -g |
| target := box | target := box | ||||
| files := src | |||||
| files := lib cmd | |||||
| includes := lib | |||||
| warnings := all extra no-unused-parameter | warnings := all extra no-unused-parameter | ||||
| std := c++14 | std := c++14 | ||||
| optimize := 3 | optimize := 3 |
| skip(); // '=' | skip(); // '=' | ||||
| skip(); // '+' | skip(); // '+' | ||||
| return Operator::EQUALS_PLUS; | return Operator::EQUALS_PLUS; | ||||
| } else if (peek() == '|' && ch2 == '|') { | |||||
| } else if (peek() == '|' && ch2 == '=') { | |||||
| skip(); // '|' | skip(); // '|' | ||||
| skip(); // '=' | skip(); // '=' | ||||
| return Operator::BAR_EQUALS; | return Operator::BAR_EQUALS; |
| static const int FLAG_NONE = 0; | static const int FLAG_NONE = 0; | ||||
| static const int FLAG_ONE_LINE = 1 << 0; | static const int FLAG_ONE_LINE = 1 << 0; | ||||
| BXParser(bufio::IStream &stream, int flags, int line = 1, int ch = 1): | |||||
| BXParser(bufio::IStream &stream, int flags = FLAG_NONE, int line = 1, int ch = 1): | |||||
| flags_(flags), line_(line), ch_(ch), buf_(stream) {} | flags_(flags), line_(line), ch_(ch), buf_(stream) {} | ||||
| void parse(BXVariables &vars); | void parse(BXVariables &vars); |
| BXVariables cachedVariables; | BXVariables cachedVariables; | ||||
| try { | try { | ||||
| bufio::IFStream f(confPath); | bufio::IFStream f(confPath); | ||||
| BXParser parser(f, BXParser::FLAG_NONE); | |||||
| BXParser parser(f); | |||||
| parser.parse(cachedVariables); | parser.parse(cachedVariables); | ||||
| } catch (BXParseError &err) { | } catch (BXParseError &err) { | ||||
| logger::log(confPath + ": " + err.what()); | logger::log(confPath + ": " + err.what()); |
| BXVariables cachedVariables; | BXVariables cachedVariables; | ||||
| try { | try { | ||||
| bufio::IFStream f(confPath); | bufio::IFStream f(confPath); | ||||
| BXParser parser(f, BXParser::FLAG_NONE); | |||||
| BXParser parser(f); | |||||
| parser.parse(cachedVariables); | parser.parse(cachedVariables); | ||||
| } catch (BXParseError &err) { | } catch (BXParseError &err) { | ||||
| logger::log(confPath + ": " + err.what()); | logger::log(confPath + ": " + err.what()); |
| class ISStream: public IStream { | class ISStream: public IStream { | ||||
| public: | public: | ||||
| ISStream(const std::string &str): str_(str) {} | |||||
| ISStream(std::string str): str_(std::move(str)) {} | |||||
| size_t read(char *buf, size_t maxlen) override; | size_t read(char *buf, size_t maxlen) override; | ||||
| private: | private: | ||||
| size_t idx_ = 0; | size_t idx_ = 0; | ||||
| const std::string &str_; | |||||
| const std::string str_; | |||||
| }; | }; | ||||
| class OStream { | class OStream { | ||||
| std::ofstream os_; | std::ofstream os_; | ||||
| }; | }; | ||||
| template<size_t bufsiz = 1024> | |||||
| template<typename IS = IStream, size_t bufsiz = 1024> | |||||
| class IBuf { | class IBuf { | ||||
| public: | public: | ||||
| IBuf(IStream &is): is_(is) {} | |||||
| IBuf(IS &is): is_(is) {} | |||||
| char get(); | char get(); | ||||
| int peek(size_t count = 1); | int peek(size_t count = 1); | ||||
| private: | private: | ||||
| IStream &is_; | |||||
| IS &is_; | |||||
| char buf_[bufsiz]; | char buf_[bufsiz]; | ||||
| size_t idx_ = 0; | size_t idx_ = 0; | ||||
| size_t len_ = 0; | size_t len_ = 0; | ||||
| }; | }; | ||||
| template<size_t bufsiz = 1024> | |||||
| template<typename OS = OStream, size_t bufsiz = 1024> | |||||
| class OBuf { | class OBuf { | ||||
| public: | public: | ||||
| OBuf(OStream &os): os_(os) {} | |||||
| OBuf(OS &os): os_(os) {} | |||||
| ~OBuf(); | ~OBuf(); | ||||
| void put(char ch); | void put(char ch); | ||||
| void put(const std::string &str) { put(str.c_str(), str.size()); } | void put(const std::string &str) { put(str.c_str(), str.size()); } | ||||
| private: | private: | ||||
| OStream &os_; | |||||
| OS &os_; | |||||
| char buf_[bufsiz]; | char buf_[bufsiz]; | ||||
| size_t idx_ = 0; | size_t idx_ = 0; | ||||
| }; | }; | ||||
| * IBuf | * IBuf | ||||
| */ | */ | ||||
| template<size_t bufsiz> | |||||
| inline char IBuf<bufsiz>::get() { | |||||
| template<typename IS, size_t bufsiz> | |||||
| inline char IBuf<IS, bufsiz>::get() { | |||||
| if (idx_ < len_) { | if (idx_ < len_) { | ||||
| return buf_[idx_++]; | return buf_[idx_++]; | ||||
| } | } | ||||
| return buf_[idx_++]; | return buf_[idx_++]; | ||||
| } | } | ||||
| template<size_t bufsiz> | |||||
| inline int IBuf<bufsiz>::peek(size_t count) { | |||||
| template<typename IS, size_t bufsiz> | |||||
| inline int IBuf<IS, bufsiz>::peek(size_t count) { | |||||
| size_t offset = count - 1; | size_t offset = count - 1; | ||||
| if (idx_ + offset < len_) { | if (idx_ + offset < len_) { | ||||
| return buf_[idx_ + offset]; | return buf_[idx_ + offset]; | ||||
| * OBuf | * OBuf | ||||
| */ | */ | ||||
| template<size_t bufsiz> | |||||
| inline OBuf<bufsiz>::~OBuf() { | |||||
| template<typename OS, size_t bufsiz> | |||||
| inline OBuf<OS, bufsiz>::~OBuf() { | |||||
| if (idx_ > 0) { | if (idx_ > 0) { | ||||
| os_.write(buf_, idx_); | os_.write(buf_, idx_); | ||||
| } | } | ||||
| } | } | ||||
| template<size_t bufsiz> | |||||
| inline void OBuf<bufsiz>::put(char ch) { | |||||
| template<typename OS, size_t bufsiz> | |||||
| inline void OBuf<OS, bufsiz>::put(char ch) { | |||||
| buf_[idx_++] = ch; | buf_[idx_++] = ch; | ||||
| if (idx_ == sizeof(buf_)) { | if (idx_ == sizeof(buf_)) { | ||||
| } | } | ||||
| } | } | ||||
| template<size_t bufsiz> | |||||
| inline void OBuf<bufsiz>::put(const char *str, size_t len) { | |||||
| template<typename OS, size_t bufsiz> | |||||
| inline void OBuf<OS, bufsiz>::put(const char *str, size_t len) { | |||||
| size_t w = sizeof(buf_) - idx_ - 1; | size_t w = sizeof(buf_) - idx_ - 1; | ||||
| if (w > len) { | if (w > len) { | ||||
| w = len; | w = len; |
| varsptr = &subvars; | varsptr = &subvars; | ||||
| bufio::IFStream stream("build.bx"); | bufio::IFStream stream("build.bx"); | ||||
| BXParser parser(stream, BXParser::FLAG_NONE); | |||||
| BXParser parser(stream); | |||||
| parser.parse(subvars); | parser.parse(subvars); | ||||
| auto it = subvars.find("files"); | auto it = subvars.find("files"); | ||||
| // Read config from file | // Read config from file | ||||
| if (sys::fileExists("build.bx")) { | if (sys::fileExists("build.bx")) { | ||||
| bufio::IFStream stream("build.bx"); | bufio::IFStream stream("build.bx"); | ||||
| BXParser parser(stream, BXParser::FLAG_NONE); | |||||
| BXParser parser(stream); | |||||
| parser.parse(variables); | parser.parse(variables); | ||||
| } | } | ||||
| #include "logger.h" | |||||
| #include <chrono> | |||||
| namespace logger { | |||||
| std::mutex mut; | |||||
| Timer::Timer() { | |||||
| restart(); | |||||
| } | |||||
| void Timer::restart() { | |||||
| std::chrono::duration<double>(std::chrono::steady_clock::now() | |||||
| .time_since_epoch()).count(); | |||||
| } | |||||
| void Timer::print(std::ostream &os) const { | |||||
| double now = std::chrono::duration<double>(std::chrono::steady_clock::now() | |||||
| .time_since_epoch()).count(); | |||||
| int deltaMs = (int)((now - start_) * 1000); | |||||
| int delta = deltaMs; | |||||
| if (deltaMs > 60 * 1000) { | |||||
| os << (deltaMs / (60 * 1000)) << "m "; | |||||
| delta %= 60 * 1000; | |||||
| } | |||||
| if (deltaMs > 1000) { | |||||
| os << (deltaMs / 1000) << "s "; | |||||
| delta %= 1000; | |||||
| } | |||||
| os << delta << "ms"; | |||||
| } | |||||
| } |
| #pragma once | |||||
| #include <string> | |||||
| #include <mutex> | |||||
| #include <iostream> | |||||
| namespace logger { | |||||
| extern std::mutex mut; | |||||
| class Timer { | |||||
| public: | |||||
| Timer(); | |||||
| void restart(); | |||||
| void print(std::ostream &os) const; | |||||
| private: | |||||
| double start_; | |||||
| }; | |||||
| template<typename T> | |||||
| inline void log(const T &msg) { | |||||
| std::unique_lock<std::mutex> lock(mut); | |||||
| std::cerr << msg << '\n'; | |||||
| } | |||||
| template<typename T> | |||||
| inline void log(const T &msg, const Timer &t) { | |||||
| std::unique_lock<std::mutex> lock(mut); | |||||
| std::cerr << msg; | |||||
| t.print(std::cerr); | |||||
| std::cerr << '\n'; | |||||
| } | |||||
| } |
| #include "logger.h" | |||||
| namespace logger { | |||||
| std::mutex mut; | |||||
| } |
| #pragma once | |||||
| #include <string> | |||||
| #include <mutex> | |||||
| #include <iostream> | |||||
| namespace logger { | |||||
| extern std::mutex mut; | |||||
| template<typename T> | |||||
| inline void log(const T &msg) { | |||||
| std::unique_lock<std::mutex> lock(mut); | |||||
| std::cerr << msg << '\n'; | |||||
| } | |||||
| } |