Skip to content

Commit 4196c18

Browse files
Added support for nautilus::val<T> and T is a enum class
1 parent 2a29e9d commit 4196c18

File tree

23 files changed

+130
-30
lines changed

23 files changed

+130
-30
lines changed

nautilus/include/nautilus/val_enum.hpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "nautilus/val_concepts.hpp"
44
#include <iostream>
55
#include <memory>
6+
#include <utility>
67

78
#ifdef ENABLE_TRACING
89

@@ -36,7 +37,7 @@ class val<T> {
3637
}
3738
val(val<T>&& t) : state(t.state), value(t.value) {
3839
}
39-
val(T val) : state(tracing::traceConstant((underlying_type_t) val)), value(val) {
40+
val(T val) : state(tracing::traceConstant(std::__to_underlying(val))), value(val) {
4041
}
4142
#else
4243
template <T>
@@ -57,20 +58,38 @@ class val<T> {
5758
}
5859
#endif
5960

60-
template <typename RHS>
61-
requires std::is_enum_v<RHS> && (!std::is_convertible_v<RHS, std::underlying_type_t<RHS>>)
62-
bool operator==(const RHS& other) const {
63-
return val(value) == val(static_cast<std::underlying_type_t<RHS>>(other));
61+
62+
val<bool> operator==(val<T>& other) const {
63+
#ifdef ENABLE_TRACING
64+
if (tracing::inTracer()) {
65+
auto tc = tracing::traceBinaryOp(tracing::EQ, Type::b, state, other.state);
66+
return val<bool>(tc);
67+
}
68+
#endif
69+
return value == other.value;
70+
}
71+
72+
bool operator==(const T& other) const {
73+
auto res = val<T>(other);
74+
return *this == res;
75+
}
76+
77+
val<bool> operator!=(val<T>& other) const {
78+
#ifdef ENABLE_TRACING
79+
if (tracing::inTracer()) {
80+
auto tc = tracing::traceBinaryOp(tracing::NEQ, Type::b, state, other.state);
81+
return val<bool>(tc);
82+
}
83+
#endif
84+
return value != other.value;
6485
}
6586

66-
template <typename RHS>
67-
requires std::is_enum_v<RHS> && (!std::is_convertible_v<RHS, std::underlying_type_t<RHS>>)
68-
bool operator!=(const RHS& other) const {
69-
return val(value) != val(static_cast<std::underlying_type_t<RHS>>(other));
87+
val<bool> operator!=(const T& other) const {
88+
return *this == val<T>(other);
7089
}
7190

7291
operator val<underlying_type_t>() const {
73-
return value;
92+
return val<underlying_type_t>(state);
7493
}
7594

7695
val<T>& operator=(const val<T>& other) {

nautilus/src/nautilus/tracing/TraceOperation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::ostream& operator<<(std::ostream& os, const TraceOperation& operation) {
5454
[&](auto&& value) -> void {
5555
using T = std::decay_t<decltype(value)>;
5656
if constexpr (!std::is_pointer_v<T>) {
57-
os << value << "\t";
57+
os << fmt::format("{}\t", value);
5858
} else {
5959
os << "*\t";
6060
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
B0($1:bool)
2-
CONST $3 1 :bool
2+
CONST $3 true :bool
33
AND $4 $1 $3 :bool
44
RETURN $4 :bool

nautilus/test/data/bool-tests/after_ssa/boolIfElse.trace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ B0($1:bool,$2:bool)
22
AND $5 $1 $2 :bool
33
CMP $6 $5 B1() B2() :void
44
B1()
5-
CONST $7 1 :bool
5+
CONST $7 true :bool
66
JMP $0 B3($7) :void
77
B2()
8-
CONST $10 0 :bool
8+
CONST $10 false :bool
99
JMP $0 B3($10) :void
1010
B3($7:bool)
1111
RETURN $7 :bool

nautilus/test/data/bool-tests/after_ssa/boolNestedFunction.trace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ B0($1:bool,$2:bool)
22
EQ $5 $1 $2 :bool
33
CMP $6 $5 B1() B2() :void
44
B1()
5-
CONST $7 1 :bool
5+
CONST $7 true :bool
66
JMP $0 B3($7) :void
77
B2()
8-
CONST $10 0 :bool
8+
CONST $10 false :bool
99
JMP $0 B3($10) :void
1010
B3($7:bool)
1111
RETURN $7 :bool
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
B0($1:bool)
22
ASSIGN $2 $1 :bool
3-
CONST $3 1 :bool
3+
CONST $3 true :bool
44
AND $4 $2 $3 :bool
55
RETURN $4 :bool

nautilus/test/data/bool-tests/tracing/boolIfElse.trace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ B0($1:bool,$2:bool)
44
AND $5 $3 $4 :bool
55
CMP $6 $5 B1() B2() :void
66
B1()
7-
CONST $7 1 :bool
7+
CONST $7 true :bool
88
RETURN $7 :bool
99
B2()
10-
CONST $10 0 :bool
10+
CONST $10 false :bool
1111
RETURN $10 :bool

nautilus/test/data/bool-tests/tracing/boolNestedFunction.trace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ B0($1:bool,$2:bool)
44
EQ $5 $3 $4 :bool
55
CMP $6 $5 B1() B2() :void
66
B1()
7-
CONST $7 1 :bool
7+
CONST $7 true :bool
88
RETURN $7 :bool
99
B2()
10-
CONST $10 0 :bool
10+
CONST $10 false :bool
1111
RETURN $10 :bool

nautilus/test/data/control-flow-tests/after_ssa/andFunction.trace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
B0($1:i32)
2-
CONST $2 1 :bool
2+
CONST $2 true :bool
33
CONST $4 42 :i64
44
CAST $5 $1 :i64
55
EQ $6 $5 $4 :bool

nautilus/test/data/control-flow-tests/tracing/andFunction.trace

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
B0($1:i32)
2-
CONST $2 1 :bool
2+
CONST $2 true :bool
33
ASSIGN $3 $2 :bool
44
CONST $4 42 :i64
55
CAST $5 $1 :i64
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
B0($1:ui8)
2+
CALL $2 nautilus::enumClassFunction(nautilus::LogLevel)($1) :i32
3+
RETURN $2 :i32
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
B0($1:ui8)
2+
CONST $2 6 :ui8
3+
EQ $3 $1 $2 :bool
4+
CMP $4 $3 B1() B2($1) :void
5+
B1()
6+
CONST $5 true :bool
7+
JMP $0 B5($5) :void
8+
B2($1:ui8)
9+
CONST $7 5 :ui8
10+
EQ $8 $1 $7 :bool
11+
CMP $9 $8 B3() B4() :void
12+
B3()
13+
CONST $10 true :bool
14+
JMP $0 B5($10) :void
15+
B4()
16+
CONST $12 false :bool
17+
JMP $0 B5($12) :void
18+
B5($5:bool)
19+
RETURN $5 :bool
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NESIR {
2+
execute() {
3+
Block_0($1:ui8):
4+
$2 = nautilus::enumClassFunction(nautilus::LogLevel)($1) :i32
5+
return ($2) :i32
6+
}
7+
} //NESIR
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
NESIR {
2+
execute() {
3+
Block_0($1:ui8):
4+
$2 = 6 :ui8
5+
$3 = $1 == $2 :bool
6+
if $3 ? Block_1() : Block_2($1) :void
7+
8+
Block_1():
9+
$5 = 1 :bool
10+
br Block_5($5) :void
11+
12+
Block_5($5:bool):
13+
return ($5) :bool
14+
15+
Block_2($1:ui8):
16+
$7 = 5 :ui8
17+
$8 = $1 == $7 :bool
18+
if $8 ? Block_3() : Block_4() :void
19+
20+
Block_3():
21+
$10 = 1 :bool
22+
br Block_5($10) :void
23+
24+
Block_4():
25+
$12 = 0 :bool
26+
br Block_5($12) :void
27+
}
28+
} //NESIR
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
B0($1:ui8)
2+
CALL $2 nautilus::enumClassFunction(nautilus::LogLevel)($1) :i32
3+
RETURN $2 :i32
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
B0($1:ui8)
2+
CONST $2 6 :ui8
3+
EQ $3 $1 $2 :bool
4+
CMP $4 $3 B1() B2() :void
5+
B1()
6+
CONST $5 true :bool
7+
RETURN $5 :bool
8+
B2()
9+
CONST $7 5 :ui8
10+
EQ $8 $1 $7 :bool
11+
CMP $9 $8 B3() B4() :void
12+
B3()
13+
CONST $10 true :bool
14+
ASSIGN $5 $10 :bool
15+
RETURN $5 :bool
16+
B4()
17+
CONST $12 false :bool
18+
ASSIGN $5 $12 :bool
19+
RETURN $5 :bool
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
B0($1:i8)
2-
CONST $2  :i8
2+
CONST $2 2 :i8
33
ADD $3 $2 $1 :i32
44
RETURN $3 :i8
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
B0($1:i8)
2-
CONST $2  :i8
2+
CONST $2 2 :i8
33
ADD $3 $2 $1 :i32
44
RETURN $3 :i8

nautilus/test/data/loop-tests/after_ssa/isPrime.trace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
B0($1:i32)
2-
CONST $2 0 :bool
3-
CONST $3 1 :bool
2+
CONST $2 false :bool
3+
CONST $3 true :bool
44
CONST $4 1 :i32
55
LTE $5 $1 $4 :bool
66
CMP $6 $5 B1($2) B2($2,$1,$3) :void

nautilus/test/data/loop-tests/tracing/isPrime.trace

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
B0($1:i32)
2-
CONST $2 0 :bool
3-
CONST $3 1 :bool
2+
CONST $2 false :bool
3+
CONST $3 true :bool
44
CONST $4 1 :i32
55
LTE $5 $1 $4 :bool
66
CMP $6 $5 B1() B2() :void
Binary file not shown.
Binary file not shown.

nautilus/test/execution-tests/TracingTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ void runTraceTests(const std::string& category, std::vector<std::tuple<std::stri
135135
for (auto& test : tests) {
136136
auto func = std::get<1>(test);
137137
auto name = std::get<0>(test);
138-
auto executionTrace = tracing::TraceContext::trace(func);
139138
DYNAMIC_SECTION(name) {
139+
auto executionTrace = tracing::TraceContext::trace(func);
140140
DYNAMIC_SECTION("tracing") {
141141
REQUIRE(checkTestFile(executionTrace.get(), category, "tracing", name));
142142
}
@@ -276,6 +276,8 @@ TEST_CASE("Enum Trace Test") {
276276
{"isEnum", details::createFunctionWrapper(isEnum)},
277277
{"getEnum", details::createFunctionWrapper(getEnum)},
278278
{"callEnumFunction", details::createFunctionWrapper(callEnumFunction)},
279+
{"callEnumClassFunction", details::createFunctionWrapper(callEnumClassFunction)},
280+
{"handleEnumLogLevel", details::createFunctionWrapper(handleEnumLogLevel)},
279281
};
280282
runTraceTests("enum-tests", tests);
281283
}

0 commit comments

Comments
 (0)