Commit b1f88766 by Ben Clayton

Vulkan/Debug: Add Type

This implements a very basic runtime type information used by debug-exposed values. Bug: b/145351270 Change-Id: I6bd9fe292bd7058307789300d562f7699e12f02b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38892Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 5e4d55f0
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Type.hpp"
namespace vk
{
namespace dbg
{
// clang-format off
std::shared_ptr<Type> TypeOf<bool>::get() { static auto ty = std::make_shared<Type>(Kind::Bool); return ty; }
std::shared_ptr<Type> TypeOf<uint8_t>::get() { static auto ty = std::make_shared<Type>(Kind::U8); return ty; }
std::shared_ptr<Type> TypeOf<int8_t>::get() { static auto ty = std::make_shared<Type>(Kind::S8); return ty; }
std::shared_ptr<Type> TypeOf<uint16_t>::get() { static auto ty = std::make_shared<Type>(Kind::U16); return ty; }
std::shared_ptr<Type> TypeOf<int16_t>::get() { static auto ty = std::make_shared<Type>(Kind::S16); return ty; }
std::shared_ptr<Type> TypeOf<float>::get() { static auto ty = std::make_shared<Type>(Kind::F32); return ty; }
std::shared_ptr<Type> TypeOf<uint32_t>::get() { static auto ty = std::make_shared<Type>(Kind::U32); return ty; }
std::shared_ptr<Type> TypeOf<int32_t>::get() { static auto ty = std::make_shared<Type>(Kind::S32); return ty; }
std::shared_ptr<Type> TypeOf<double>::get() { static auto ty = std::make_shared<Type>(Kind::F64); return ty; }
std::shared_ptr<Type> TypeOf<uint64_t>::get() { static auto ty = std::make_shared<Type>(Kind::U64); return ty; }
std::shared_ptr<Type> TypeOf<int64_t>::get() { static auto ty = std::make_shared<Type>(Kind::S64); return ty; }
std::shared_ptr<Type> TypeOf<VariableContainer>::get() { static auto ty = std::make_shared<Type>(Kind::VariableContainer); return ty; }
// clang-format on
std::string Type::string() const
{
switch(kind)
{
case Kind::Bool:
return "bool";
case Kind::U8:
return "uint8_t";
case Kind::S8:
return "int8_t";
case Kind::U16:
return "uint16_t";
case Kind::S16:
return "int16_t";
case Kind::F32:
return "float";
case Kind::U32:
return "uint32_t";
case Kind::S32:
return "int32_t";
case Kind::F64:
return "double";
case Kind::U64:
return "uint64_t";
case Kind::S64:
return "int64_t";
case Kind::Ptr:
return elem->string() + "*";
case Kind::VariableContainer:
return "struct";
}
return "";
}
} // namespace dbg
} // namespace vk
\ No newline at end of file
// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef VK_DEBUG_TYPE_HPP_
#define VK_DEBUG_TYPE_HPP_
#include <memory>
#include <cstdint>
#include <string>
namespace vk
{
namespace dbg
{
class VariableContainer;
class Value;
// Kind is an enumerator of type kinds.
enum class Kind
{
Bool, // Boolean
U8, // 8-bit unsigned integer.
S8, // 8-bit signed integer.
U16, // 16-bit unsigned integer.
S16, // 16-bit signed integer.
F32, // 32-bit unsigned integer.
U32, // 32-bit signed integer.
S32, // 32-bit unsigned integer.
F64, // 64-bit signed integer.
U64, // 64-bit unsigned integer.
S64, // 64-bit signed integer.
Ptr, // A pointer.
VariableContainer, // A VariableContainer.
};
// Type describes the type of a value.
class Type
{
public:
Type() = default;
inline Type(Kind kind);
inline Type(Kind kind, const std::shared_ptr<const Type>& elem);
// string() returns a string representation of the type.
std::string string() const;
const Kind kind; // Type kind.
const std::shared_ptr<const Type> elem; // Element type of pointer.
};
Type::Type(Kind kind) :
kind(kind) {}
Type::Type(Kind kind, const std::shared_ptr<const Type>& elem) :
kind(kind),
elem(elem) {}
// clang-format off
template <typename T> struct TypeOf;
template <> struct TypeOf<bool> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<uint8_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<int8_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<uint16_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<int16_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<float> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<uint32_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<int32_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<double> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<uint64_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<int64_t> { static std::shared_ptr<Type> get(); };
template <> struct TypeOf<VariableContainer> { static std::shared_ptr<Type> get(); };
// clang-format on
} // namespace dbg
} // namespace vk
#endif // VK_DEBUG_TYPE_HPP_
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment