diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index cc36ea172..74366204d 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -1457,15 +1457,6 @@ struct AstCondBound : public AstNodeCond { ASTNODE_NODE_FUNCS(CondBound, CONDBOUND) }; -struct AstCondD : public AstNodeCond { - // Conditional ?: statement, double rhs/lhs/out - // Parents: MATH - // Children: MATH - AstCondD(FileLine* fl, AstNode* condp, AstNode* expr1p, AstNode* expr2p) - : AstNodeCond(fl, condp, expr1p, expr2p) { numeric(AstNumeric::DOUBLE); } - ASTNODE_NODE_FUNCS(CondD, CONDD) -}; - struct AstCoverDecl : public AstNodeStmt { // Coverage analysis point declaration // Parents: {statement list} @@ -3988,25 +3979,6 @@ struct AstCReturn : public AstNodeStmt { AstNode* lhsp() const { return op1p(); } }; -struct AstCInclude : public AstNode { - // C++ use of another class - // Parents: MODULE - // Children: None -private: - AstNodeModule* m_modp; -public: - AstCInclude(FileLine* fl, AstNodeModule* modp) - : AstNode(fl) { - m_modp = modp; - } - ASTNODE_NODE_FUNCS(CInclude, CINCLUDE) - virtual bool broken() const { return (m_modp && !m_modp->brokeExists()); } - virtual void cloneRelink() { if (m_modp && m_modp->clonep()) { - m_modp = m_modp->clonep()->castNodeModule(); - }} - AstNodeModule* modp() const { return m_modp; } -}; - struct AstCMath : public AstNodeMath { private: bool m_cleanOut; diff --git a/src/astgen b/src/astgen index a94e61133..c164208c8 100755 --- a/src/astgen +++ b/src/astgen @@ -7,28 +7,36 @@ use Getopt::Long; use IO::File; use Pod::Usage; use strict; -use vars qw ($Debug @Types %Classes); +use vars qw ($Debug @Types %Classes %ClassRefs %Stages); #====================================================================== # main $Debug = 0; my $opt_classes; +my $opt_report; my @Opt_Cpt; my @Opt_I; Getopt::Long::config ("pass_through", "no_auto_abbrev"); if (! GetOptions ( - "help" => \&usage, - "debug" => \&debug, - "classes!" => \$opt_classes, - "<>" => \¶meter, - )) { + "help" => \&report, + "debug" => \&debug, + "classes!" => \$opt_classes, + "report!" => \$opt_report, + "<>" => \¶meter, + )) { usage(); } read_types("$Opt_I[0]/V3Ast.h"); read_types("$Opt_I[0]/V3AstNodes.h"); +read_stages("$Opt_I[0]/Verilator.cpp"); +read_refs(glob("$Opt_I[0]/*.y"), glob("$Opt_I[0]/*.h"), glob("$Opt_I[0]/*.cpp")); +if ($opt_report) { + write_report(undef); +} if ($opt_classes) { + write_report("V3Ast__gen_report.txt"); write_classes("V3Ast__gen_classes.h"); write_visitor("V3Ast__gen_visitor.h"); write_intf("V3Ast__gen_interface.h"); @@ -85,6 +93,44 @@ sub read_types { } } +sub read_stages { + my $filename = shift; + + my $fh = IO::File->new($filename) or die "%Error: $! $filename,"; + my $n = 0; + while (defined (my $line = $fh->getline())) { + $line =~ s/\/\/.*$//; + next if $line =~ /^\s*$/; + if ($line =~ /^\s*([A-Za-z0-9]+)::/) { + my $stage = $1.".cpp"; + if (!defined ($Stages{$stage})) { + $Stages{$stage} = $n++; + } + } + } +} + +sub read_refs { + my @filenames = @_; + + foreach my $filename (@filenames) { + (my $basename = $filename) =~ s!.*/!!; + my $fh = IO::File->new($filename) or die "%Error: $! $filename,"; + while (defined (my $line = $fh->getline())) { + $line =~ s/\/\/.*$//; + while ($line =~ /\bnew\s*(Ast[A-Za-z0-9_]+)/g) { + $ClassRefs{$1}{newed}{$basename} = 1; + } + while ($line =~ /\b(Ast[A-Za-z0-9_]+)/g) { + $ClassRefs{$1}{used}{$basename} = 1; + } + } + } + #use Data::Dumper;print Dumper(\%ClassRefs); +} + +#---------------------------------------------------------------------- + sub open_file { my $filename = shift; my $fh = IO::File->new($filename,"w") or die "%Error: $! $filename,"; @@ -108,6 +154,42 @@ sub subclasses_of { #---------------------------------------------------------------------- +sub write_report { + my $filename = shift; + my $fh = defined($filename) ? open_file($filename) : \*STDOUT; + + $fh->print("Processing stages (approximate, based on order in Verilator.cpp):\n"); + foreach my $class (sort {$Stages{$a} <=> $Stages{$b}} keys %Stages) { + $fh->print("\t$class\n"); + } + + $fh->print("\nProcessing stages (approximate, based on order in Verilator.cpp):\n"); + foreach my $type (sort (keys %Classes)) { + printf $fh " class %-20s\n", "Ast${type}"; + $fh->print("\tparent:\t"); + foreach my $subclass (subclasses_of($type)) { + next if $subclass eq 'Node'; + printf $fh "Ast%-12s ",$subclass; + } + printf $fh "\n"; + if (my $refs = $ClassRefs{"Ast${type}"}) { + $fh->print("\tnewed:\t"); + foreach my $stage (sort {($Stages{$a}||-1) <=> ($Stages{$b}||-1)} + keys %{$refs->{newed}}) { + $fh->print($stage." "); + } + $fh->print("\n"); + $fh->print("\tused:\t"); + foreach my $stage (sort {($Stages{$a}||-1) <=> ($Stages{$b}||-1)} + keys %{$refs->{used}}) { + $fh->print($stage." "); + } + $fh->print("\n"); + } + $fh->print("\n"); + } +} + sub write_classes { my $fh = open_file(@_); foreach my $type (sort (keys %Classes)) { @@ -501,7 +583,11 @@ Displays this message and program version and exits. =item --classes -Makes class declaration files +Makes class declaration files. + +=item --report + +Makes a report report. =back @@ -526,5 +612,5 @@ Wilson Snyder ###################################################################### ### Local Variables: -### compile-command: "./astgen " +### compile-command: "./astgen -I. --report" ### End: