#ifndef DBG_EXPORT_H
#define DBG_EXPORT_H

#include <map>

#include "trav.h"
#include "export.h"
#include "hub/hub.h"
#include "util/indent.h"
#include "hub/attr.h"
#include "hub/symfunc.h"
#include "hub/fsm.h"
#include "hub/pla.h"

class DbgExport: 
public TopTraverserClient, 
public StructArchTravClient,
public Export {
    TopTraverser traverser_;
    bool netBegins_;

    static std::map < hub::AttrIndex <hub::PortProto>, std::string > portAttrMap;
    static std::map < hub::AttrIndex <hub::Architecture>, std::string > archAttrMap;
    static std::map < hub::AttrIndex <hub::Net>, std::string > netAttrMap;

    void initPortAttrMap (void);
    void initArchAttrMap (void);
    void initNetAttrMap (void);

    void havePortAttr (hub::PortProto*);
    void haveArchAttr (hub::Architecture*);
    void haveNetAttr  (hub::Net*);
    
public:
    virtual void haveUnit (void);
    virtual void endUnit  (void);
    virtual void haveLibrary (hub::Library*);
    virtual void endLibrary  (hub::Library*);
    virtual void haveDesign (hub::Design*);
    virtual void endDesign  (hub::Design*);
    virtual void haveEntity (hub::Entity*);
    virtual void endEntity  (hub::Entity*);
    virtual void havePortProto (hub::PortProto*);
    virtual void haveArch (hub::Architecture*);
    virtual void endArch  (hub::Architecture*);

    virtual void haveNet (hub::Net*);
    virtual void endNet  (hub::Net*);
    virtual void haveJoined (hub::Joinable*);
    virtual void havePort (hub::Port <hub::StructArch>*);
    virtual void haveInst (hub::Instance*);

public:
    virtual void operator() (std::ostream* os, Export::Source* src); 
    DbgExport (hub::Hub*);
   ~DbgExport () {}
};
// ========== wrappers that introduce repr functions into exportMap =======
class DbgSymFunc {
public:
	static const char* ftab [hub::SymFunc::fNull+1];
	static bool Represent (DbgExport&, hub::SymFunc&);
	static int wantInit;
};
class DbgRTLReg {
public:
	static bool Represent (DbgExport&, hub::RTLReg&);
	static int wantInit;
};
class DbgKissTable {
public:
	static bool Represent (DbgExport&, hub::FsmDescr&);
	static int wantInit;
};
class DbgPlaTable {
public:
	static bool Represent (DbgExport&, hub::PlaDescr&);
	static int wantInit;
};

// ======================================================================================
class DbgExpLang: public ExportLang {
public:
    static void enregister (void);
    DbgExpLang (const std::string& n): ExportLang(n) {}
    Export* getExporter (hub::Hub& theHub) { return new DbgExport (&theHub); }
    void getDefaults (hub::Hub* h, const std::string& fn, Export::Source&);

};
 
#endif
