15#ifndef OR_TOOLS_MATH_OPT_ELEMENTAL_CODEGEN_GEN_H_
16#define OR_TOOLS_MATH_OPT_ELEMENTAL_CODEGEN_GEN_H_
23#include "absl/strings/string_view.h"
24#include "absl/types/span.h"
65 static std::shared_ptr<Type>
Named(std::string name);
67 static std::shared_ptr<Type>
Pointer(std::shared_ptr<Type> pointee);
76 virtual void Print(absl::string_view attr_value_type,
77 std::string* out)
const = 0;
90 std::shared_ptr<Type>
type;
102 : attr_op_function_infos_(*attr_op_function_infos) {}
113 virtual void EmitElements(absl::Span<const absl::string_view> elements,
114 std::string* out)
const {}
121 absl::Span<const CodegenAttrTypeDescriptor> descriptors,
122 std::string* out)
const;
126 std::string* out)
const {}
132 std::string* out)
const {}
136 std::string* out)
const;
std::string GenerateCode() const
Generates code.
CodeGenerator(const AttrOpFunctionInfos *attr_op_function_infos)
virtual void EmitElements(absl::Span< const absl::string_view > elements, std::string *out) const
Emits code for elements.
virtual void StartAttrType(const CodegenAttrTypeDescriptor &descriptor, std::string *out) const
Called before generating code for an attribute type.
virtual void EmitAttributes(absl::Span< const CodegenAttrTypeDescriptor > descriptors, std::string *out) const
virtual void EmitAttrOp(absl::string_view op_name, const CodegenAttrTypeDescriptor &descriptor, const AttrOpFunctionInfo &info, std::string *out) const
Emits code for operation info for attribute described by descriptor.
virtual void EmitHeader(std::string *out) const
Emits the header for the generated code.
virtual ~CodeGenerator()=default
Representations for types.
static std::shared_ptr< Type > Named(std::string name)
A named type, e.g. "double".
static std::shared_ptr< Type > Pointer(std::shared_ptr< Type > pointee)
A pointer type.
virtual void Print(absl::string_view attr_value_type, std::string *out) const =0
static std::shared_ptr< Type > AttrValueType()
Language-agnostic utilities for Elemental codegen.
static constexpr int kNumAttrOps
AttrOp
The list of attribute operations supported by Elemental.
std::array< AttrOpFunctionInfo, kNumAttrOps > AttrOpFunctionInfos
Information about how to codegen a given AttrOp in a given language.
bool has_key_parameter
If true, the function has an AttrKey parameter.
std::shared_ptr< Type > return_type
The return type of the function.
std::vector< ExtraParameter > extra_parameters
A struct to represent an attribute type descriptor during codegen.
ValueType
The value type of the attribute.
absl::string_view name
The attribute type name.
int num_key_elements
The number of key elements.
std::string symmetry
The key symmetry.
std::vector< absl::string_view > attribute_names
The names of the attributes of this type.