blob: 46cd77006e0cb2fa2791f68837245a643129ce96 [file] [log] [blame]
#!/usr/bin/env python3
# Copyright 2020 The Skywater PDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
import json
import os
import re
from collections import defaultdict
from pathlib import Path
sourcetodests = defaultdict(list)
Copyright_header = ('// Copyright 2020 The Skywater PDK Authors\n'
'//\n'
'// Licensed under the Apache License, Version 2.0 (the "License");\n'
'// you may not use this file except in compliance with the License.\n'
'// You may obtain a copy of the License at\n'
'//\n'
'// https://www.apache.org/licenses/LICENSE-2.0\n'
'//\n'
'// Unless required by applicable law or agreed to in writing, software\n'
'// distributed under the License is distributed on an "AS IS" BASIS,\n'
'// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
'// See the License for the specific language governing permissions and\n'
'// limitations under the License.\n'
'//\n')
def main(in_file, out_file = None):
with open(in_file, 'r') as in_f:
contents = in_f.read()
specify_blocks = re.findall(r'(?s)specify.*?endspecify', contents)
if specify_blocks == []:
print(' No specify blocks')
return
unindented_blocks = []
for block in specify_blocks:
lines = block.split('\n')
indent = len(lines[-1]) - len(lines[-1].lstrip())
out = lines[0]
for line in lines[1:]:
out += "\n" + line[indent:]
unindented_blocks.append(out)
output = Copyright_header + '\n'.join(unindented_blocks) + '\n'
if out_file is not None:
with open(out_file, 'w') as out_f:
out_f.write(output)
else:
print(">>> Output:")
print(output)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"input",
help="The path to the source directory",
type = Path)
parser.add_argument(
"sourcetodests",
help="output file mapping input to output",
type = Path)
args = parser.parse_args()
files = args.input.rglob('*.full.v')
for f in files:
f = str(f)
out_f = f[:-7] + ".specify.v"
print(f)
sourcetodests[f].append(out_f)
main(f, out_f)
with open(args.sourcetodests, 'w') as srctodst:
json.dump(sourcetodests, srctodst, indent=2)