Skip to content

Commit

Permalink
Added and relicensed Tcl scripts
Browse files Browse the repository at this point in the history
Added aux directory
Extracted common Tcl utility commands into another Tcl sctipt

Signed-off-by: Krzysztof Boronski <[email protected]>
  • Loading branch information
kboronski-ant committed Jul 11, 2022
1 parent 273c4aa commit 587d188
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 103 deletions.
9 changes: 5 additions & 4 deletions f4pga/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@

F4CACHEPATH = '.f4cache'

binpath = str(Path(sys_argv[0]).resolve().parent.parent)
bin_path = str(Path(sys_argv[0]).resolve().parent.parent)
mypath = str(Path(__file__).resolve().parent)

share_dir_path = str(Path(f"{environ.get('F4PGA_INSTALL_DIR', '/usr/local')}/xc7/install/share/symbiflow").resolve())
aux_path = str(Path(mypath).joinpath('aux'))

class DependencyNotProducedException(F4PGAException):
dep_name: str
Expand Down Expand Up @@ -214,7 +215,7 @@ def config_mod_runctx(stage: Stage, values: 'dict[str, ]',
config_paths: 'dict[str, str | list[str]]'):
config = prepare_stage_input(stage, values,
dep_paths, config_paths)
return ModRunCtx(share_dir_path, binpath, config)
return ModRunCtx(share_dir_path, bin_path, aux_path, config)

def _process_dep_path(path: str, f4cache: F4Cache):
f4cache.process_file(Path(path))
Expand Down Expand Up @@ -510,8 +511,8 @@ def setup_resolution_env():

r_env = ResolutionEnv({
'shareDir': share_dir_path,
'binDir': str((Path(share_dir_path) / '../../bin').resolve()),
'devDir': mypath
'binDir': bin_path,
'auxDir': aux_path
})

def _noisy_warnings():
Expand Down
34 changes: 34 additions & 0 deletions f4pga/aux/tool_data/yosys/scripts/common/common.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 F4PGA 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
#
# http://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.
#
# SPDX-License-Identifier: Apache-2.0

proc noext { varref } {
# Extension is striped by the f4pga python tool. This code just modifies
# variable refernces to inform f4pga that it should strip the extension.
regsub -all {\${([A-Za-z_:]*)}} $varref {${\1[noext]}} varref_noext
return $varref_noext
}

proc contains { l e } {
foreach entry [split l " "] {
if { $entry == $e } {
return true
}
}
return false
}
35 changes: 35 additions & 0 deletions f4pga/aux/tool_data/yosys/scripts/common/f4pga_exec.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 F4PGA 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
#
# http://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.
#
# SPDX-License-Identifier: Apache-2.0

