Skip to content

Generate op_enum.h during build rather than a separate step #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@
__pycache__/

# Build outputs
/src/match_token.c
/src/scanner.c
/src/gen/*
/simulator/tt
/module/gitversion.c
/tests/tests
/docs/*.pdf
/docs/*.html
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v5.0.x:

- **FIX**: fix risk of crash/corruption in help mode reverse search
- **NEW**: op_enums.py runs automatically during build

## v5.0.0

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ See section 6.3 in the Ragel manual for information on the `=>` scanner construc
If you want to add a new `OP` or `MOD`, please create the relevant `tele_op_t` or `tele_mod_t` in the `src/ops` directory. You will then need to reference it in the following places:

- `src/ops/op.c`: add a reference to your struct to the relevant table, `tele_ops` or `tele_mods`. Ideally grouped with other ops from the same file.
- `src/ops/op_enum.h`: please run `python3 utils/op_enums.py` to generate this file.
- `src/match_token.rl`: add an entry to the Ragel list to match the token to the struct. Again, please try to keep the order in the list sensible.
- `module/config.mk`: add a reference to any added .c files in the CSRCS list.
- `tests/Makefile`: add a reference to any added .c files in /src, replacing ".c" with ".o", in the tests: recipe.
Expand Down
15 changes: 15 additions & 0 deletions codegen.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Add a rule to build match_token.c from match_token.rl
../src/gen/match_token.c: ../src/match_token.rl ../src/gen/op_enum.h
ragel -C -G2 ../src/match_token.rl -o ../src/gen/match_token.c

# Add a rule to build scanner.c from scanner.rl
../src/gen/scanner.c: ../src/scanner.rl
ragel -C -G2 ../src/scanner.rl -o ../src/gen/scanner.c

# Add a rule to build op_enum.h from op.c and make it an additional dependency of object files that include it
../src/gen/op_enum.h: ../src/ops/op.c
python3 ../utils/op_enums.py

../src/ops/op.h: ../src/gen/op_enum.h
../src/ops/op.o: ../src/gen/op_enum.h
../src/command.o: ../src/gen/op_enum.h
15 changes: 4 additions & 11 deletions module/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,16 @@

SHELL=bash

# Makefile.avr32.in defines an unused variable build, which is used in the clean
# target, it's probably there to list other build targets
build += ../src/scanner.c ../src/match_token.c ../module/gitversion.c
# Makefile.avr32.in defines the build variable to list other build targets
build += ../src/gen/*.c ../src/gen/*.h

# Include the common Makefile, which will also include the project specific
# config.mk file.
MAKEFILE_PATH = ../libavr32/asf/avr32/utils/make/Makefile.avr32.in
include $(MAKEFILE_PATH)

# Add a rule to build match_token.c from match_token.rl
../src/match_token.c: ../src/match_token.rl
ragel -C -G2 ../src/match_token.rl -o ../src/match_token.c

# Add a rule to build scanner.c from scanner.rl
../src/scanner.c: ../src/scanner.rl
ragel -C -G2 ../src/scanner.rl -o ../src/scanner.c
include ../codegen.mk

# Add the git commit id to a file for use when printing out the version
../module/gitversion.c: ../.git/HEAD ../.git/index
../src/gen/gitversion.c: ../.git/HEAD ../.git/index
echo "const char *git_version = \"$(shell cut -d '-' -f 1 <<< $(shell git describe --tags | cut -c 1-)) $(shell git describe --always --dirty --exclude '*' | tr '[a-z]' '[A-Z]')\";" > $@
9 changes: 6 additions & 3 deletions module/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ CSRCS = \
../module/main.c \
../module/edit_mode.c \
../module/flash.c \
../module/gitversion.c \
../module/grid.c \
../module/help_mode.c \
../module/line_editor.c \
Expand All @@ -77,8 +76,9 @@ CSRCS = \
../src/every.c \
../src/helpers.c \
../src/drum_helpers.c \
../src/match_token.c \
../src/scanner.c \
../src/gen/match_token.c \
../src/gen/scanner.c \
../src/gen/gitversion.c \
../src/scale.c \
../src/scene_serialization.c \
../src/state.c \
Expand Down Expand Up @@ -264,3 +264,6 @@ LDFLAGS = -Wl,-e,_trampoline,--defsym=__flash_nvram_size__=200K
# Pre- and post-build commands
PREBUILD_CMD =
POSTBUILD_CMD =

# Make GCC-produced header dependency infomation visible to the Makefile
-include $(OBJS:.o=.d)
15 changes: 5 additions & 10 deletions simulator/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.PHONY: clean
CFLAGS=-std=c99 -g -Wall -fno-common -DSIM -I. -I../src -I../libavr32/src
DEPS =
DEPS = ../src/gen/op_enum.h
OBJ = tt.o ../src/teletype.o ../src/command.o ../src/helpers.o ../src/drum_helpers.o \
../src/every.o ../src/match_token.o ../src/scanner.o \
../src/every.o ../src/gen/match_token.o ../src/gen/scanner.o \
../src/scale.o ../src/scene_serialization.o \
../src/state.o ../src/table.o ../src/turtle.o ../src/chaos.o \
../src/ops/op.o ../src/ops/ansible.c ../src/ops/controlflow.o \
Expand All @@ -18,19 +18,15 @@ OBJ = tt.o ../src/teletype.o ../src/command.o ../src/helpers.o ../src/drum_helpe
../src/ops/wslash_shared.o ../src/ops/crow.o ../src/ops/i2c2midi.o\
../libavr32/src/euclidean/euclidean.o ../libavr32/src/euclidean/data.o \
../libavr32/src/music.o ../libavr32/src/util.o ../libavr32/src/random.o \
../src/ops/midi.o
../src/ops/midi.o

%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)

tt: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)

../src/match_token.c: ../src/match_token.rl
ragel -C -G2 ../src/match_token.rl -o ../src/match_token.c

../src/scanner.c: ../src/scanner.rl
ragel -C -G2 ../src/scanner.rl -o ../src/scanner.c
include ../codegen.mk

clean:
rm -f tt
Expand All @@ -40,5 +36,4 @@ clean:
rm -f ../src/ops/*.o
rm -f ../libavr32/src/euclidean/*.o
rm -f ../libavr32/src/*.o
rm -f ../src/match_token.c
rm -f ../src/scanner.c
rm -f ../src/gen/*
2 changes: 1 addition & 1 deletion src/match_token.rl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdio.h>

#include "ops/op.h"
#include "ops/op_enum.h"
#include "gen/op_enum.h"
#include "helpers.h"

%%{
Expand Down
18 changes: 9 additions & 9 deletions src/ops/grid_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ static void op_G_BTN_X_set(const void *NOTUSED(data), scene_state_t *ss,
s16 y = GBC.y;
s16 w = GBC.w;
s16 h = GBC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GBC.x = x;
GBC.y = y;
Expand All @@ -640,7 +640,7 @@ static void op_G_BTN_Y_set(const void *NOTUSED(data), scene_state_t *ss,
s16 x = GBC.x;
s16 w = GBC.w;
s16 h = GBC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GBC.x = x;
GBC.y = y;
Expand Down Expand Up @@ -691,7 +691,7 @@ static void op_G_BTNX_set(const void *NOTUSED(data), scene_state_t *ss,
s16 y = GBC.y;
s16 w = GBC.w;
s16 h = GBC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GBC.x = x;
GBC.y = y;
Expand All @@ -713,7 +713,7 @@ static void op_G_BTNY_set(const void *NOTUSED(data), scene_state_t *ss,
s16 x = GBC.x;
s16 w = GBC.w;
s16 h = GBC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GBC.x = x;
GBC.y = y;
Expand Down Expand Up @@ -1138,7 +1138,7 @@ static void op_G_FDR_X_set(const void *NOTUSED(data), scene_state_t *ss,
s16 y = GFC.y;
s16 w = GFC.w;
s16 h = GFC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GFC.x = x;
GFC.y = y;
Expand All @@ -1162,7 +1162,7 @@ static void op_G_FDR_Y_set(const void *NOTUSED(data), scene_state_t *ss,
s16 x = GFC.x;
s16 w = GFC.w;
s16 h = GFC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GFC.x = x;
GFC.y = y;
Expand Down Expand Up @@ -1252,7 +1252,7 @@ static void op_G_FDRX_set(const void *NOTUSED(data), scene_state_t *ss,
s16 y = GFC.y;
s16 w = GFC.w;
s16 h = GFC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GFC.x = x;
GFC.y = y;
Expand All @@ -1274,7 +1274,7 @@ static void op_G_FDRY_set(const void *NOTUSED(data), scene_state_t *ss,
s16 x = GFC.x;
s16 w = GFC.w;
s16 h = GFC.h;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GFC.x = x;
GFC.y = y;
Expand Down Expand Up @@ -1398,7 +1398,7 @@ static void op_G_XYP_get(const void *NOTUSED(data), scene_state_t *ss,

if (i < (s16)0 || i >= (s16)GRID_XYPAD_COUNT) return;
if (script < 0 || script > INIT_SCRIPT) script = -1;
CLAMP_X_Y_W_H(return );
CLAMP_X_Y_W_H(return);

GXYC.enabled = true;
GXYC.group = SG.current_group;
Expand Down
3 changes: 1 addition & 2 deletions src/ops/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
/////////////////////////////////////////////////////////////////
// OPS //////////////////////////////////////////////////////////

// If you edit this array, you need to run 'utils/op_enums.py' to update the
// values in 'op_enum.h' so that the order matches.

const tele_op_t *tele_ops[E_OP__LENGTH] = {
// variables
&op_A, &op_B, &op_C, &op_D, &op_DRUNK, &op_DRUNK_MAX, &op_DRUNK_MIN,
Expand Down
2 changes: 1 addition & 1 deletion src/ops/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stddef.h>

#include "command.h"
#include "op_enum.h"
#include "gen/op_enum.h"
#include "state.h"

typedef struct {
Expand Down
Loading