aboutsummaryrefslogtreecommitdiff
path: root/scripts/generate_target_board
blob: c4d91eebc9fb00106e6b1afc85243b46cc735a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3

import argparse
import sys

def parse_options(argv):
  parser = argparse.ArgumentParser()

  parser.add_argument('--sim-name', type = str, required = True,
                      help = 'The sim name of target board, like riscv-sim.')
  parser.add_argument('--build-arch-abi', type = str, required = True,
                      help = 'The arch and abi when build, like ' +
                             '--with-arch=rv64gcv --with-abi=lp64d' +
                             'in riscv-gnu-toolchain configure, ' +
                             'within format rv64gcv-lp64d.')
  parser.add_argument('--extra-test-arch-abi-flags-list', type=str,
                      help = 'The arch, abi and flags list for extra test,' +
                             'like =rv64gcv_zvl256b-lp64d:' +
                             '--param=riscv-autovec-lmul=dynamic:' +
                             '--param=riscv-autovec-preference=fixed-vlmax.',
                      default = '')
  parser.add_argument('--cmodel', type = str, default = 'medlow',
                      help = 'The name of the cmodel, like medlow.')

  options = parser.parse_args()
  return options

# Generate only one target board like below:
#   riscv-sim/-march=rv64gcv_zvl256b/-mabi=lp64d/-mcmodel=medlow
# From the config_string like below, --param is optional
#   rv64gcv_zvl128b-lp64d:--param=riscv-autovec-lmul=m1
def generate_one_target_board(arch_abi, flags, options):
  arch_and_abi = arch_abi.split("-")
  arch = arch_and_abi[0]
  abi = arch_and_abi[1]

  if len(flags) == 0:
    return "{0}/-march={1}/-mabi={2}/-mcmodel={3}".format(
      options.sim_name, arch, abi, options.cmodel)

  flags = flags.replace(":", "/")

  return "{0}/-march={1}/-mabi={2}/-mcmodel={3}/{4}".format(
    options.sim_name, arch, abi, options.cmodel, flags)

def main(argv):
  options = parse_options(argv)

  if not options.sim_name or not options.build_arch_abi:
    print ("The --sim-name and/or --build-arch-abi cannot be empty or null.")
    return

  target_board_list = [
    generate_one_target_board(options.build_arch_abi, "", options)
  ]

  if options.extra_test_arch_abi_flags_list:
    extra_test_list = options.extra_test_arch_abi_flags_list.split (";")

    for extra_test in extra_test_list:
      idx = extra_test.find(":")

      if idx == -1:
        one_target_board = generate_one_target_board(extra_test, "", options)
        target_board_list.append(one_target_board)
      else:
        arch_abi = extra_test[:idx]
        flags = extra_test[idx + 1:]

        for flag in flags.split(","):
          one_target_board = generate_one_target_board(arch_abi, flag, options)
          target_board_list.append(one_target_board)

  print(' '.join(target_board_list))

if __name__ == '__main__':
    sys.exit(main(sys.argv))