Added POD tests and a Perl::Critic test
[nasm/perl-rewrite.git] / perl / lib / Nasm / insns / Flags.pm
blob0da554bf3059260ff93aced6da3a43c8f06eedeb
1 =head1 NAME
3 Nasm::insns::Flags
5 =cut
7 package Nasm::insns::Flags;
8 use strict;
9 use warnings;
10 use YAML::XS ':all';
12 #our @arch = qw{
13 # AMD
14 # 8086 186 286 386 486
15 # X64 X86_64 PENT CYRIX P6 IA64
16 # PRESCOTT
17 # FPU
18 # MMX SSE SSE2 3DNOW
19 #};
21 our( %map2id, %also_enable, @arch);
23 # load up variables from the data below __DATA__
25 my @yaml_streams;
27 ## no critic
28 open( my $data, '<&DATA' ) or die;
29 ## use critic
30 seek( $data, 0, 0 );
33 # seek to end of Perl code
34 local $/ = "\n__DATA__\n";
35 scalar <$data>;
38 # split the embedded YAML code on '...'
39 local $/ = "\n...\n";
40 @yaml_streams = <$data>;
42 close $data;
45 #use Data::Dump 'dump';
46 #use 5.010;
47 use Scalar::Util qw'reftype';
49 my $dir = Load $yaml_streams[0];
50 for my $variable_name ( keys %$dir ){
51 my $index = $dir->{$variable_name};
53 $variable_name =~ s/^([%@\$])//;
54 my $type = $1;
56 ## no critic
57 no strict qw'refs';
58 no warnings qw'once';
59 ## use critic
61 # load on demand
62 my $ref = Load $yaml_streams[$index] or
63 warn "unable to load YAML item \"$variable_name\"\n";
65 my $reftype = reftype $ref;
66 my %type_map = (
67 HASH => '%',
68 ARRAY => '@',
69 SCALAR => '$',
70 REF => '$'
73 $type ||= $type_map{$reftype};
75 if( $type eq '%' ){
76 die unless $reftype eq 'HASH';
77 %{*$variable_name} = %$ref;
78 }elsif( $type eq '@' ){
79 die unless $reftype eq 'ARRAY';
80 @{*$variable_name} = @$ref;
81 }elsif( $type eq '$' ){
82 ${*$variable_name} = $ref;
87 #use 5.010;
88 #use Data::Dump 'dump';
90 #say dump $_ for ( \%map2id, \%also_enable, \@arch);
91 # end of initialization
97 =head2 new
99 Creates a new Nasm::insns::Flags object
101 =cut
103 sub new{
104 my( $class, $string ) = @_;
106 my $self = bless [], $class;
108 $string =~ s/^ \s+ //gx;
109 $string =~ s/ \s+ $//gx;
111 return $self unless $string;
112 return $self if $string eq 'ignore';
114 @$self = split ',', $string;
116 return $self;
122 # All YAML streams must be seperated by a single "..." line
124 # The first YAML stream should start immediately after the __DATA__ line
126 # The first YAML stream is the dir stream, it is used to map the global variable
127 # to the YAML stream
129 __DATA__
131 # "global variable": "YAML stream number"
132 # all of the following global variables should have been
133 # defined with "our %global" at the top of the file
135 # any stream not referenced here will not be loaded
136 "%map2id": 1
137 "%also_enable": 3
138 "@arch": 4
141 # "external name": "internal id"
142 PENT: Pentium
143 80186: 186
144 80286: 286
145 80386: 386
148 # "internal id": "external name"
149 # if an internal id is not in this stream
150 # then use the internal id for external name
151 Pentium: PENT
154 # when Pentium is enabled: 486 is also enabled
155 # which then enables 386, etc
156 Pentium:
157 - 486
158 486:
159 - 386
160 386:
161 - 286
162 286:
163 - 186
164 186:
165 - 8086
168 - KATMAI
169 - PRESCOTT
170 - NEHALEM
171 - WILLAMETTE
172 - WESTMERE
173 - SANDYBRIDGE
174 - SSE
175 - SSE2
176 - SSE3
177 - SSE4A
178 - SSE41
179 - SSE42
180 - SSE5