1 /*
2 * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com)
3 *
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 # include "fpga_priv.h"
21 # include <string.h>
22 # include <stdlib.h>
23 # include "ivl_alloc.h"
24
xnf_mangle_scope_name(ivl_scope_t net,char * buf,size_t nbuf)25 static size_t xnf_mangle_scope_name(ivl_scope_t net, char*buf, size_t nbuf)
26 {
27 unsigned cnt = 0;
28 ivl_scope_t parent = ivl_scope_parent(net);
29
30 if (parent) {
31 cnt = xnf_mangle_scope_name(parent, buf, nbuf);
32 buf += cnt;
33 nbuf -= cnt;
34 *buf++ = '/';
35 nbuf -= 1;
36 cnt += 1;
37 }
38
39 strcpy(buf, ivl_scope_basename(net));
40 cnt += strlen(buf);
41
42 return cnt;
43 }
44
xnf_mangle_logic_name(ivl_net_logic_t net,char * buf,size_t nbuf)45 void xnf_mangle_logic_name(ivl_net_logic_t net, char*buf, size_t nbuf)
46 {
47 size_t cnt = xnf_mangle_scope_name(ivl_logic_scope(net), buf, nbuf);
48 buf[cnt++] = '/';
49 strcpy(buf+cnt, ivl_logic_basename(net));
50 }
51
xnf_mangle_lpm_name(ivl_lpm_t net,char * buf,size_t nbuf)52 void xnf_mangle_lpm_name(ivl_lpm_t net, char*buf, size_t nbuf)
53 {
54 size_t cnt = xnf_mangle_scope_name(ivl_lpm_scope(net), buf, nbuf);
55 buf[cnt++] = '/';
56 strcpy(buf+cnt, ivl_lpm_basename(net));
57 }
58
59 /*
60 * Nexus names are used in pin records to connect things together. It
61 * almost doesn't matter what the nexus name is, but for readability
62 * we choose a name that is close to the nexus name. This function
63 * converts the existing name to a name that XNF can use.
64 *
65 * For speed, this function saves the calculated string into the real
66 * nexus by using the private pointer. Every nexus is used at least
67 * twice, so this cuts the mangling time in half at least.
68 */
xnf_mangle_nexus_name(ivl_nexus_t net)69 const char* xnf_mangle_nexus_name(ivl_nexus_t net)
70 {
71 char*name = ivl_nexus_get_private(net);
72 char*cp;
73
74 if (name != 0) {
75 return name;
76 }
77
78 name = malloc(strlen(ivl_nexus_name(net)) + 1);
79 strcpy(name, ivl_nexus_name(net));
80
81 for (cp = name ; *cp ; cp += 1) switch (*cp) {
82
83 case '.':
84 *cp = '/';
85 break;
86 default:
87 break;
88 }
89
90 ivl_nexus_set_private(net, name);
91 return name;
92 }
93