aboutsummaryrefslogtreecommitdiff
path: root/src/parser/parse_element.h
blob: ebd08ab6f47ebc6de5f05972fa432034bca7beab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once

#include "alldevices.h"
#include "subcircuit_instance.h"
#include "parse_tree.h"
#include "specs.h"

#include <initializer_list>
#include <utility>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <iostream>

using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::map;
using std::cout;
using std::cerr;
using std::endl;
using std::pair;
using std::unique_ptr;

/** ******************************************* **/
/**  Helper macros for declaring devices        **/
/** ******************************************* **/
#define DECLARE_UNIDIR_ELEMENT(ELEM_NAME, ELEM_NAME_LONG, MOD_CLASS_PREFIX, N_NETS)    \
    struct ELEM_NAME : public ParseElement {                                           \
        typedef MOD_CLASS_PREFIX element_type_base;                                    \
        typedef MOD_CLASS_PREFIX element_type_uni;                                     \
                                                                                       \
        const size_t n_nets = N_NETS;                                                  \
                                                                                       \
        /* Import constructor from ParseElement */                                     \
        using ParseElement::ParseElement;                                              \
                                                                                       \
        virtual ParseElement *clone() const                                            \
        { return new ELEM_NAME(*this); }                                               \
        /* Implement virtual function create(...) to construct element */              \
        virtual sc_module *create(ParseTreeCreationHelper &pt_helper) const;           \
        virtual element_type_base *                                                    \
        instantiate_and_connect_uni(ParseTreeCreationHelper &pt_helper) const;         \
                                                                                       \
        virtual string kind() const { return ELEM_NAME_LONG; }                         \
        virtual bool bidir_capable() const { return false; }                           \
    };

/*************************************************/

#define DECLARE_BIDIR_ELEMENT(ELEM_NAME, ELEM_NAME_LONG, MOD_CLASS_PREFIX, N_NETS)     \
                                                                                       \
    struct ELEM_NAME : public ParseElement {                                           \
        typedef MOD_CLASS_PREFIX##Base element_type_base;                              \
        typedef MOD_CLASS_PREFIX##Uni element_type_uni;                                \
        typedef MOD_CLASS_PREFIX##Bi element_type_bi;                                  \
                                                                                       \
        const size_t n_nets = N_NETS;                                                  \
                                                                                       \
        /* Import constructor from ParseElement */                                     \
        using ParseElement::ParseElement;                                              \
                                                                                       \
        virtual ParseElement *clone() const                                            \
        { return new ELEM_NAME(*this); }                                               \
        /* Implement virtual function create(...) to construct element */              \
        virtual sc_module *create(ParseTreeCreationHelper &pt_helper) const;           \
        virtual element_type_base *                                                    \
        instantiate_and_connect_uni(ParseTreeCreationHelper &pt_helper) const;         \
        virtual element_type_base *                                                    \
        instantiate_and_connect_bi(ParseTreeCreationHelper &pt_helper) const;          \
                                                                                       \
        virtual string kind() const { return string(ELEM_NAME_LONG) + " (bidir)"; }    \
        virtual bool bidir_capable() const { return true; }                            \
    };

/** ******************************************* **/
/**            Devices declarations             **/
/** ******************************************* **/
DECLARE_BIDIR_ELEMENT(WGElement, "WAVEGUIDE", Waveguide, 2);
DECLARE_BIDIR_ELEMENT(DCElement, "DIRECTIONAL COUPLER", DirectionalCoupler, 4);
DECLARE_UNIDIR_ELEMENT(MergerElement, "MERGER", Merger, 3);
DECLARE_UNIDIR_ELEMENT(SplitterElement, "SPLITTER", Splitter, 3);
DECLARE_BIDIR_ELEMENT(PhaseShifterElement, "PHASE SHIFTER", PhaseShifter, 3);
DECLARE_BIDIR_ELEMENT(MZIElement, "MZI MODULATOR", MZIActive, 5);
//DECLARE_UNIDIR_ELEMENT(MZIElement, "MZI MODULATOR (2 PHASE-SHIFTER)", MZI, 6);
DECLARE_BIDIR_ELEMENT(CrossingElement, "CROSSING", Crossing, 4);
DECLARE_UNIDIR_ELEMENT(CWSourceElement, "CW SOURCE", CWSource, 1);
DECLARE_UNIDIR_ELEMENT(VLSourceElement, "VALUE LIST SOURCE (OPTICAL)", VLSource, 1);
DECLARE_UNIDIR_ELEMENT(EVLSourceElement, "VALUE LIST SOURCE (ELECTRICAL)", EVLSource, 1);

// TODO: make the following bidirectional
DECLARE_UNIDIR_ELEMENT(PCMCellElement, "PCM CELL", PCMElement, 2);
DECLARE_UNIDIR_ELEMENT(PhotodetectorElement, "PHOTODETECTOR", Detector, 2);
DECLARE_UNIDIR_ELEMENT(ProbeElement, "PROBE", Probe, 1);
DECLARE_UNIDIR_ELEMENT(MLProbeElement, "MULTIWAVELENGTH PROBE", MLambdaProbe, 1);

// TODO: take care of subcircuit instance...
DECLARE_UNIDIR_ELEMENT(XElement, "SUBCIRCUIT", SubcircuitInstance, 1);

/** ******************************************* **/
/**        Undefine macros                      **/
/** ******************************************* **/
#undef DECLARE_UNIDIR_ELEMENT
#undef DECLARE_BIDIR_ELEMENT