Fletchgen
The Fletcher Design Generator
array.h
1 // Copyright 2018-2019 Delft University of Technology
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <cerata/api.h>
18 #include <fletcher/common.h>
19 
20 #include <string>
21 #include <memory>
22 #include <utility>
23 
24 #include "fletchgen/basic_types.h"
25 
26 namespace fletchgen {
27 
28 using cerata::Component;
29 using cerata::Instance;
30 using cerata::intl;
31 using cerata::Literal;
32 
33 // ArrayReader/Writer parameters:
34 PARAM_DECL_FACTORY(index_width, 32)
35 PARAM_DECL_FACTORY(tag_width, 1)
36 
38 size_t GetCtrlBufferCount(const arrow::Field &field);
40 uint32_t GetTagWidth(const arrow::Field &field);
41 
42 // ArrayReader/Writer types:
43 
45 std::shared_ptr<Type> cmd_type(const std::shared_ptr<Node> &index_width,
46  const std::shared_ptr<Node> &tag_width,
47  const std::optional<std::shared_ptr<Node>> &ctrl_width = std::nullopt);
49 std::shared_ptr<Type> unlock_type(const std::shared_ptr<Node> &tag_width);
50 
52 std::shared_ptr<Type> array_reader_out(uint32_t num_streams = 0, uint32_t full_width = 0);
54 std::shared_ptr<Type> array_reader_out(std::pair<uint32_t, uint32_t> spec);
55 
57 std::shared_ptr<Type> array_writer_in(uint32_t num_streams = 0, uint32_t full_width = 0);
59 std::shared_ptr<Type> array_writer_in(std::pair<uint32_t, uint32_t> spec);
60 
62 enum class ConfigType {
63  ARB,
64  NUL,
65  PRIM,
66  LIST,
67  LIST_PRIM,
68  STRUCT
69 };
70 
76 std::shared_ptr<Node> GetWidthNode(const arrow::DataType &type);
77 
83 ConfigType GetConfigType(const arrow::DataType &type);
84 
91 std::string GenerateConfigString(const arrow::Field &field, int level = 0);
92 
101 std::shared_ptr<TypeMapper> GetStreamTypeMapper(Type *stream_type, Type *other);
102 
110 std::shared_ptr<Type> GetStreamType(const arrow::Field &arrow_field, fletcher::Mode mode, int level = 0);
111 
117 std::pair<uint32_t, uint32_t> GetArrayDataSpec(const arrow::Field &arrow_field);
118 
124 Component *array(fletcher::Mode mode);
125 
126 } // namespace fletchgen
Contains all classes and functions related to Fletchgen.
Definition: array.cc:29
std::shared_ptr< Type > cmd_type(const std::shared_ptr< Node > &index_width, const std::shared_ptr< Node > &tag_width, const std::optional< std::shared_ptr< Node >> &ctrl_width)
Return a Fletcher command stream type.
Definition: array.cc:62
std::shared_ptr< TypeMapper > GetStreamTypeMapper(Type *stream_type, Type *other)
Get a type mapper for an Arrow::Field-based stream to an ArrayReader/Writer stream.
Definition: array.cc:323
std::string GenerateConfigString(const arrow::Field &field, int level)
Return the configuration string for a ArrayReader/Writer.
Definition: array.cc:256
std::shared_ptr< Node > GetWidthNode(const arrow::DataType &type)
Return a node representing the width of a (flat) Arrow DataType.
Definition: array.cc:209
std::pair< uint32_t, uint32_t > GetArrayDataSpec(const arrow::Field &arrow_field)
Get the ArrayR/W number of streams and data width from an Arrow Field.
Definition: array.cc:478
std::shared_ptr< Type > unlock_type(const std::shared_ptr< Node > &tag_width)
Fletcher unlock stream.
Definition: array.cc:80
std::shared_ptr< Type > GetStreamType(const arrow::Field &arrow_field, fletcher::Mode mode, int level)
Convert an Arrow::Field into a stream type.
Definition: array.cc:369
uint32_t GetTagWidth(const arrow::Field &field)
Return the tag width of this field as a literal node. Settable through Arrow metadata....
Definition: array.cc:58
ConfigType
Types for ArrayReader/Writer configuration string.
Definition: array.h:62
@ LIST
Variable length fields.
@ PRIM
Primitive (fixed-width) fields.
@ LIST_PRIM
List of primitives. Can have EPC > 1.
@ STRUCT
Structs, composed of multiple fields.
@ ARB
Arbiter level.
std::shared_ptr< Type > array_writer_in(uint32_t num_streams, uint32_t full_width)
Fletcher write data.
Definition: array.cc:94
size_t GetCtrlBufferCount(const arrow::Field &field)
Return the number of buffers for the control field.
Definition: array.cc:51
Component * array(Mode mode)
Return a Cerata component model of an Array(Reader/Writer).
Definition: array.cc:139
ConfigType GetConfigType(const arrow::DataType &type)
Return the configuration string type version of an arrow::DataType.
Definition: array.cc:188
std::shared_ptr< Type > array_reader_out(uint32_t num_streams, uint32_t full_width)
Fletcher read data.
Definition: array.cc:85