28 #include <boost/iterator/indirect_iterator.hpp>
29 #include <boost/multi_index_container.hpp>
30 #include <boost/range/iterator_range.hpp>
85 using ModuleSet = boost::multi_index::multi_index_container<
86 Module*, boost::multi_index::indexed_by<
87 boost::multi_index::ordered_non_unique<
88 boost::multi_index::tag<by_name>,
89 boost::multi_index::const_mem_fun<
91 boost::multi_index::hashed_unique<
92 boost::multi_index::tag<by_pointer>,
93 boost::multi_index::identity<Module*>>>>;
95 class ModuleObserverImpl;
128 boost::indirect_iterator<ModuleSet::const_iterator, const Module>;
153 return boost::make_iterator_range(modules_begin(), modules_end());
157 return boost::make_iterator_range(modules_begin(), modules_end());
164 using module_name_iterator =
165 boost::indirect_iterator<ModuleSet::index<by_name>::type::iterator>;
176 boost::indirect_iterator<ModuleSet::index<by_name>::type::const_iterator,
183 boost::iterator_range<const_module_name_iterator>;
193 auto& Index = Modules.get<by_pointer>();
194 if (
auto Iter = Index.find(M); Iter != Index.end()) {
198 M->setParent(
nullptr,
nullptr);
215 M->setParent(
this, MO.get());
228 return addModule(Module::Create(C, A...));
238 auto Found = Modules.get<by_name>().equal_range(N);
239 return boost::make_iterator_range(Found.first, Found.second);
249 auto Found = Modules.get<by_name>().equal_range(N);
250 return boost::make_iterator_range(Found.first, Found.second);
261 void save(std::ostream& Out)
const;
268 void saveJSON(std::ostream& Out)
const;
274 IncorrectVersion = 1,
306 ArbitraryLess<ProxyBlock>>;
312 ArbitraryLess<ProxyBlock>>;
315 boost::iterator_range<const_proxy_block_iterator>;
320 boost::make_transform_iterator(this->modules_begin(),
321 NodeToProxyBlockRange<Module>()),
322 boost::make_transform_iterator(this->modules_end(),
323 NodeToProxyBlockRange<Module>()));
332 return boost::make_iterator_range(proxy_blocks_begin(), proxy_blocks_end());
338 boost::make_transform_iterator(this->modules_begin(),
339 NodeToProxyBlockRange<const Module>()),
340 boost::make_transform_iterator(this->modules_end(),
341 NodeToProxyBlockRange<const Module>()));
352 return boost::make_iterator_range(proxy_blocks_begin(), proxy_blocks_end());
363 using symbol_iterator =
364 MergeSortedIterator<Module::symbol_iterator, ArbitraryLess<Symbol>>;
373 MergeSortedIterator<Module::const_symbol_iterator, ArbitraryLess<Symbol>>;
382 boost::make_transform_iterator(this->modules_begin(),
383 NodeToSymbolRange<Module>()),
384 boost::make_transform_iterator(this->modules_end(),
385 NodeToSymbolRange<Module>()));
393 return boost::make_iterator_range(symbols_begin(), symbols_end());
399 boost::make_transform_iterator(this->modules_begin(),
400 NodeToSymbolRange<const Module>()),
401 boost::make_transform_iterator(this->modules_end(),
402 NodeToSymbolRange<const Module>()));
410 return boost::make_iterator_range(symbols_begin(), symbols_end());
419 using section_iterator =
420 MergeSortedIterator<Module::section_iterator, AddressLess>;
425 MergeSortedIterator<Module::section_subrange::iterator, AddressLess>>;
428 MergeSortedIterator<Module::const_section_iterator, AddressLess>;
433 Module::const_section_subrange::iterator, AddressLess>>;
436 MergeSortedIterator<Module::section_name_iterator, AddressLess>;
441 MergeSortedIterator<Module::const_section_name_iterator, AddressLess>;
444 boost::iterator_range<const_section_name_iterator>;
449 boost::make_transform_iterator(this->modules_begin(),
450 NodeToSectionRange<Module>()),
451 boost::make_transform_iterator(this->modules_end(),
452 NodeToSectionRange<Module>()));
460 return boost::make_iterator_range(sections_begin(), sections_end());
466 boost::make_transform_iterator(this->modules_begin(),
467 NodeToSectionRange<const Module>()),
468 boost::make_transform_iterator(this->modules_end(),
469 NodeToSectionRange<const Module>()));
479 return boost::make_iterator_range(sections_begin(), sections_end());
489 section_subrange::iterator(
490 boost::make_transform_iterator(this->modules_begin(),
491 FindSectionsIn<Module>(A)),
492 boost::make_transform_iterator(this->modules_end(),
493 FindSectionsIn<Module>(A))),
494 section_subrange::iterator());
504 const_section_subrange::iterator(
505 boost::make_transform_iterator(this->modules_begin(),
506 FindSectionsIn<const Module>(A)),
507 boost::make_transform_iterator(this->modules_end(),
508 FindSectionsIn<const Module>(A))),
509 const_section_subrange::iterator());
519 section_range::iterator(
520 boost::make_transform_iterator(this->modules_begin(),
521 FindSectionsAt<Module>(A)),
522 boost::make_transform_iterator(this->modules_end(),
523 FindSectionsAt<Module>(A))),
524 section_range::iterator());
535 section_range::iterator(
536 boost::make_transform_iterator(
537 this->modules_begin(), FindSectionsBetween<Module>(Low, High)),
538 boost::make_transform_iterator(
539 this->modules_end(), FindSectionsBetween<Module>(Low, High))),
540 section_range::iterator());
550 const_section_range::iterator(
551 boost::make_transform_iterator(this->modules_begin(),
552 FindSectionsAt<const Module>(A)),
553 boost::make_transform_iterator(this->modules_end(),
554 FindSectionsAt<const Module>(A))),
555 const_section_range::iterator());
566 const_section_range::iterator(
567 boost::make_transform_iterator(
568 this->modules_begin(),
569 FindSectionsBetween<const Module>(Low, High)),
570 boost::make_transform_iterator(
572 FindSectionsBetween<const Module>(Low, High))),
573 const_section_range::iterator());
582 section_name_range::iterator(
583 boost::make_transform_iterator(this->modules_begin(),
584 FindSections<Module>(X)),
585 boost::make_transform_iterator(this->modules_end(),
586 FindSections<Module>(X))),
587 section_name_range::iterator());
597 const_section_name_range::iterator(
598 boost::make_transform_iterator(this->modules_begin(),
599 FindSections<const Module>(X)),
600 boost::make_transform_iterator(this->modules_end(),
601 FindSections<const Module>(X))),
602 const_section_name_range::iterator());
611 using byte_interval_iterator =
612 MergeSortedIterator<Module::byte_interval_iterator, AddressLess>;
617 Module::byte_interval_subrange::iterator, AddressLess>>;
620 MergeSortedIterator<Module::const_byte_interval_iterator, AddressLess>;
623 boost::iterator_range<const_byte_interval_iterator>;
626 boost::iterator_range<MergeSortedIterator<
627 Module::const_byte_interval_subrange::iterator, AddressLess>>;
632 boost::make_transform_iterator(this->modules_begin(),
633 NodeToByteIntervalRange<Module>()),
634 boost::make_transform_iterator(this->modules_end(),
635 NodeToByteIntervalRange<Module>()));
646 return boost::make_iterator_range(byte_intervals_begin(),
647 byte_intervals_end());
653 boost::make_transform_iterator(this->modules_begin(),
654 NodeToByteIntervalRange<const Module>()),
655 boost::make_transform_iterator(
656 this->modules_end(), NodeToByteIntervalRange<const Module>()));
667 return boost::make_iterator_range(byte_intervals_begin(),
668 byte_intervals_end());
680 byte_interval_subrange::iterator(
681 boost::make_transform_iterator(this->modules_begin(),
682 FindByteIntervalsIn<Module>(A)),
683 boost::make_transform_iterator(this->modules_end(),
684 FindByteIntervalsIn<Module>(A))),
685 byte_interval_subrange::iterator());
697 const_byte_interval_subrange::iterator(
698 boost::make_transform_iterator(
699 this->modules_begin(), FindByteIntervalsIn<const Module>(A)),
700 boost::make_transform_iterator(
701 this->modules_end(), FindByteIntervalsIn<const Module>(A))),
702 const_byte_interval_subrange::iterator());
712 byte_interval_range::iterator(
713 boost::make_transform_iterator(this->modules_begin(),
714 FindByteIntervalsAt<Module>(A)),
715 boost::make_transform_iterator(this->modules_end(),
716 FindByteIntervalsAt<Module>(A))),
717 byte_interval_range::iterator());
729 byte_interval_range::iterator(
730 boost::make_transform_iterator(
731 this->modules_begin(),
732 FindByteIntervalsBetween<Module>(Low, High)),
733 boost::make_transform_iterator(
735 FindByteIntervalsBetween<Module>(Low, High))),
736 byte_interval_range::iterator());
746 const_byte_interval_range::iterator(
747 boost::make_transform_iterator(
748 this->modules_begin(), FindByteIntervalsAt<const Module>(A)),
749 boost::make_transform_iterator(
750 this->modules_end(), FindByteIntervalsAt<const Module>(A))),
751 const_byte_interval_range::iterator());
763 const_byte_interval_range::iterator(
764 boost::make_transform_iterator(
765 this->modules_begin(),
766 FindByteIntervalsBetween<const Module>(Low, High)),
767 boost::make_transform_iterator(
769 FindByteIntervalsBetween<const Module>(Low, High))),
770 const_byte_interval_range::iterator());
783 MergeSortedIterator<Module::block_iterator, BlockAddressLess>;
794 MergeSortedIterator<Module::block_subrange::iterator, BlockAddressLess>>;
800 MergeSortedIterator<Module::const_block_iterator, BlockAddressLess>;
811 Module::const_block_subrange::iterator, BlockAddressLess>>;
816 boost::make_transform_iterator(this->modules_begin(),
817 NodeToBlockRange<Module>()),
818 boost::make_transform_iterator(this->modules_end(),
819 NodeToBlockRange<Module>()));
827 return boost::make_iterator_range(blocks_begin(), blocks_end());
833 boost::make_transform_iterator(this->modules_begin(),
834 NodeToBlockRange<const Module>()),
835 boost::make_transform_iterator(this->modules_end(),
836 NodeToBlockRange<const Module>()));
844 return boost::make_iterator_range(blocks_begin(), blocks_end());
856 block_subrange::iterator(
857 boost::make_transform_iterator(this->modules_begin(),
858 FindBlocksIn<Module>(A)),
859 boost::make_transform_iterator(this->modules_end(),
860 FindBlocksIn<Module>(A))),
861 block_subrange::iterator());
873 const_block_subrange::iterator(
874 boost::make_transform_iterator(this->modules_begin(),
875 FindBlocksIn<const Module>(A)),
876 boost::make_transform_iterator(this->modules_end(),
877 FindBlocksIn<const Module>(A))),
878 const_block_subrange::iterator());
889 boost::make_transform_iterator(
890 this->modules_begin(), FindBlocksAt<Module>(A)),
891 boost::make_transform_iterator(
892 this->modules_end(), FindBlocksAt<Module>(A))),
893 block_range::iterator());
905 block_range::iterator(
906 boost::make_transform_iterator(
907 this->modules_begin(), FindBlocksBetween<Module>(Low, High)),
908 boost::make_transform_iterator(
909 this->modules_end(), FindBlocksBetween<Module>(Low, High))),
910 block_range::iterator());
921 const_block_range::iterator(
922 boost::make_transform_iterator(this->modules_begin(),
923 FindBlocksAt<const Module>(A)),
924 boost::make_transform_iterator(this->modules_end(),
925 FindBlocksAt<const Module>(A))),
926 const_block_range::iterator());
938 const_block_range::iterator(
939 boost::make_transform_iterator(
940 this->modules_begin(),
941 FindBlocksBetween<const Module>(Low, High)),
942 boost::make_transform_iterator(
944 FindBlocksBetween<const Module>(Low, High))),
945 const_block_range::iterator());
957 using code_block_iterator =
958 MergeSortedIterator<Module::code_block_iterator, AddressLess>;
970 MergeSortedIterator<Module::code_block_subrange::iterator, AddressLess>>;
976 MergeSortedIterator<Module::const_code_block_iterator, AddressLess>;
982 boost::iterator_range<const_code_block_iterator>;
988 Module::const_code_block_subrange::iterator, AddressLess>>;
993 boost::make_transform_iterator(this->modules_begin(),
994 NodeToCodeBlockRange<Module>()),
995 boost::make_transform_iterator(this->modules_end(),
996 NodeToCodeBlockRange<Module>()));
1005 return boost::make_iterator_range(code_blocks_begin(), code_blocks_end());
1011 boost::make_transform_iterator(this->modules_begin(),
1012 NodeToCodeBlockRange<const Module>()),
1013 boost::make_transform_iterator(this->modules_end(),
1014 NodeToCodeBlockRange<const Module>()));
1025 return boost::make_iterator_range(code_blocks_begin(), code_blocks_end());
1036 code_block_subrange::iterator(
1037 boost::make_transform_iterator(this->modules_begin(),
1038 FindCodeBlocksIn<Module>(A)),
1039 boost::make_transform_iterator(this->modules_end(),
1040 FindCodeBlocksIn<Module>(A))),
1041 code_block_subrange::iterator());
1052 const_code_block_subrange::iterator(
1053 boost::make_transform_iterator(this->modules_begin(),
1054 FindCodeBlocksIn<const Module>(A)),
1055 boost::make_transform_iterator(this->modules_end(),
1056 FindCodeBlocksIn<const Module>(A))),
1057 const_code_block_subrange::iterator());
1067 code_block_range::iterator(
1068 boost::make_transform_iterator(this->modules_begin(),
1069 FindCodeBlocksAt<Module>(A)),
1070 boost::make_transform_iterator(this->modules_end(),
1071 FindCodeBlocksAt<Module>(A))),
1072 code_block_range::iterator());
1083 code_block_range::iterator(
1084 boost::make_transform_iterator(
1085 this->modules_begin(),
1086 FindCodeBlocksBetween<Module>(Low, High)),
1087 boost::make_transform_iterator(
1088 this->modules_end(), FindCodeBlocksBetween<Module>(Low, High))),
1089 code_block_range::iterator());
1099 const_code_block_range::iterator(
1100 boost::make_transform_iterator(this->modules_begin(),
1101 FindCodeBlocksAt<const Module>(A)),
1102 boost::make_transform_iterator(this->modules_end(),
1103 FindCodeBlocksAt<const Module>(A))),
1104 const_code_block_range::iterator());
1115 const_code_block_range::iterator(
1116 boost::make_transform_iterator(
1117 this->modules_begin(),
1118 FindCodeBlocksBetween<const Module>(Low, High)),
1119 boost::make_transform_iterator(
1120 this->modules_end(),
1121 FindCodeBlocksBetween<const Module>(Low, High))),
1122 const_code_block_range::iterator());
1134 using data_block_iterator =
1135 MergeSortedIterator<Module::data_block_iterator, AddressLess>;
1147 MergeSortedIterator<Module::data_block_subrange::iterator, AddressLess>>;
1153 MergeSortedIterator<Module::const_data_block_iterator, AddressLess>;
1158 boost::iterator_range<const_data_block_iterator>;
1165 Module::const_data_block_subrange::iterator, AddressLess>>;
1170 boost::make_transform_iterator(this->modules_begin(),
1171 NodeToDataBlockRange<Module>()),
1172 boost::make_transform_iterator(this->modules_end(),
1173 NodeToDataBlockRange<Module>()));
1182 return boost::make_iterator_range(data_blocks_begin(), data_blocks_end());
1188 boost::make_transform_iterator(this->modules_begin(),
1189 NodeToDataBlockRange<const Module>()),
1190 boost::make_transform_iterator(this->modules_end(),
1191 NodeToDataBlockRange<const Module>()));
1202 return boost::make_iterator_range(data_blocks_begin(), data_blocks_end());
1213 data_block_subrange::iterator(
1214 boost::make_transform_iterator(this->modules_begin(),
1215 FindDataBlocksIn<Module>(A)),
1216 boost::make_transform_iterator(this->modules_end(),
1217 FindDataBlocksIn<Module>(A))),
1218 data_block_subrange::iterator());
1229 const_data_block_subrange::iterator(
1230 boost::make_transform_iterator(this->modules_begin(),
1231 FindDataBlocksIn<const Module>(A)),
1232 boost::make_transform_iterator(this->modules_end(),
1233 FindDataBlocksIn<const Module>(A))),
1234 const_data_block_subrange::iterator());
1244 data_block_range::iterator(
1245 boost::make_transform_iterator(this->modules_begin(),
1246 FindDataBlocksAt<Module>(A)),
1247 boost::make_transform_iterator(this->modules_end(),
1248 FindDataBlocksAt<Module>(A))),
1249 data_block_range::iterator());
1260 data_block_range::iterator(
1261 boost::make_transform_iterator(
1262 this->modules_begin(),
1263 FindDataBlocksBetween<Module>(Low, High)),
1264 boost::make_transform_iterator(
1265 this->modules_end(), FindDataBlocksBetween<Module>(Low, High))),
1266 data_block_range::iterator());
1276 const_data_block_range::iterator(
1277 boost::make_transform_iterator(this->modules_begin(),
1278 FindDataBlocksAt<const Module>(A)),
1279 boost::make_transform_iterator(this->modules_end(),
1280 FindDataBlocksAt<const Module>(A))),
1281 const_data_block_range::iterator());
1292 const_data_block_range::iterator(
1293 boost::make_transform_iterator(
1294 this->modules_begin(),
1295 FindDataBlocksBetween<const Module>(Low, High)),
1296 boost::make_transform_iterator(
1297 this->modules_end(),
1298 FindDataBlocksBetween<const Module>(Low, High))),
1299 const_data_block_range::iterator());
1310 using symbolic_expression_iterator =
1317 boost::iterator_range<symbolic_expression_iterator>;
1328 boost::iterator_range<const_symbolic_expression_iterator>;
1333 boost::make_transform_iterator(this->modules_begin(),
1334 NodeToSymbolicExpressionRange<Module>()),
1335 boost::make_transform_iterator(
1336 this->modules_end(), NodeToSymbolicExpressionRange<Module>()));
1347 return boost::make_iterator_range(symbolic_expressions_begin(),
1348 symbolic_expressions_end());
1354 boost::make_transform_iterator(
1355 this->modules_begin(),
1356 NodeToSymbolicExpressionRange<const Module>()),
1357 boost::make_transform_iterator(
1358 this->modules_end(),
1359 NodeToSymbolicExpressionRange<const Module>()));
1370 return boost::make_iterator_range(symbolic_expressions_begin(),
1371 symbolic_expressions_end());
1382 symbolic_expression_range::iterator(
1383 boost::make_transform_iterator(this->modules_begin(),
1384 FindSymExprsAt<Module>(A)),
1385 boost::make_transform_iterator(this->modules_end(),
1386 FindSymExprsAt<Module>(A))),
1387 symbolic_expression_range::iterator());
1400 symbolic_expression_range::iterator(
1401 boost::make_transform_iterator(
1402 this->modules_begin(), FindSymExprsBetween<Module>(Low, High)),
1403 boost::make_transform_iterator(
1404 this->modules_end(), FindSymExprsBetween<Module>(Low, High))),
1405 symbolic_expression_range::iterator());
1416 const_symbolic_expression_range::iterator(
1417 boost::make_transform_iterator(this->modules_begin(),
1418 FindSymExprsAt<const Module>(A)),
1419 boost::make_transform_iterator(this->modules_end(),
1420 FindSymExprsAt<const Module>(A))),
1421 const_symbolic_expression_range::iterator());
1435 const_symbolic_expression_range::iterator(
1436 boost::make_transform_iterator(
1437 this->modules_begin(),
1438 FindSymExprsBetween<const Module>(Low, High)),
1439 boost::make_transform_iterator(
1440 this->modules_end(),
1441 FindSymExprsBetween<const Module>(Low, High))),
1442 const_symbolic_expression_range::iterator());
1448 static bool classof(
const Node* N) {
return N->getKind() == Kind::IR; }
1468 using MessageType = proto::IR;
1475 void toProtobuf(MessageType* Message)
const;
1490 std::unique_ptr<ModuleObserver> MO;
1510 struct is_error_code_enum<
gtirb::IR::load_error> : std::true_type {};
1513 #endif // GTIRB_IR_H