diff --git a/.clang-tidy b/.clang-tidy index 4dfb6407..da1d1121 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,7 +17,6 @@ Checks: > bugprone-throw-keyword-missing, bugprone-unused-raii, bugprone-unused-return-value, - cppcoreguidelines-macro-usage, llvm-include-order, llvm-namespace-comment, misc-confusable-identifiers, diff --git a/compiler/include/compiler/optree/adaptors.hpp b/compiler/include/compiler/optree/adaptors.hpp index b0e67065..b8d1c428 100644 --- a/compiler/include/compiler/optree/adaptors.hpp +++ b/compiler/include/compiler/optree/adaptors.hpp @@ -1,9 +1,14 @@ #pragma once -#include -#include +#include +#include +#include #include "compiler/optree/base_adaptor.hpp" +#include "compiler/optree/definitions.hpp" +#include "compiler/optree/operation.hpp" +#include "compiler/optree/types.hpp" +#include "compiler/optree/value.hpp" namespace optree { @@ -40,7 +45,7 @@ struct ModuleOp : Adaptor { struct FunctionOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Function", specId) - void init(const std::string &name, Type::Ptr funcType); + void init(const std::string &name, const Type::Ptr &funcType); OPTREE_ADAPTOR_ATTRIBUTE(name, setName, std::string, 0) OPTREE_ADAPTOR_ATTRIBUTE_TYPE(type, FunctionType, 1) @@ -51,7 +56,7 @@ struct FunctionOp : Adaptor { struct FunctionCallOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "FunctionCall", specId) - void init(const std::string &name, Type::Ptr resultType, const std::vector &arguments); + void init(const std::string &name, const Type::Ptr &resultType, const std::vector &arguments); void init(const FunctionOp &callee, const std::vector &arguments); OPTREE_ADAPTOR_ATTRIBUTE(name, setName, std::string, 0) @@ -64,7 +69,7 @@ struct ReturnOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Return", specId) void init(); - void init(Value::Ptr value); + void init(const Value::Ptr &value); OPTREE_ADAPTOR_OPERAND(value, setValue, 0) @@ -74,9 +79,9 @@ struct ReturnOp : Adaptor { struct ConstantOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Constant", specId) - void init(Type::Ptr type, int64_t value); - void init(Type::Ptr type, double value); - void init(Type::Ptr type, const std::string &value); + void init(const Type::Ptr &type, int64_t value); + void init(const Type::Ptr &type, double value); + void init(const Type::Ptr &type, const std::string &value); OPTREE_ADAPTOR_ATTRIBUTE_OPAQUE(value, 0) OPTREE_ADAPTOR_RESULT(result, 0) @@ -98,7 +103,7 @@ struct LogicUnaryOp; struct BinaryOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Binary", specId) - void init(Type::Ptr resultType, Value::Ptr lhs, Value::Ptr rhs); + void init(const Type::Ptr &resultType, const Value::Ptr &lhs, const Value::Ptr &rhs); OPTREE_ADAPTOR_OPERAND(lhs, setLhs, 0) OPTREE_ADAPTOR_OPERAND(rhs, setRhs, 1) @@ -110,8 +115,8 @@ struct BinaryOp : Adaptor { struct ArithBinaryOp : BinaryOp { OPTREE_ADAPTOR_HELPER(BinaryOp, "ArithBinary", specId) - void init(ArithBinOpKind kind, Type::Ptr resultType, Value::Ptr lhs, Value::Ptr rhs); - void init(ArithBinOpKind kind, Value::Ptr lhs, Value::Ptr rhs); + void init(ArithBinOpKind kind, const Type::Ptr &resultType, const Value::Ptr &lhs, const Value::Ptr &rhs); + void init(ArithBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs); OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, ArithBinOpKind, 0) @@ -121,7 +126,7 @@ struct ArithBinaryOp : BinaryOp { struct LogicBinaryOp : BinaryOp { OPTREE_ADAPTOR_HELPER(BinaryOp, "LogicBinary", specId) - void init(LogicBinOpKind kind, Value::Ptr lhs, Value::Ptr rhs); + void init(LogicBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs); OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, LogicBinOpKind, 0) @@ -131,7 +136,7 @@ struct LogicBinaryOp : BinaryOp { struct UnaryOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Unary", specId) - void init(Type::Ptr resultType, Value::Ptr value); + void init(const Type::Ptr &resultType, const Value::Ptr &value); OPTREE_ADAPTOR_OPERAND(value, setValue, 0) OPTREE_ADAPTOR_RESULT(result, 0) @@ -142,7 +147,7 @@ struct UnaryOp : Adaptor { struct ArithCastOp : UnaryOp { OPTREE_ADAPTOR_HELPER(UnaryOp, "ArithCast", specId) - void init(ArithCastOpKind kind, Type::Ptr resultType, Value::Ptr value); + void init(ArithCastOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value); OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, ArithCastOpKind, 0) @@ -152,7 +157,7 @@ struct ArithCastOp : UnaryOp { struct LogicUnaryOp : UnaryOp { OPTREE_ADAPTOR_HELPER(UnaryOp, "LogicUnary", specId) - void init(LogicUnaryOpKind kind, Type::Ptr resultType, Value::Ptr value); + void init(LogicUnaryOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value); OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, LogicUnaryOpKind, 0) @@ -170,7 +175,7 @@ struct StoreOp; struct AllocateOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Allocate", specId) - void init(Type::Ptr type); + void init(const Type::Ptr &type); OPTREE_ADAPTOR_RESULT(result, 0) @@ -180,8 +185,8 @@ struct AllocateOp : Adaptor { struct LoadOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Load", specId) - void init(Type::Ptr resultType, Value::Ptr src); - void init(Value::Ptr src); + void init(const Type::Ptr &resultType, const Value::Ptr &src); + void init(const Value::Ptr &src); OPTREE_ADAPTOR_OPERAND(src, setSrc, 0) OPTREE_ADAPTOR_RESULT(result, 0) @@ -192,7 +197,7 @@ struct LoadOp : Adaptor { struct StoreOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Store", specId) - void init(Value::Ptr dst, Value::Ptr valueToStore); + void init(const Value::Ptr &dst, const Value::Ptr &valueToStore); OPTREE_ADAPTOR_OPERAND(dst, setDst, 0) OPTREE_ADAPTOR_OPERAND(valueToStore, setValueToStore, 1) @@ -214,7 +219,7 @@ struct ForOp; struct IfOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "If", specId) - void init(Value::Ptr cond, bool withElse = false); + void init(const Value::Ptr &cond, bool withElse = false); OPTREE_ADAPTOR_OPERAND(cond, setCond, 0); @@ -263,7 +268,7 @@ struct ConditionOp : Adaptor { struct ForOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "For", specId) - void init(Type::Ptr iteratorType, Value::Ptr start, Value::Ptr stop, Value::Ptr step); + void init(const Type::Ptr &iteratorType, const Value::Ptr &start, const Value::Ptr &stop, const Value::Ptr &step); OPTREE_ADAPTOR_OPERAND(start, setStart, 0) OPTREE_ADAPTOR_OPERAND(stop, setStop, 1) @@ -283,7 +288,7 @@ struct PrintOp; struct InputOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Input", specId) - void init(Type::Ptr inputType); + void init(const Type::Ptr &inputType); OPTREE_ADAPTOR_RESULT(value, 0) @@ -293,7 +298,7 @@ struct InputOp : Adaptor { struct PrintOp : Adaptor { OPTREE_ADAPTOR_HELPER(Adaptor, "Print", specId) - void init(Value::Ptr valueToPrint); + void init(const Value::Ptr &valueToPrint); OPTREE_ADAPTOR_OPERAND(value, setValue, 0) diff --git a/compiler/include/compiler/optree/attribute.hpp b/compiler/include/compiler/optree/attribute.hpp index 33c6c0ac..cef6bdb9 100644 --- a/compiler/include/compiler/optree/attribute.hpp +++ b/compiler/include/compiler/optree/attribute.hpp @@ -1,7 +1,8 @@ #pragma once -#include -#include +#include +#include +#include #include #include diff --git a/compiler/include/compiler/optree/base_adaptor.hpp b/compiler/include/compiler/optree/base_adaptor.hpp index d64c4ab6..ade97d4a 100644 --- a/compiler/include/compiler/optree/base_adaptor.hpp +++ b/compiler/include/compiler/optree/base_adaptor.hpp @@ -3,6 +3,7 @@ #include #include "compiler/optree/operation.hpp" +#include "compiler/utils/source_ref.hpp" #define OPTREE_ADAPTOR_HELPER(BASE_ADAPTOR_CLASS, OPERATION_NAME, SPECID_MEMBER_NAME) \ public: \ @@ -12,11 +13,11 @@ return (OPERATION_NAME); \ } \ static Operation::SpecId getSpecId() { \ - return &SPECID_MEMBER_NAME; \ + return &(SPECID_MEMBER_NAME); \ } \ \ private: \ - static inline char SPECID_MEMBER_NAME; \ + static inline char(SPECID_MEMBER_NAME); \ \ public: diff --git a/compiler/include/compiler/optree/builder.hpp b/compiler/include/compiler/optree/builder.hpp index ae1ad00d..eef70a99 100644 --- a/compiler/include/compiler/optree/builder.hpp +++ b/compiler/include/compiler/optree/builder.hpp @@ -1,8 +1,9 @@ #pragma once -#include "compiler/optree/operation.hpp" #include "compiler/utils/source_ref.hpp" +#include "compiler/optree/operation.hpp" + namespace optree { class Builder { @@ -11,7 +12,8 @@ class Builder { Operation::Ptr currentOp; InsertPoint insertPoint; - Builder(Operation::Ptr currentOp, InsertPoint insertPoint) : currentOp(currentOp), insertPoint(insertPoint){}; + Builder(const Operation::Ptr ¤tOp, const InsertPoint &insertPoint) + : currentOp(currentOp), insertPoint(insertPoint){}; public: Builder() = default; diff --git a/compiler/include/compiler/optree/operation.hpp b/compiler/include/compiler/optree/operation.hpp index bb77e589..2b186291 100644 --- a/compiler/include/compiler/optree/operation.hpp +++ b/compiler/include/compiler/optree/operation.hpp @@ -1,13 +1,13 @@ #pragma once -#include +#include #include #include #include -#include +#include #include +#include #include -#include #include #include "compiler/utils/source_ref.hpp" @@ -41,10 +41,10 @@ struct Operation { Operation(Operation &&) = default; ~Operation() = default; - explicit Operation(Ptr parent = {}, Body::iterator position = {}) + explicit Operation(const Ptr &parent = {}, const Body::iterator &position = {}) : parent(parent), position(position), specId(nullptr), verifier([](const Operation *) { return true; }){}; - Operation(SpecId specId, const Verifier &verifier, std::string_view name = "Unknown", Ptr parent = Ptr(), - Body::iterator position = {}) + Operation(SpecId specId, const Verifier &verifier, std::string_view name = "Unknown", const Ptr &parent = {}, + const Body::iterator &position = {}) : parent(parent), position(position), specId(specId), verifier(verifier), name(name){}; const Value::Ptr &operand(size_t index) const { @@ -84,7 +84,7 @@ struct Operation { for (const auto &a : attributes) if (a.is()) return a.as(); - throw std::exception("There are no attributes with a given type"); + throw std::logic_error("There are no attributes with a given type"); } operator bool() const { @@ -133,11 +133,11 @@ struct Operation { return attributes.emplace_back(value); } - void addOperand(Value::Ptr value); + void addOperand(const Value::Ptr &value); void eraseOperand(size_t operandNumber); - Value::Ptr addResult(Type::Ptr type); - Value::Ptr addInward(Type::Ptr type); - Body::iterator addToBody(Operation::Ptr op); + Value::Ptr addResult(const Type::Ptr &type); + Value::Ptr addInward(const Type::Ptr &type); + Body::iterator addToBody(const Operation::Ptr &op); void erase(); bool verify() const; @@ -146,7 +146,7 @@ struct Operation { void dump(std::ostream &stream) const; template - static AdaptorType make(Ptr parent = {}, Body::iterator position = {}) { + static AdaptorType make(const Ptr &parent = {}, const Body::iterator &position = {}) { auto op = std::make_shared(AdaptorType::getSpecId(), AdaptorType::verify, AdaptorType::getOperationName(), parent, position); return {op}; diff --git a/compiler/include/compiler/optree/program.hpp b/compiler/include/compiler/optree/program.hpp index 11e95b84..9c3fcce8 100644 --- a/compiler/include/compiler/optree/program.hpp +++ b/compiler/include/compiler/optree/program.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include "compiler/optree/operation.hpp" namespace optree { diff --git a/compiler/include/compiler/optree/traits.hpp b/compiler/include/compiler/optree/traits.hpp index d1a9fd31..0b14af29 100644 --- a/compiler/include/compiler/optree/traits.hpp +++ b/compiler/include/compiler/optree/traits.hpp @@ -1,8 +1,11 @@ #pragma once +#include #include #include "compiler/optree/operation.hpp" +#include "compiler/optree/types.hpp" +#include "compiler/optree/value.hpp" namespace optree { diff --git a/compiler/include/compiler/optree/types.hpp b/compiler/include/compiler/optree/types.hpp index b7b7d0d7..1a6475ad 100644 --- a/compiler/include/compiler/optree/types.hpp +++ b/compiler/include/compiler/optree/types.hpp @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include #include @@ -123,7 +121,7 @@ struct FunctionType : public Type { const PtrVector arguments; const Type::Ptr result; - FunctionType(const PtrVector &arguments, Type::Ptr result) : arguments(arguments), result(result){}; + FunctionType(const PtrVector &arguments, const Type::Ptr &result) : arguments(arguments), result(result){}; bool operator==(const Type &other) const override; using Type::operator!=; @@ -136,7 +134,7 @@ struct PointerType : public Type { const Type::Ptr pointee; - PointerType(Type::Ptr pointee) : pointee(pointee){}; + PointerType(const Type::Ptr &pointee) : pointee(pointee){}; bool operator==(const Type &other) const override; using Type::operator!=; diff --git a/compiler/include/compiler/optree/value.hpp b/compiler/include/compiler/optree/value.hpp index 46490bef..630a5861 100644 --- a/compiler/include/compiler/optree/value.hpp +++ b/compiler/include/compiler/optree/value.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -35,8 +36,8 @@ struct Value { Value(Value &&) = default; ~Value() = default; - Value(Type::Ptr type, Operation *owner) : type(type), owner(owner){}; - Value(Type::Ptr type, std::shared_ptr owner) : Value(type, owner.get()){}; + Value(const Type::Ptr &type, Operation *owner) : type(type), owner(owner){}; + Value(const Type::Ptr &type, const std::shared_ptr &owner) : Value(type, owner.get()){}; operator bool() const { return type.operator bool(); diff --git a/compiler/include/compiler/utils/helpers.hpp b/compiler/include/compiler/utils/helpers.hpp index 986918c7..68a9f2d5 100644 --- a/compiler/include/compiler/utils/helpers.hpp +++ b/compiler/include/compiler/utils/helpers.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace utils { diff --git a/compiler/lib/optree/adaptors.cpp b/compiler/lib/optree/adaptors.cpp index 92fdcc46..130363ca 100644 --- a/compiler/lib/optree/adaptors.cpp +++ b/compiler/lib/optree/adaptors.cpp @@ -1,13 +1,22 @@ #include "adaptors.hpp" -#include "compiler/optree/traits.hpp" +#include +#include +#include + +#include "base_adaptor.hpp" +#include "definitions.hpp" +#include "operation.hpp" +#include "traits.hpp" +#include "types.hpp" +#include "value.hpp" using namespace optree; using namespace trait; // The following definitions for the methods of the operation classes should be arranged in alphabetical order. -void AllocateOp::init(Type::Ptr type) { +void AllocateOp::init(const Type::Ptr &type) { op->results.emplace_back(Value::make(type, op)); } @@ -15,12 +24,13 @@ bool AllocateOp::verify(const Operation *op) { return Adaptor::verify(op) && numOperands<0U>(op) && numResults<1U>(op); } -void ArithBinaryOp::init(ArithBinOpKind kind, Type::Ptr resultType, Value::Ptr lhs, Value::Ptr rhs) { +void ArithBinaryOp::init(ArithBinOpKind kind, const Type::Ptr &resultType, const Value::Ptr &lhs, + const Value::Ptr &rhs) { BinaryOp::init(resultType, lhs, rhs); op->addAttr(kind); } -void ArithBinaryOp::init(ArithBinOpKind kind, Value::Ptr lhs, Value::Ptr rhs) { +void ArithBinaryOp::init(ArithBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs) { init(kind, lhs->type, lhs, rhs); } @@ -28,7 +38,7 @@ bool ArithBinaryOp::verify(const Operation *op) { return BinaryOp::verify(op) && oneAttrOfType(op) && operandsAndResultsHaveSameType(op); } -void ArithCastOp::init(ArithCastOpKind kind, Type::Ptr resultType, Value::Ptr value) { +void ArithCastOp::init(ArithCastOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value) { UnaryOp::init(resultType, value); op->addAttr(kind); } @@ -37,7 +47,7 @@ bool ArithCastOp::verify(const Operation *op) { return UnaryOp::verify(op) && oneAttrOfType(op); } -void BinaryOp::init(Type::Ptr resultType, Value::Ptr lhs, Value::Ptr rhs) { +void BinaryOp::init(const Type::Ptr &resultType, const Value::Ptr &lhs, const Value::Ptr &rhs) { op->addResult(resultType); op->addOperand(lhs); op->addOperand(rhs); @@ -61,17 +71,17 @@ bool ConditionOp::verify(const Operation *op) { numResults<1U>(op->body.back().get()); } -void ConstantOp::init(Type::Ptr type, int64_t value) { +void ConstantOp::init(const Type::Ptr &type, int64_t value) { op->results.emplace_back(Value::make(type, op)); op->addAttr(value); } -void ConstantOp::init(Type::Ptr type, double value) { +void ConstantOp::init(const Type::Ptr &type, double value) { op->results.emplace_back(Value::make(type, op)); op->addAttr(value); } -void ConstantOp::init(Type::Ptr type, const std::string &value) { +void ConstantOp::init(const Type::Ptr &type, const std::string &value) { op->results.emplace_back(Value::make(type, op)); op->addAttr(value); } @@ -87,7 +97,8 @@ bool ElseOp::verify(const Operation *op) { return Adaptor::verify(op); } -void ForOp::init(Type::Ptr iteratorType, Value::Ptr start, Value::Ptr stop, Value::Ptr step) { +void ForOp::init(const Type::Ptr &iteratorType, const Value::Ptr &start, const Value::Ptr &stop, + const Value::Ptr &step) { op->addOperand(start); op->addOperand(stop); op->addOperand(step); @@ -98,10 +109,10 @@ bool ForOp::verify(const Operation *op) { return Adaptor::verify(op) && numOperands<3U>(op) && numResults<0U>(op); } -void FunctionOp::init(const std::string &name, Type::Ptr funcType) { +void FunctionOp::init(const std::string &name, const Type::Ptr &funcType) { op->addAttr(name); op->addAttr(funcType); - for (auto argType : funcType->as().arguments) + for (const auto &argType : funcType->as().arguments) op->addInward(argType); } @@ -110,7 +121,8 @@ bool FunctionOp::verify(const Operation *op) { op->attr(1).isType(); } -void FunctionCallOp::init(const std::string &name, Type::Ptr resultType, const std::vector &arguments) { +void FunctionCallOp::init(const std::string &name, const Type::Ptr &resultType, + const std::vector &arguments) { op->operands = arguments; op->results.emplace_back(Value::make(resultType, op)); op->addAttr(name); @@ -133,7 +145,7 @@ bool FunctionCallOp::verify(const Operation *op) { return false; } -void IfOp::init(Value::Ptr cond, bool withElse) { +void IfOp::init(const Value::Ptr &cond, bool withElse) { op->addOperand(cond); op->addToBody(Operation::make(op).op); if (withElse) @@ -152,7 +164,7 @@ bool IfOp::verify(const Operation *op) { return Adaptor::verify(op) && numOperands<1U>(op) && numResults<0U>(op); } -void InputOp::init(Type::Ptr inputType) { +void InputOp::init(const Type::Ptr &inputType) { op->addResult(inputType); } @@ -160,12 +172,12 @@ bool InputOp::verify(const Operation *op) { return Adaptor::verify(op) && numOperands<0U>(op) && numResults<1U>(op); } -void LoadOp::init(Type::Ptr resultType, Value::Ptr src) { +void LoadOp::init(const Type::Ptr &resultType, const Value::Ptr &src) { op->addOperand(src); op->results.emplace_back(Value::make(resultType, op)); } -void LoadOp::init(Value::Ptr src) { +void LoadOp::init(const Value::Ptr &src) { auto resultType = src->type->as().pointee; init(resultType, src); } @@ -175,7 +187,7 @@ bool LoadOp::verify(const Operation *op) { op->operand(0)->canPointTo(op->result(0)); } -void LogicBinaryOp::init(LogicBinOpKind kind, Value::Ptr lhs, Value::Ptr rhs) { +void LogicBinaryOp::init(LogicBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs) { BinaryOp::init(TypeStorage::integerType(), lhs, rhs); op->addAttr(kind); } @@ -185,7 +197,7 @@ bool LogicBinaryOp::verify(const Operation *op) { op->result(0)->type->is(); } -void LogicUnaryOp::init(LogicUnaryOpKind kind, Type::Ptr resultType, Value::Ptr value) { +void LogicUnaryOp::init(LogicUnaryOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value) { UnaryOp::init(resultType, value); op->addAttr(kind); } @@ -202,7 +214,7 @@ bool ModuleOp::verify(const Operation *op) { return Adaptor::verify(op) && numOperands<0U>(op) && numResults<0U>(op) && bodyContainsOnly(op); } -void PrintOp::init(Value::Ptr valueToPrint) { +void PrintOp::init(const Value::Ptr &valueToPrint) { op->addOperand(valueToPrint); } @@ -213,7 +225,7 @@ bool PrintOp::verify(const Operation *op) { void ReturnOp::init() { } -void ReturnOp::init(Value::Ptr value) { +void ReturnOp::init(const Value::Ptr &value) { op->addOperand(value); } @@ -221,7 +233,7 @@ bool ReturnOp::verify(const Operation *op) { return Adaptor::verify(op) && numResults<0U>(op) && op->numOperands() <= 1U; } -void StoreOp::init(Value::Ptr dst, Value::Ptr valueToStore) { +void StoreOp::init(const Value::Ptr &dst, const Value::Ptr &valueToStore) { op->addOperand(dst); op->addOperand(valueToStore); } @@ -238,7 +250,7 @@ bool ThenOp::verify(const Operation *op) { return Adaptor::verify(op); } -void UnaryOp::init(Type::Ptr resultType, Value::Ptr value) { +void UnaryOp::init(const Type::Ptr &resultType, const Value::Ptr &value) { op->addResult(resultType); op->addOperand(value); } diff --git a/compiler/lib/optree/attribute.cpp b/compiler/lib/optree/attribute.cpp index ca137ace..bb6a1224 100644 --- a/compiler/lib/optree/attribute.cpp +++ b/compiler/lib/optree/attribute.cpp @@ -1,5 +1,13 @@ #include "attribute.hpp" +#include +#include +#include +#include + +#include "definitions.hpp" +#include "types.hpp" + using namespace optree; void Attribute::dump(std::ostream &stream) const { diff --git a/compiler/lib/optree/builder.cpp b/compiler/lib/optree/builder.cpp index a627ae1c..99cea9c2 100644 --- a/compiler/lib/optree/builder.cpp +++ b/compiler/lib/optree/builder.cpp @@ -2,6 +2,8 @@ #include +#include "operation.hpp" + using namespace optree; Builder Builder::before(const Operation::Ptr &op) { diff --git a/compiler/lib/optree/operation.cpp b/compiler/lib/optree/operation.cpp index 0e1f8369..608a2007 100644 --- a/compiler/lib/optree/operation.cpp +++ b/compiler/lib/optree/operation.cpp @@ -1,14 +1,21 @@ #include "operation.hpp" +#include #include #include +#include +#include #include #include "compiler/utils/helpers.hpp" +#include "attribute.hpp" +#include "types.hpp" +#include "value.hpp" + using namespace optree; -void Operation::addOperand(Value::Ptr value) { +void Operation::addOperand(const Value::Ptr &value) { size_t operandNumber = operands.size(); operands.emplace_back(value); value->uses.emplace_front(this, operandNumber); @@ -20,15 +27,15 @@ void Operation::eraseOperand(size_t operandNumber) { operands.erase(operands.begin() + operandNumber); } -Value::Ptr Operation::addResult(Type::Ptr type) { +Value::Ptr Operation::addResult(const Type::Ptr &type) { return results.emplace_back(Value::make(type, this)); } -Value::Ptr Operation::addInward(Type::Ptr type) { +Value::Ptr Operation::addInward(const Type::Ptr &type) { return inwards.emplace_back(Value::make(type, this)); } -Operation::Body::iterator Operation::addToBody(Operation::Ptr op) { +Operation::Body::iterator Operation::addToBody(const Operation::Ptr &op) { auto it = body.emplace(body.end(), op); op->position = it; return it; @@ -62,13 +69,15 @@ std::string Operation::dump() const { return str.str(); } -static void dumpValue(const Value::Ptr &value, std::ostream &stream, int valueId) { +namespace { + +void dumpValue(const Value::Ptr &value, std::ostream &stream, int valueId) { stream << '#' << valueId << " : "; value->type->dump(stream); } -static void dumpOperation(const Operation *op, std::ostream &stream, int depth, - std::unordered_map &valueIds, int &nextValueId) { +void dumpOperation(const Operation *op, std::ostream &stream, int depth, + std::unordered_map &valueIds, int &nextValueId) { for (int i = 0; i < depth; i++) stream << " "; stream << op->name; @@ -97,6 +106,8 @@ static void dumpOperation(const Operation *op, std::ostream &stream, int depth, dumpOperation(op.get(), stream, depth + 1, valueIds, nextValueId); } +} // namespace + void Operation::dump(std::ostream &stream) const { std::unordered_map valueIds; int valueId = 0; diff --git a/compiler/lib/optree/program.cpp b/compiler/lib/optree/program.cpp deleted file mode 100644 index 1d3b5cbe..00000000 --- a/compiler/lib/optree/program.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "program.hpp" -#include "adaptors.hpp" diff --git a/compiler/lib/optree/types.cpp b/compiler/lib/optree/types.cpp index 48380bed..ee58af24 100644 --- a/compiler/lib/optree/types.cpp +++ b/compiler/lib/optree/types.cpp @@ -1,11 +1,15 @@ #include "types.hpp" +#include +#include +#include + #include "compiler/utils/helpers.hpp" #define TYPE_COMPARE_EARLY_RETURN(CLASS_NAME, OTHER_NAME) \ - if (this == &OTHER_NAME) \ + if (this == &(OTHER_NAME)) \ return true; \ - if (!OTHER_NAME.is()) \ + if (!(OTHER_NAME).is()) \ return false; using namespace optree; diff --git a/compiler/lib/optree/value.cpp b/compiler/lib/optree/value.cpp index 86d8c016..f74efab0 100644 --- a/compiler/lib/optree/value.cpp +++ b/compiler/lib/optree/value.cpp @@ -1,6 +1,8 @@ #include "value.hpp" -#include "compiler/optree/operation.hpp" +#include "compiler/utils/source_ref.hpp" + +#include "operation.hpp" using namespace optree;