Add a wrapper script for the instruction generator build

This is the first such script, but the idea is that we're going to
move a bunch of logic out of the Makefile and into Python scripts
where things are a bit easier to understand.
This commit is contained in:
Rupert Swarbrick 2022-04-13 12:48:02 +01:00 committed by Rupert Swarbrick
parent a0638a8592
commit 9b14d0c908
3 changed files with 93 additions and 8 deletions

View file

@ -99,6 +99,10 @@ OUT-DIR := $(dir $(OUT)/)
# get printed when VERBOSE.
verb = $(if $(filter-out 0,$(VERBOSE)),,@)
# Like verb, but expands to --verbose if we're in verbose mode (used
# for running sub-commands)
verb-arg = $(if $(filter-out 0,$(VERBOSE)),--verbose,)
SHELL=/bin/bash
export PRJ_DIR:= $(realpath ../../..)
@ -286,15 +290,15 @@ risc-dv-files := $(shell find $(GEN_DIR) -type f)
# than running it for every target otherwise.
$(metadata)/.instr_gen.build.stamp: \
$(instr-gen-build-vars-prereq) $(risc-dv-files) | $(metadata)
$(instr-gen-build-vars-prereq) \
$(risc-dv-files) scripts/build-instr-gen.py | $(metadata)
$(verb)rm -rf $(OUT-SEED)/instr_gen
$(verb)python3 ${GEN_DIR}/run.py \
--co --steps=gen \
--output=$(OUT-SEED)/instr_gen \
--simulator="${SIMULATOR}" \
${_RISCV_DV_OPTS} \
--isa=${ISA} \
${CSR_OPTS}
$(verb)scripts/build-instr-gen.py \
$(verb-arg) \
--simulator $(SIMULATOR) \
--end-signature-addr $(SIGNATURE_ADDR) \
--output $(OUT-SEED)/instr_gen \
--isa $(ISA)
$(call dump-vars,$(metadata)/.instr_gen.build.vars.mk,gen,$(instr-gen-build-var-deps))
@touch $@

View file

@ -0,0 +1,34 @@
#!/usr/bin/env python3
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
import argparse
import sys
from scripts_lib import run_one, start_riscv_dv_run_cmd
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--simulator', required=True)
parser.add_argument('--end-signature-addr', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--isa', required=True)
args = parser.parse_args()
cmd = (start_riscv_dv_run_cmd(args.verbose) +
['--co', '--steps=gen',
'--simulator', args.simulator,
'--output', args.output,
'--isa', args.isa,
'--end_signature_addr', args.end_signature_addr])
return run_one(args.verbose, cmd)
if __name__ == '__main__':
sys.exit(main())

View file

@ -0,0 +1,47 @@
#!/usr/bin/env python3
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
import os
import shlex
import subprocess
import sys
from typing import List
THIS_DIR = os.path.dirname(__file__)
IBEX_ROOT = os.path.join(THIS_DIR, 4 * '../')
RISCV_DV_ROOT = os.path.normpath(os.path.join(IBEX_ROOT,
'vendor/google_riscv-dv'))
def run_one(verbose: bool, cmd: List[str]) -> int:
if verbose:
# The equivalent of bash -x
print('+ ' + ' '.join(shlex.quote(w) for w in cmd),
file=sys.stderr)
# Passing close_fds=False ensures that if cmd is a call to Make then we'll
# pass through the jobserver fds. If you don't do this, you get a warning
# starting "warning: jobserver unavailable".
return subprocess.run(cmd, close_fds=False).returncode
def start_riscv_dv_run_cmd(verbose: bool):
'''Return the command parts of a call to riscv-dv's run.py'''
riscv_dv_extension = os.path.join(THIS_DIR, '../riscv_dv_extension')
csr_desc = os.path.join(riscv_dv_extension, 'csr_description.yaml')
testlist = os.path.join(riscv_dv_extension, 'testlist.yaml')
cmd = ['python3',
os.path.join(RISCV_DV_ROOT, 'run.py'),
'--testlist', testlist,
'--gcc_opts=-mno-strict-align',
'--custom_target', riscv_dv_extension,
'--csr_yaml', csr_desc,
'--mabi=ilp32']
if verbose:
cmd.append('--verbose')
return cmd