summaryrefslogtreecommitdiff
path: root/src/readverilog.h
blob: a50fde9aba851056b2beba077ffa2f1a5837f70d (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
107
108
109
110
111
112
113
114
115
116
117
118
/*----------------------------------------------------------------------*/
/* readverilog.h -- Input for Verilog format (structural verilog only)	*/
/*----------------------------------------------------------------------*/

/*------------------------------------------------------*/
/* Definitions and structures 				*/
/*------------------------------------------------------*/

#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE  1
#endif

/* 'X' is used here to separate the single-character delimiters	*/
/* from the two-character delimiters.				*/

#define VLOG_DELIMITERS "///**/(**)#(X,;:(){}[]="
#define VLOG_PIN_NAME_DELIMITERS "///**/(**)X()"
#define VLOG_PIN_CHECK_DELIMITERS "///**/(**)X(),{}"

#define VERILOG_EXTENSION ".v"

/*------------------------------------------------------*/
/* Ports and instances are hashed for quick lookup but	*/
/* also placed in a linked list so that they can be	*/
/* output in the same order as the original file.	*/
/*------------------------------------------------------*/

struct portrec {
    char *name;
    char *net;			/* May be a {...} list */
    int   direction;
    struct portrec *next;
};

struct instance {		/* Hashed by instance name */
    char *instname;
    char *cellname;
    int arraystart;		/* -1 if not arrayed */
    int arrayend;		/* -1 if not arrayed */
    struct portrec *portlist;
    struct hashtable propdict;	/* Instance properties */
    struct instance *next;
};

/*------------------------------------------------------*/
/* Basic cell definition (hashed by name)		*/
/*------------------------------------------------------*/

struct cellrec {
    char *name;			/* Cellname */

    struct hashtable nets;		/* Internal nets */
    struct hashtable propdict;		/* Properties */

    struct portrec *portlist;
    struct instance *instlist;
    struct instance *lastinst;		/* Track last item in list */
};

/*------------------------------------------------------*/

#define PORT_NONE	 0	
#define PORT_INPUT	 1
#define PORT_OUTPUT	 2
#define PORT_INOUT	 3

#define BUS_NONE	-1

/*------------------------------------------------------*/
/* Net structure (hashed by root name, if a bus)	*/
/*------------------------------------------------------*/

struct netrec {
    int start;		/* start index, if a bus */
    int end;		/* end index, if a bus */
};

/*------------------------------------------------------*/
/* Structure for stacking nested module definitions	*/
/*------------------------------------------------------*/

struct cellstack {
   struct cellrec *cell;
   struct cellstack *next;
};

/*------------------------------------------------------*/
/* Structure for nested "include" files			*/
/*------------------------------------------------------*/

struct filestack {
    FILE *file;
    struct filestack *next;
};

/*------------------------------------------------------*/
/* External variable declarations			*/
/*------------------------------------------------------*/

extern int vlinenum;

/*------------------------------------------------------*/
/* External function declarations 			*/
/*------------------------------------------------------*/

extern void IncludeVerilog(char *, struct cellstack **, int);
extern struct cellrec *ReadVerilog(char *);
extern void FreeVerilog(struct cellrec *);
extern void VerilogDefine(char *, char *);
extern struct instance *AppendInstance(struct cellrec *cell, char *cellname);
extern struct instance *PrependInstance(struct cellrec *cell, char *cellname);
extern struct portrec *InstPort(struct instance *inst, char *portname, char *netname);
extern void *BusHashLookup(char *s, struct hashtable *table);

// readverilog.h