From 4a6106e9f6f968f26efeebe17fedf09c71079a44 Mon Sep 17 00:00:00 2001 From: "rginda%netscape.com" Date: Mon, 24 Apr 2000 21:43:49 +0000 Subject: [PATCH] adding comments git-svn-id: svn://10.0.0.236/trunk@66997 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/js2/tools/gencode.pl | 44 ++++++++++++++++++++++++++++++++- mozilla/js2/tools/gencode.pl | 44 ++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/mozilla/js/js2/tools/gencode.pl b/mozilla/js/js2/tools/gencode.pl index 6fc7eb95e8c..cb34dc6f3e2 100644 --- a/mozilla/js/js2/tools/gencode.pl +++ b/mozilla/js/js2/tools/gencode.pl @@ -7,6 +7,27 @@ my $class_decs = ""; my @name_array; my $opcode_maxlen = 0; +# +# template definitions for compare, arithmetic, and conditional branch ops +# +# fields are: +# +# * super: Class to inherit from, if super is Instruction_(1|2|3), the script +# will automatically append the correct template info based on |params| +# * super_has_print: Set to 1 if you want to inherit the print() method from the +# superclass, set to 0 (or just don't set) otherwise. +# * rem: Remark you want to show up after the enum def, and inside the class. +# * params: The parameter list expected by the constructor, you can specify a +# default value, using the syntax, [ ("Type = default") ]. +# +# class namea will be generated based on the opcode mnemonic. See the +# subroutine get_classname for the implementation. Basically underscores will +# be removes and the class name will be WordCapped, using the positions where the +# underscores were as word boundries. The only exception occurs when a word is +# two characters, in which case both characters will be capped, +# as in BRANCH_GT -> BranchGT. +# + my $compare_op = { super => "Compare", @@ -31,6 +52,10 @@ my $cbranch_op = params => [ ("Label*", "Register") ] }; + +# +# op defititions +# my %ops; $ops{"NOP"} = { @@ -144,21 +169,29 @@ $ops{"CALL"} = params => [ ("Register" , "Register", "RegisterList") ] }; +# +# nasty perl code, you probably don't need to muck around below this line +# + my $k; if (!$ARGV[0]) { + # no args, collect all opcodes for $k (sort(keys(%ops))) { &collect($k); } } else { + # collect defs for only the opcodes specified on the command line while ($k = pop(@ARGV)) { - &collect ($k); + &collect (uc($k)); } } &spew; sub collect { + # grab the info from the $k record in $ops, and append it to + # $enum_decs, @name_aray, and $class_decs. my ($k) = @_; if (length($k) > $opcode_maxlen) { @@ -166,6 +199,10 @@ sub collect { } my $c = $ops{$k}; + if (!$c) { + die ("Unknown opcode, $k\n"); + } + my $opname = $k; my $cname = get_classname ($k); my $super = $c->{"super"}; @@ -207,6 +244,7 @@ sub collect { } sub spew { + # print the info in $enum_decs, @name_aray, and $class_decs to stdout. my $opname; print $tab . "enum ICodeOp {\n$enum_decs$tab};\n\n"; @@ -224,6 +262,7 @@ sub spew { } sub get_classname { + # munge an OPCODE_MNEMONIC into a ClassName my ($enum_name) = @_; my @words = split ("_", $enum_name); my $cname = ""; @@ -242,6 +281,8 @@ sub get_classname { } sub get_paramlists { + # parse the params entry (passed into @types) into various parameter lists + # used in the class declaration my @types = @_; my @dec; my @call; @@ -274,6 +315,7 @@ sub get_paramlists { } sub get_printbody { + # generate the body of the print() function my (@types) = @_; my $type; my @oplist; diff --git a/mozilla/js2/tools/gencode.pl b/mozilla/js2/tools/gencode.pl index 6fc7eb95e8c..cb34dc6f3e2 100644 --- a/mozilla/js2/tools/gencode.pl +++ b/mozilla/js2/tools/gencode.pl @@ -7,6 +7,27 @@ my $class_decs = ""; my @name_array; my $opcode_maxlen = 0; +# +# template definitions for compare, arithmetic, and conditional branch ops +# +# fields are: +# +# * super: Class to inherit from, if super is Instruction_(1|2|3), the script +# will automatically append the correct template info based on |params| +# * super_has_print: Set to 1 if you want to inherit the print() method from the +# superclass, set to 0 (or just don't set) otherwise. +# * rem: Remark you want to show up after the enum def, and inside the class. +# * params: The parameter list expected by the constructor, you can specify a +# default value, using the syntax, [ ("Type = default") ]. +# +# class namea will be generated based on the opcode mnemonic. See the +# subroutine get_classname for the implementation. Basically underscores will +# be removes and the class name will be WordCapped, using the positions where the +# underscores were as word boundries. The only exception occurs when a word is +# two characters, in which case both characters will be capped, +# as in BRANCH_GT -> BranchGT. +# + my $compare_op = { super => "Compare", @@ -31,6 +52,10 @@ my $cbranch_op = params => [ ("Label*", "Register") ] }; + +# +# op defititions +# my %ops; $ops{"NOP"} = { @@ -144,21 +169,29 @@ $ops{"CALL"} = params => [ ("Register" , "Register", "RegisterList") ] }; +# +# nasty perl code, you probably don't need to muck around below this line +# + my $k; if (!$ARGV[0]) { + # no args, collect all opcodes for $k (sort(keys(%ops))) { &collect($k); } } else { + # collect defs for only the opcodes specified on the command line while ($k = pop(@ARGV)) { - &collect ($k); + &collect (uc($k)); } } &spew; sub collect { + # grab the info from the $k record in $ops, and append it to + # $enum_decs, @name_aray, and $class_decs. my ($k) = @_; if (length($k) > $opcode_maxlen) { @@ -166,6 +199,10 @@ sub collect { } my $c = $ops{$k}; + if (!$c) { + die ("Unknown opcode, $k\n"); + } + my $opname = $k; my $cname = get_classname ($k); my $super = $c->{"super"}; @@ -207,6 +244,7 @@ sub collect { } sub spew { + # print the info in $enum_decs, @name_aray, and $class_decs to stdout. my $opname; print $tab . "enum ICodeOp {\n$enum_decs$tab};\n\n"; @@ -224,6 +262,7 @@ sub spew { } sub get_classname { + # munge an OPCODE_MNEMONIC into a ClassName my ($enum_name) = @_; my @words = split ("_", $enum_name); my $cname = ""; @@ -242,6 +281,8 @@ sub get_classname { } sub get_paramlists { + # parse the params entry (passed into @types) into various parameter lists + # used in the class declaration my @types = @_; my @dec; my @call; @@ -274,6 +315,7 @@ sub get_paramlists { } sub get_printbody { + # generate the body of the print() function my (@types) = @_; my $type; my @oplist;