Skip to content

Commit

Permalink
cg: Update policy naming and formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Aug 29, 2024
1 parent cebf049 commit 00640d1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion include/vast/CodeGen/CodeGenFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace vast::cg {
void emit_implicit_return_zero(const clang_function *decl);
void emit_implicit_void_return(const clang_function *decl);

std::shared_ptr< policy_base > policy;
std::shared_ptr< codegen_policy > policy;
};

//
Expand Down
18 changes: 6 additions & 12 deletions include/vast/CodeGen/CodeGenPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ namespace vast::cg {

enum class missing_return_policy { emit_unreachable, emit_trap };

struct policy_base
struct codegen_policy
{
virtual ~policy_base() = default;
virtual ~codegen_policy() = default;

virtual bool emit_strict_function_return([[maybe_unused]] const clang_function *decl
) const = 0;

virtual missing_return_policy
missing_return_policy([[maybe_unused]] const clang_function *decl) const = 0;

virtual bool skip_function_body([[maybe_unused]] const clang_function *decl) const = 0;

virtual bool skip_global_initializer([[maybe_unused]] const clang_var_decl *decl
) const = 0;
virtual bool emit_strict_function_return(const clang_function *decl) const = 0;
virtual missing_return_policy get_missing_return_policy(const clang_function *decl) const = 0;
virtual bool skip_function_body(const clang_function *decl) const = 0;
virtual bool skip_global_initializer(const clang_var_decl *decl) const = 0;
};

} // namespace vast::cg
25 changes: 9 additions & 16 deletions include/vast/CodeGen/DefaultCodeGenPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,34 @@

namespace vast::cg {

struct default_policy : policy_base
struct default_policy : codegen_policy
{
default_policy(cc::action_options &opts)
: opts(opts)
, default_missing_return(
opts.codegen.OptimizationLevel == 0 ? missing_return_policy::emit_trap
: missing_return_policy::emit_unreachable
) {}
{}

~default_policy() = default;

bool emit_strict_function_return([[maybe_unused]] const clang_function *decl
) const override {
bool emit_strict_function_return(const clang_function * /* decl */) const override {
return opts.codegen.StrictReturn;
};

enum missing_return_policy
missing_return_policy([[maybe_unused]] const clang_function *decl) const override {
return default_missing_return;
missing_return_policy get_missing_return_policy(const clang_function * /* decl */) const override {
return opts.codegen.OptimizationLevel == 0
? missing_return_policy::emit_trap
: missing_return_policy::emit_unreachable;
}

bool skip_function_body([[maybe_unused]] const clang_function *decl) const override {
bool skip_function_body(const clang_function * /* decl */) const override {
return opts.front.SkipFunctionBodies;
}

bool skip_global_initializer([[maybe_unused]] const clang_var_decl *decl
) const override {
bool skip_global_initializer(const clang_var_decl * /* decl */) const override {
return false;
};

protected:
cc::action_options &opts;

private:
enum missing_return_policy default_missing_return;
};

} // namespace vast::cg
2 changes: 1 addition & 1 deletion include/vast/CodeGen/DefaultDeclVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace vast::cg {
template< typename RecordDeclOp >
operation mk_record_decl(const clang::RecordDecl *decl);

std::shared_ptr< policy_base > policy;
std::shared_ptr< codegen_policy > policy;
};

template< typename RecordDeclOp >
Expand Down
7 changes: 3 additions & 4 deletions include/vast/CodeGen/DefaultVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace vast::cg {
default_visitor(
visitor_base &head, mcontext_t &mctx, acontext_t &actx, codegen_builder &bld,
std::shared_ptr< meta_generator > mg, std::shared_ptr< symbol_generator > sg,
std::shared_ptr< policy_base > policy
std::shared_ptr< codegen_policy > policy
)
: mctx(mctx)
, actx(actx)
Expand All @@ -32,8 +32,7 @@ namespace vast::cg {
mlir_type visit(const clang_type *type, scope_context &scope) override;
mlir_type visit(clang_qual_type type, scope_context &scope) override;

std::optional< named_attr >
visit(const clang_attr *attr, scope_context &scope) override;
std::optional< named_attr > visit(const clang_attr *attr, scope_context &scope) override;

operation visit_prototype(const clang_function *decl, scope_context &scope) override;

Expand All @@ -51,7 +50,7 @@ namespace vast::cg {

std::shared_ptr< meta_generator > mg;
std::shared_ptr< symbol_generator > sg;
std::shared_ptr< policy_base > policy;
std::shared_ptr< codegen_policy > policy;
};

} // namespace vast::cg
4 changes: 2 additions & 2 deletions lib/vast/CodeGen/CodeGenDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace vast::cg {
return std::make_shared< default_symbol_generator >(actx.createMangleContext());
}

std::shared_ptr< policy_base > mk_policy(cc::action_options &opts) {
std::shared_ptr< codegen_policy > mk_codegen_policy(cc::action_options &opts) {
return std::make_shared< default_policy >(opts);
}

Expand All @@ -124,7 +124,7 @@ namespace vast::cg {

auto mg = mk_meta_generator(&actx, &mctx, vargs);
auto sg = mk_symbol_generator(actx);
auto policy = mk_policy(opts);
auto policy = mk_codegen_policy(opts);

auto visitors = std::make_shared< visitor_list >()
| as_node_with_list_ref< attr_visitor_proxy >()
Expand Down
2 changes: 1 addition & 1 deletion lib/vast/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace vast::cg
// function call is used by the caller, the behavior is undefined.

// TODO: skip if SawAsmBlock
switch (policy->missing_return_policy(decl)) {
switch (policy->get_missing_return_policy(decl)) {
case missing_return_policy::emit_trap:
emit_trap(decl);
break;
Expand Down

0 comments on commit 00640d1

Please sign in to comment.