Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SIR inconsistency with globals #931

Merged
merged 3 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions dawn/src/dawn/SIR/SIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,36 +453,36 @@ class Value {

template <class T>
Value(T value)
: value_{std::move(value)}, is_constexpr_{false}, type_{TypeInfo<std::decay_t<T>>::Type} {}
: value_{std::move(value)}, isConstexpr_{false}, type_{TypeInfo<std::decay_t<T>>::Type} {}

template <class T>
Value(T value, bool is_constexpr)
: value_{std::move(value)},
is_constexpr_{is_constexpr}, type_{TypeInfo<std::decay_t<T>>::Type} {}
isConstexpr_{is_constexpr}, type_{TypeInfo<std::decay_t<T>>::Type} {}

Value(const Value& other)
: value_{other.value_}, is_constexpr_{other.isConstexpr()}, type_{other.getType()} {}
: value_{other.value_}, isConstexpr_{other.isConstexpr()}, type_{other.getType()} {}

Value(Value& other)
: value_{other.value_}, is_constexpr_{other.isConstexpr()}, type_{other.getType()} {}
: value_{other.value_}, isConstexpr_{other.isConstexpr()}, type_{other.getType()} {}

Value(Value&& other)
: value_{std::move(other.value_)}, is_constexpr_{other.isConstexpr()}, type_{
other.getType()} {}
: value_{std::move(other.value_)}, isConstexpr_{other.isConstexpr()}, type_{other.getType()} {
}

Value(Kind type) : value_{}, is_constexpr_{false}, type_{type} {}
Value(Kind type) : value_{}, isConstexpr_{false}, type_{type} {}

virtual ~Value() = default;

Value& operator=(const Value& other) {
value_ = other.value_;
is_constexpr_ = other.isConstexpr();
isConstexpr_ = other.isConstexpr();
type_ = other.getType();
return *this;
}

/// @brief Get/Set if the variable is `constexpr`
virtual bool isConstexpr() const { return is_constexpr_; }
virtual bool isConstexpr() const { return isConstexpr_; }

/// @brief `Type` to string
static const char* typeToString(Kind type);
Expand Down Expand Up @@ -521,7 +521,7 @@ class Value {

protected:
std::optional<std::variant<bool, int, float, double, std::string>> value_;
bool is_constexpr_;
bool isConstexpr_;
Kind type_;
};

Expand Down
2 changes: 2 additions & 0 deletions dawn/src/dawn/SIR/proto/SIR/SIR.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ message StencilFunction {
* GlobalVariableMap
\*===------------------------------------------------------------------------------------------===*/

// TODO this needs to be changed to accept a type independent of a value if we
// want it to be 1-to-1 with the SIR structures.
// @brief Value of a global variable
message GlobalVariableValue {
// Type and value of the variable
Expand Down
42 changes: 21 additions & 21 deletions dawn/src/dawn/Serialization/SIRSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,30 +190,30 @@ static std::string serializeImpl(const SIR* sir, SIRSerializer::Format kind) {

// SIR.GlobalVariableMap
auto mapProto = sirProto.mutable_global_variables()->mutable_map();
for(const auto& nameValuePair : *sir->GlobalVariableMap) {
const std::string& name = nameValuePair.first;
const sir::Global& value = nameValuePair.second;
for(const auto& [name, value] : *sir->GlobalVariableMap) {

// is_constexpr
sir::proto::GlobalVariableValue valueProto;
valueProto.set_is_constexpr(value.isConstexpr());
if(value.has_value()) {
switch(value.getType()) {
case sir::Value::Kind::Boolean:
valueProto.set_boolean_value(value.getValue<bool>());
break;
case sir::Value::Kind::Integer:
valueProto.set_integer_value(value.getValue<int>());
break;
case sir::Value::Kind::Double:
valueProto.set_double_value(value.getValue<double>());
break;
case sir::Value::Kind::Float:
valueProto.set_float_value(value.getValue<float>());
break;
case sir::Value::Kind::String:
valueProto.set_string_value(value.getValue<std::string>());
break;
}

// Value
switch(value.getType()) {
case sir::Value::Kind::Boolean:
valueProto.set_boolean_value(value.has_value() ? value.getValue<bool>() : bool());
break;
case sir::Value::Kind::Integer:
valueProto.set_integer_value(value.has_value() ? value.getValue<int>() : int());
break;
case sir::Value::Kind::Double:
valueProto.set_double_value(value.has_value() ? value.getValue<double>() : double());
break;
case sir::Value::Kind::Float:
valueProto.set_float_value(value.has_value() ? value.getValue<float>() : float());
break;
case sir::Value::Kind::String:
valueProto.set_string_value(value.has_value() ? value.getValue<std::string>()
: std::string());
break;
}

mapProto->insert({name, valueProto});
Expand Down