diff --git a/Makefile b/Makefile index a39afb6..3d41192 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ WARNINGS += -Werror=vla -Werror=switch -Werror=implicit-fallthrough -Werr WARNINGS_C := -Werror=implicit-function-declaration -Werror=incompatible-pointer-types WARNINGS_CXX := +TABLE_GEN := tools/table_gen.sh + ifeq ($(CC),gcc) WARNINGS += -Wno-cast-function-type endif @@ -66,6 +68,12 @@ OXX_FILES := $(foreach f,$(CXX_FILES:.cpp=.o),build/$f) DEP_FILES := $(O_FILES:%.o=%.d) $(OXX_FILES:%.o=%.d) +TABLE_DIRS := $(shell find include rabbitizer -type d) +TABLE_TEMPLATES := $(foreach dir,$(TABLE_DIRS),$(wildcard $(dir)/*.table.template)) +TABLE_GENERATED := $(TABLE_TEMPLATES:%.table.template=%.table.h) + +TABLE_DEP_FILES := $(TABLE_GENERATED:%.table.h=%.table.d) + TESTS_DIRS := $(shell find tests -type d) TESTS_C := $(foreach dir,$(TESTS_DIRS),$(wildcard $(dir)/*.c)) TESTS_CXX := $(foreach dir,$(TESTS_DIRS),$(wildcard $(dir)/*.cpp)) @@ -102,6 +110,7 @@ clean: distclean: clean $(RM) -rf dist *.egg-info .mypy_cache + $(RM) -rf $(TABLE_GENERATED) format: clang-format-11 -i -style=file $(C_FILES) @@ -131,16 +140,22 @@ build/%.a: build/%.so: $(CC) -shared -o $@ $^ -build/%.o: %.c +build/%.o: %.c $(TABLE_GENERATED) # The -MMD flags additionaly creates a .d file with the same name as the .o file. $(CC) -MMD -MP -c $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(WARNINGS_C) $(CFLAGS) -o $@ $< -build/%.o: %.cpp +build/%.o: %.cpp $(TABLE_GENERATED) # The -MMD flags additionaly creates a .d file with the same name as the .o file. $(CXX) -MMD -MP -c $(CXXSTD) $(OPTFLAGS) $(IINC_XX) $(WARNINGS) $(WARNINGS_CXX) $(CXXFLAGS) -o $@ $< +%.table.h: %.table.template + $(CC) -x c -MMD -MP -fsyntax-only -o $@ $< + $(TABLE_GEN) $< $@ $(@F) + + -include $(DEP_FILES) +-include $(TABLE_DEP_FILES) # Print target for debugging print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true diff --git a/include/common/Abi_enum.table.h b/include/common/Abi_enum.table.h new file mode 100644 index 0000000..a915348 --- /dev/null +++ b/include/common/Abi_enum.table.h @@ -0,0 +1,14 @@ +#ifndef Abi_enum_table_h_automatic +#define Abi_enum_table_h_automatic + +/* Automatically generated. DO NOT MODIFY */ + +typedef enum RabbitizerAbi { +RABBITIZER_ABI_NUMERIC, +RABBITIZER_ABI_O32, +RABBITIZER_ABI_N32, +RABBITIZER_ABI_N64, + RABBITIZER_ABI_MAX, +} RabbitizerAbi; + +#endif diff --git a/include/common/Abi_enum.table.template b/include/common/Abi_enum.table.template new file mode 100644 index 0000000..77e3f9b --- /dev/null +++ b/include/common/Abi_enum.table.template @@ -0,0 +1,10 @@ + +#define RABBITIZER_DEF_ABI(name) RABBITIZER_ABI_##name + +typedef enum RabbitizerAbi { + #include "Abi.inc" + + RABBITIZER_DEF_ABI(MAX), +} RabbitizerAbi; + +#undef RABBITIZER_DEF_ABI diff --git a/include/common/RabbitizerConfig.h b/include/common/RabbitizerConfig.h index 8b9def7..ed4caa0 100644 --- a/include/common/RabbitizerConfig.h +++ b/include/common/RabbitizerConfig.h @@ -11,15 +11,7 @@ extern "C" { #endif -#define RABBITIZER_DEF_ABI(name) RABBITIZER_ABI_##name - -typedef enum RabbitizerAbi { - #include "Abi.inc" - - RABBITIZER_DEF_ABI(MAX), -} RabbitizerAbi; - -#undef RABBITIZER_DEF_ABI +#include "Abi_enum.table.h" RabbitizerAbi RabbitizerAbi_fromStr(const char *name); diff --git a/tests/c/logic_checks/run_logic_checks.sh b/tests/c/logic_checks/run_logic_checks.sh index 3603dd1..958c45e 100755 --- a/tests/c/logic_checks/run_logic_checks.sh +++ b/tests/c/logic_checks/run_logic_checks.sh @@ -1,5 +1,8 @@ #!/bin/bash +# SPDX-FileCopyrightText: © 2022 Decompollaborate +# SPDX-License-Identifier: MIT + set -e ./build/tests/c/logic_checks/descriptor_logic_check.elf diff --git a/tools/table_gen.sh b/tools/table_gen.sh new file mode 100755 index 0000000..59ee9a1 --- /dev/null +++ b/tools/table_gen.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: © 2022 Decompollaborate +# SPDX-License-Identifier: MIT + +set -e + +INPUT_FILE=$1 +OUTPUT_FILE=$2 +HEADER_GUARD_BAD=$3 + +# Change dots to underscores +HEADER_GUARD=$(echo ${HEADER_GUARD_BAD} | sed 's/\./_/g') + +echo "#ifndef ${HEADER_GUARD}_automatic" > ${OUTPUT_FILE} +echo "#define ${HEADER_GUARD}_automatic" >> ${OUTPUT_FILE} + +echo >> ${OUTPUT_FILE} +echo "/* Automatically generated. DO NOT MODIFY */" >> ${OUTPUT_FILE} +echo >> ${OUTPUT_FILE} + +cpp -P ${INPUT_FILE} >> ${OUTPUT_FILE} + +echo >> ${OUTPUT_FILE} + +echo "#endif" >> ${OUTPUT_FILE}