Skip to content

Commit

Permalink
cg: Remove redundant visitor base.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Oct 27, 2023
1 parent bd59b89 commit 0a4a55f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 69 deletions.
7 changes: 7 additions & 0 deletions include/vast/CodeGen/CodeGenBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include "vast/Util/Common.hpp"
#include "vast/CodeGen/CodeGenVisitorLens.hpp"

#include "vast/Dialect/Core/CoreOps.hpp"
#include "vast/Dialect/Core/CoreAttributes.hpp"

#include "vast/Dialect/HighLevel/HighLevelOps.hpp"
#include "vast/Dialect/HighLevel/HighLevelAttributes.hpp"
#include "vast/Dialect/HighLevel/HighLevelTypes.hpp"

namespace vast::cg {

template< typename scope_t >
Expand Down
1 change: 1 addition & 0 deletions include/vast/CodeGen/CodeGenDeclVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "vast/Util/Warnings.hpp"

VAST_RELAX_WARNINGS
#include <llvm/ADT/ScopedHashTable.h>
#include <clang/AST/DeclVisitor.h>
#include <clang/AST/Attr.h>
#include <clang/Basic/Diagnostic.h>
Expand Down
72 changes: 50 additions & 22 deletions include/vast/CodeGen/CodeGenVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,68 @@ namespace vast::cg
struct visitor_instance
: builder_t< visitor_instance< context_t, visitor_mixin, meta_generator_t > >
, visitor_mixin< visitor_instance< context_t, visitor_mixin, meta_generator_t > >
, visitor_base< context_t, meta_generator_t >
{
using base = visitor_base< context_t, meta_generator_t >;
using mixin = visitor_mixin< visitor_instance< context_t, visitor_mixin, meta_generator_t > >;
using meta_generator = meta_generator_t;
using builder = builder_t< visitor_instance< context_t, visitor_mixin, meta_generator_t > >;
using vast_builder = builder_t< visitor_instance< context_t, visitor_mixin, meta_generator_t > >;

visitor_instance(context_t &ctx, meta_generator &gen)
: base(ctx, gen)
: ctx(ctx), meta(gen), builder(ctx.getBodyRegion())
{}

using builder::set_insertion_point_to_start;
using builder::set_insertion_point_to_end;
using builder::has_insertion_block;
using builder::clear_insertion_point;
using vast_builder::set_insertion_point_to_start;
using vast_builder::set_insertion_point_to_end;
using vast_builder::has_insertion_block;
using vast_builder::clear_insertion_point;

using builder::make_scoped;
using vast_builder::make_scoped;

using builder::make_cond_builder;
using builder::make_operation;
using builder::make_region_builder;
using builder::make_stmt_expr_region;
using builder::make_type_yield_builder;
using builder::make_value_builder;
using builder::make_value_yield_region;
using builder::make_yield_true;
using vast_builder::make_cond_builder;
using vast_builder::make_operation;
using vast_builder::make_region_builder;
using vast_builder::make_stmt_expr_region;
using vast_builder::make_type_yield_builder;
using vast_builder::make_value_builder;
using vast_builder::make_value_yield_region;
using vast_builder::make_yield_true;

using builder::constant;

using base::base_builder;
using base::meta_location;
using base::make_insertion_guard;
using vast_builder::constant;

using mixin::Visit;

void set_insertion_point_to_start(region_ptr region) {
builder.setInsertionPointToStart(&region->front());
}

void set_insertion_point_to_end(region_ptr region) {
builder.setInsertionPointToEnd(&region->back());
}

void set_insertion_point_to_start(block_ptr block) {
builder.setInsertionPointToStart(block);
}

void set_insertion_point_to_end(block_ptr block) {
builder.setInsertionPointToEnd(block);
}

void clear_insertion_point() {
builder.clearInsertionPoint();
}

insertion_guard make_insertion_guard() {
return { builder };
}

mlir_builder& base_builder() { return builder; }

loc_t meta_location(auto token) const {
return meta.location(token);
}

context_t &ctx;
meta_generator &meta;
mlir_builder builder;
};

} // namespace vast::cg
46 changes: 0 additions & 46 deletions include/vast/CodeGen/CodeGenVisitorBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ VAST_RELAX_WARNINGS
#include <clang/AST/TypeVisitor.h>
VAST_UNRELAX_WARNINGS

#include "vast/CodeGen/CodeGenContext.hpp"
#include "vast/CodeGen/CodeGenMeta.hpp"
#include "vast/CodeGen/Mangler.hpp"

#include "vast/Util/Common.hpp"

Expand All @@ -31,47 +28,4 @@ namespace vast::cg {
template< typename derived_t >
using attr_visitor_base = clang::ConstAttrVisitor< derived_t, mlir_attr >;

template< typename context_t, typename meta_gen >
struct visitor_base
{
visitor_base(context_t &ctx, meta_gen &meta)
: ctx(ctx), meta(meta), _builder(ctx.getBodyRegion())
{}

void set_insertion_point_to_start(region_ptr region) {
_builder.setInsertionPointToStart(&region->front());
}

void set_insertion_point_to_end(region_ptr region) {
_builder.setInsertionPointToEnd(&region->back());
}

void set_insertion_point_to_start(block_ptr block) {
_builder.setInsertionPointToStart(block);
}

void set_insertion_point_to_end(block_ptr block) {
_builder.setInsertionPointToEnd(block);
}

void clear_insertion_point() {
_builder.clearInsertionPoint();
}

insertion_guard make_insertion_guard() {
return { _builder };
}

mlir_builder& base_builder() { return _builder; }

loc_t meta_location(auto token) const {
return meta.location(token);
}

context_t &ctx;
meta_gen &meta;

mlir_builder _builder;
};

} // namespace vast::cg
3 changes: 2 additions & 1 deletion include/vast/CodeGen/CodeGenVisitorLens.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ VAST_UNRELAX_WARNINGS

#include "vast/CodeGen/CodeGenMeta.hpp"
#include "vast/CodeGen/CodeGenVisitorBase.hpp"
#include "vast/CodeGen/Mangler.hpp"
#include "vast/CodeGen/Util.hpp"

namespace vast::cg {
Expand Down Expand Up @@ -103,7 +104,7 @@ namespace vast::cg {
template< typename Token >
mlir_type visit_as_lvalue_type(Token token) { return derived().VisitLValueType(token); }

core::FunctionType visit_function_type(const clang::FunctionType *fty, bool variadic) {
decltype(auto) visit_function_type(const clang::FunctionType *fty, bool variadic) {
return derived().VisitCoreFunctionType(fty, variadic);
}

Expand Down

0 comments on commit 0a4a55f

Please sign in to comment.