⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 if_ath_hal_generator.pl.svn-base

📁 最新之atheros芯片driver source code, 基于linux操作系统,內含atheros芯片HAL全部代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
#endif				/* #ifndef _IF_ATH_HAL_H_ */ /* *** THIS IS A GENERATED FILE -- DO NOT EDIT *** */ /* *** THIS IS A GENERATED FILE -- DO NOT EDIT *** */ /* *** THIS IS A GENERATED FILE -- DO NOT EDIT *** */EOF  ;# Parsed Function Data# hash of string->string (hal's function name to return type)my %return_types = ();# hash of string->list of strings (ordered list of parameter names)my %parameter_names = ();# hash of string->list of strings (ordered list of parameter types)my %parameter_types = ();# Pick apart the return type, parameter types, and parameter names for each HAL functionsub parse_prototype($) {    my $proto = shift @_;    $proto =~/^((?:(?:const|struct)\s*)*[^\s]+(?:[\s]*\*)?)[\s]*__ahdecl\(\*([^\)]*)\)\((.*)\);/;    my $return_type   = $1;    my $member_name   = $2;    my $parameterlist = $3;    my $api_name = $wrapper_names{$member_name};    if ( exists $wrapper_names{$member_name} ) {        if ( !defined $api_name ) {            return;    # known name, but no wrapper needed        }    }    else {        print STDERR "No wrapper name for $member_name\n";        exit 1;    }    $return_types{"$member_name"} = $return_type;    @{ $parameter_names{"$member_name"} } = ();    @{ $parameter_types{"$member_name"} } = ();    my @parameters = split /,\s?/, $parameterlist;    my $argnum = 0;    foreach (@parameters) {        s/ \*/\* /;        /^((?:(?:const|struct|\*)\s*)*)([^\s]+\*?)\s*([^\s]*)\s*/;        my $type = "$1$2";        my $name = "$3";        if ( 0 == length($name) ) {            if ( $argnum == 0 && $type =~ /ath_hal/ ) {                $name = "ah";            }            else {                $name = "a$argnum";            }        }        push @{ $parameter_names{$member_name} }, $name;        push @{ $parameter_types{$member_name} }, $type;        $argnum++;    }}# Parse and scrub the hal structure's member function declarationssub parse_input() {    my $line_continued = 0;    my $line_buffer    = "";    foreach (<INPUT>) {        chomp($_);        s/\s+$//g;        s/^\s+//g;        s/\s+/ /g;        if ( /__ahdecl\s*\(.*/ || $line_continued ) {            $line_buffer .= "$_";            if ( /__ahdecl.*;/ || ( $line_continued && /;/ ) ) {                parse_prototype($line_buffer);                $line_buffer    = "";                $line_continued = 0;            }            else {                $line_buffer .= " ";                $line_continued = 1;            }        }    }}# Arrange spaces in the type name nicelysub format_type($) {    my $type = shift @_;    if ( $type =~ /\*$/ ) {        $type =~ s/^([^*]*[^*\s])\s*(\*+)$/$1 $2/;    }    else {        $type .= " ";    }    return $type;}# Generate the header filesub generate_output() {    print OUTPUT $header;    for my $member_name ( keys %return_types ) {        my $api_name        = $wrapper_names{$member_name};        my $api_return_type = $return_types{$member_name};        my $ret_void        = ( $api_return_type =~ /void/ );        print OUTPUT "\nstatic inline "          . format_type($api_return_type)          . "$api_name(";        my @names = @{ $parameter_names{$member_name} };        my @types = @{ $parameter_types{$member_name} };        for my $i ( 0 .. $#names ) {            if ($i) {                print OUTPUT ", ";            }            print OUTPUT format_type( $types[$i] ) . $names[$i];        }        print OUTPUT ")\n{";        if ( !$ret_void ) {            print OUTPUT "\n\t" . format_type($api_return_type) . "ret;";        }        print OUTPUT "\n\tATH_HAL_LOCK_IRQ(ah->ah_sc);";        print OUTPUT "\n\tath_hal_set_function(__func__);";        print OUTPUT "\n\tath_hal_set_device(SC_DEV_NAME(ah->ah_sc));";        print OUTPUT "\n\t";        if ( !$ret_void ) {            print OUTPUT "ret = ";        }        print OUTPUT "ah->$member_name(";        for my $j ( 0 .. $#names ) {            if ($j) {                print OUTPUT ", ";            }            print OUTPUT $names[$j];        }        print OUTPUT ");";        print OUTPUT "\n\tath_hal_set_function(NULL);";        print OUTPUT "\n\tath_hal_set_device(NULL);";        print OUTPUT "\n\tATH_HAL_UNLOCK_IRQ(ah->ah_sc);";        if ( !$ret_void ) {            print OUTPUT "\n\treturn ret;";        }        print OUTPUT "\n}\n";    }    print OUTPUT "\n/* Example script to create a HAL function unmangling SED script: ";    print OUTPUT "\n";    print OUTPUT "\n   dmesg -c &>/dev/null && iwpriv ath0 dump_hal_map && dmesg | \\";    print OUTPUT "\n           sed -n -r -e \"/zz[0-9a-f]{8}/ { s~^([^+]*)[^=]*=(.*)~s/\\1\\\/\\2 (\\1)/g~; p; } \" \\";    print OUTPUT "\n           >hal_unmangle.sed";    print OUTPUT "\n";    print OUTPUT "\n * Example usage:";    print OUTPUT "\n";    print OUTPUT "\n           tail -f /var/log/messages | sed -f hal_unmangle.sed ";    print OUTPUT "\n */";    print OUTPUT "\nstatic inline void ath_hal_dump_map(struct ath_hal* ah) {";    print OUTPUT "\n#ifdef CONFIG_KALLSYMS\n";    for my $member_name ( keys %return_types ) {	my $api_name        = $member_name;	my $api_return_type = $return_types{$member_name};	my $ret_void        = ( $api_return_type =~ /void/ );	print OUTPUT "\n\t/* "	  . format_type($api_return_type)	  . "$api_name(";	my @names = @{ $parameter_names{$member_name} };	my @types = @{ $parameter_types{$member_name} };	for my $i ( 0 .. $#names ) {	    if ($i) {		print OUTPUT ", ";	    }	    print OUTPUT format_type( $types[$i] ) . $names[$i];	}	print OUTPUT ") */";	print OUTPUT "\n\t__print_symbol(\"%s=" . $member_name 	   . "\\n\", (unsigned long)ah->"	   . $member_name . ");";    }    print OUTPUT "\n#else /* #ifdef CONFIG_KALLSYMS */\n";    print OUTPUT "\nprintk(\"To use this feature you must enable "	       . "CONFIG_KALLSYMS in your kernel.\");\n";    print OUTPUT "\n#endif /* #ifndef CONFIG_KALLSYMS */\n";    print OUTPUT "\n}\n";    print OUTPUT $footer;}sub main () {    # Get input and output files from the arguments    if ( $#ARGV != 1 ) {        print STDERR "Need two arguments: input and output\n";        exit 1;    }    my $input_header  = $ARGV[0];    my $output_header = $ARGV[1];    if ( !open INPUT, "<$input_header" ) {        die "Cannot open \"$input_header\": $!";    }    parse_input();    close INPUT;    if ( !open OUTPUT, ">$output_header" ) {        close INPUT;        die "Cannot open \"$output_header\": $!";    }    generate_output();    close OUTPUT;}main();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -