Skip to content

Commit

Permalink
Make spdlog optional (#54)
Browse files Browse the repository at this point in the history
set -DENABLE_LOGGING=OFF to disable the dependency on spdlog
  • Loading branch information
PhilippGrulich authored Oct 5, 2024
1 parent 93880c8 commit faf97b8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: cmake
shell: bash
run: |
cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -DENABLE_BENCHMARKS=ON ${{ matrix.flags }} -G Ninja -S . -B .
cmake -DCMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache -DENABLE_BENCHMARKS=ON -DENABLE_LOGGING=OFF ${{ matrix.flags }} -G Ninja -S . -B .
- name: build
shell: bash
run: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
cc: 'gcc-10'
cxx: 'g++-10'
flags: '-DENABLE_TRACING=OFF'
- os: 'ubuntu-22.04'
cc: 'gcc-10'
cxx: 'g++-10'
flags: '-DENABLE_TRACING=OFF -DENABLE_LOGGING=OFF'
- os: 'ubuntu-22.04'
cc: 'clang-15'
cxx: 'clang++-15'
Expand Down
2 changes: 1 addition & 1 deletion nautilus/src/nautilus/compiler/DumpHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "nautilus/compiler/DumpHandler.hpp"
#include "nautilus/common/File.hpp"
#include "spdlog/fmt/fmt.h"
#include "fmt/core.h"
#include <filesystem>

namespace nautilus::compiler {
Expand Down
27 changes: 19 additions & 8 deletions nautilus/src/nautilus/logging.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
#pragma once

#include <nautilus/config.hpp>
#ifdef ENABLE_LOGGING
#include <spdlog/spdlog.h>
#endif

namespace nautilus::log {
template <typename... Args>
void info(spdlog::format_string_t<Args...> fmt, Args&&... args) {
spdlog::info(fmt, std::forward<Args>(args)...);
void info([[maybe_unused]] const char* fmt, [[maybe_unused]]Args&&... args) {
#ifdef ENABLE_LOGGING
spdlog::info("{}", fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
#endif
}

template <typename... Args>
void debug(spdlog::format_string_t<Args...> fmt, Args&&... args) {
spdlog::debug(fmt, std::forward<Args>(args)...);
void debug([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
#ifdef ENABLE_LOGGING
spdlog::debug("{}", fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
#endif
}

template <typename... Args>
void trace(spdlog::format_string_t<Args...> fmt, Args&&... args) {
spdlog::trace(fmt, std::forward<Args>(args)...);
void trace([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
#ifdef ENABLE_LOGGING
spdlog::trace("{}",fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
#endif
}

template <typename... Args>
void error(spdlog::format_string_t<Args...> fmt, Args&&... args) {
spdlog::debug(fmt, std::forward<Args>(args)...);
void error([[maybe_unused]] const char* fmt, [[maybe_unused]] Args&&... args) {
#ifdef ENABLE_LOGGING
spdlog::error("{}", fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
#endif
}
} // namespace nautilus::log
2 changes: 1 addition & 1 deletion nautilus/src/nautilus/tracing/ExecutionTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ value_ref ExecutionTrace::addOperationWithResult(Snapshot& snapshot, Op& operati
return to.resultRef;
}

void ExecutionTrace::addCmpOperation(Snapshot& snapshot, nautilus::tracing::value_ref inputs) {
void ExecutionTrace::addCmpOperation(Snapshot& snapshot, value_ref inputs) {
if (blocks.empty()) {
createBlock();
}
Expand Down
3 changes: 0 additions & 3 deletions nautilus/src/nautilus/tracing/ExecutionTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ class ExecutionTrace {
uint16_t lastValueRef = 0;
std::unordered_map<Snapshot, operation_identifier> globalTagMap;
std::unordered_map<Snapshot, operation_identifier> localTagMap;

operation_identifier getNextOperationIdentifier();
};

} // namespace nautilus::tracing


37 changes: 13 additions & 24 deletions nautilus/src/nautilus/tracing/TraceContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
#include "nautilus/logging.hpp"
#include "symbolic_execution/SymbolicExecutionContext.hpp"
#include "symbolic_execution/TraceTerminationException.hpp"
#include <fmt/format.h>
#include <cassert>

namespace fmt {
template <>
struct formatter<nautilus::tracing::ExecutionTrace> : formatter<std::string_view> {
static auto format(const nautilus::tracing::ExecutionTrace& trace, format_context& ctx) -> format_context::iterator;
};
}


namespace nautilus::tracing {

static thread_local TraceContext* traceContext;
Expand Down Expand Up @@ -38,17 +47,7 @@ value_ref TraceContext::registerFunctionArgument(Type type, size_t index) {
}

void TraceContext::traceValueDestruction(nautilus::tracing::value_ref) {
/*if (symbolicExecutionContext->getCurrentMode() ==
SymbolicExecutionContext::MODE::FOLLOW) { auto currentOperation =
executionTrace->getCurrentOperation(); executionTrace->nextOperation();
assert(currentOperation.op == FREE);
return;
}*/
// auto op = Op::FREE;
// auto valueType = Type::v;
// auto tag = tagRecorder.createTag();
// executionTrace->addOperation(tag, varRefMap, op, valueType, 0, target);
return;
// currently yed not implemented
}

value_ref TraceContext::traceLoad(const value_ref& src, Type resultType) {
Expand Down Expand Up @@ -138,7 +137,6 @@ value_ref TraceContext::traceCall(const std::string& functionName, const std::st
auto currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
assert(currentOperation.op == CALL);
// executionTrace->variableBitset[currentOperation.resultRef] = true;
return currentOperation.resultRef;
}

Expand All @@ -165,16 +163,6 @@ void TraceContext::traceAssignment(const value_ref& targetRef, const value_ref&
return;
}
auto tag = recordSnapshot();
/*
auto found = executionTrace->globalTagMap.find(tag);
if (found != executionTrace->globalTagMap.end()) {
auto currentOp =
executionTrace->getBlock(found->second.blockIndex).operations[found->second.operationIndex];
if(std::get<value_ref>(currentOp.input[0]) != sourceRef){
executionTrace->addAssignmentOperation(tag, targetRef, sourceRef,
resultType); return;
};
}*/
if (executionTrace->checkTag(tag)) {
executionTrace->addAssignmentOperation(tag, targetRef, sourceRef, resultType);
return;
Expand Down Expand Up @@ -292,7 +280,7 @@ std::unique_ptr<ExecutionTrace> TraceContext::trace(std::function<void()>& trace
try {
traceIteration = traceIteration + 1;
log::trace("Trace Iteration {}", traceIteration);
log::trace("{}", tc->executionTrace->toString());
log::trace("{}", *tc->executionTrace);
tc->symbolicExecutionContext->next();
tc->executionTrace->resetExecution();
TraceContext::get()->resume();
Expand All @@ -303,7 +291,7 @@ std::unique_ptr<ExecutionTrace> TraceContext::trace(std::function<void()>& trace
auto trace = std::move(tc->executionTrace);
terminate();
log::debug("Tracing Terminated with {} iterations", traceIteration);
log::trace("Final trace: {}", trace->toString());
log::trace("Final trace: {}", *trace);
return trace;
}

Expand Down Expand Up @@ -353,3 +341,4 @@ Snapshot TraceContext::recordSnapshot() {
}

} // namespace nautilus::tracing

16 changes: 1 addition & 15 deletions nautilus/src/nautilus/tracing/phases/SSACreationPhase.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#include <nautilus/exceptions/RuntimeException.hpp>
#include <nautilus/logging.hpp>
#include <nautilus/tracing/ExecutionTrace.hpp>
#include <nautilus/tracing/phases/SSACreationPhase.hpp>
#include <unordered_map>
#include "fmt/core.h"

namespace nautilus::tracing {

Expand Down Expand Up @@ -241,20 +241,6 @@ void SSACreationPhase::SSACreationPhaseContext::makeBlockArgumentsUnique() {
for (Block& block : trace->getBlocks()) {
std::unordered_map<uint16_t, uint16_t> blockArgumentMap;

// iterate over all arguments of this block and create new ValRefs if the
// argument ref is not local. for (uint64_t argIndex = 0; argIndex <
// block.arguments.size(); argIndex++) {
// auto argRef = block.arguments[argIndex];
// if (argRef.blockId != block.blockId) {
// auto newLocalRef =
// ValueRef(block.blockId, block.operations.size() +
// blockArgumentMap.size() + 100,
// argRef.type);
// blockArgumentMap[argRef] = newLocalRef;
// block.arguments[argIndex] = newLocalRef;
// }
//}

// set the new ValRefs to all depending on operations.
for (uint64_t i = 0; i < block.operations.size(); i++) {
auto& operation = block.operations[i];
Expand Down

0 comments on commit faf97b8

Please sign in to comment.