Skip to content

Commit

Permalink
Put SPDX on first line of debug_defines.[ch]
Browse files Browse the repository at this point in the history
  • Loading branch information
rtwfroody committed Feb 23, 2024
1 parent 5b9d354 commit d14e1f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 3 additions & 8 deletions build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ build-registers: $(REGISTERS_ADOC)
../registers.py --adoc $@ --adoc-definitions $(patsubst %.adoc,%-def.adoc,$@) $<

debug_defines: debug_defines.h debug_defines.c $(patsubst %,../xml/%,$(REGISTERS_ADOC:.adoc=.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 >> $@
../registers.py $@ --cgetters $(filter %.xml, $^) \
--create "This file was auto-generated by running 'make debug_defines' in \
https://github.com/riscv/riscv-debug-spec/ (`git describe --always --dirty --exclude '*'`)"

%.scala: ../xml/%.xml ../registers.py
../registers.py --chisel $(basename $@).scala $< > /dev/null
Expand Down
12 changes: 9 additions & 3 deletions registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def parse_bits( field ):
def parse_spdx( path ):
with open( path ) as f:
data = f.read(4096)
return set(re.findall(r"SPDX-License-Identifier:\s*(.+)$", data, re.MULTILINE))
return set(re.findall(r"SPDX-License-Identifier:\s*(.+?)\s*(?:-->.*)?$", data, re.MULTILINE))

def parse_xml( path ):
licenses = parse_spdx(path)
Expand Down Expand Up @@ -1078,6 +1078,8 @@ def main():
parser.add_argument( '--chisel',
help='Write Scala Classes to the named file.' )
parser.add_argument( '--cgetters', dest='xml_paths', nargs='+')
parser.add_argument( '--create',
help='Line included in the output described how the file was created.' )
parsed = parser.parse_args()

if (parsed.xml_paths):
Expand All @@ -1086,11 +1088,15 @@ def main():
# Assert every license list is the same
assert all(license_lists[0] == license_list for license_list in license_lists), \
"All XML files must have the same SPDX-License-Identifier"
fd_h = open( parsed.path + ".h", "a" )
fd_h = open( parsed.path + ".h", "w" )
write_c_licenses( fd_h, license_lists[0] )
if (parsed.create):
fd_h.write(f"/* {parsed.create} */\n\n")
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" )
write_c_licenses( fd_c, license_lists[0] )
if (parsed.create):
fd_c.write(f"/* {parsed.create} */\n\n")
fd_c.write(f'#include "{parsed.path}.h"\n#include <stddef.h>\n#include <assert.h>\n')
for registers in registers_list:
write_cheader( fd_h, registers )
Expand Down

0 comments on commit d14e1f3

Please sign in to comment.