Repository navigation
Add plugins of the shell, and the extension points a plugin and a Session subclass need - #2907
Open
ganeshgore wants to merge 3 commits into
Open
ganeshgore wants to merge 3 commits into
ganeshgore wants to merge 3 commits into
Conversation
ganeshgore
force-pushed
the
shell-plugins
branch
from
December 1, 2026 03:42
ff2911b to
9612ced
Compare
ganeshgore
force-pushed
the
shell-plugins
branch
from
December 2, 2026 05:23
9612ced to
d313205
Compare
A plugin of the shell is a static library that is built into OpenFPGA: OPENFPGA_PLUGINS lists the plugins of a build (none by default), found in openfpga/plugins or in a folder of OPENFPGA_PLUGIN_DIRS. Each one is made with openfpga_add_plugin(NAME VERSION SOURCES) and has a function register_plugin_<name>(PluginApi&), which CMake lists so that the plugins register in order, after the commands of the shell and before the basic ones. The executable, the Tcl module and the Python module have the same plugins. The shell records who registered each command. A name defined twice now throws ShellRegistrationError instead of returning an invalid id, and a plugin that cannot register stops the start with the reason. A plugin may override how a command runs and add options to it, remove a command (not a basic one, nor one that others depend on), and hook a command: before it (and refuse it), after it (with its status), or after every command. OpenfpgaContext keeps one object of each type for the data of a plugin (extension<T>()). report_plugins answers with what each plugin added, overrode, removed and hooked (schema plugins); the start title, version and help name them. Session.plugins() reads it, and the checkpoints and journals of a Session record the plugins of the build: a checkpoint or a journal of a build with other plugins is not restored or replayed, as their commands may not do the same. openfpga/plugins/example shows each feature, with its test.
The helpers of the reports of the shell move to query_answer.h, so that the commands of a plugin answer as they do: answer_query() checks the stage, runs a query on the data of VPR and gives the answer to the caller, with stage_data(), count_option(), string_option(), add_value_option(), add_query_command() and QUERY_LIST_DEFAULT_LIMIT. A session keeps attachments: data of a plugin, as JSON, under a key that starts with its name (set_attachment(), attachment(), clear_attachment(), attachment_keys()). Reading an architecture, failing to, and reset() clear them. report_session lists them, and the new command set_attachment sets one from a script or a restore. nlohmann/json is vendored in libs/EXTERNAL, which format-cpp leaves out, to check them. Reading an architecture also forgets two more things that a plugin can set with the architectures it reads: the owner of a channel width that is read only (set_fixed_channel_width_owner(); set_app_option and reset_app_option refuse another value of router.route_chan_width, and say who fixed it), and the options that read cached files of the device (set_cache_options()), which go back to their default. make_flow_device() makes the device at once, and stage_generation() tells when a stage completed again. PluginApi::register_app_option() adds an option named <plugin>.<name> with the stage it tunes; report_app_option --json gives each option its owner (vpr, openfpga or the plugin). The example plugin adds one. IoLocationMap gets empty() and io_ports(), plain accessors of its map.
Session.set_attachment() and attachments() read and write the attachments of the session; a checkpoint keeps them, and restore() sets again those the restored session does not have. The journal keeps a copy of the value of each set_attachment, as it does of the scripts of Yosys. restore() now calls documented hooks, in order, on the new session: the options are set, _restore_inputs(manifest, directory) reads the architectures (a subclass that reads them another way overrides it), then _restore_extra(extra, directory) gets back what _checkpoint_extra(directory) saved under "extra" in checkpoint.json, then the attachments are set, and the circuit and the results of the stages are read. A subclass no longer relies on the order of the calls inside restore(). RemoteSession(session_class="module:Class"), or OPENFPGA_SESSION_CLASS, runs a subclass of Session in the worker, which makes and restores its session with it (also RemoteSession.restore(..., session_class=...)). The worker takes the public methods of Session and those that Class.REMOTE_METHODS lists. AppOption.owner says whose an option is.
tangxifan
force-pushed
the
shell-plugins
branch
from
December 2, 2026 21:59
d313205 to
c7765a7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2906 (base
session-tcl). It lets a project built on top of OpenFPGA add its own commands to the shell and its own methods to the Python Session, without patching OpenFPGA.What it adds
Plugins of the shell (commit 1)
OPENFPGA_PLUGINSlists the plugins of a build (none by default), found inopenfpga/pluginsor inOPENFPGA_PLUGIN_DIRS. A plugin is a static library made withopenfpga_add_plugin(NAME VERSION SOURCES)and a functionregister_plugin_<name>(PluginApi&); the executable, the Tcl module and the Python module get the same plugins.ShellRegistrationErrorand stops the start with the reason.report_plugins(schemaplugins), the start title,versionandhelpsay what each plugin did;Session.plugins()reads it; checkpoints and journals record the plugins and refuse another set.openfpga/plugins/exampleshows each feature, with its test.Extension points for plugins (commit 2)
query_answer.h: the helpers of the session reports (answer_query,stage_data,count_option,string_option,add_value_option,add_query_command,QUERY_LIST_DEFAULT_LIMIT) move out ofsession_report_commands.cpp, which uses them.set_attachment,attachment,clear_attachment,attachment_keys), cleared when an architecture is read, listed byreport_session, set from a script with the new commandset_attachment.set_fixed_channel_width_owner) and the options that read cached device files (set_cache_options).make_flow_device()makes the device at once,stage_generation()tells when a stage completed again.PluginApi::register_app_option(name, default, stage);report_app_option --jsongives each option itsowner.IoLocationMap::empty()andio_ports(). nlohmann/json is vendored inlibs/EXTERNAL(header only, left out offormat-cpp) to check attachments.Extension points for a Session subclass (commit 3)
restore()calls documented hooks in order: options,_restore_inputs(manifest, directory),_restore_extra(extra, directory)(what_checkpoint_extra(directory)saved underextra), the attachments, then the circuit and the results.RemoteSession(session_class="module:Class")/OPENFPGA_SESSION_CLASSruns a subclass in the worker, which makes and restores its session with it; the worker takes the methods ofSessionplusClass.REMOTE_METHODS.Session.set_attachment(),attachments(); the journal keeps a copy of each attachment value;AppOption.owner.Tests
test_shell_plugins(registrars, overrides, removals, hooks),test_openfpga_session(attachments, fixed width owner, cache options, stage generation, plugin options),test_example_plugin(with-DOPENFPGA_PLUGINS=example).test_plugins,test_session_extensions(attachments, owners, subclass hooks, session class of a worker, journal of attachments).openfpga_flow/tasks/python_binding_testsand the ctest subset pass in a build without plugins (3 tests of the example plugin skip) and in a build with the example plugin.Not included
pyproject.tomlsets no plugin.