Added info to insns.dat
[nasm/perl-rewrite.git] / perl / lib / Nasm / insns.pm
blob563b4fcaf01803b158e0e953add89ad0595c1c7e
1 package Nasm::insns;
2 use strict;
3 use warnings;
5 use base 'Exporter';
7 require Nasm::insns::Operands;
8 require Nasm::insns::Flags;
10 # Opcode prefixes which need their own opcode tables
11 # LONGER PREFIXES FIRST!
12 our @disasm_prefixes = qw(0F24 0F25 0F38 0F3A 0F7A 0FA6 0FA7 0F);
14 # This should match MAX_OPERANDS from nasm.h
15 our $MAX_OPERANDS = 5;
17 # Add VEX prefixes
18 our @vexlist;
19 for( my $m = 0; $m < 32; $m++ ){
20 for( my $lp = 0; $lp < 8; $lp++ ){
21 push(@vexlist, sprintf("VEX%02X%01X", $m, $lp));
24 @disasm_prefixes = (@vexlist, @disasm_prefixes);
26 our @bytecode_count = (0) x 256;
28 sub new{
29 my($class,$filename) = @_;
31 my $self = bless {}, $class;
33 if($filename){
34 $self->ProcessFile($filename);
37 return $self;
40 sub ProcessFile{
41 my( $self, $filename ) = @_;
42 open( my $file, '<', $filename ) || die "unable to open $filename";
44 $self->{filename} = $filename;
46 my $line_number = 0;
47 while( my $line = <$file> ){
48 $line_number++;
49 chomp $line;
51 # /^\s*(?:;\#)(.*)$/ # special lines
52 next if $line =~ /^\s*(?:;|$)/ ; # comments or blank lines
54 $self->ProcessLine($line,$line_number);
58 sub ProcessLine{
59 my( $self, $line, $line_number ) = @_;
61 unless( $line =~ m{
62 ^\s*+
63 (\S+)\s++
64 (\S+)\s++
66 \[.*?\] |
67 \S+
68 )\s++
69 (\S++)\s*+
71 }x){
72 die;
75 my($name,$operands,$code_string,$flags) = ($1,$2,$3,$4);
77 my $op_obj = Nasm::insns::Operands->new($operands);
78 my $flag_obj = Nasm::insns::Flags->new($flags);
80 my $ref = $self->{ops}{$name.':'.$op_obj->string} = {
81 operands => $op_obj,
82 flags => $flag_obj,
83 codestring => $code_string