diff mbox series

[RISU,RFC,v2,03/14] risugen_x86_emit: add module

Message ID 20190701043536.26019-4-jan.bobek@gmail.com (mailing list archive)
State New, archived
Headers show
Series Support for generating x86 MMX/SSE/AVX test images | expand

Commit Message

Jan Bobek July 1, 2019, 4:35 a.m. UTC
The helper module risugen_x86_emit.pm exports a single function
"parse_emitblock", which serves to capture and return instruction
constraints described by "emit" blocks in an x86 configuration file.

Signed-off-by: Jan Bobek <jan.bobek@gmail.com>
---
 risugen             |  2 +-
 risugen_x86_emit.pm | 91 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 risugen_x86_emit.pm

Comments

Richard Henderson July 3, 2019, 3:47 p.m. UTC | #1
On 7/1/19 6:35 AM, Jan Bobek wrote:
> +sub parse_emitblock($$)
> +{
> +    my ($rec, $insn) = @_;
> +    my $insnname = $rec->{name};
> +    my $opcode = $insn->{opcode}{value};
> +
> +    $emit_opts = {};
> +
> +    my $emitblock = $rec->{blocks}{"emit"};
> +    if (defined $emitblock) {
> +        eval_with_fields($insnname, $opcode, $rec, "emit", $emitblock);
> +    }

And if !defined?  Silently discard?

Is this just weirdness higher in the risugen stack,
such that this might be called maybe_parse_emitblock?


r~
Jan Bobek July 10, 2019, 6:08 p.m. UTC | #2
On 7/3/19 11:47 AM, Richard Henderson wrote:
> On 7/1/19 6:35 AM, Jan Bobek wrote:
>> +sub parse_emitblock($$)
>> +{
>> +    my ($rec, $insn) = @_;
>> +    my $insnname = $rec->{name};
>> +    my $opcode = $insn->{opcode}{value};
>> +
>> +    $emit_opts = {};
>> +
>> +    my $emitblock = $rec->{blocks}{"emit"};
>> +    if (defined $emitblock) {
>> +        eval_with_fields($insnname, $opcode, $rec, "emit", $emitblock);
>> +    }
> 
> And if !defined?  Silently discard?
> 
> Is this just weirdness higher in the risugen stack,
> such that this might be called maybe_parse_emitblock?

If !defined, there _is_ no emit block, and we treat that as an empty
block. The caller gets an empty hash, and it's up to them to decide
what that means. I could rename it, but the difference doesn't seem
that important to me...?

-Jan
diff mbox series

Patch

diff --git a/risugen b/risugen
index e690b18..fe3d00e 100755
--- a/risugen
+++ b/risugen
@@ -43,7 +43,7 @@  my @pattern_re = ();            # include pattern
 my @not_pattern_re = ();        # exclude pattern
 
 # Valid block names (keys in blocks hash)
-my %valid_blockname = ( constraints => 1, memory => 1 );
+my %valid_blockname = ( constraints => 1, memory => 1, emit => 1 );
 
 sub parse_risu_directive($$@)
 {
diff --git a/risugen_x86_emit.pm b/risugen_x86_emit.pm
new file mode 100644
index 0000000..127a524
--- /dev/null
+++ b/risugen_x86_emit.pm
@@ -0,0 +1,91 @@ 
+#!/usr/bin/perl -w
+###############################################################################
+# Copyright (c) 2019 Linaro Limited
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Jan Bobek - initial implementation
+###############################################################################
+
+# risugen_x86_emit -- risugen_x86's helper module for emit blocks
+package risugen_x86_emit;
+
+use strict;
+use warnings;
+
+use risugen_common;
+use risugen_x86_asm;
+
+our @ISA    = qw(Exporter);
+our @EXPORT = qw(parse_emitblock);
+
+my $emit_opts;
+
+sub rep(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{rep} = \%opts;
+}
+
+sub repne(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{repne} = \%opts;
+}
+
+sub data16(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{data16} = \%opts;
+}
+
+sub rex(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{rex} = \%opts;
+}
+
+sub vex(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{vex} = \%opts;
+}
+
+sub modrm(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{modrm} = \%opts;
+}
+
+sub mem(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{mem} = \%opts;
+}
+
+sub imm(%)
+{
+    my (%opts) = @_;
+    $emit_opts->{imm} = \%opts;
+}
+
+sub parse_emitblock($$)
+{
+    my ($rec, $insn) = @_;
+    my $insnname = $rec->{name};
+    my $opcode = $insn->{opcode}{value};
+
+    $emit_opts = {};
+
+    my $emitblock = $rec->{blocks}{"emit"};
+    if (defined $emitblock) {
+        eval_with_fields($insnname, $opcode, $rec, "emit", $emitblock);
+    }
+
+    return $emit_opts;
+}
+
+1;