Add opcodes XML file
[mono.git] / mono / cil / make-opcodes-def.pl
1 #!/usr/bin/perl
2 #
3 # make-opcodes-def.pl: Loads the opcodes from the CIL-opcodes.xml and
4 # generates a spec compliant opcodes.def file
5 #
6 # Author: 
7 #   Miguel de Icaza (miguel@ximian.com)
8 #
9 # (C) 2001 Ximian, Inc.
10 #
11 # We should really be doing this with XSLT, but I know nothing about XSLT
12 # ;-)
13
14
15 open OPCODES, "cil-opcodes.xml" || die "Can not open cil-opcodes.xml";
16 open OUTPUT, ">opcode.def" || die "Can not create opcode.def file";
17
18 while (<OPCODES>){
19     chop;
20     next if (!/<opcode .*\/>/);
21
22     ($name, $input, $output, $args, $o1, $o2, $flow) = $_ =~ /name=\"([\w\.]+)\"\s+input=\"([\w+]+)\"\s+output=\"([\w+]+)\"\s+args=\"(\w+)\"\s+o1=\"0x(\w+)\"\s+o2=\"0x(\w+)\"\s+flow=\"([\w-]+)\"\/>/;
23     print "NAME: $1\n";
24     $name = $1;
25     $input = $2;
26     $output = $3;
27     $args = $4;
28     $o1 = $5;
29     $o2 = $6;
30     $flow = $7;
31
32     $uname = $name;
33     $uname =~ s/\./_/g;
34     $uname =~ tr [a-z] [A-Z];
35     if ($o1 =~ /0xff/){
36         $count = 1;
37     } else {
38         $count = 2;
39     }
40
41     $ff = "ERROR";
42     $ff = "NEXT" if ($flow =~ /^next$/);
43     $ff = "CALL" if ($flow =~ /^call$/);
44     $ff = "RETURN" if ($flow =~ /^return$/);
45     $ff = "BRANCH" if ($flow =~ /^branch$/);
46     $ff = "COND_BRANCH" if ($flow =~ /^cond-branch$/);
47     $ff = "META" if ($flow =~ /^meta$/);
48
49     print OUTPUT "OPDEF(CEE_$uname, \"$name\", $input, $output, $args, X, $count, 0x$o1, 0x$o2, $ff)\n";
50     
51 }
52
53 print OUTPUT<<EOF
54 #ifndef OPALIAS
55 #define _MONO_CIL_OPALIAS_DEFINED_
56 #define OPALIAS(a,s,r)
57 #endif
58
59 OPALIAS(CEE_BRNULL,     "brnull",    CEE_BRFALSE)
60 OPALIAS(CEE_BRNULL_S,   "brnull.s",  CEE_BRFALSE_S)
61 OPALIAS(CEE_BRZERO,     "brzero",    CEE_BRFALSE)
62 OPALIAS(CEE_BRZERO_S,   "brzero.s",  CEE_BRFALSE_S)
63 OPALIAS(CEE_BRINST,     "brinst",    CEE_BRTRUE)
64 OPALIAS(CEE_BRINST_S,   "brinst.s",  CEE_BRTRUE_S)
65 OPALIAS(CEE_LDIND_U8,   "ldind.u8",  CEE_LDIND_I8)
66 OPALIAS(CEE_LDELEM_U8,  "ldelem.u8", CEE_LDELEM_I8)
67 OPALIAS(CEE_LDX_I4_MIX, "ldc.i4.M1", CEE_LDC_I4_M1)
68 OPALIAS(CEE_ENDFAULT,   "endfault",  CEE_ENDFINALLY)
69
70 #ifdef _MONO_CIL_OPALIAS_DEFINED_
71 #undef OPALIAS
72 #undef _MONO_CIL_OPALIAS_DEFINED_
73 #endif
74 EOF