-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
191 lines (180 loc) · 3.47 KB
/
main.c
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright (C) 2008 Joseph H. Allen
// See file COPYING for license.
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
//#include <strstream>
using namespace std;
#include "lisp.h"
#include "hash.h"
#include "dlist.h"
#include "net.h"
#include "edif.h"
#include "inf.h"
#include "verilog.h"
int debug;
extern int orcad_edif_bug;
enum {
NONE,
VERILOG,
VHDL,
INF,
EDIF,
NET
};
int ifmt = NONE;
int ofmt = NONE;
char *in_name;
int main(int argc,char *argv[])
{
char *opath = 0;
int x;
Node *e;
Design *d;
string cmd;
string s;
if(argc < 2)
{
goto show_help;
}
for (x = 1; x != argc; ++x)
if (!strcmp(argv[x], "-ifmt"))
{
++x;
if (!strcmp(argv[x], "orcad_inf"))
ifmt = INF;
else if (!strcmp(argv[x], "edif"))
ifmt = EDIF;
else if (!strcmp(argv[x], "orcad_edif"))
{
ifmt = EDIF;
orcad_edif_bug = 1;
}
else if (!strcmp(argv[x], "verilog"))
ifmt = VERILOG;
else
{
cerr << "unknown input format\n";
return -1;
}
}
else if (!strcmp(argv[x], "-v"))
{
debug = 1;
}
else if (!strcmp(argv[x], "-ofmt"))
{
++x;
if (!strcmp(argv[x], "net"))
ofmt = NET;
else if (!strcmp(argv[x], "verilog"))
ofmt = VERILOG;
else
{
cerr << "unknown output format\n";
return -1;
}
}
else if (!strcmp(argv[x], "-opath"))
{
opath = argv[++x];
}
else if (!strcmp(argv[x], "-h"))
{
show_help:
cout << "netlist -ifmt [orcad_inf|edif|orcad_edif] -ofmt [net|verilog] name [-opath path]\n";
cout << " Orcad_edif is for edif output from DOS OrCAD which has string escaping bug\n";
cout << " For simple netlist (net) output, -opath gives output file name\n";
cout << " For verilog output, -opath gives output directory\n";
cout << " Version 3 - by Joe Allen jhallen@world.std.com\n";
return 0;
}
else if (argv[x][0]=='-')
{
cerr << "unknown option " << argv[x] << "\n";
return -1;
}
else
{
if (in_name)
{
cerr << "input file name already given\n";
return -1;
}
else
{
in_name = argv[x];
}
}
if (!in_name)
{
cerr << "missing input file name\n";
return -1;
}
switch (ifmt)
{
case NONE:
{
cerr << "no input format specified\n";
return -1;
}
case INF:
{
d = inf_load(in_name);
break;
}
case EDIF:
{
e = lisp_load(in_name);
d = parse_edif(e);
break;
}
default:
{
cerr << "input format not supported yet\n";
return -1;
}
}
switch (ofmt)
{
case NONE:
{
return 0;
}
case NET:
{
if (opath)
{
fstream l;
l.open(opath,ios::out);
if (!l)
{
cerr << "couldn't open " << opath << "\n";
return -1;
}
net_dump(d, l);
l.close();
if (!l)
{
cerr << "close error\n";
return -1;
}
return 0;
}
else
net_dump(d, cout);
return 0;
}
case VERILOG:
{
verilog_dump(d, opath, cout);
return 0;
}
default:
{
cerr << "output format not supported yet\n";
return -1;
}
}
}