Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
vla5924 committed Oct 18, 2024
1 parent 376ddbd commit 07ae23e
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 26 deletions.
24 changes: 24 additions & 0 deletions compiler/include/compiler/backend/optree/semantizer/traits.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <algorithm>

#include "compiler/optree/operation.hpp"
#include "compiler/optree/types.hpp"

Expand Down Expand Up @@ -53,6 +55,17 @@ struct HasOperands {
}
};

struct HasOperandsOfType {
static bool verify(const Operation::Ptr &op, SemantizerContext &ctx, size_t numOperands, const Type::Ptr &type) {
if (op->numOperands() == numOperands &&
std::all_of(op->operands.begin(), op->operands.end(),
[&](const Value::Ptr &operand) { return operand->hasType(type); }))
return true;
ctx.pushOpError(op) << "must have " << numOperands << " operands of " << type;
return false;
}
};

struct HasResults {
static bool verify(const Operation::Ptr &op, SemantizerContext &ctx, size_t numResults) {
if (op->numResults() == numResults)
Expand Down Expand Up @@ -80,6 +93,17 @@ struct HasInwards {
}
};

struct HasInwardsOfType {
static bool verify(const Operation::Ptr &op, SemantizerContext &ctx, size_t numInwards, const Type::Ptr &type) {
if (op->numInwards() == numInwards &&
std::all_of(op->inwards.begin(), op->inwards.end(),
[&](const Value::Ptr &inward) { return inward->hasType(type); }))
return true;
ctx.pushOpError(op) << "must have " << numInwards << " inwards of " << type;
return false;
}
};

struct HasAttributes {
static bool verify(const Operation::Ptr &op, SemantizerContext &ctx, size_t numAttrs) {
if (op->numAttrs() == numAttrs)
Expand Down
3 changes: 3 additions & 0 deletions compiler/include/compiler/optree/adaptors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ struct FunctionOp : Adaptor {

OPTREE_ADAPTOR_ATTRIBUTE(name, setName, std::string, 0)
OPTREE_ADAPTOR_ATTRIBUTE_TYPE(type, FunctionType, 1)

size_t numArguments() const;
size_t numResults() const;
};

struct FunctionCallOp : Adaptor {
Expand Down
Loading

0 comments on commit 07ae23e

Please sign in to comment.