#!/usr/bin/perl # # make-opcodes-def.pl: Loads the opcodes from the CIL-opcodes.xml and # generates a spec compliant opcodes.def file # # Author: # Miguel de Icaza (miguel@ximian.com) # # (C) 2001 Ximian, Inc. # # We should really be doing this with XSLT, but I know nothing about XSLT # ;-) # or maybe just an XML::Parser... - lupus use strict; use XML::Parser; my %valid_flow; # the XML file also includes "throw" @valid_flow{qw(next call return branch meta cond-branch)} = (); open OUTPUT, ">$ARGV[1]" || die "Can not create $ARGV[1] file: $!"; my $parser = new XML::Parser (Handlers => {Start => \&handle_opcode}); print_header(); $parser->parsefile($ARGV[0]); print_trailer(); close(OUTPUT) || die "Can not close file: $!"; sub handle_opcode { my ($parser, $elem, %attrs) = @_; my ($name, $input, $output, $args, $o1, $o2, $flow, $uname, $count, $ff); return if ($elem ne 'opcode'); ($name, $input, $output, $args, $o1, $o2, $flow) = @attrs{qw(name input output args o1 o2 flow)}; $uname = uc $name; $uname =~ tr/./_/; if (hex($o1) == 0xff){ $count = 1; } else { $count = 2; } $ff = "ERROR"; if (exists $valid_flow{$flow}) { $ff = uc $flow; $ff =~ tr/-/_/; } print OUTPUT "OPDEF(CEE_$uname, \"$name\", $input, $output, $args, X, $count, $o1, $o2, $ff)\n"; } sub print_header { print OUTPUT<