From f353545f980576c44a4b5edc0aecd6edd537db89 Mon Sep 17 00:00:00 2001 From: Philipp Grulich Date: Sat, 23 Mar 2024 15:01:11 +0100 Subject: [PATCH] first commit --- .../include/Interface/DataTypes/Val.hpp | 42 ++++++++++++------- .../ExecutionTests/ExpressionFunctions.hpp | 2 - nautilus-jit/src/Tracing/tracing.cpp | 2 + 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/nautilus-api/include/Interface/DataTypes/Val.hpp b/nautilus-api/include/Interface/DataTypes/Val.hpp index 530dd9f5..ab4be499 100644 --- a/nautilus-api/include/Interface/DataTypes/Val.hpp +++ b/nautilus-api/include/Interface/DataTypes/Val.hpp @@ -141,9 +141,11 @@ namespace nautilus { inline val(ValueType value, const std::source_location loc = std::source_location::current()) : value(value), loc(loc), state(tracing::traceConstant(value)) { //std::cout << loc.file_name() << std::endl; - // ((auto tag = tracing::getTag(); - tracing::getVarRefMap()[state]++; - // std::cout << "value constructor " << state << " - " << tag << std::endl; + // ((auto tag = tracing::getTag(); + if (tracing::inTracer()) { + tracing::getVarRefMap()[state]++; + } + // std::cout << "value constructor " << state << " - " << tag << std::endl; }; @@ -151,7 +153,9 @@ namespace nautilus { const std::source_location loc = std::source_location::current()) : value(other.value), loc(loc), state(other.state) { - tracing::getVarRefMap()[state]++; + if (tracing::inTracer()) { + tracing::getVarRefMap()[state]++; + } //std::cout << "copy constructor " << this->state << " - " << other.state << " - " << tag << std::endl; //std::cout << "copy constructor " << this->state << " - " << other.state << " - " << std::endl; // tracing::traceAssignment(other.state, other.state); @@ -174,25 +178,31 @@ namespace nautilus { #ifdef ENABLE_TRACING - inline val(ValueType, tracing::value_ref &tc) : state(tc) { - // auto tag = tracing::getTag(); - tracing::getVarRefMap()[state]++; - // std::cout << "trace constructor " << state << " - " << tag << std::endl; + inline val(ValueType, tracing::value_ref &tc) : state(tc) { + // auto tag = tracing::getTag(); + if (tracing::inTracer()) { + tracing::getVarRefMap()[state]++; + } + // std::cout << "trace constructor " << state << " - " << tag << std::endl; }; #endif ~val() { - // auto tag = tracing::getTag(); - tracing::getVarRefMap()[state]--; - if (tracing::getVarRefMap()[state] == 0) { - tracing::traceValueDestruction(state); - //std::cout << "destructor " << state << " - " << tag << std::endl; + // auto tag = tracing::getTag(); + if (tracing::inTracer()) { + + tracing::getVarRefMap()[state]--; + if (tracing::getVarRefMap()[state] == 0) { + tracing::traceValueDestruction(state); + //std::cout << "destructor " << state << " - " << tag << std::endl; + } + } } val &operator=(const val &other) { - // auto tag = tracing::getTag(); + // auto tag = tracing::getTag(); //std::cout << "copy assignment " << this->state << "<- " << other.state << " - " << tag << std::endl; #ifdef ENABLE_TRACING if (tracing::inTracer()) { @@ -470,7 +480,7 @@ namespace nautilus { val inline lAnd(val &left, val &right) { if (tracing::inTracer()) { auto tc = tracing::traceBinaryOp(left.state, right.state); - return val{true,tc}; + return val{true, tc}; } return left.value && right.value; } @@ -478,7 +488,7 @@ namespace nautilus { val inline lNot(val &val) { if (tracing::inTracer()) { auto tc = tracing::traceUnaryOp(val.state); - return ::nautilus::val{true,tc}; + return ::nautilus::val{true, tc}; } return !val.value; } diff --git a/nautilus-api/test/ExecutionTests/ExpressionFunctions.hpp b/nautilus-api/test/ExecutionTests/ExpressionFunctions.hpp index 42d17c91..f9f95cb9 100644 --- a/nautilus-api/test/ExecutionTests/ExpressionFunctions.hpp +++ b/nautilus-api/test/ExecutionTests/ExpressionFunctions.hpp @@ -5,8 +5,6 @@ namespace nautilus::engine { val int8AddExpression(val x) { val y = (int8_t) 2; - auto res = x + y; - y = res; return y + x; } diff --git a/nautilus-jit/src/Tracing/tracing.cpp b/nautilus-jit/src/Tracing/tracing.cpp index 049fc300..509f82e0 100644 --- a/nautilus-jit/src/Tracing/tracing.cpp +++ b/nautilus-jit/src/Tracing/tracing.cpp @@ -34,6 +34,8 @@ namespace nautilus::tracing { template [[maybe_unused]] value_ref traceConstant(T value) { + if (!inTracer()) + return 0; auto anyValue = std::any(value); return TraceContext::get()->traceConstValue(to_type(), anyValue); }