FreeCalypso > hg > ueda-linux
comparison ueda/unet-utils/unet-excise.c @ 142:7bdce91da1a5
unet-excise utility added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 19 Sep 2020 22:50:24 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
141:fddb020e9b68 | 142:7bdce91da1a5 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <strings.h> | |
5 #include "../libunet/unetrd.h" | |
6 | |
7 static char *input_filename; | |
8 static char **excise_nets; | |
9 static struct unetrd_state rdstate; | |
10 static struct unetrd_out rdout; | |
11 | |
12 static void | |
13 process_net() | |
14 { | |
15 char **ap; | |
16 | |
17 for (ap = excise_nets; *ap; ap++) { | |
18 if (!strcmp(*ap, rdout.objname)) { | |
19 printf("# net %s excised\n", *ap); | |
20 return; | |
21 } | |
22 } | |
23 printf("NET %s\n", rdout.objname); | |
24 } | |
25 | |
26 static void | |
27 process_component_pin() | |
28 { | |
29 char **ap; | |
30 | |
31 if (!rdout.connect_to_net) { | |
32 printf(" %s %s = NC (%s)\n", rdout.keyword, rdout.objname, | |
33 rdout.nc_comment); | |
34 return; | |
35 } | |
36 for (ap = excise_nets; *ap; ap++) { | |
37 if (!strcmp(*ap, rdout.connect_to_net)) { | |
38 printf(" %s %s = NC (net %s excised)\n", | |
39 rdout.keyword, rdout.objname, *ap); | |
40 return; | |
41 } | |
42 } | |
43 printf(" %s %s = NET %s\n", rdout.keyword, rdout.objname, | |
44 rdout.connect_to_net); | |
45 } | |
46 | |
47 static void | |
48 process_component() | |
49 { | |
50 printf("\nCOMPONENT %s {\n", rdout.objname); | |
51 for (;;) { | |
52 if (!read_unet_line(&rdstate, &rdout)) { | |
53 fprintf(stderr, "%s error: EOF in COMPONENT block\n", | |
54 input_filename); | |
55 exit(1); | |
56 } | |
57 if (rdout.typecode == UNETOBJ_CLOSINGBRACE) | |
58 break; | |
59 switch(rdout.typecode) { | |
60 case UNETOBJ_PRIMITIVE: | |
61 case UNETOBJ_ALTNAME: | |
62 printf(" %s %s\n", rdout.keyword, rdout.objname); | |
63 continue; | |
64 case UNETOBJ_ATTR: | |
65 printf(" ATTR %s=%s\n", rdout.objname, | |
66 rdout.attr_value); | |
67 continue; | |
68 case UNETOBJ_PIN: | |
69 case UNETOBJ_PINMAP: | |
70 process_component_pin(); | |
71 continue; | |
72 default: | |
73 fprintf(stderr, | |
74 "%s line %d: object type %s unexpected in COMPONENT block\n", | |
75 input_filename, rdstate.lineno, rdout.keyword); | |
76 exit(1); | |
77 } | |
78 } | |
79 puts("}"); | |
80 } | |
81 | |
82 static void | |
83 process_input_unet() | |
84 { | |
85 open_unet_input_file(input_filename, &rdstate); | |
86 while (read_unet_line(&rdstate, &rdout)) { | |
87 switch(rdout.typecode) { | |
88 case UNETOBJ_CLOSINGBRACE: | |
89 fprintf(stderr, | |
90 "%s line %d: unexpected '}' outside of component block\n", | |
91 input_filename, rdstate.lineno); | |
92 exit(1); | |
93 case UNETOBJ_NET: | |
94 process_net(); | |
95 continue; | |
96 case UNETOBJ_COMPONENT: | |
97 process_component(); | |
98 continue; | |
99 case UNETOBJ_STARPOINT: | |
100 fprintf(stderr, | |
101 "error: STARPOINT objects not expected in unet-excise input (%s line %d)\n", | |
102 input_filename, rdstate.lineno); | |
103 exit(1); | |
104 default: | |
105 fprintf(stderr, | |
106 "%s line %d: unexpected object type %s\n", | |
107 input_filename, rdstate.lineno, rdout.keyword); | |
108 exit(1); | |
109 } | |
110 } | |
111 } | |
112 | |
113 main(argc, argv) | |
114 char **argv; | |
115 { | |
116 if (argc < 3) { | |
117 fprintf(stderr, "usage: %s input.unet excise-net[s]\n", | |
118 argv[0]); | |
119 exit(1); | |
120 } | |
121 input_filename = argv[1]; | |
122 excise_nets = argv + 2; | |
123 process_input_unet(); | |
124 exit(0); | |
125 } |