[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mono / cil / make-opcodes-def.pl
blob521b486fb439413dd1f441eb99729561b1a65364
1 #!/usr/bin/perl
3 # make-opcodes-def.pl: Loads the opcodes from the CIL-opcodes.xml and
4 # generates a spec compliant opcodes.def file
6 # Author:
7 # Miguel de Icaza (miguel@ximian.com)
9 # (C) 2001 Ximian, Inc.
11 # We should really be doing this with XSLT, but I know nothing about XSLT
12 # ;-)
13 # or maybe just an XML::Parser... - lupus
15 use strict;
16 use XML::Parser;
18 my %valid_flow;
19 # the XML file also includes "throw"
20 @valid_flow{qw(next call return branch meta cond-branch)} = ();
22 open OUTPUT, ">$ARGV[1]" || die "Can not create $ARGV[1] file: $!";
24 my $parser = new XML::Parser (Handlers => {Start => \&handle_opcode});
25 print_header();
26 $parser->parsefile($ARGV[0]);
27 print_trailer();
28 close(OUTPUT) || die "Can not close file: $!";
30 sub handle_opcode {
31 my ($parser, $elem, %attrs) = @_;
32 my ($count);
34 return if ($elem ne 'opcode');
36 my ($name, $input, $output, $args, $o1, $o2, $flow, $constant) =
37 @attrs{qw(name input output args o1 o2 flow constant)};
39 $constant ||= 0;
40 my $uname = uc $name;
41 $uname =~ tr/./_/;
42 if (hex($o1) == 0xff) {
43 $count = 1;
44 } else {
45 $count = 2;
48 my $ff = "ERROR";
49 if (exists $valid_flow{$flow}) {
50 $ff = uc $flow;
51 $ff =~ tr/-/_/;
54 print OUTPUT "OPDEF(CEE_$uname, \"$name\", $input, $output, $args, $constant, $count, $o1, $o2, $ff)\n";
58 sub print_header {
59 print OUTPUT<<EOF;
60 /* GENERATED FILE, DO NOT EDIT. Edit cil-opcodes.xml instead and run "make opcode.def" to regenerate. */
61 EOF
64 sub print_trailer {
65 print OUTPUT<<EOF;
66 #ifndef OPALIAS
67 #define _MONO_CIL_OPALIAS_DEFINED_
68 #define OPALIAS(a,s,r)
69 #endif
71 OPALIAS(CEE_BRNULL, "brnull", CEE_BRFALSE)
72 OPALIAS(CEE_BRNULL_S, "brnull.s", CEE_BRFALSE_S)
73 OPALIAS(CEE_BRZERO, "brzero", CEE_BRFALSE)
74 OPALIAS(CEE_BRZERO_S, "brzero.s", CEE_BRFALSE_S)
75 OPALIAS(CEE_BRINST, "brinst", CEE_BRTRUE)
76 OPALIAS(CEE_BRINST_S, "brinst.s", CEE_BRTRUE_S)
77 OPALIAS(CEE_LDIND_U8, "ldind.u8", CEE_LDIND_I8)
78 OPALIAS(CEE_LDELEM_U8, "ldelem.u8", CEE_LDELEM_I8)
79 OPALIAS(CEE_LDX_I4_MIX, "ldc.i4.M1", CEE_LDC_I4_M1)
80 OPALIAS(CEE_ENDFAULT, "endfault", CEE_ENDFINALLY)
82 #ifdef _MONO_CIL_OPALIAS_DEFINED_
83 #undef OPALIAS
84 #undef _MONO_CIL_OPALIAS_DEFINED_
85 #endif
86 EOF