Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/mlir/cxx/mlir/codegen_units.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,28 @@

// cxx
#include <cxx/ast.h>
#include <cxx/ast_visitor.h>
#include <cxx/translation_unit.h>

namespace cxx {

namespace {
struct ForEachExternalDefinition final : ASTVisitor {
std::function<void(FunctionDefinitionAST*)> functionCallback;

void visit(TemplateDeclarationAST*) override {
// Skip template declarations, we only want to visit function definitions.
}

void visit(FunctionDefinitionAST* ast) override {
if (functionCallback) functionCallback(ast);

ASTVisitor::visit(ast);
}
};

} // namespace

struct Codegen::UnitVisitor {
Codegen& gen;

Expand All @@ -46,8 +64,15 @@ auto Codegen::UnitVisitor::operator()(TranslationUnitAST* ast) -> UnitResult {

std::swap(gen.module_, module);

ForEachExternalDefinition forEachExternalDefinition;

forEachExternalDefinition.functionCallback =
[&](FunctionDefinitionAST* function) {
auto functionResult = gen.declaration(function);
};

for (auto node : ListView{ast->declarationList}) {
auto value = gen.declaration(node);
forEachExternalDefinition.accept(node);
}

std::swap(gen.module_, module);
Expand Down
8 changes: 8 additions & 0 deletions src/parser/cxx/binder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,14 @@ void Binder::bind(ParameterDeclarationAST* ast, const Decl& decl,
bool inTemplateParameters) {
ast->type = getDeclaratorType(unit_, ast->declarator, decl.specs.type());

// decay the type of the parameters
if (control()->is_array(ast->type))
ast->type = control()->add_pointer(control()->remove_extent(ast->type));
else if (control()->is_function(ast->type))
ast->type = control()->add_pointer(ast->type);
else if (control()->is_scalar(ast->type))
ast->type = control()->remove_cv(ast->type);

if (auto declId = decl.declaratorId; declId && declId->unqualifiedId) {
auto paramName = get_name(control(), declId->unqualifiedId);
if (auto identifier = name_cast<Identifier>(paramName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/cxx/external_name_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ struct ExternalNameEncoder::EncodeType {
// todo: "Y" prefix for the bare function type encodes extern "C"
encoder.out("F");

encoder.encodeBareFunctionType(type);
encoder.encodeBareFunctionType(type, /*includeReturnType=*/true);

if (type->refQualifier() == RefQualifier::kLvalue)
encoder.out("R");
Expand Down
Loading