2000-04-28 17:17:35 +04:00
|
|
|
#!perl
|
|
|
|
|
2000-04-18 04:22:51 +04:00
|
|
|
use strict;
|
|
|
|
|
|
|
|
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
|
|
|
|
2000-04-25 01:43:49 +04:00
|
|
|
#
|
|
|
|
# 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|
|
2000-04-28 06:33:36 +04:00
|
|
|
# * super_has_print: Set to 1 if you want to inherit the print() and print_args()
|
|
|
|
# methods from the superclass, set to 0 (or just don't set)
|
|
|
|
# to generate print methods.
|
2000-04-25 01:43:49 +04:00
|
|
|
# * 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") ].
|
|
|
|
#
|
2000-04-28 06:26:14 +04:00
|
|
|
# class names will be generated based on the opcode mnemonic. See the
|
2000-04-25 01:43:49 +04:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2000-04-28 06:26:14 +04:00
|
|
|
#
|
|
|
|
# template definitions for compare, arithmetic, and conditional branch ops
|
|
|
|
#
|
2000-05-23 04:09:02 +04:00
|
|
|
my $binary_op =
|
2000-04-18 04:22:51 +04:00
|
|
|
{
|
2000-05-23 04:09:02 +04:00
|
|
|
super => "Instruction_3",
|
2000-04-21 04:04:14 +04:00
|
|
|
super_has_print => 1,
|
2000-05-23 04:09:02 +04:00
|
|
|
rem => "dest, source1, source2",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
my $math_op =
|
|
|
|
{
|
|
|
|
super => "Arithmetic",
|
2000-04-21 04:04:14 +04:00
|
|
|
super_has_print => 1,
|
2000-04-18 04:22:51 +04:00
|
|
|
rem => "dest, source1, source2",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
my $cbranch_op =
|
|
|
|
{
|
|
|
|
super => "GenericBranch",
|
2000-04-21 04:04:14 +04:00
|
|
|
super_has_print => 1,
|
2000-04-18 04:22:51 +04:00
|
|
|
rem => "target label, condition",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("Label*", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
|
2000-05-06 01:36:36 +04:00
|
|
|
my $unary_op =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "dest, source",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister") ]
|
2000-05-06 01:36:36 +04:00
|
|
|
};
|
|
|
|
|
2000-04-25 01:43:49 +04:00
|
|
|
|
|
|
|
#
|
|
|
|
# op defititions
|
|
|
|
#
|
2000-04-18 04:22:51 +04:00
|
|
|
my %ops;
|
|
|
|
$ops{"NOP"} =
|
|
|
|
{
|
|
|
|
super => "Instruction",
|
|
|
|
rem => "do nothing and like it",
|
|
|
|
};
|
2000-06-24 02:27:17 +04:00
|
|
|
$ops{"DEBUGGER"} =
|
|
|
|
{
|
|
|
|
super => "Instruction",
|
|
|
|
rem => "drop to the debugger",
|
|
|
|
};
|
2000-07-13 04:14:54 +04:00
|
|
|
$ops{"GENERIC_BINARY_OP"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_4",
|
|
|
|
rem => "dest, op, source1, source2",
|
|
|
|
params => [ ("TypedRegister", "BinaryOperator::BinaryOp", "TypedRegister", "TypedRegister") ]
|
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"MOVE"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "dest, source",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
$ops{"LOAD_IMMEDIATE"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "dest, immediate value (double)",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "double" ) ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-06-21 02:44:46 +04:00
|
|
|
$ops{"LOAD_BOOLEAN"} =
|
2000-05-18 04:04:15 +04:00
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
2000-06-21 02:44:46 +04:00
|
|
|
rem => "dest, immediate value (boolean)",
|
|
|
|
params => [ ("TypedRegister", "bool" ) ]
|
2000-05-18 04:04:15 +04:00
|
|
|
};
|
2000-05-06 03:23:13 +04:00
|
|
|
$ops{"LOAD_STRING"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "dest, immediate value (string)",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "JSString*" ) ]
|
2000-05-06 03:23:13 +04:00
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"LOAD_NAME"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "dest, name",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "const StringAtom*" ) ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-07-08 05:08:29 +04:00
|
|
|
$ops{"SUPER"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_1",
|
|
|
|
rem => "dest",
|
|
|
|
params => [ ("TypedRegister" ) ]
|
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"SAVE_NAME"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "name, source",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("const StringAtom*", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
$ops{"NEW_OBJECT"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_1",
|
|
|
|
rem => "dest",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-06-24 03:41:27 +04:00
|
|
|
$ops{"NEW_CLASS"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
2000-07-08 05:08:29 +04:00
|
|
|
rem => "dest, class",
|
|
|
|
params => [ ("TypedRegister", "JSClass*") ]
|
2000-06-24 03:41:27 +04:00
|
|
|
};
|
2000-06-22 02:32:21 +04:00
|
|
|
$ops{"NEW_FUNCTION"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "dest, ICodeModule",
|
2000-07-11 03:18:07 +04:00
|
|
|
params => [ ("TypedRegister", "ICodeModule*") ]
|
2000-06-22 02:32:21 +04:00
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"NEW_ARRAY"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_1",
|
|
|
|
rem => "dest",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-06-29 21:11:50 +04:00
|
|
|
$ops{"DELETE_PROP"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "dest, object, prop name",
|
|
|
|
params => [ ("TypedRegister", "TypedRegister", "const StringAtom*") ]
|
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"GET_PROP"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "dest, object, prop name",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "const StringAtom*") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
$ops{"SET_PROP"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "object, name, source",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "const StringAtom*", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-06-24 03:43:24 +04:00
|
|
|
$ops{"GET_SLOT"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "dest, object, slot number",
|
|
|
|
params => [ ("TypedRegister", "TypedRegister", "uint32") ]
|
|
|
|
};
|
|
|
|
$ops{"SET_SLOT"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "object, slot number, source",
|
|
|
|
params => [ ("TypedRegister", "uint32", "TypedRegister") ]
|
|
|
|
};
|
2000-06-27 06:39:32 +04:00
|
|
|
$ops{"GET_STATIC"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
2000-06-28 20:13:12 +04:00
|
|
|
rem => "dest, class, index",
|
|
|
|
params => [ ("TypedRegister", "JSClass*", "uint32") ]
|
2000-06-27 06:39:32 +04:00
|
|
|
};
|
|
|
|
$ops{"SET_STATIC"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
2000-06-28 20:13:12 +04:00
|
|
|
rem => "class, index, source",
|
|
|
|
params => [ ("JSClass*", "uint32", "TypedRegister") ]
|
2000-06-27 06:39:32 +04:00
|
|
|
};
|
|
|
|
$ops{"STATIC_XCR"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_4",
|
2000-06-28 20:13:12 +04:00
|
|
|
rem => "dest, class, index, value",
|
|
|
|
params => [ ("TypedRegister", "JSClass*", "uint32", "double") ]
|
2000-06-27 06:39:32 +04:00
|
|
|
};
|
2000-06-24 03:43:24 +04:00
|
|
|
$ops{"SLOT_XCR"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_4",
|
|
|
|
rem => "dest, source, slot number, value",
|
|
|
|
params => [ ("TypedRegister", "TypedRegister", "uint32", "double") ]
|
|
|
|
};
|
2000-05-11 04:35:43 +04:00
|
|
|
$ops{"PROP_XCR"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_4",
|
|
|
|
rem => "dest, source, name, value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "const StringAtom*", "double") ]
|
2000-05-11 04:35:43 +04:00
|
|
|
};
|
2000-05-18 04:04:15 +04:00
|
|
|
$ops{"ELEM_XCR"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_4",
|
|
|
|
rem => "dest, base, index, value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "TypedRegister", "double") ]
|
2000-05-18 04:04:15 +04:00
|
|
|
};
|
2000-05-11 04:35:43 +04:00
|
|
|
$ops{"NAME_XCR"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "dest, name, value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "const StringAtom*", "double") ]
|
2000-05-11 04:35:43 +04:00
|
|
|
};
|
|
|
|
$ops{"VAR_XCR"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "dest, source, value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "double") ]
|
2000-05-11 04:35:43 +04:00
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"GET_ELEMENT"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
2000-05-18 04:04:15 +04:00
|
|
|
rem => "dest, base, index",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
$ops{"SET_ELEMENT"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
2000-05-18 04:04:15 +04:00
|
|
|
rem => "base, index, value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "TypedRegister") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-05-06 01:36:36 +04:00
|
|
|
$ops{"ADD"} = $math_op;
|
|
|
|
$ops{"SUBTRACT"} = $math_op;
|
|
|
|
$ops{"MULTIPLY"} = $math_op;
|
|
|
|
$ops{"DIVIDE"} = $math_op;
|
|
|
|
$ops{"REMAINDER"} = $math_op;
|
|
|
|
$ops{"SHIFTLEFT"} = $math_op;
|
|
|
|
$ops{"SHIFTRIGHT"} = $math_op;
|
|
|
|
$ops{"USHIFTRIGHT"}= $math_op;
|
|
|
|
$ops{"AND"} = $math_op;
|
|
|
|
$ops{"OR"} = $math_op;
|
|
|
|
$ops{"XOR"} = $math_op;
|
2000-05-23 04:09:02 +04:00
|
|
|
$ops{"COMPARE_LT"} = $binary_op;
|
|
|
|
$ops{"COMPARE_LE"} = $binary_op;
|
|
|
|
$ops{"COMPARE_EQ"} = $binary_op;
|
|
|
|
$ops{"COMPARE_NE"} = $binary_op;
|
|
|
|
$ops{"COMPARE_GE"} = $binary_op;
|
|
|
|
$ops{"COMPARE_GT"} = $binary_op;
|
|
|
|
$ops{"COMPARE_IN"} = $binary_op;
|
|
|
|
$ops{"STRICT_EQ"} = $binary_op;
|
|
|
|
$ops{"STRICT_NE"} = $binary_op;
|
|
|
|
$ops{"INSTANCEOF"} = $binary_op;
|
2000-05-06 01:36:36 +04:00
|
|
|
$ops{"BITNOT"} = $unary_op;
|
|
|
|
$ops{"NOT"} = $unary_op;
|
2000-05-18 04:04:15 +04:00
|
|
|
$ops{"TEST"} = $unary_op;
|
2000-05-06 01:36:36 +04:00
|
|
|
$ops{"NEGATE"} = $unary_op;
|
|
|
|
$ops{"POSATE"} = $unary_op;
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"BRANCH"} =
|
|
|
|
{
|
|
|
|
super => "GenericBranch",
|
|
|
|
rem => "target label",
|
|
|
|
params => [ ("Label*") ]
|
|
|
|
};
|
2000-05-18 04:04:15 +04:00
|
|
|
$ops{"BRANCH_TRUE"} = $cbranch_op;
|
|
|
|
$ops{"BRANCH_FALSE"} = $cbranch_op;
|
2000-04-18 04:22:51 +04:00
|
|
|
$ops{"RETURN"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_1",
|
2000-04-21 04:04:14 +04:00
|
|
|
rem => "return value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister") ]
|
2000-04-21 04:04:14 +04:00
|
|
|
};
|
|
|
|
$ops{"RETURN_VOID"} =
|
|
|
|
{
|
|
|
|
super => "Instruction",
|
|
|
|
rem => "Return without a value"
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
|
|
|
$ops{"CALL"} =
|
|
|
|
{
|
2000-06-22 02:32:21 +04:00
|
|
|
super => "Instruction_4",
|
2000-07-19 00:53:03 +04:00
|
|
|
rem => "result, base, target, args",
|
2000-07-08 05:08:29 +04:00
|
|
|
params => [ ("TypedRegister", "TypedRegister", "TypedRegister", "RegisterList") ]
|
|
|
|
};
|
2000-07-19 00:53:03 +04:00
|
|
|
$ops{"GET_METHOD"} =
|
2000-07-08 05:08:29 +04:00
|
|
|
{
|
2000-07-19 00:53:03 +04:00
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "result, target base, index",
|
|
|
|
params => [ ("TypedRegister", "TypedRegister", "uint32") ]
|
2000-04-18 04:22:51 +04:00
|
|
|
};
|
2000-04-25 02:40:53 +04:00
|
|
|
$ops{"THROW"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_1",
|
|
|
|
rem => "exception value",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister") ]
|
2000-04-25 02:40:53 +04:00
|
|
|
};
|
2000-05-06 01:36:36 +04:00
|
|
|
$ops{"TRYIN"} =
|
2000-04-25 02:40:53 +04:00
|
|
|
{
|
|
|
|
super => "Instruction_2",
|
|
|
|
rem => "catch target, finally target",
|
|
|
|
params => [ ("Label*", "Label*") ]
|
|
|
|
};
|
2000-05-06 01:36:36 +04:00
|
|
|
$ops{"TRYOUT"} =
|
2000-04-25 02:40:53 +04:00
|
|
|
{
|
|
|
|
super => "Instruction",
|
|
|
|
rem => "mmm, there is no try, only do",
|
|
|
|
};
|
|
|
|
$ops{"JSR"} =
|
|
|
|
{
|
|
|
|
super => "GenericBranch",
|
|
|
|
rem => "target",
|
|
|
|
params => [ ("Label*") ]
|
|
|
|
};
|
|
|
|
$ops{"RTS"} =
|
|
|
|
{
|
|
|
|
super => "Instruction",
|
|
|
|
rem => "Return to sender",
|
|
|
|
};
|
2000-04-29 18:10:53 +04:00
|
|
|
$ops{"WITHIN"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_1",
|
|
|
|
rem => "within this object",
|
2000-06-21 02:44:46 +04:00
|
|
|
params => [ ("TypedRegister") ]
|
2000-04-29 18:10:53 +04:00
|
|
|
};
|
|
|
|
$ops{"WITHOUT"} =
|
|
|
|
{
|
|
|
|
super => "Instruction",
|
|
|
|
rem => "without this object",
|
|
|
|
};
|
2000-07-11 03:18:07 +04:00
|
|
|
$ops{"CAST"} =
|
|
|
|
{
|
|
|
|
super => "Instruction_3",
|
|
|
|
rem => "dest, rvalue, toType",
|
|
|
|
params => [ ("TypedRegister", "TypedRegister", "JSType*") ]
|
|
|
|
};
|
2000-04-18 04:22:51 +04:00
|
|
|
|
2000-04-25 01:43:49 +04:00
|
|
|
#
|
|
|
|
# nasty perl code, you probably don't need to muck around below this line
|
|
|
|
#
|
|
|
|
|
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-04-18 04:22:51 +04:00
|
|
|
for $k (sort(keys(%ops))) {
|
|
|
|
&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-04-18 04:22:51 +04:00
|
|
|
my $c = $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;
|
|
|
|
my $cname = get_classname ($k);
|
|
|
|
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, ";
|
|
|
|
$printops_decl .= ($printops_body ne "" ?
|
|
|
|
"const JSValues& registers" :
|
|
|
|
"const JSValues& /*registers*/");
|
|
|
|
$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_classname {
|
2000-04-25 01:43:49 +04:00
|
|
|
# munge an OPCODE_MNEMONIC into a ClassName
|
2000-04-18 04:22:51 +04:00
|
|
|
my ($enum_name) = @_;
|
|
|
|
my @words = split ("_", $enum_name);
|
|
|
|
my $cname = "";
|
2000-05-06 01:36:36 +04:00
|
|
|
my $i = 0;
|
2000-04-18 04:22:51 +04:00
|
|
|
my $word;
|
|
|
|
|
|
|
|
for $word (@words) {
|
2000-05-06 01:36:36 +04:00
|
|
|
if ((length($word) == 2) && ($i != 0)) {
|
2000-04-18 04:22:51 +04:00
|
|
|
$cname .= uc($word);
|
|
|
|
} else {
|
|
|
|
$cname .= uc(substr($word, 0, 1)) . lc(substr($word, 1));
|
|
|
|
}
|
2000-05-06 01:36:36 +04:00
|
|
|
$i++;
|
2000-04-18 04:22:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $cname;
|
|
|
|
}
|
|
|
|
|
|
|
|
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" );
|
|
|
|
|
|
|
|
# push (@oplist, "\"R\" << ((mOp$op.first == NotARegister) ? -1 : mOp$op.first)");
|
|
|
|
|
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-07-11 03:18:07 +04:00
|
|
|
} elsif ($type =~ /JSType\*/) {
|
2000-07-12 00:54:06 +04:00
|
|
|
push (@oplist, "\"'\" << mOp$op->getName() << \"'\"");
|
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-06-29 05:21:41 +04:00
|
|
|
} elsif ($type =~ /JSClass\*/) {
|
|
|
|
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-07-19 00:53:03 +04:00
|
|
|
push (@oplist, "mOp$op.first");
|
|
|
|
# push (@oplist, "\"R\" << mOp$op.first << '=' << registers[mOp$op.first]");
|
2000-04-28 09:39:27 +04:00
|
|
|
} elsif ($type eq "RegisterList") {
|
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
|
|
|
}
|