~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to erts/emulator/utils/beam_makeops

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20090215164252-dxpjjuq108nz4noa
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
$pack_mask[2]  = ['BEAM_LOOSE_MASK', $WHOLE_WORD];
44
44
$pack_mask[3]  = ['BEAM_TIGHT_MASK', 'BEAM_TIGHT_MASK', 'BEAM_TIGHT_MASK'];
45
45
 
 
46
# There are two types of instructions: generic and specific.
 
47
# The generic instructions are those generated by the Beam compiler.
 
48
# Corresponding to each generic instruction, there is generally a
 
49
# whole family of related specific instructions. Specific instructions
 
50
# are those executed by the VM interpreter during run-time.
 
51
 
 
52
# Maximum number of operands for a generic instruction.
 
53
# In beam_load.c the MAX_OPARGS refers to the maximum
 
54
# number of operands for generic instructions.
 
55
my $max_gen_operands = 8;
 
56
 
46
57
# Maximum number of operands for a specific instruction.
47
58
# Must be even. The beam_load.c file must be updated, too.
48
 
my $max_operands = 6;
 
59
my $max_spec_operands = 6;
49
60
 
50
61
my %gen_opnum;
51
62
my %num_specific;
268
279
    #
269
280
    my($name, @args) = split;
270
281
    &error("too many operands")
271
 
        if @args > $max_operands;
 
282
        if @args > $max_spec_operands;
272
283
    &syntax_check($name, @args);
273
284
    my $arity = @args;
274
285
    if ($obsolete[$gen_opnum{$name,$arity}]) {
410
421
            # instruction.
411
422
            #
412
423
 
413
 
            my(@bits) = (0) x ($max_operands/2);
 
424
            my(@bits) = (0) x ($max_spec_operands/2);
414
425
            my($shift) = 16;
415
426
            my($i);
416
 
            for ($i = 0; $i < $max_operands && defined $args[$i]; $i++) {
 
427
            for ($i = 0; $i < $max_spec_operands && defined $args[$i]; $i++) {
417
428
                my $t = $args[$i];
418
429
                if (defined $type_bit{$t}) {
419
430
                    $bits[int($i/2)] |= $type_bit{$t} << (16*($i%2));
667
678
    print "-export([format_number/0]).\n";
668
679
    print "-export([opcode/2,opname/1]).\n";
669
680
    print "\n";
 
681
    print "-spec format_number() -> $BEAM_FORMAT_NUMBER.\n";
670
682
    print "format_number() -> $BEAM_FORMAT_NUMBER.\n\n";
671
683
 
 
684
    print "-spec opcode(atom(), 0..", $max_gen_operands, ") -> 1..", $num_file_opcodes-1, ".\n";
672
685
    for ($i = 0; $i < @gen_opname; $i++) {
673
686
        next unless defined $gen_opname[$i];
674
687
        print "%%" if $obsolete[$i];
676
689
    }
677
690
    print "opcode(Name, Arity) -> erlang:error(badarg, [Name,Arity]).\n\n";
678
691
 
 
692
    print "-spec opname(1..", $num_file_opcodes-1, ") -> {atom(),0..", $max_gen_operands, "}.\n";
679
693
    for ($i = 0; $i < @gen_opname; $i++) {
680
694
        next unless defined $gen_opname[$i];
681
695
        print "opname($i) -> {",
1093
1107
    my($src, $op) = @_;
1094
1108
    my($var) = '';
1095
1109
    my($type) = '';
 
1110
    my($type_val) = 0;
1096
1111
    my($cond) = '';
1097
1112
    my($cond_val) = '';
1098
1113
 
1119
1134
        }
1120
1135
    }
1121
1136
 
1122
 
    # Get an optional condition.
 
1137
    # Get an optional condition. (In source.)
1123
1138
 
1124
1139
    if (/^==(.*)/) {
1125
1140
        $cond = 'is_eq';
1148
1163
        $_ = $4;
1149
1164
    }
1150
1165
 
1151
 
   # Nothing more is allowed after the command.
 
1166
    # Get an optional value. (In destination.)
 
1167
    if (/^=(.*)/) {
 
1168
        $type_val = $1;
 
1169
        $_ = '';
 
1170
    }
 
1171
 
 
1172
    # Nothing more is allowed after the command.
1152
1173
 
1153
1174
    &error("garbage '$_' after operand: $op")
1154
1175
        unless /^\s*$/;
1155
1176
 
1156
1177
    # Test that destination has no conditions.
 
1178
 
1157
1179
    unless ($src) {
1158
 
        &error("condition not allowed in destination: $op")
 
1180
        error("condition not allowed in destination: $op")
1159
1181
            if $cond;
1160
 
        &error("variable name and type cannot be combined in destination: $op")
 
1182
        error("variable name and type cannot be combined in destination: $op")
1161
1183
            if $var && $type;
1162
1184
    }
1163
1185
 
1164
 
    ($var, $type, $cond, $cond_val);
 
1186
    # Test that source has no values.
 
1187
    if ($src) {
 
1188
        error("value not allowed in source: $op")
 
1189
            if $type_val;
 
1190
    }
 
1191
    ($var,$type,$type_val,$cond,$cond_val);
1165
1192
}
1166
1193
 
1167
1194
#
1257
1284
        push(@code, &make_op("$name/$arity", 'is_op', $opnum));
1258
1285
        $min_window++;
1259
1286
        foreach $op (@ops) {
1260
 
            my($var, $type, $cond, $val) = @$op;
 
1287
            my($var, $type, $type_val, $cond, $val) = @$op;
1261
1288
 
1262
1289
            if ($type ne '' && $type ne '*') {
1263
1290
                my($types) = '';
1402
1429
        push(@code, &make_op('', 'new_instr'));
1403
1430
        push(@code, &make_op("$name/$arity", 'store_op', $opnum, $arity));
1404
1431
        foreach $op (@ops) {
1405
 
            my($var, $type) = @$op;
 
1432
            my($var, $type, $type_val) = @$op;
1406
1433
 
1407
1434
            if ($var ne '') {
1408
1435
                &error($where, "variable '$var' unbound")
1410
1437
                push(@code, &make_op($var, 'store_var', $var{$var}));
1411
1438
            } elsif ($type ne '') {
1412
1439
                push(@code, &make_op('', 'store_type', "TAG_$type"));
 
1440
                if ($type_val) {
 
1441
                    push(@code, &make_op('', 'store_val', $type_val));
 
1442
                }
1413
1443
            }
1414
1444
            push(@code, &make_op('', 'next_arg'));
1415
1445
        }