24 auto Indent(
size_t size) -> std::string {
25 std::string indent(size * 4,
' ');
39 out <<
Indent(indent) <<
"namespace " << node.
name() <<
" {\n";
44 out <<
Indent(indent) <<
"} // namespace " << node.
name() <<
'\n';
49 out <<
Indent(indent) <<
"class " << node.
name() <<
" {\n"
50 <<
Indent(indent + 1) <<
"char __data[" << node.
size() <<
"];\n"
51 <<
Indent(indent) <<
"public:\n";
56 out <<
Indent(indent) <<
"} __attribute((aligned(" << node.
align() <<
")));\n";
63 context.
error(std::format(
"unrecognized return type of function '{}'", node.
symbol()));
68 if (std::dynamic_pointer_cast<ObjectDecl>(node.
parent())) {
71 out << ret.value() <<
' ' << node.
name() <<
'(';
77 out <<
") asm(\"" << node.
symbol() <<
"\");\n";
84 context.
error(std::format(
"unrecognized builtin type '{}'", node.
returns().
terms()[0]));
88 out <<
Indent(indent) << ret.value() <<
' ' << node.
name() <<
'(';
95 context.
error(std::format(
"unrecognized builtin type '{}'", node.
type().
terms()[0]));
99 out << type.value() <<
' ' << node.
name();
const std::shared_ptr< Decl > & parent() const
const std::string & name() const
const Type & returns() const
const std::string & symbol() const
void error(const std::string &what)
const std::string & align() const
const std::string & size() const
const Type & type() const
const std::vector< std::string > & terms() const
bool handleAssemblyBegin(MLLIFContext &context, const AssemblyDecl &node, std::ostream &out, std::size_t indent) override
bool handleParam(MLLIFContext &context, const ParamDecl &node, std::ostream &out, std::size_t indent) override
bool handleMethodBegin(MLLIFContext &context, const MethodDecl &node, std::ostream &out, std::size_t indent) override
void writeParamDelimiter(std::ostream &os) override
bool handleNamespaceEnd(MLLIFContext &context, const NamespaceDecl &node, std::ostream &out, std::size_t indent) override
bool handleNamespaceBegin(MLLIFContext &context, const NamespaceDecl &node, std::ostream &out, std::size_t indent) override
bool handleAssemblyEnd(MLLIFContext &context, const AssemblyDecl &node, std::ostream &out, std::size_t indent) override
bool handleFunctionEnd(MLLIFContext &context, const FunctionDecl &node, std::ostream &out, std::size_t indent) override
bool handleFunctionBegin(MLLIFContext &context, const FunctionDecl &node, std::ostream &out, std::size_t indent) override
bool handleObjectBegin(MLLIFContext &context, const ObjectDecl &node, std::ostream &out, std::size_t indent) override
bool handleObjectEnd(MLLIFContext &context, const ObjectDecl &node, std::ostream &out, std::size_t indent) override
std::optional< std::string > TypeToCxx(const Type &type)
Gets C++-compliant typename of type.
auto Indent(size_t size) -> std::string