Add ast::type_alignment
This commit is contained in:
parent
d5eab856c8
commit
e2781fef8f
2 changed files with 42 additions and 0 deletions
|
|
@ -60,5 +60,6 @@ namespace pslang::ast
|
|||
};
|
||||
|
||||
std::size_t type_size(types::type const & type);
|
||||
std::size_t type_alignment(types::type const & type);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,42 @@ namespace pslang::ast
|
|||
}
|
||||
};
|
||||
|
||||
struct alignment_visitor
|
||||
: types::const_visitor<alignment_visitor>
|
||||
{
|
||||
using const_visitor::apply;
|
||||
|
||||
std::size_t apply(types::unit_type const & type)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t apply(types::primitive_type const & type)
|
||||
{
|
||||
return types::type_size(type);
|
||||
}
|
||||
|
||||
std::size_t apply(types::array_type const & type)
|
||||
{
|
||||
return apply(*type.element_type);
|
||||
}
|
||||
|
||||
std::size_t apply(types::function_type const &)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
std::size_t apply(types::pointer_type const &)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
std::size_t apply(types::struct_type const & type)
|
||||
{
|
||||
return type.node->layout.alignment;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
types::type_ptr get_type(type const & type)
|
||||
|
|
@ -94,4 +130,9 @@ namespace pslang::ast
|
|||
return size_visitor{}.apply(type);
|
||||
}
|
||||
|
||||
std::size_t type_alignment(types::type const & type)
|
||||
{
|
||||
return alignment_visitor{}.apply(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue