Skip to content

Commit

Permalink
Fix debug_defines make process.
Browse files Browse the repository at this point in the history
With the old version I ended up with a debug_defines.h that had many
copies of itself. Have registers.py always generate the whole thing, so
there is no chance of repeated executions simply appending again and
again.
  • Loading branch information
timsifive committed Nov 1, 2023
1 parent c4d9ff1 commit 0b46055
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ changelog.tex: .git/logs/HEAD Makefile
git log --no-merges --date=short --pretty="format:vhEntry{%h}{%ad}{%an}{%s}" | \
sed -e "s,\\\\,{\\\\textbackslash},g" -e "s,[_#^],\\\\&,g" -e s/^/\\\\/ >> changelog.tex

debug_defines: debug_defines.h debug_defines.c $(patsubst %,xml/%,$(REGISTERS_TEX:.tex=.xml)) registers.py
./registers.py $@ --cgetters $(filter %.xml, $^)

debug_defines.%:
echo "/*" > $@
echo " * This file is auto-generated by running 'make debug_defines' in" >> $@
echo " * https://github.com/riscv/riscv-debug-spec/ (`git describe --always --dirty --exclude '*'`)" >> $@
echo " */" >> $@
echo >> $@
.PHONY: debug_defines
debug_defines: debug_defines.h debug_defines.c

debug_defines.c: debug_defines.h

debug_defines.h: $(patsubst %,xml/%,$(REGISTERS_TEX:.tex=.xml)) registers.py
./registers.py debug_defines --cgetters $(filter %.xml, $^)

%.eps: %.dot
dot -Teps $< -o $@
Expand Down
15 changes: 13 additions & 2 deletions registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import operator
from functools import cmp_to_key
from functools import reduce
import subprocess

class Registers( object ):
def __init__( self, name, label, prefix, description, skip_index,
Expand Down Expand Up @@ -810,9 +811,19 @@ def main():
parsed = parser.parse_args()

if (parsed.xml_paths):
fd_h = open( parsed.path + ".h", "a" )
git_version = subprocess.run("git describe --always --dirty --exclude *".split(),
capture_output=True, check=True, text=True).stdout.strip()
header = ("/*\n"
" * This file is auto-generated by running 'make debug_defines' in\n"
f" * https://github.com/riscv/riscv-debug-spec/ ({git_version})\n"
" */\n"
"\n")

fd_h = open( parsed.path + ".h", "w" )
fd_h.write(header)
fd_h.write("#ifndef DEBUG_DEFINES_H\n#define DEBUG_DEFINES_H\n")
fd_c = open( parsed.path + ".c", "a" )
fd_c = open( parsed.path + ".c", "w" )
fd_c.write(header)
fd_c.write(f'#include "{parsed.path}.h"\n#include <stddef.h>\n#include <assert.h>\n')
registers_list = [parse_xml( xml_path ) for xml_path in parsed.xml_paths]
for registers in registers_list:
Expand Down

0 comments on commit 0b46055

Please sign in to comment.