pre-geneate table system

This commit is contained in:
angie 2022-12-16 14:36:53 -03:00
parent 44b847f04f
commit 12537e6706
6 changed files with 71 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

26
tools/table_gen.sh Executable file
View File

@ -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}