proc f4pga {action name args} {
regsub {(.*)[!?]} $name {\1} name_dec
upvar f4pga_${name_dec} f4pgavar

if { $action eq "take" || $action eq "produce" } {
set f4pgavar $::env(DEP_${name_dec})
} elseif { $action eq "value" } {
set f4pgavar $::env(VAL_${name_dec})
} elseif { $action eq "tempfile" } {
set f4pgavar $::env(TMP_${name_dec})
} else {
error "Unsupported f4pga subcommand `${action}`" 99
}

return $f4pgavar
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Symbiflow Authors
# Copyright (C) 2022 F4PGA Authors
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 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
#
# SPDX-License-Identifier: ISC
# http://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.
#
# SPDX-License-Identifier: Apache-2.0

yosys -import

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Symbiflow Authors
# Copyright (C) 2022 F4PGA Authors
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 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
#
# SPDX-License-Identifier: ISC
# http://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.
#
# SPDX-License-Identifier: Apache-2.0

yosys -import

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Symbiflow Authors
# Copyright (C) 2022 F4PGA Authors
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 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
#
# SPDX-License-Identifier: ISC
# http://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.
#
# SPDX-License-Identifier: Apache-2.0

# Update the CLKOUT[0-5]_PHASE and CLKOUT[0-5]_DUTY_CYCLE parameter values.
# Due to the fact that Yosys doesn't support floating parameter values
Expand Down Expand Up @@ -62,19 +62,3 @@ proc clean_processes {} {
proc_memwr
proc_clean
}

proc noext { varref } {
# Extension is striped by the f4pga python tool. This code just modifies
# variable refernces to inform f4pga that it should strip the extension.
regsub -all {\${([A-Za-z_:]*)}} $varref {${\1[noext]}} varref_noext
return $varref_noext
}

proc contains { l e } {
foreach entry [split l " "] {
if { $entry == $e } {
return true
}
}
return false
}
21 changes: 16 additions & 5 deletions f4pga/common_modules/yosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def tcl_f4pga(*args, meta=self, tcl: tkinter.Tcl = tcl,
return tcl_f4pga
self.build_tcl_f4pga_cmd = _build_tcl_f4pga_cmd

def interrogate_tcl_script(self, script_path: str):
def interrogate_tcl_script(self, *script_paths: str):
"""
Run the yosys TCL script with fake implementations of yosys commands
in order to discover its I/O.
Expand All @@ -232,7 +232,8 @@ def interrogate_tcl_script(self, script_path: str):
tcl.createcommand('f4pga', self.build_tcl_f4pga_cmd(tcl, tf))

try:
tcl.evalfile(script_path)
for path in script_paths:
tcl.evalfile(path)
except tkinter.TclError as e:
# tkinter discards exceptions thrown by commands implemented in
# python. To recover those exceptions we store them early in
Expand Down Expand Up @@ -276,6 +277,9 @@ def make_env(self, ctx: ModuleContext, tempfiles: YosysTempFiles):

class YosysModule(Module):
extra_products: 'list[str]'
yosys_meta: YosysScriptMeta
tcl_script_path: str
common_script_dir: Path

def map_io(self, ctx: ModuleContext):
mapping = {}
Expand All @@ -285,8 +289,9 @@ def map_io(self, ctx: ModuleContext):
return mapping

def execute(self, ctx: ModuleContext):
dev_dir = ctx.r_env.resolve("${devDir}")
cmd = f'tcl {dev_dir}/scripts/f4pga_exec.tcl; tcl {self.tcl_script_path}'
f4pga_tcl = str(self.common_script_dir.joinpath('f4pga.tcl'))
common_tcl = str(self.common_script_dir.joinpath('common.tcl'))
cmd = f'tcl {f4pga_tcl}; tcl {common_tcl}; tcl {self.tcl_script_path}'
with yosys_temp_files(self.yosys_meta.tempfiles) as tf:
extra_opts = []

Expand Down Expand Up @@ -316,9 +321,15 @@ def param_require(name: str):
self.no_of_phases = 1

self.tcl_script_path = r_env.resolve(param_require('tcl_script'))
self.common_script_dir = Path(r_env.values.get('auxDir')).joinpath(
'tool_data/yosys/scripts/common'
)

self.yosys_meta = YosysScriptMeta(r_env)
self.yosys_meta.interrogate_tcl_script(self.tcl_script_path)
self.yosys_meta.interrogate_tcl_script(
str(self.common_script_dir.joinpath('common.tcl')),
self.tcl_script_path
)

self.takes = list(self.yosys_meta.inputs)
self.produces = [
Expand Down
5 changes: 4 additions & 1 deletion f4pga/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class ModuleContext:

share: str # Absolute path to F4PGA's share directory
bin: str # Absolute path to F4PGA's bin directory
aux: str # Absolute path to F4PGA's aux directory
takes: SimpleNamespace # Maps symbolic dependency names to relative paths.
produces: SimpleNamespace # Contains mappings for explicitely specified dependencies.
# Useful mostly for checking for on-demand optional outputs (such as logs) with
Expand Down Expand Up @@ -131,7 +132,8 @@ def __init__(
config: 'dict[str, ]',
r_env: ResolutionEnv,
share: str,
bin: str
bin: str,
aux: str
):
self.stage_name = module.name
self.takes = SimpleNamespace()
Expand All @@ -141,6 +143,7 @@ def __init__(
self.r_env = r_env
self.share = share
self.bin = bin
self.aux = aux

self._getreqmaybe(self.takes, module.takes, config['takes'])
self._getreqmaybe(self.values, module.values, config['values'])
Expand Down
13 changes: 9 additions & 4 deletions f4pga/module_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ def get_module(path: str):
mod = import_module_from_path(path)
preloaded_modules[path] = mod

# All F4PGA modules should expose a `ModuleClass` type/alias which is a class implementing a Module interface
# All F4PGA modules should expose a `ModuleClass` type/alias which is a class
# implementing a Module interface
return mod.ModuleClass


class ModRunCtx:
share: str
bin: str
aux: str
config: 'dict[str, ]'

def __init__(self, share: str, bin: str, config: 'dict[str, ]'):
def __init__(self, share: str, bin: str, aux: str, config: 'dict[str, ]'):
self.share = share
self.bin = bin
self.aux = aux
self.config = config

def make_r_env(self):
Expand Down Expand Up @@ -116,7 +119,8 @@ def module_map(module: Module, ctx: ModRunCtx):
ctx.config,
ctx.make_r_env(),
ctx.share,
ctx.bin
ctx.bin,
ctx.aux
)
except Exception as e:
raise ModuleFailException(module.name, 'map', e)
Expand All @@ -132,7 +136,8 @@ def module_exec(module: Module, ctx: ModRunCtx):
ctx.config,
ctx.make_r_env(),
ctx.share,
ctx.bin
ctx.bin,
ctx.aux
)
except Exception as e:
raise ModuleFailException(module.name, 'exec', e)
Expand Down
5 changes: 3 additions & 2 deletions f4pga/platforms/xc7a100t.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@

"synth": {
"params": {
"tcl_script": "${devDir}/scripts/xc7/synth.tcl"
"tcl_script": "${auxDir}/tool_data/yosys/scripts/vendor/xilinx/xc7/synth.tcl"
},
"values": {
"yosys_plugins": [],
"use_roi": "FALSE"
}
},
Expand All @@ -89,7 +90,7 @@

"make_eblif": {
"params": {
"tcl_script": "${devDir}/scripts/xc7/conv.tcl"
"tcl_script": "${auxDir}/tool_data/yosys/scripts/vendor/xilinx/xc7/conv.tcl"
},
"values": {
"use_lut_constants": "FALSE"
Expand Down
5 changes: 3 additions & 2 deletions f4pga/platforms/xc7a200t.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@

"synth": {
"params": {
"tcl_script": "${devDir}/scripts/xc7/synth.tcl"
"tcl_script": "${auxDir}/tool_data/yosys/scripts/vendor/xilinx/xc7/synth.tcl"
},
"values": {
"yosys_plugins": [],
"use_roi": "FALSE"
}
},
Expand All @@ -89,7 +90,7 @@

"make_eblif": {
"params": {
"tcl_script": "${devDir}/scripts/xc7/conv.tcl"
"tcl_script": "${auxDir}/tool_data/yosys/scripts/vendor/xilinx/xc7/conv.tcl"
},
"values": {
"use_lut_constants": "FALSE"
Expand Down
Loading

0 comments on commit 587d188

Please sign in to comment.