2000-10-11 06:42:39 +04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
2002-03-19 07:30:17 +03:00
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
2000-10-11 06:42:39 +04:00
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
2000-10-19 00:41:03 +04:00
|
|
|
# The Original Code is JavaScript 2 Prototype.
|
2000-10-11 06:42:39 +04:00
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape
|
|
|
|
# Communications Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1997-1999 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the
|
|
|
|
# terms of the GNU Public License (the "GPL"), in which case the
|
|
|
|
# provisions of the GPL are applicable instead of those above.
|
|
|
|
# If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of the GPL and not to allow others to use your
|
|
|
|
# version of this file under the NPL, indicate your decision by
|
|
|
|
# deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this
|
|
|
|
# file under either the NPL or the GPL.
|
|
|
|
#
|
|
|
|
# Contributers:
|
|
|
|
#
|
2000-04-28 17:17:35 +04:00
|
|
|
|
2000-04-18 04:22:51 +04:00
|
|
|
use strict;
|
2000-10-11 06:42:39 +04:00
|
|
|
use jsicodes;
|
|
|
|
##############################################################################
|
|
|
|
# HELLO, ARE YOU READING THIS?
|
|
|
|
# The opcode definition is now in jsicodes.pm, please go there to make changes.
|
|
|
|
##############################################################################
|
2000-04-18 04:22:51 +04:00
|
|
|
|
|
|
|
my $tab = " ";
|
2000-04-19 01:51:45 +04:00
|
|
|
my $init_tab = $tab;
|
2000-04-18 04:22:51 +04:00
|
|
|
my $enum_decs = "";
|
|
|
|
my $class_decs = "";
|
2000-04-18 05:19:12 +04:00
|
|
|
my @name_array;
|
|
|
|
my $opcode_maxlen = 0;
|
2000-04-18 04:22:51 +04:00
|
|
|
|
|
|
|
my $k;
|
|
|
|
|
|
|
|
if (!$ARGV[0]) {
|
2000-04-25 01:43:49 +04:00
|
|
|
# no args, collect all opcodes
|
2000-10-11 06:42:39 +04:00
|
|
|
for $k (sort(keys(%jsicodes::ops))) {
|
2000-04-18 04:22:51 +04:00
|
|
|
&collect($k);
|
|
|
|
}
|
|
|
|
} else {
|
2000-04-25 01:43:49 +04:00
|
|
|
# collect defs for only the opcodes specified on the command line
|
2000-04-18 04:22:51 +04:00
|
|
|
while ($k = pop(@ARGV)) {
|
2000-04-25 01:43:49 +04:00
|
|
|
&collect (uc($k));
|
2000-04-18 04:22:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&spew;
|
|
|
|
|
|
|
|
sub collect {
|
2000-04-25 01:43:49 +04:00
|
|
|
# grab the info from the $k record in $ops, and append it to
|
2000-06-15 03:27:28 +04:00
|
|
|
# $enum_decs, @name_array, and $class_decs.
|
2000-04-18 04:22:51 +04:00
|
|
|
my ($k) = @_;
|
|
|
|
|
2000-04-18 05:19:12 +04:00
|
|
|
if (length($k) > $opcode_maxlen) {
|
|
|
|
$opcode_maxlen = length($k);
|
|
|
|
}
|
|
|
|
|
2000-10-11 06:42:39 +04:00
|
|
|
my $c = $jsicodes::ops{$k};
|
2000-04-25 01:43:49 +04:00
|
|
|
if (!$c) {
|
|
|
|
die ("Unknown opcode, $k\n");
|
|
|
|
}
|
|
|
|
|
2000-04-18 04:22:51 +04:00
|
|
|
my $opname = $k;
|
2000-10-20 05:13:03 +04:00
|
|
|
my $cname = jsicodes::get_classname ($k);
|
2000-04-18 04:22:51 +04:00
|
|
|
my $super = $c->{"super"};
|
|
|
|
my $constructor = $super;
|
2000-04-25 02:40:53 +04:00
|
|
|
my @params;
|
|
|
|
|
|
|
|
if ($c->{"params"}) {
|
|
|
|
@params = @{$c->{"params"}};
|
|
|
|
} else {
|
|
|
|
@params = ();
|
|
|
|
}
|
2000-04-18 04:22:51 +04:00
|
|
|
|
|
|
|
my $rem = $c->{"rem"};
|
2000-04-18 11:04:24 +04:00
|
|
|
my ($dec_list, $call_list, $template_list) =
|
2000-04-25 02:40:53 +04:00
|
|
|
&get_paramlists(@params);
|
2000-04-28 06:20:23 +04:00
|
|
|
my @types = split (", ", $template_list);
|
|
|
|
|
2000-04-25 02:40:53 +04:00
|
|
|
my $constr_params = $call_list ? $opname . ", " . $call_list : $opname;
|
2000-04-18 11:04:24 +04:00
|
|
|
|
2000-04-18 04:22:51 +04:00
|
|
|
if ($super =~ /Instruction_\d/) {
|
|
|
|
$super .= "<" . $template_list . ">";
|
2000-04-18 05:19:12 +04:00
|
|
|
}
|
2000-04-18 04:22:51 +04:00
|
|
|
|
2000-04-18 05:19:12 +04:00
|
|
|
push (@name_array, $opname);
|
2000-04-19 01:51:45 +04:00
|
|
|
$enum_decs .= "$init_tab$tab$opname, /* $rem */\n";
|
2000-06-15 03:27:28 +04:00
|
|
|
if ($super) {
|
|
|
|
$class_decs .= ($init_tab . "class $cname : public $super {\n" .
|
|
|
|
$init_tab . "public:\n" .
|
|
|
|
$init_tab . $tab . "/* $rem */\n" .
|
|
|
|
$init_tab . $tab . "$cname ($dec_list) :\n" .
|
|
|
|
$init_tab . $tab . $tab . "$super\n" .
|
|
|
|
"$init_tab$tab$tab($constr_params) " .
|
|
|
|
"{};\n");
|
2000-04-28 19:32:54 +04:00
|
|
|
|
2000-06-15 03:27:28 +04:00
|
|
|
if (!$c->{"super_has_print"}) {
|
|
|
|
$class_decs .= ($init_tab . $tab .
|
|
|
|
"virtual Formatter& print(Formatter& f) {\n" .
|
|
|
|
$init_tab . $tab . $tab . "f << opcodeNames[$opname]" .
|
|
|
|
&get_print_body(@types) . ";\n" .
|
|
|
|
$init_tab . $tab . $tab . "return f;\n" .
|
|
|
|
$init_tab . $tab . "}\n");
|
2000-04-28 06:33:36 +04:00
|
|
|
|
2000-06-15 03:27:28 +04:00
|
|
|
my $printops_body = &get_printops_body(@types);
|
|
|
|
my $printops_decl = "virtual Formatter& printOperands(Formatter& f, ";
|
2000-07-29 06:00:12 +04:00
|
|
|
|
2000-09-20 00:35:05 +04:00
|
|
|
# $printops_decl .= ($dec_list =~ /ArgumentList/) ?
|
|
|
|
# "const JSValues& registers" :
|
|
|
|
# "const JSValues& registers";
|
|
|
|
$printops_decl .= ($printops_body eq "") ?
|
|
|
|
"const JSValues& /*registers*/" :
|
2000-08-23 05:07:19 +04:00
|
|
|
"const JSValues& registers";
|
2000-06-15 03:27:28 +04:00
|
|
|
$printops_decl .= ") {\n";
|
2000-04-28 17:17:35 +04:00
|
|
|
|
2000-06-15 03:27:28 +04:00
|
|
|
$class_decs .= ($init_tab . $tab .
|
|
|
|
$printops_decl .
|
|
|
|
$printops_body .
|
|
|
|
$init_tab . $tab . $tab . "return f;\n" .
|
|
|
|
$init_tab . $tab . "}\n");
|
2000-04-28 06:33:36 +04:00
|
|
|
|
2000-06-15 03:27:28 +04:00
|
|
|
} else {
|
|
|
|
$class_decs .= $init_tab . $tab .
|
|
|
|
"/* print() and printOperands() inherited from $super */\n";
|
|
|
|
}
|
2000-04-21 04:04:14 +04:00
|
|
|
|
2000-06-15 03:27:28 +04:00
|
|
|
$class_decs .= $init_tab . "};\n\n";
|
|
|
|
}
|
2000-04-18 04:22:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub spew {
|
2000-04-25 01:43:49 +04:00
|
|
|
# print the info in $enum_decs, @name_aray, and $class_decs to stdout.
|
2000-04-18 05:19:12 +04:00
|
|
|
my $opname;
|
2000-06-29 08:21:00 +04:00
|
|
|
|
|
|
|
print "// THIS FILE IS MACHINE GENERATED! DO NOT EDIT BY HAND!\n\n";
|
|
|
|
|
|
|
|
print "#if !defined(OPCODE_NAMES)\n\n";
|
|
|
|
|
|
|
|
print $tab . "enum {\n$enum_decs$tab};\n\n";
|
|
|
|
|
|
|
|
print $class_decs;
|
|
|
|
|
|
|
|
print "#else\n\n";
|
2000-04-18 05:19:12 +04:00
|
|
|
|
2000-06-29 08:21:00 +04:00
|
|
|
print $tab . "char *opcodeNames[] = {\n";
|
2000-04-18 05:19:12 +04:00
|
|
|
|
|
|
|
for $opname (@name_array) {
|
|
|
|
print "$tab$tab\"$opname";
|
|
|
|
for (0 .. $opcode_maxlen - length($opname) - 1) {
|
|
|
|
print " ";
|
|
|
|
}
|
|
|
|
print "\",\n"
|
|
|
|
}
|
|
|
|
print "$tab};\n\n";
|
2000-06-29 08:21:00 +04:00
|
|
|
|
|
|
|
print "#endif\n\n"
|
2000-04-18 04:22:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_paramlists {
|
2000-04-25 01:43:49 +04:00
|
|
|
# parse the params entry (passed into @types) into various parameter lists
|
|
|
|
# used in the class declaration
|
2000-04-18 04:22:51 +04:00
|
|
|
my @types = @_;
|
|
|
|
my @dec;
|
|
|
|
my @call;
|
|
|
|
my @tostr;
|
|
|
|
my @template;
|
|
|
|
my $op = 1;
|
|
|
|
my $type;
|
|
|
|
|
|
|
|
for $type (@types) {
|
|
|
|
my $pfx;
|
|
|
|
my $deref;
|
|
|
|
my $member;
|
|
|
|
my $default;
|
|
|
|
|
|
|
|
($type, $default) = split (" = ", $type);
|
|
|
|
if ($default ne "") {
|
|
|
|
$default = " = " . $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
$pfx = $deref = "";
|
2000-04-21 04:04:14 +04:00
|
|
|
$member = "mOp$op";
|
2000-04-18 04:22:51 +04:00
|
|
|
|
2000-04-21 04:04:14 +04:00
|
|
|
push (@dec, "$type aOp$op" . "$default");
|
|
|
|
push (@call, "aOp$op");
|
2000-04-18 04:22:51 +04:00
|
|
|
push (@template, $type);
|
2000-04-18 11:04:24 +04:00
|
|
|
$op++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (join (", ", @dec), join (", ", @call), join (", ", @template));
|
|
|
|
}
|
|
|
|
|
2000-04-28 06:20:23 +04:00
|
|
|
sub get_print_body {
|
2000-04-25 01:43:49 +04:00
|
|
|
# generate the body of the print() function
|
2000-04-18 11:04:24 +04:00
|
|
|
my (@types) = @_;
|
|
|
|
my $type;
|
|
|
|
my @oplist;
|
|
|
|
my $op = 1;
|
2000-04-19 01:51:45 +04:00
|
|
|
my $in = $init_tab . $tab . $tab;
|
2000-04-18 11:04:24 +04:00
|
|
|
|
|
|
|
for $type (@types) {
|
|
|
|
|
2000-06-21 02:44:46 +04:00
|
|
|
if ($type eq "TypedRegister") {
|
2000-07-12 00:54:06 +04:00
|
|
|
push (@oplist, "mOp$op" );
|
2000-04-18 04:22:51 +04:00
|
|
|
} elsif ($type eq "Label*") {
|
2000-05-27 02:35:36 +04:00
|
|
|
push (@oplist, "\"Offset \" << ((mOp$op) ? mOp$op->mOffset : NotAnOffset)")
|
2000-06-29 05:21:41 +04:00
|
|
|
} elsif ($type =~ /String/) {
|
2000-04-21 04:04:14 +04:00
|
|
|
push (@oplist, "\"'\" << *mOp$op << \"'\"");
|
2000-08-05 00:28:35 +04:00
|
|
|
} elsif ($type =~ /JSType *\*/) {
|
2000-07-12 00:54:06 +04:00
|
|
|
push (@oplist, "\"'\" << mOp$op->getName() << \"'\"");
|
2000-08-05 00:28:35 +04:00
|
|
|
} elsif ($type =~ /JSFunction *\*/) {
|
|
|
|
push (@oplist, "\"JSFunction\"");
|
2000-06-21 02:44:46 +04:00
|
|
|
} elsif ($type =~ /bool/) {
|
|
|
|
push (@oplist, "\"'\" << ((mOp$op) ? \"true\" : \"false\") << \"'\"");
|
2000-06-22 02:32:21 +04:00
|
|
|
} elsif ($type =~ /ICodeModule/) {
|
|
|
|
push (@oplist, "\"ICodeModule\"");
|
2000-09-02 05:01:41 +04:00
|
|
|
} elsif ($type =~ /FunctionDefinition/) {
|
|
|
|
push (@oplist, "\"FunctionDefinition\"");
|
2000-08-05 00:28:35 +04:00
|
|
|
} elsif ($type =~ /JSClass *\*/) {
|
2000-06-29 05:21:41 +04:00
|
|
|
push (@oplist, "mOp$op->getName()");
|
2000-04-18 04:22:51 +04:00
|
|
|
} else {
|
2000-04-21 04:04:14 +04:00
|
|
|
push (@oplist, "mOp$op");
|
2000-04-18 04:22:51 +04:00
|
|
|
}
|
2000-04-18 11:04:24 +04:00
|
|
|
|
2000-04-18 04:22:51 +04:00
|
|
|
$op++;
|
|
|
|
}
|
|
|
|
|
2000-04-21 04:04:14 +04:00
|
|
|
my $rv = join (" << \", \" << ", @oplist);
|
2000-04-18 11:04:24 +04:00
|
|
|
if ($rv ne "") {
|
2000-04-21 04:04:14 +04:00
|
|
|
$rv = " << \"\\t\" << " . $rv;
|
2000-04-18 11:04:24 +04:00
|
|
|
}
|
2000-04-28 09:39:27 +04:00
|
|
|
|
|
|
|
return $rv;
|
2000-04-18 04:22:51 +04:00
|
|
|
}
|
2000-04-28 06:20:23 +04:00
|
|
|
|
2000-04-28 09:39:27 +04:00
|
|
|
sub get_printops_body {
|
2000-04-28 19:32:54 +04:00
|
|
|
# generate the body of the printOperands() function
|
2000-04-28 09:39:27 +04:00
|
|
|
my (@types) = @_;
|
|
|
|
my $type;
|
|
|
|
my @oplist;
|
|
|
|
my $op = 1;
|
|
|
|
my $in = $init_tab . $tab . $tab;
|
2000-04-28 06:20:23 +04:00
|
|
|
|
2000-04-28 09:39:27 +04:00
|
|
|
for $type (@types) {
|
|
|
|
|
2000-06-21 02:44:46 +04:00
|
|
|
if ($type eq "TypedRegister") {
|
2000-08-23 05:07:19 +04:00
|
|
|
push (@oplist, "getRegisterValue(registers, mOp$op.first)");
|
|
|
|
# push (@oplist, "mOp$op.first");
|
2000-07-19 00:53:03 +04:00
|
|
|
# push (@oplist, "\"R\" << mOp$op.first << '=' << registers[mOp$op.first]");
|
2000-09-02 05:01:41 +04:00
|
|
|
} elsif ($type eq "ArgumentList") {
|
2000-04-28 17:17:35 +04:00
|
|
|
push (@oplist, "ArgList(mOp$op, registers)");
|
2000-04-28 09:39:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$op++;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $rv = join (" << \", \" << ", @oplist);
|
|
|
|
if ($rv ne "") {
|
|
|
|
$rv = $init_tab . $tab . $tab . "f << " . $rv . ";\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rv;
|
2000-04-28 06:20:23 +04:00
|
|
|
}
|