Parse IP-XACT component description.
86 {
88 using boost::property_tree::ptree;
89
90 ptree pt;
91 read_xml(file, pt);
92 boost::optional<ptree&> parameters =
93 pt.get_child_optional("ipxact:component.ipxact:parameters");
94 ptree ports = pt.get_child("ipxact:component.ipxact:model.ipxact:ports");
95 module.name = pt.get_child("ipxact:component.ipxact:name").data();
96
97
98 if (parameters) {
99 for (auto&& p : *parameters) {
100 if (p.first == "ipxact:parameter") {
101 std::string id =
102 p.second.get_child("<xmlattr>.parameterId").data();
103 std::string type =
104 p.second.get_child("<xmlattr>.type").data();
105 std::string name = p.second.get_child("ipxact:name").data();
106 std::string value = p.second.get_child("ipxact:value").data();
107 Parameter parameter = {id, type, name, value};
108 module.parameters.emplace_back(parameter);
109 }
110 }
111 }
112
113
114 for (auto&& p : ports) {
115 if (p.first == "ipxact:port") {
116 std::string name = p.second.get_child("ipxact:name").data();
117 std::string direction =
118 p.second.get_child("ipxact:wire.ipxact:direction").data();
119 std::transform(
120 direction.begin(), direction.end(), direction.begin(),
121 ::tolower);
122 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
123 bool vector = false;
124 std::string left = "0";
125 std::string right = "0";
126 std::string width = "0";
127 ptree wire = p.second.get_child("ipxact:wire");
128 for (auto&& w : wire) {
129 if (w.first == "ipxact:vectors") {
130 vector = true;
131 left = w.second.get_child("ipxact:vector.ipxact:left")
132 .data();
133 width = left;
134 right = w.second.get_child("ipxact:vector.ipxact:right")
135 .data();
136 }
137 }
138
139 for (auto&& m : module.parameters) {
140 boost::regex expr("\\b" + m.id + "\\b");
141 width = boost::regex_replace(width, expr, m.value);
142 left = boost::regex_replace(left, expr, m.name);
143 right = "0";
144 }
145 width += "+1";
146
147 module.ports.emplace_back(
148 Port{name, direction, vector, left, right, width, ""});
149 }
150 }
151
152 return module;
153}