Skip to content

Commit

Permalink
[ESI][Runtime] Fixing Windows build and logging bug
Browse files Browse the repository at this point in the history
- Fixed MSVC build warning.
- Fixed MSVC build errors.
- Respect minLevel.
  • Loading branch information
teqdruid committed Sep 3, 2024
1 parent 063f744 commit 7c9f8fb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/Dialect/ESI/runtime/cpp/include/esi/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@
#include <iosfwd>
#include <map>
#include <memory>
#include <mutex>
#include <string>

namespace esi {

class Logger {
public:
enum class Level {
Error, // Many errors will be followed by exceptions which may get caught.
Warning, // May indicate a problem.
Info, // General information, like connecting to an accelerator.
Debug, // Everything and the kitchen sink, possibly including _all_
// messages written and read.
Info, // General information, like connecting to an accelerator.
Warning, // May indicate a problem.
Error, // Many errors will be followed by exceptions which may get caught.
};
Logger(bool debugEnabled) : debugEnabled(debugEnabled) {}
virtual ~Logger() = default;
Expand Down
2 changes: 2 additions & 0 deletions lib/Dialect/ESI/runtime/cpp/lib/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ StreamLogger::StreamLogger(Level minLevel)
void StreamLogger::logImpl(Level level, const std::string &subsystem,
const std::string &msg,
const std::map<std::string, std::any> *details) {
if (level < minLevel)
return;
std::ostream &os = level == Level::Error ? errorStream : outStream;
unsigned indentSpaces = 0;

Expand Down
4 changes: 2 additions & 2 deletions lib/Dialect/ESI/runtime/cpp/lib/Services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ MMIO::MMIO(Context &ctxt, AppIDPath idPath, std::string implName,
throw std::runtime_error("MMIO client missing 'offset' option");
Constant offset = std::any_cast<Constant>(offsetIter->second);
uint64_t offsetVal = std::any_cast<uint64_t>(offset.value);
if (offsetVal >= 1ul << 32)
if (offsetVal >= 1ull << 32)
throw std::runtime_error("MMIO client offset mustn't exceed 32 bits");

auto sizeIter = client.implOptions.find("size");
if (sizeIter == client.implOptions.end())
throw std::runtime_error("MMIO client missing 'size' option");
Constant size = std::any_cast<Constant>(sizeIter->second);
uint64_t sizeVal = std::any_cast<uint64_t>(size.value);
if (sizeVal >= 1ul << 32)
if (sizeVal >= 1ull << 32)
throw std::runtime_error("MMIO client size mustn't exceed 32 bits");
regions[client.relPath] =
RegionDescriptor{(uint32_t)offsetVal, (uint32_t)sizeVal};
Expand Down
4 changes: 3 additions & 1 deletion lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,13 @@ class CosimMMIO : public MMIO {
cmdMMIO->connect();
}

#pragma pack(push, 1)
struct MMIOCmd {
uint64_t data;
uint32_t offset;
bool write;
} __attribute__((packed));
};
#pragma pack(pop)

// Call the read function and wait for a response.
uint64_t read(uint32_t addr) const override {
Expand Down

0 comments on commit 7c9f8fb

Please sign in to comment.