From 2f87a0d7cc4399cad59b71e912ebe03c7936b6c5 Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Fri, 1 Mar 2024 08:32:26 +0000 Subject: [PATCH] Small code refactoring Can be treated as part of #180. --- .../nil/blueprint/non_native_marshalling.hpp | 28 +++++++++++++++---- include/nil/blueprint/stack.hpp | 16 ++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/include/nil/blueprint/non_native_marshalling.hpp b/include/nil/blueprint/non_native_marshalling.hpp index 9a5a1542..e1a23aaa 100644 --- a/include/nil/blueprint/non_native_marshalling.hpp +++ b/include/nil/blueprint/non_native_marshalling.hpp @@ -26,6 +26,22 @@ #ifndef CRYPTO3_ASSIGNER_NON_NATIVE_MARSHALLING_HPP #define CRYPTO3_ASSIGNER_NON_NATIVE_MARSHALLING_HPP +#include + +#include +#include +#include +// TODO: this include should be replaced with more precise and appropriate one, but I couldn't find it. +#include +#include +#include + +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/ZK/ZKEnums.h" + +#include + namespace nil { namespace blueprint { @@ -125,16 +141,16 @@ namespace nil { } + /// @brief Get number of native fields ("chunks") used to store a single non-native field element. template - std::size_t field_arg_num(llvm::Type *arg_type) { - ASSERT_MSG(llvm::isa(arg_type), "only fields can be handled here"); - return field_kind_size(llvm::cast(arg_type)->getFieldKind()); + std::size_t field_chunks_num(llvm::GaloisFieldType *type) { + return field_kind_size(type->getFieldKind()); } + /// @brief Get number of native fields ("chunks") used to store a single non-native curve element. template - std::size_t curve_arg_num(llvm::Type *arg_type) { - ASSERT_MSG(llvm::isa(arg_type), "only curves can be handled here"); - return 2 * field_kind_size(llvm::cast(arg_type)->GetBaseFieldKind()); + std::size_t curve_chunks_num(llvm::EllipticCurveType *type) { + return 2 * field_kind_size(type->GetBaseFieldKind()); } template diff --git a/include/nil/blueprint/stack.hpp b/include/nil/blueprint/stack.hpp index dd42fb7b..e7624caa 100644 --- a/include/nil/blueprint/stack.hpp +++ b/include/nil/blueprint/stack.hpp @@ -39,15 +39,23 @@ #include #include "llvm/IR/Constants.h" -#include - namespace nil { namespace blueprint { template struct stack_frame { - std::map scalars; - std::map> vectors; + /// @brief Type representing scalar registers. + using scalar_regs = std::map; + + /// @brief Type representing vector registers. + using vector_regs = std::map>; + + /// @brief Registers holding scalar values (integers, pointers, native fields). + scalar_regs scalars; + + /// @brief Registers holding vector values (non-native fields, curves, vectors, etc.). + vector_regs vectors; + const llvm::CallInst *caller; };