changeset 13:5bf045527a94

update opcode2function.pl
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 27 Nov 2018 13:05:20 +0900
parents ee60403fc119
children 2e4c952bcdfb
files lib/OPCODE2Function.pm name2opcode.pl opcode2function.pl
diffstat 3 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/OPCODE2Function.pm	Fri Nov 09 20:45:02 2018 +0900
+++ b/lib/OPCODE2Function.pm	Tue Nov 27 13:05:20 2018 +0900
@@ -2,8 +2,7 @@
 use strict;
 use warnings;
 
-sub codes {
-    my @CODES = qw/
+my @CODES = qw/
        cbc_no_op
        cbc_const_i8
        cbc_const_i16
@@ -2054,7 +2053,12 @@
        cbc_op_call_extop
     /;
 
+my %REV_CODES = ();
 
+#map { $REV_CODES{$CODES[$_]} = [] } (0..@CODES-1);
+map { push @{$REV_CODES{$CODES[$_]}}, $_} (0..@CODES-1);
+
+sub codes {
     my ($class,$input) = @_;
 
     if ( 0 <= $input && $input < @CODES){
@@ -2065,4 +2069,11 @@
 
 }
 
+sub name2bitecode {
+    my ($class,$input) = @_;
+
+     return $REV_CODES{$input} ? $REV_CODES{$input} : "not codes";
+
+}
+
 1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/name2opcode.pl	Tue Nov 27 13:05:20 2018 +0900
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use OPCODE2Function;
+
+my $input =  shift or die 'use input cur_op';
+chomp $input;
+
+my $ref = OPCODE2Function->name2bitecode($input);
+
+if (ref($ref ) eq "ARRAY"){
+    map { print "$_\n";} @$ref;
+} else {
+    print "$_\n";
+}
--- a/opcode2function.pl	Fri Nov 09 20:45:02 2018 +0900
+++ b/opcode2function.pl	Tue Nov 27 13:05:20 2018 +0900
@@ -5,7 +5,7 @@
 use lib "$FindBin::Bin/lib";
 use OPCODE2Function;
 
-my $input =  shift or die 'use input cur_op';
+my $input =  shift; #or die 'use input cur_op';
 chomp $input;
 
 print OPCODE2Function->codes($input)."\n";