[Firebug-cvs] fireboard/tools/src/xlisten genc.pm,1.3,1.4
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2004-08-02 23:07:10
|
Update of /cvsroot/firebug/fireboard/tools/src/xlisten In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26430 Modified Files: genc.pm Log Message: Moved some of the generation code to subs. Index: genc.pm =================================================================== RCS file: /cvsroot/firebug/fireboard/tools/src/xlisten/genc.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** genc.pm 31 Jul 2004 00:25:13 -0000 1.3 --- genc.pm 2 Aug 2004 23:07:01 -0000 1.4 *************** *** 17,28 **** ! ## TODO ## ---------------------------------------------------------- ## Several things need to be done to make this viable for the ! ## kinds of messages we want to process. The first part is ## to get rid of the java type conversions, and preserve the ## structure as defined the tinyos header file. We can do this ## because nesc native types are identical to c native types. ! ## true; --- 17,32 ---- ! ## TODO for autogenerating C code. ## ---------------------------------------------------------- ## Several things need to be done to make this viable for the ! ## kinds of messages we want to process. The first part is ## to get rid of the java type conversions, and preserve the ## structure as defined the tinyos header file. We can do this ## because nesc native types are identical to c native types. ! ## ! ! ## Parts of this code were written for the NSF_ITR funded ! ## firebug project. ! true; *************** *** 43,46 **** --- 47,55 ---- } + $I = " "; + $smallskip = "\n\n"; + $medskip = "\n\n\n\n"; + $bigskip = "\n\n\n\n\n\n"; + print "/**\n"; print " * This class is automatically generated by mig. DO NOT EDIT THIS FILE.\n"; *************** *** 51,64 **** print "#include <stdio.h>\n"; print "#include <stdlib.h>\n"; ! $I = " "; ! $smallskip = "\n\n"; ! $medskip = "\n\n\n\n"; ! $bigskip = "\n\n\n\n\n\n"; ! print "typedef struct _$java_classname $java_classname;\n\n"; print "typedef struct _XbowSensorboardPacket XbowSensorboardPacket;\n"; print "// This struct is defined to keep gcc happy while the module\n"; print "// is under development. At some point in the near future, a\n"; --- 60,81 ---- print "#include <stdio.h>\n"; print "#include <stdlib.h>\n"; + print "#include <memory.h>\n"; ! print $medskip; + print "/** Private header is programmer specified for handling\n"; + print " * conversion functions, etc.\n */\n"; + print "//#include \"$java_classname\_private.h\"\n"; ! ! ! print $medskip; ! ! print "/** These need to be moved to a header file. */\n"; ! print "typedef struct _$java_classname $java_classname;\n"; print "typedef struct _XbowSensorboardPacket XbowSensorboardPacket;\n"; + print $smallskip; + print "// This struct is defined to keep gcc happy while the module\n"; print "// is under development. At some point in the near future, a\n"; *************** *** 71,122 **** print $medskip; ! print "struct _$java_classname {\n"; ! ## todo move this to sub print_msg_struct(). for (@fields) { ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; - ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! ! # This is clunky but will work. A better way to do it would be to store ! # the nested struct internally in the field array somehow. ! # Maybe a perl guru can figure that out. ! # What needs to be done is to find one of these, then ! # store it until all the members written out, ! # then print it. ! if ($field =~ /(.*)\.([^.]*)$/) { ! $struct = $1; ! $member = $2; ! #print STDERR $struct;#.", "$member."\n"; ! } ! ! ## Gets an array of format specifiers useful in *print* functions ! ## in libc. the @format array can be passed ! push(@format, &formatstring($type, $bitlength, 0)); ! $field =~ s/\./_/g; ! printf "$I$ctype $field;\n"; } - print "};"; - print $medskip; ! ## The get/set code is more to investigate the mechanics of ! ## the autogeneration of structs. It's probably more useful ! ## use the defined type directly, at least for now. ! ## ! ## todo move this to sub_get_set_methods() for (@fields) { ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); $field =~ s/\./_/g; ! print "void\n"; ! print "$java_classname\_set\_$field($java_classname * userdata, $ctype $field) {\n"; ! print " userdata->$field = $field\n"; ! print "}\n\n"; ! } --- 88,139 ---- print $medskip; ! # print "struct _$java_classname {\n"; ! # for (@fields) { ! # ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ! # ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! # if ($field =~ /(.*)\.([^.]*)$/) { ! # $struct = $1; ! # $member = $2; ! # } ! # push(@format, &formatstring($type, $bitlength, 0)); ! # $field =~ s/\./_/g; ! # printf "$I$ctype $field;\n"; ! # } ! # print "};"; + &gen_struct(); + print $medskip; + &gen_get_set(); + print $medskip; ! ## Default behavior is to return the input as output. ! ## User is responsible for "cooking" the data. for (@fields) { ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); ! $field =~ s/\./_/g; ! print "/** \@brief Default behavior is to return the input as output.\n"; ! print " * User is responsible for \"cooking\" the data.\n */\n"; ! print "static $ctype\n"; ! print "$field\_convert($ctype $field) {\n"; ! print " return $field;\n"; ! print "}\n\n"; } ! ## Function for cooking whole packet. Fields are ! ## by calling the individual "cook" functions for ! ## each member. ! print "void\n"; ! print "$java_classname\_cook\_packet($java_classname * userdata) {\n"; for (@fields) { ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); $field =~ s/\./_/g; ! print " userdata->$field = $field\_convert(userdata->$field);\n"; } + print "}\n\n"; *************** *** 196,199 **** --- 213,271 ---- } + sub gen_struct() { + + print "struct _$java_classname {\n"; + + ## todo move this to sub print_msg_struct(). + for (@fields) { + ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; + + ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); + + # This is clunky but will work. A better way to do it would be to store + # the nested struct internally in the field array somehow. + # Maybe a perl guru can figure that out. + # What needs to be done is to find one of these, then + # store it until all the members written out, + # then print it. + if ($field =~ /(.*)\.([^.]*)$/) { + $struct = $1; + $member = $2; + #print STDERR $struct;#.", "$member."\n"; + } + + ## Gets an array of format specifiers useful in *print* functions + ## in libc. the @format array can be passed + push(@format, &formatstring($type, $bitlength, 0)); + $field =~ s/\./_/g; + printf "$I$ctype $field;\n"; + } + print "};"; + } + + sub gen_get_set() { + + ## The get/set code is more to investigate the mechanics of + ## the autogeneration of structs. It's probably more useful + ## use the defined type directly, at least for now. + ## + ## todo move this to sub_get_set_methods() + for (@fields) { + ($field, $type, $bitlength, $offset, $amax, $abitsize, $aoffset) = @{$_}; + ($ctype, $java_access, $arrayspec) = &cbasetype($type, $bitlength, 0); + $field =~ s/\./_/g; + print "void\n"; + print "$java_classname\_set\_$field($java_classname * userdata, $ctype $field) {\n"; + print " userdata->$field = $field;\n"; + print "}\n\n"; + #### Get methods + print "$ctype\n"; + print "$java_classname\_get\_$field($java_classname * userdata) {\n"; + print " return userdata->$field;\n"; + print "}\n\n"; + } + } + + ## TODO Change all these back to the base types available in c, which are *************** *** 208,212 **** if ($basetype eq "U") { $acc = "UIntElement"; ! if ($bitlength < 8) { $jtype = "byte"; } elsif ($bitlength < 16) { $jtype = "uint8_t"; } elsif ($bitlength < 32) { $jtype = "uint16_t"; } --- 280,284 ---- if ($basetype eq "U") { $acc = "UIntElement"; ! if ($bitlength < 8) { $jtype = "unsigned char"; } elsif ($bitlength < 16) { $jtype = "uint8_t"; } elsif ($bitlength < 32) { $jtype = "uint16_t"; } *************** *** 215,219 **** elsif ($basetype eq "I") { $acc = "SIntElement"; ! if ($bitlength <= 8) { $jtype = "byte"; } elsif ($bitlength <= 16) { $jtype = "short"; } elsif ($bitlength <= 32) { $jtype = "int"; } --- 287,291 ---- elsif ($basetype eq "I") { $acc = "SIntElement"; ! if ($bitlength <= 8) { $jtype = "char"; } elsif ($bitlength <= 16) { $jtype = "short"; } elsif ($bitlength <= 32) { $jtype = "int"; } *************** *** 374,379 **** } } - - - - --- 446,447 ---- |