FreeCalypso > hg > ueda-linux
annotate ueda/unet-utils/unet2tedax.c @ 135:25634b3977a9
ueda: unet2tedax added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 07 Sep 2020 01:22:36 +0000 |
parents | |
children |
rev | line source |
---|---|
135
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <stdio.h> |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdlib.h> |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <unistd.h> |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include "../libunet/unetrd.h" |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 static char *input_filename, *output_filename; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 static struct unetrd_state rdstate; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 static struct unetrd_out rdout; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 static FILE *outFILE; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static void |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 process_component() |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char compname[64]; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 strcpy(compname, rdout.objname); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 for (;;) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (!read_unet_line(&rdstate, &rdout)) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 fprintf(stderr, "%s error: EOF in COMPONENT block\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 input_filename); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (rdout.typecode == UNETOBJ_CLOSINGBRACE) |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 break; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 switch(rdout.typecode) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 case UNETOBJ_PRIMITIVE: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case UNETOBJ_ALTNAME: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 continue; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 case UNETOBJ_ATTR: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (strcmp(rdout.objname, "footprint")) |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 continue; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(outFILE, "footprint %s %s\n", compname, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 rdout.attr_value); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 continue; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 case UNETOBJ_PIN: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (rdout.connect_to_net) |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 fprintf(outFILE, "conn %s %s %s\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rdout.connect_to_net, compname, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 rdout.objname); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 continue; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 case UNETOBJ_PINMAP: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fprintf(stderr, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 "%s line %d: PINMAP objects not expected in unet2tedax input\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 input_filename, rdstate.lineno); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 default: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 "%s line %d: object type %s unexpected in COMPONENT block\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 input_filename, rdstate.lineno, rdout.keyword); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 static void |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 process_input_unet() |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 while (read_unet_line(&rdstate, &rdout)) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 switch(rdout.typecode) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 case UNETOBJ_CLOSINGBRACE: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fprintf(stderr, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 "%s line %d: unexpected '}' outside of component block\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 input_filename, rdstate.lineno); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 case UNETOBJ_NET: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 /* not needed for tEDAx netlist */ |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 continue; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 case UNETOBJ_COMPONENT: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 process_component(); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 continue; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 case UNETOBJ_STARPOINT: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 fprintf(stderr, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 "error: STARPOINT objects not expected in unet2tedax input (%s line %d)\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 input_filename, rdstate.lineno); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 default: |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 fprintf(stderr, |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 "%s line %d: unexpected object type %s\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 input_filename, rdstate.lineno, rdout.keyword); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 main(argc, argv) |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 char **argv; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (argc < 2 || argc > 3) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, "usage: %s input.unet [output-file]\n", |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 argv[0]); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 input_filename = argv[1]; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 output_filename = argv[2]; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 open_unet_input_file(input_filename, &rdstate); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (output_filename) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 outFILE = fopen(output_filename, "w"); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 if (!outFILE) { |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 perror(output_filename); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 exit(1); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } else |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 outFILE = stdout; |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(outFILE, "tEDAx v1\nbegin netlist v1 ueda_netlist\n\n"); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 process_input_unet(); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 fprintf(outFILE, "\nend netlist\n"); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 exit(0); |
25634b3977a9
ueda: unet2tedax added
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |