/*
IITH Compilers
authors: S Venkata Keerthy, D Tharun
email: {cs17mtech11018, cs15mtech11002}@iith.ac.in

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.
*/

#ifndef _BACKENDS_BMV2_DEPARSER_H_
#define _BACKENDS_BMV2_DEPARSER_H_

#include "ir/ir.h"
#include "frontends/p4/typeMap.h"
#include "frontends/common/resolveReferences/referenceMap.h"
#include "backend.h"
#include "toIR.h"

namespace LLBMV2 {

class ConvertDeparser : public Inspector {
    Backend*               backend;
    P4::ReferenceMap*      refMap;
    P4::TypeMap*           typeMap;
    ToIR* toIR;

 protected:
    void convertDeparser(const IR::P4Control* ctrl);
    void convertDeparserBody(const IR::Vector<IR::StatOrDecl>* body);
 public:
    bool preorder(const IR::PackageBlock* block);
    bool preorder(const IR::ControlBlock* ctrl);

    explicit ConvertDeparser(Backend* backend) :
        backend(backend), refMap(backend->getRefMap()),
        typeMap(backend->getTypeMap()),
        toIR(new ToIR(this->backend)){ setName("ConvertDeparser"); }
};

}  // namespace LLBMV2

#endif  /* _BACKENDS_BMV2_DEPARSER_H_ */
