// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include "paddle/ap/include/axpr/anf_expr.h" #include "paddle/ap/include/axpr/atomic_builder.h" namespace ap::axpr { class AnfExprBuilder : public AtomicExprBuilder { public: AnfExprBuilder() {} AnfExprBuilder(const AnfExprBuilder&) = delete; AnfExprBuilder(AnfExprBuilder&&) = delete; Combined Call(const Atomic& f, const std::vector>& args) { return Combined{ap::axpr::Call{f, args}}; } Combined If(const Atomic& c, const AnfExpr& t, const AnfExpr& f) { return Combined{ap::axpr::If{c, t, f}}; } ap::axpr::Bind Bind(const std::string& var, const Combined& val) { return ap::axpr::Bind{tVar{var}, val}; } ap::axpr::Let Let( const std::vector>& assigns, const AnfExpr& body) { return ap::axpr::Let{assigns, body}; } AnfExpr operator()(const Atomic& atomic) { return AnfExpr{atomic}; } AnfExpr operator()(const Combined& combined) { return AnfExpr{combined}; } AnfExpr operator()(const ap::axpr::Let& let) { return AnfExpr{let}; } private: }; } // namespace ap::axpr