Skip to content
Browse files

Autogenerate the ops list for m0.h

Add a way to generate ops lists for C files, add m0.h to
the list of files to process and add templates to m0.h.

Also, change M0_ITON and M0_NTOI to M0_CONVERT_I_N and
M0_CONVERT_N_I respectively.
  • Loading branch information...
1 parent 655c43d commit 557ee0711f58b586ad256919180c9e1beebe4d61 @nbrown nbrown committed Jun 9, 2012
Showing with 22 additions and 4 deletions.
  1. +4 −2 src/m0/c/m0.h
  2. +2 −2 src/m0/c/ops.c
  3. +16 −0 tools/dev/m0_opcheck.pl
View
6 src/m0/c/m0.h
@@ -17,6 +17,7 @@ enum {
};
enum M0_OPS {
+ /* gen_c_opnames_from(m0.ops) template(' M0_UC_OP,') */
M0_NOOP,
M0_GOTO,
M0_GOTO_IF,
@@ -35,8 +36,8 @@ enum M0_OPS {
M0_ISGT_N,
M0_ISGE_I,
M0_ISGE_N,
- M0_ITON,
- M0_NTOI,
+ M0_CONVERT_I_N,
+ M0_CONVERT_N_I,
M0_ASHR,
M0_LSHR,
M0_SHL,
@@ -63,6 +64,7 @@ enum M0_OPS {
M0_PRINT_I,
M0_PRINT_N,
M0_EXIT
+ /* end_gen */
};
typedef uint64_t M0_Config[8];
View
4 src/m0/c/ops.c
@@ -518,11 +518,11 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
M0_EXEC_OP(get_word, cf, ops, pc);
break;
- case (M0_ITON):
+ case (M0_CONVERT_I_N):
M0_EXEC_OP(convert_i_n, cf, ops, pc);
break;
- case (M0_NTOI):
+ case (M0_CONVERT_N_I):
M0_EXEC_OP(convert_n_i, cf, ops, pc);
break;
View
16 tools/dev/m0_opcheck.pl
@@ -16,6 +16,7 @@
my @m0_files = qw<
src/m0/perl5/m0_assembler.pl
src/m0/perl5/m0_interp.pl
+src/m0/c/m0.h
>;
@@ -37,6 +38,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 557ee07

Please sign in to comment.
Something went wrong with that request. Please try again.