Skip to content

Commit

Permalink
simplify trace operation
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrulich committed Oct 6, 2024
1 parent 2531770 commit 5cbbf58
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 98 deletions.
2 changes: 1 addition & 1 deletion nautilus/include/nautilus/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ std::function<void()> createFunctionWrapper(std::index_sequence<Indices...>, std
auto traceFunc = [=]() {
if constexpr (std::is_void_v<R>) {
func(details::createTraceableArgument<FunctionArguments, Indices>()...);
tracing::traceReturnOperation(Type::v, tracing::value_ref());
tracing::traceReturnOperation(Type::v, tracing::TypedValueRef());
} else {
auto returnValue = func(details::createTraceableArgument<FunctionArguments, Indices>()...);
auto type = tracing::to_type<typename decltype(returnValue)::raw_type>();
Expand Down
4 changes: 2 additions & 2 deletions nautilus/include/nautilus/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace nautilus {

template <typename... ValueArguments>
auto getArgumentReferences(const ValueArguments&... arguments) {
std::vector<tracing::value_ref> functionArgumentReferences;
std::vector<tracing::TypedValueRef> functionArgumentReferences;
if constexpr (sizeof...(ValueArguments) > 0) {
functionArgumentReferences.reserve(sizeof...(ValueArguments));
for (const tracing::value_ref& p : {details::getState(arguments)...}) {
for (const tracing::TypedValueRef& p : {details::getState(arguments)...}) {
functionArgumentReferences.emplace_back(p);
}
}
Expand Down
22 changes: 11 additions & 11 deletions nautilus/include/nautilus/tracing/TracingUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ namespace nautilus::tracing {

bool inTracer();

value_ref traceBinaryOp(Op operation, Type resultType, const TypedValueRef& leftState, const TypedValueRef& rightState);
value_ref traceUnaryOp(Op operation, Type resultType, const TypedValueRef& inputState);
TypedValueRef traceBinaryOp(Op operation, Type resultType, const TypedValueRef& leftState, const TypedValueRef& rightState);
TypedValueRef traceUnaryOp(Op operation, Type resultType, const TypedValueRef& inputState);

bool traceBool(const TypedValueRef& state);
value_ref traceConstant(Type type, const ConstantLiteral& value);
TypedValueRef traceConstant(Type type, const ConstantLiteral& value);
template <typename T>
value_ref traceConstant(T&& value) {
TypedValueRef traceConstant(T&& value) {
if (inTracer()) {
return traceConstant(to_type<T>(), createConstLiteral(value));
}
return {0, to_type<T>()};
}

value_ref traceLoad(const TypedValueRef& src, Type resultType);
TypedValueRef traceLoad(const TypedValueRef& src, Type resultType);
void traceStore(const TypedValueRef& target, const TypedValueRef& src, Type valueType);

value_ref traceCast(const value_ref& state, Type resultType);
TypedValueRef traceCast(const TypedValueRef& state, Type resultType);
void traceAssignment(const TypedValueRef& target, const TypedValueRef& source, Type resultType);
value_ref traceCopy(const TypedValueRef& state);
TypedValueRef traceCopy(const TypedValueRef& state);

value_ref traceCall(void* fptn, Type resultType, const std::vector<tracing::value_ref>& arguments);
TypedValueRef traceCall(void* fptn, Type resultType, const std::vector<tracing::TypedValueRef>& arguments);

value_ref registerFunctionArgument(Type type, size_t index);
TypedValueRef registerFunctionArgument(Type type, size_t index);

void traceReturnOperation(Type type, const value_ref& ref);
void traceValueDestruction(value_ref ref);
void traceReturnOperation(Type type, const TypedValueRef& ref);
void traceValueDestruction(TypedValueRef ref);

void pushStaticVal(void* ptr);
void popStaticVal();
Expand Down
1 change: 0 additions & 1 deletion nautilus/include/nautilus/tracing/TypedValueRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ class TypedValueRefHolder {
TypedValueRef valueRef;
};

using value_ref = TypedValueRef;
} // namespace nautilus::tracing
6 changes: 3 additions & 3 deletions nautilus/include/nautilus/val.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LHS getRawValue(const val<LHS>& val);
#define DEDUCT_RETURN_TYPE(OP) val<decltype(getRawValue(left) OP getRawValue(right))>

template <typename T>
tracing::value_ref getState(T&& value) {
tracing::TypedValueRef getState(T&& value) {
return value.state;
}

Expand All @@ -48,7 +48,7 @@ class val<ValueType> {
// move constructor
val(const val<ValueType>&& other) noexcept : state(std::move(other.state)), value(other.value) {
}
val(tracing::value_ref& tc) : state(tc), value() {
val(tracing::TypedValueRef& tc) : state(tc), value() {
}
#else
val() {
Expand Down Expand Up @@ -145,7 +145,7 @@ class val<bool> {
// move constructor
val(const val<bool>&& other) : state(other.state), value(other.value) {
}
val(tracing::value_ref& tc) : state(tc) {
val(tracing::TypedValueRef& tc) : state(tc) {
}

#else
Expand Down
16 changes: 8 additions & 8 deletions nautilus/include/nautilus/val_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class val<ValueType> {
const tracing::TypedValueRefHolder state;
#endif
#ifdef ENABLE_TRACING
val(ValueType ref) : state(tracing::value_ref()), ptr(&ref) {
val(ValueType ref) : state(tracing::TypedValueRef()), ptr(&ref) {
}
val(ValueType ref, tracing::value_ref value_ref) : state(value_ref), ptr(&ref) {
val(ValueType ref, tracing::TypedValueRef TypedValueRef) : state(TypedValueRef), ptr(&ref) {
}
val(val<ptrType> ptr, tracing::value_ref ref) : state(ref), ptr(ptr) {
val(val<ptrType> ptr, tracing::TypedValueRef ref) : state(ref), ptr(ptr) {
}
#else
val(ValueType ref) : ptr(&ref) {
Expand Down Expand Up @@ -90,12 +90,12 @@ class base_ptr_val {
#ifdef ENABLE_TRACING
base_ptr_val(ValuePtrType ptr) : state(tracing::traceConstant((void*) ptr)), value(ptr) {
}
base_ptr_val(ValuePtrType ptr, tracing::value_ref tc) : state(tc), value(ptr) {
base_ptr_val(ValuePtrType ptr, tracing::TypedValueRef tc) : state(tc), value(ptr) {
}
base_ptr_val(ValuePtrType ptr, tracing::TypedValueRefHolder tc) : state(std::move(tc)), value(ptr) {
}

base_ptr_val(tracing::value_ref ref) : state(ref), value(nullptr) {
base_ptr_val(tracing::TypedValueRef ref) : state(ref), value(nullptr) {
}
#else
base_ptr_val(ValuePtrType ptr) : value(ptr) {
Expand Down Expand Up @@ -356,11 +356,11 @@ class val<bool&> {

#ifdef ENABLE_TRACING
tracing::TypedValueRefHolder state;
val(bool ref) : state(tracing::value_ref()), ptr(&ref) {
val(bool ref) : state(tracing::TypedValueRef()), ptr(&ref) {
}
val(bool& ref, tracing::value_ref value_ref) : state(value_ref), ptr(&ref) {
val(bool& ref, tracing::TypedValueRef TypedValueRef) : state(TypedValueRef), ptr(&ref) {
}
val(val<ptrType> ptr, tracing::value_ref ref) : state(ref), ptr(ptr) {
val(val<ptrType> ptr, tracing::TypedValueRef ref) : state(ref), ptr(ptr) {
}
#else
val(bool ref) : ptr(&ref) {
Expand Down
20 changes: 10 additions & 10 deletions nautilus/src/nautilus/tracing/ExecutionTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool ExecutionTrace::checkTag(Snapshot& snapshot) {
return true;
}

void ExecutionTrace::addReturn(Snapshot& snapshot, Type resultType, value_ref ref) {
void ExecutionTrace::addReturn(Snapshot& snapshot, Type resultType, TypedValueRef ref) {
if (blocks.empty()) {
createBlock();
}
Expand All @@ -68,7 +68,7 @@ void ExecutionTrace::addReturn(Snapshot& snapshot, Type resultType, value_ref re
returnRefs.emplace_back(operationIdentifier);
}

void ExecutionTrace::addAssignmentOperation(Snapshot& snapshot, nautilus::tracing::value_ref targetRef, nautilus::tracing::value_ref srcRef, Type resultType) {
void ExecutionTrace::addAssignmentOperation(Snapshot& snapshot, nautilus::tracing::TypedValueRef targetRef, nautilus::tracing::TypedValueRef srcRef, Type resultType) {
if (blocks.empty()) {
createBlock();
}
Expand All @@ -80,28 +80,28 @@ void ExecutionTrace::addAssignmentOperation(Snapshot& snapshot, nautilus::tracin
addTag(snapshot, operationIdentifier);
}

void ExecutionTrace::addOperation(Snapshot& snapshot, Op& operation, Type& resultType, nautilus::tracing::value_ref targetRef, nautilus::tracing::value_ref srcRef) {
void ExecutionTrace::addOperation(Snapshot& snapshot, Op& operation, Type& resultType, nautilus::tracing::TypedValueRef targetRef, nautilus::tracing::TypedValueRef srcRef) {
if (blocks.empty()) {
createBlock();
}
auto& operations = blocks[currentBlockIndex].operations;
operations.emplace_back(snapshot, operation, resultType, targetRef, std::vector<InputVariant> {srcRef});
}

value_ref ExecutionTrace::addOperationWithResult(Snapshot& snapshot, Op& operation, Type& resultType, std::vector<InputVariant>&& inputs) {
TypedValueRef ExecutionTrace::addOperationWithResult(Snapshot& snapshot, Op& operation, Type& resultType, std::vector<InputVariant>&& inputs) {
if (blocks.empty()) {
createBlock();
}

auto& operations = blocks[currentBlockIndex].operations;
auto& to = operations.emplace_back(snapshot, operation, resultType, value_ref(getNextValueRef(), resultType), std::forward<std::vector<InputVariant>>(inputs));
auto& to = operations.emplace_back(snapshot, operation, resultType, TypedValueRef(getNextValueRef(), resultType), std::forward<std::vector<InputVariant>>(inputs));

auto operationIdentifier = getNextOperationIdentifier();
addTag(snapshot, operationIdentifier);
return to.resultRef;
}

void ExecutionTrace::addCmpOperation(Snapshot& snapshot, value_ref inputs) {
void ExecutionTrace::addCmpOperation(Snapshot& snapshot, TypedValueRef inputs) {
if (blocks.empty()) {
createBlock();
}
Expand All @@ -112,7 +112,7 @@ void ExecutionTrace::addCmpOperation(Snapshot& snapshot, value_ref inputs) {
auto falseBlock = createBlock();
getBlock(falseBlock).predecessors.emplace_back(getCurrentBlockIndex());
auto& operations = blocks[currentBlockIndex].operations;
operations.emplace_back(snapshot, CMP, Type::v, value_ref(getNextValueRef(), Type::v), std::vector<InputVariant> {inputs, BlockRef(trueBlock), BlockRef(falseBlock)});
operations.emplace_back(snapshot, CMP, Type::v, TypedValueRef(getNextValueRef(), Type::v), std::vector<InputVariant> {inputs, BlockRef(trueBlock), BlockRef(falseBlock)});
auto operationIdentifier = getNextOperationIdentifier();
addTag(snapshot, operationIdentifier);
}
Expand Down Expand Up @@ -204,15 +204,15 @@ Block& ExecutionTrace::processControlFlowMerge(operation_identifier oi) {
return mergeBlock;
}

value_ref ExecutionTrace::setArgument(Type type, size_t index) {
TypedValueRef ExecutionTrace::setArgument(Type type, size_t index) {
++lastValueRef;
uint16_t argRef = index + 1;
auto& arguments = blocks[0].arguments;
if (arguments.size() < argRef) {
arguments.resize(argRef);
}
// arguments[index] = {argRef, type};
arguments[index] = value_ref(argRef, type);
arguments[index] = TypedValueRef(argRef, type);
return arguments[index];
}

Expand Down Expand Up @@ -346,7 +346,7 @@ auto formatter<nautilus::tracing::TraceOperation>::format(const nautilus::tracin
fmt::format_to(out, "\t{}\t", toString(operation.op));
fmt::format_to(out, "{}\t", operation.resultRef);
for (const auto& opInput : operation.input) {
if (auto inputRef = std::get_if<nautilus::tracing::value_ref>(&opInput)) {
if (auto inputRef = std::get_if<nautilus::tracing::TypedValueRef>(&opInput)) {
fmt::format_to(out, "{}\t", *inputRef);
} else if (auto blockRef = std::get_if<nautilus::tracing::BlockRef>(&opInput)) {
fmt::format_to(out, "{}\t", *blockRef);
Expand Down
12 changes: 6 additions & 6 deletions nautilus/src/nautilus/tracing/ExecutionTrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class ExecutionTrace {

~ExecutionTrace() = default;

value_ref addOperationWithResult(Snapshot& snapshot, Op& operation, Type& resultType, std::vector<InputVariant>&& inputs);
TypedValueRef addOperationWithResult(Snapshot& snapshot, Op& operation, Type& resultType, std::vector<InputVariant>&& inputs);

void addCmpOperation(Snapshot& snapshot, value_ref inputs);
void addCmpOperation(Snapshot& snapshot, TypedValueRef inputs);

void addAssignmentOperation(Snapshot&, value_ref targetRef, value_ref srcRef, Type resultType);
void addAssignmentOperation(Snapshot&, TypedValueRef targetRef, TypedValueRef srcRef, Type resultType);

void addReturn(Snapshot&, Type type, value_ref ref);
void addReturn(Snapshot&, Type type, TypedValueRef ref);

bool checkTag(Snapshot& snapshot);

Expand All @@ -36,7 +36,7 @@ class ExecutionTrace {
* @brief Adds arguments that are passed to the traced function
* @param argument
*/
value_ref setArgument(Type type, size_t index);
TypedValueRef setArgument(Type type, size_t index);

/**
* @brief Returns all arguments of this trace.
Expand Down Expand Up @@ -69,7 +69,7 @@ class ExecutionTrace {
*/
uint16_t getCurrentBlockIndex() const;

void addOperation(Snapshot& snapshot, Op& operation, Type& resultType, value_ref targetRef, value_ref srcRef);
void addOperation(Snapshot& snapshot, Op& operation, Type& resultType, TypedValueRef targetRef, TypedValueRef srcRef);

/**
* @brief Returns the current block
Expand Down
26 changes: 13 additions & 13 deletions nautilus/src/nautilus/tracing/TraceContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ void TraceContext::terminate() {
TraceContext::TraceContext(TagRecorder& tagRecorder) : tagRecorder(tagRecorder), executionTrace(std::make_unique<ExecutionTrace>()), symbolicExecutionContext(std::make_unique<SymbolicExecutionContext>()) {
}

value_ref TraceContext::registerFunctionArgument(Type type, size_t index) {
TypedValueRef TraceContext::registerFunctionArgument(Type type, size_t index) {
return executionTrace->setArgument(type, index);
}

void TraceContext::traceValueDestruction(nautilus::tracing::value_ref) {
void TraceContext::traceValueDestruction(nautilus::tracing::TypedValueRef) {
// currently yed not implemented
}

value_ref TraceContext::traceLoad(const value_ref& src, Type resultType) {
TypedValueRef TraceContext::traceLoad(const TypedValueRef& src, Type resultType) {
if (isFollowing()) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -65,7 +65,7 @@ value_ref TraceContext::traceLoad(const value_ref& src, Type resultType) {
throw TraceTerminationException();
}

void TraceContext::traceStore(const value_ref& target, const value_ref& src, Type valueType) {
void TraceContext::traceStore(const TypedValueRef& target, const TypedValueRef& src, Type valueType) {
if (isFollowing()) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -85,7 +85,7 @@ bool TraceContext::isFollowing() {
return symbolicExecutionContext->getCurrentMode() == SymbolicExecutionContext::MODE::FOLLOW;
}

value_ref TraceContext::traceConstValue(Type type, const ConstantLiteral& constValue) {
TypedValueRef TraceContext::traceConstValue(Type type, const ConstantLiteral& constValue) {
log::debug("Trace Constant");
auto op = Op::CONST;
if (isFollowing()) {
Expand All @@ -108,7 +108,7 @@ value_ref TraceContext::traceConstValue(Type type, const ConstantLiteral& constV
}
}

value_ref TraceContext::traceCopy(const value_ref& ref) {
TypedValueRef TraceContext::traceCopy(const TypedValueRef& ref) {
log::debug("Trace Copy");
if (symbolicExecutionContext->getCurrentMode() == SymbolicExecutionContext::MODE::FOLLOW) {
auto& currentOperation = executionTrace->getCurrentOperation();
Expand All @@ -125,7 +125,7 @@ value_ref TraceContext::traceCopy(const value_ref& ref) {
throw TraceTerminationException();
}

value_ref TraceContext::traceCall(const std::string& functionName, const std::string& mangledName, void* fptn, Type resultType, const std::vector<tracing::value_ref>& arguments) {
TypedValueRef TraceContext::traceCall(const std::string& functionName, const std::string& mangledName, void* fptn, Type resultType, const std::vector<tracing::TypedValueRef>& arguments) {

auto op = Op::CALL;
if (symbolicExecutionContext->getCurrentMode() == SymbolicExecutionContext::MODE::FOLLOW) {
Expand All @@ -149,7 +149,7 @@ value_ref TraceContext::traceCall(const std::string& functionName, const std::st
throw TraceTerminationException();
}

void TraceContext::traceAssignment(const value_ref& targetRef, const value_ref& sourceRef, Type resultType) {
void TraceContext::traceAssignment(const TypedValueRef& targetRef, const TypedValueRef& sourceRef, Type resultType) {
if (symbolicExecutionContext->getCurrentMode() == SymbolicExecutionContext::MODE::FOLLOW) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -164,7 +164,7 @@ void TraceContext::traceAssignment(const value_ref& targetRef, const value_ref&
throw TraceTerminationException();
}

value_ref TraceContext::traceCast(const value_ref& state, Type resultType) {
TypedValueRef TraceContext::traceCast(const TypedValueRef& state, Type resultType) {
if (isFollowing()) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -183,7 +183,7 @@ value_ref TraceContext::traceCast(const value_ref& state, Type resultType) {
throw TraceTerminationException();
}

void TraceContext::traceReturnOperation(Type type, const value_ref& ref) {
void TraceContext::traceReturnOperation(Type type, const TypedValueRef& ref) {
if (symbolicExecutionContext->getCurrentMode() == SymbolicExecutionContext::MODE::FOLLOW) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -194,7 +194,7 @@ void TraceContext::traceReturnOperation(Type type, const value_ref& ref) {
executionTrace->addReturn(tag, type, ref);
}

value_ref TraceContext::traceUnaryOperation(nautilus::tracing::Op op, Type resultType, const value_ref& inputRef) {
TypedValueRef TraceContext::traceUnaryOperation(nautilus::tracing::Op op, Type resultType, const TypedValueRef& inputRef) {
if (isFollowing()) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -210,7 +210,7 @@ value_ref TraceContext::traceUnaryOperation(nautilus::tracing::Op op, Type resul
throw TraceTerminationException();
}

value_ref TraceContext::traceBinaryOperation(Op op, Type resultType, const value_ref& leftRef, const value_ref& rightRef) {
TypedValueRef TraceContext::traceBinaryOperation(Op op, Type resultType, const TypedValueRef& leftRef, const TypedValueRef& rightRef) {
if (isFollowing()) {
auto& currentOperation = executionTrace->getCurrentOperation();
executionTrace->nextOperation();
Expand All @@ -226,7 +226,7 @@ value_ref TraceContext::traceBinaryOperation(Op op, Type resultType, const value
throw TraceTerminationException();
}

bool TraceContext::traceCmp(const value_ref& targetRef) {
bool TraceContext::traceCmp(const TypedValueRef& targetRef) {
bool result;
if (symbolicExecutionContext->getCurrentMode() == SymbolicExecutionContext::MODE::FOLLOW) {
// eval execution path one step
Expand Down
Loading

0 comments on commit 5cbbf58

Please sign in to comment.