Skip to content

Commit

Permalink
Autogenerate the ops list for m0_ops.h and m0_debugger.h
Browse files Browse the repository at this point in the history
Add a way to generate ops lists for C files, add m0_ops.h and m0_debugger.h to
the list of files to process and add templates to m0_ops.h and m0_debugger.h.
  • Loading branch information
nbrown committed May 8, 2012
1 parent 2ecac89 commit 7f8e446
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/m0/c/include/m0_ops.h
Expand Up @@ -3,6 +3,7 @@
# include "m0_interp_structures.h"

enum M0_OPS {
/* gen_c_opnames_enum_from(m0.ops) template(' M0_UC_OP,') */
M0_NOOP,
M0_GOTO,
M0_GOTO_IF,
Expand Down Expand Up @@ -45,6 +46,7 @@ enum M0_OPS {
M0_PRINT_I,
M0_PRINT_N,
M0_EXIT
/* end_gen */
};

int
Expand Down
2 changes: 2 additions & 0 deletions src/m0/c/m0_debugger.c
Expand Up @@ -13,6 +13,7 @@ Copyright (C) 2011-2012, Parrot Foundation.
#include "include/m0_debugger.h"

const char *M0_OPS_NAMES[] = {
/* gen_c_opnames_enum_from(m0.ops) template(' "M0_UC_OP",') */
"M0_NOOP",
"M0_GOTO",
"M0_GOTO_IF",
Expand Down Expand Up @@ -55,6 +56,7 @@ const char *M0_OPS_NAMES[] = {
"M0_PRINT_I",
"M0_PRINT_N",
"M0_EXIT"
/* end_gen */
};

static char *M0_REGISTER_NAMES[] = {
Expand Down
17 changes: 17 additions & 0 deletions tools/dev/m0_opcheck.pl
Expand Up @@ -16,6 +16,8 @@
my @m0_files = qw<
src/m0/perl5/m0_assembler.pl
src/m0/perl5/m0_interp.pl
src/m0/c/include/m0_ops.h
src/m0/c/m0_debugger.c
>;


Expand All @@ -37,6 +39,21 @@
push @fixed_lines, "$op_name\n";
}
}
elsif ($line =~ /gen_c_opnames_from\(m0\.ops\)/) {
push @fixed_lines, $line;
my $template = $line;
$template =~ s/.*template\('([^']*)'\).*\*\/.*\n/$1/;
$op_gen = 'names';
foreach my $op (m0_ops()) {
my $op_name = $template;
my $uc_op = uc($op);
$op_name =~ s/UC_OP/$uc_op/;
push @fixed_lines, "$op_name\n";
}
my $last_line = pop @fixed_lines;
$last_line =~ s/,\s*$/\n/;
push @fixed_lines, $last_line
}
elsif ($op_gen) {
if ($line =~ /end_gen/) {
$op_gen = '';
Expand Down

0 comments on commit 7f8e446

Please sign in to comment.