217 hasElementType(hasUnqualifiedDesugaredType(
220 cxxRecordDecl(hasName(name)).bind(
"desugar_"+name)
229 hasElementType(hasUnqualifiedDesugaredType(
230 arrayType(hasElementType(hasUnqualifiedDesugaredType(
240 hasElementType(hasUnqualifiedDesugaredType(
241 arrayType(hasElementType(hasUnqualifiedDesugaredType(
242 arrayType(hasElementType(hasUnqualifiedDesugaredType(
255 hasType(hasUnqualifiedDesugaredType(
259 cxxRecordDecl(hasName(name)).bind(
"desugar_"+name)
265 cxxRecordDecl(hasName(name)).bind(
"desugar_"+name)
311 llvm::StringRef base_class{
"::sc_core::sc_module"};
315 hasType(hasUnqualifiedDesugaredType(
321 isDerivedFrom(hasName(
"::sc_core::sc_module")),
322 unless(isDerivedFrom(matchesName(
"sc_event_queue")))
334 hasElementType(hasUnqualifiedDesugaredType(
343 hasElementType(hasUnqualifiedDesugaredType(
344 arrayType(hasElementType(
356 ).bind(
"submodule_fd");
393 if (
auto *fd = dyn_cast<clang::FieldDecl>(decl)) {
394 name = fd->getIdentifier()->getNameStart();
400 if (sizes.size() > 0 ) {
401 new_pd->setArrayType();
402 for (
auto const &array_size : sizes ) {
403 new_pd->addArraySize(array_size);
407 auto port_entry{std::make_tuple(name, new_pd)};
408 port.push_back(port_entry);
412 if (
auto *vd = dyn_cast<clang::VarDecl>(decl)) {
413 name = vd->getIdentifier()->getNameStart();
416 auto field_type{vd->getType()};
418 auto array_type{dyn_cast<ConstantArrayType>(field_type)};
420 new_pd->setArrayType();
421 while (array_type !=
nullptr) {
422 llvm::APInt array_size{};
423 array_size = array_type->getSize();
424 LLVM_DEBUG(llvm::dbgs()
425 <<
"Size of array: " << array_size <<
"\n";);
427 dyn_cast<ConstantArrayType>(array_type->getElementType());
429 new_pd->addArraySize(array_size);
433 auto port_entry{std::make_tuple(name, new_pd)};
434 port.push_back(port_entry);
445 auto match_module_decls =
449 unless( isImplicit() ),
451 hasName(
"::sc_core::sc_module")
453 unless(isDerivedFrom(matchesName(
"sc_event_queue")))
458 auto match_sc_ports = cxxRecordDecl(
463 cxxRecordDecl(isDerivedFrom(hasName(
"sc_port")))
469 auto match_all_ports = cxxRecordDecl(
494 auto match_non_sc_types_fdecl =
511 ).bind(
"other_fvdecl")));
513 auto match_non_sc_types_vdecl = cxxRecordDecl(
529 ).bind(
"other_fvdecl")));
531 auto match_submodules = cxxRecordDecl(
539 finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, match_all_ports) ,
this);
540 finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, match_non_sc_types_fdecl),
this);
541 finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, match_non_sc_types_vdecl),
this);
546 virtual void run(
const MatchFinder::MatchResult &result) {
552 auto sc_signal_field{
554 auto sc_stream_in_field{
556 auto sc_stream_out_field{
558 auto sc_rvd_in_field{
560 auto sc_rvd_out_field{
574 auto name{submodule_fd->getNameAsString()};
575 LLVM_DEBUG(llvm::dbgs() <<
"Found submodule: " << name <<
"\n");
579 if (sc_in_field && other_fields) {
580 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
582 auto port_name{fd->getIdentifier()->getNameStart()};
583 LLVM_DEBUG(llvm::dbgs() <<
" Found sc_in: " << port_name <<
"\n");
588 if (sc_out_field && other_fields) {
589 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
591 auto port_name{fd->getIdentifier()->getNameStart()};
592 LLVM_DEBUG(llvm::dbgs() <<
" Found sc_out: " << port_name <<
"\n");
598 if (sc_inout_field && other_fields) {
599 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
601 auto port_name{fd->getIdentifier()->getNameStart()};
602 LLVM_DEBUG(llvm::dbgs() <<
" Found sc_inout: " << port_name <<
"\n");
607 if (sc_signal_field && other_fields) {
608 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
610 auto signal_name{fd->getIdentifier()->getNameStart()};
611 llvm::dbgs() <<
" Found sc_signal: " << signal_name <<
"\n";
616 if (sc_stream_in_field && other_fields) {
617 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
619 auto field_name{fd->getIdentifier()->getNameStart()};
620 LLVM_DEBUG(llvm::dbgs()
621 <<
" Found sc_stream_in: " << field_name <<
"\n");
626 if (sc_stream_out_field && other_fields) {
627 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
629 auto field_name{fd->getIdentifier()->getNameStart()};
630 LLVM_DEBUG(llvm::dbgs()
631 <<
" Found sc_stream_out: " << field_name <<
"\n");
636 if (sc_rvd_in_field && other_fields) {
637 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
639 auto field_name{fd->getIdentifier()->getNameStart()};
640 LLVM_DEBUG(llvm::dbgs() <<
" Found sc_rvd_in: " << field_name <<
"\n");
645 if (sc_rvd_out_field && other_fields) {
646 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
648 auto field_name{fd->getIdentifier()->getNameStart()};
649 LLVM_DEBUG(llvm::dbgs() <<
" Found sc_rvd_out: " << field_name <<
"\n");
654 if (sc_port_field && other_fields) {
655 if (
auto *p_field{dyn_cast<clang::FieldDecl>(other_fields)}) {
657 auto field_name{fd->getIdentifier()->getNameStart()};
658 LLVM_DEBUG(llvm::dbgs() <<
" Found sc_port : " << field_name <<
"\n");
663 auto is_ports{(sc_in_field) || sc_out_field || sc_inout_field ||
664 sc_signal_field || sc_stream_in_field || sc_stream_out_field};
669 auto fd{other_fvdecl};
671 LLVM_DEBUG(llvm::dbgs() <<
"Print out the other fd\n");
673 if (
auto *p_field{dyn_cast<clang::FieldDecl>(fd)}) {
674 auto field_name{p_field->getIdentifier()->getNameStart()};
675 LLVM_DEBUG(llvm::dbgs()
676 <<
" Found field other_fields: " << field_name <<
"\n");
682 auto *p_var{dyn_cast<clang::VarDecl>(fd)};
683 auto field_name{p_var->getIdentifier()->getNameStart()};
684 LLVM_DEBUG(llvm::dbgs()
685 <<
" Found var other_fields: " << field_name <<
"\n");