Skip to content

Commit

Permalink
Added constructors to ir::data_type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Goubermouche committed Dec 17, 2023
1 parent 27eeb02 commit 6c6b962
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace sigma::ir {

auto function::create_signed_integer(i64 value, u8 bit_width) -> handle<node> {
const handle<node> integer_node = create_node<integer>(node::INTEGER_CONSTANT, 1);
integer_node->dt = { .ty = data_type::INTEGER, .bit_width = bit_width };
integer_node->dt = data_type(data_type::INTEGER, bit_width);

auto& integer_prop = integer_node->get<integer>();
integer_prop.bit_width = bit_width;
Expand Down
3 changes: 2 additions & 1 deletion source/intermediate_representation/node_hierarchy/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ namespace sigma::ir {
template<typename extra_type>
auto function::create_node(node::type type, u64 input_count) -> handle<node> {
void* node_allocation = allocator.allocate(sizeof(node));
const handle node_ptr = new (node_allocation) node{ .ty = type };
const handle node_ptr = static_cast<node*>(node_allocation);
node_ptr->ty = type;

// initialize the base sea of nodes layout
node_ptr->inputs = utility::slice<handle<node>>(allocator, input_count);
Expand Down
5 changes: 5 additions & 0 deletions source/intermediate_representation/node_hierarchy/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <utility/macros.h>

namespace sigma::ir {
data_type::data_type() : ty(UNKNOWN), bit_width(0) {}
data_type::data_type(type t, u8 bw) : ty(t), bit_width(bw) {}

auto data_type::to_string() const -> std::string {
switch (ty) {
case INTEGER:
Expand All @@ -16,6 +19,8 @@ namespace sigma::ir {
return "control";
case MEMORY:
return "memory";
case UNKNOWN:
return "unknown";
default:
NOT_IMPLEMENTED();
return "";
Expand Down
18 changes: 11 additions & 7 deletions source/intermediate_representation/node_hierarchy/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ namespace sigma::ir {

struct data_type {
enum type : u8 {
INTEGER, // void is an i0 and bool is an i1
FLOAT, // f{32, 64}
POINTER, // pointer{0-2047}
TUPLE, // tuples, can only be accessed by projections
CONTROL, // represents control flow for regions and branches
MEMORY, // represents memory and I/O
CONTINUATION // continuation (usually just the return addresses)
INTEGER, // void is an i0 and bool is an i1
FLOAT, // f{32, 64}
POINTER, // pointer{0-2047}
TUPLE, // tuples, can only be accessed by projections
CONTROL, // represents control flow for regions and branches
MEMORY, // represents memory and I/O
CONTINUATION, // continuation (usually just the return addresses)
UNKNOWN
};

data_type();
data_type(type t, u8 bw = 0);

auto to_string() const -> std::string;
auto operator==(const data_type& other) const -> bool;

Expand Down
2 changes: 1 addition & 1 deletion source/ir_translator/ir_translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace sigma {
default: NOT_IMPLEMENTED();
}

return {};
return ir::data_type();
}

auto ir_translator::translate() -> ir::module {
Expand Down

0 comments on commit 6c6b962

Please sign in to comment.