Skip to content
This repository
Browse code

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...
commit 557ee0711f58b586ad256919180c9e1beebe4d61 1 parent 655c43d
Nathan Brown nbrown authored
6 src/m0/c/m0.h
@@ -17,6 +17,7 @@ enum {
17 17 };
18 18
19 19 enum M0_OPS {
  20 + /* gen_c_opnames_from(m0.ops) template(' M0_UC_OP,') */
20 21 M0_NOOP,
21 22 M0_GOTO,
22 23 M0_GOTO_IF,
@@ -35,8 +36,8 @@ enum M0_OPS {
35 36 M0_ISGT_N,
36 37 M0_ISGE_I,
37 38 M0_ISGE_N,
38   - M0_ITON,
39   - M0_NTOI,
  39 + M0_CONVERT_I_N,
  40 + M0_CONVERT_N_I,
40 41 M0_ASHR,
41 42 M0_LSHR,
42 43 M0_SHL,
@@ -63,6 +64,7 @@ enum M0_OPS {
63 64 M0_PRINT_I,
64 65 M0_PRINT_N,
65 66 M0_EXIT
  67 + /* end_gen */
66 68 };
67 69
68 70 typedef uint64_t M0_Config[8];
4 src/m0/c/ops.c
@@ -518,11 +518,11 @@ run_ops( M0_Interp *interp, M0_CallFrame *cf ) {
518 518 M0_EXEC_OP(get_word, cf, ops, pc);
519 519 break;
520 520
521   - case (M0_ITON):
  521 + case (M0_CONVERT_I_N):
522 522 M0_EXEC_OP(convert_i_n, cf, ops, pc);
523 523 break;
524 524
525   - case (M0_NTOI):
  525 + case (M0_CONVERT_N_I):
526 526 M0_EXEC_OP(convert_n_i, cf, ops, pc);
527 527 break;
528 528
16 tools/dev/m0_opcheck.pl
@@ -16,6 +16,7 @@
16 16 my @m0_files = qw<
17 17 src/m0/perl5/m0_assembler.pl
18 18 src/m0/perl5/m0_interp.pl
  19 +src/m0/c/m0.h
19 20 >;
20 21
21 22
@@ -37,6 +38,21 @@
37 38 push @fixed_lines, "$op_name\n";
38 39 }
39 40 }
  41 + elsif ($line =~ /gen_c_opnames_from\(m0\.ops\)/) {
  42 + push @fixed_lines, $line;
  43 + my $template = $line;
  44 + $template =~ s/.*template\('([^']*)'\).*\*\/.*\n/$1/;
  45 + $op_gen = 'names';
  46 + foreach my $op (m0_ops()) {
  47 + my $op_name = $template;
  48 + my $uc_op = uc($op);
  49 + $op_name =~ s/UC_OP/$uc_op/;
  50 + push @fixed_lines, "$op_name\n";
  51 + }
  52 + my $last_line = pop @fixed_lines;
  53 + $last_line =~ s/,\s*$/\n/;
  54 + push @fixed_lines, $last_line
  55 + }
40 56 elsif ($op_gen) {
41 57 if ($line =~ /end_gen/) {
42 58 $op_gen = '';

0 comments on commit 557ee07

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