Permalink
Browse files

Autogenerate the ops list for m0_ops.h and m0_debugger.h

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...
1 parent 2ecac89 commit 7f8e44662ed065580c29b40589d51c456333cdbf @nbrown nbrown committed May 8, 2012
Showing with 21 additions and 0 deletions.
  1. +2 −0 src/m0/c/include/m0_ops.h
  2. +2 −0 src/m0/c/m0_debugger.c
  3. +17 −0 tools/dev/m0_opcheck.pl
@@ -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,
@@ -45,6 +46,7 @@ enum M0_OPS {
M0_PRINT_I,
M0_PRINT_N,
M0_EXIT
+ /* end_gen */
};
int
View
@@ -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",
@@ -55,6 +56,7 @@ const char *M0_OPS_NAMES[] = {
"M0_PRINT_I",
"M0_PRINT_N",
"M0_EXIT"
+ /* end_gen */
};
static char *M0_REGISTER_NAMES[] = {
View
@@ -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
>;
@@ -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 = '';

0 comments on commit 7f8e446

Please sign in to comment.