mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-28 10:19:26 +00:00 
			
		
		
		
	docs/functional: Add dummy toy example
Add `dummy.cc`, loosely based on `backends/functional/test_generic.cc` but as an actualy backend and without the memory testing. Skeleton section for minimal functional backend, describing the aforementioned `dummy.cc`.
This commit is contained in:
		
							parent
							
								
									db823a6acb
								
							
						
					
					
						commit
						560b5fe6bd
					
				
					 2 changed files with 79 additions and 0 deletions
				
			
		|  | @ -144,6 +144,41 @@ S-expressions can be constructed with ``SExpr::list``, for example ``SExpr expr | |||
|   parentheses. | ||||
| - The destructor calls ``flush`` but also closes all unclosed parentheses. | ||||
| 
 | ||||
| Example: A minimal functional backend | ||||
| ------------------------------------- | ||||
| 
 | ||||
| .. literalinclude:: /code_examples/functional/dummy.cc | ||||
|    :language: c++ | ||||
|    :caption: Example source code for a minimal functional backend | ||||
| 
 | ||||
| - three main steps needed | ||||
| 
 | ||||
|   + convert to FunctionalIR | ||||
|   + handle nodes | ||||
|   + handle outputs and next state | ||||
| 
 | ||||
| - backend pass boiler plate gives us ``write_functional_dummy`` command | ||||
| - pointer ``f`` is a ``std::ostream`` we can write to, being either a file or | ||||
|   stdout | ||||
| - FunctionalIR conversion done by ``Functional::IR::from_module()`` | ||||
| - each node performs some function or operation (including reading input/current | ||||
|   state) | ||||
| 
 | ||||
|   + each variable is assigned exactly once before being used | ||||
|   + ``node.name()`` returns a ``RTLIL::IdString``, which we convert for | ||||
|     printing with ``id2cstr()`` | ||||
|   + ``node.to_string()`` converts the node into a string of the form | ||||
|     ``function(args)`` | ||||
| 
 | ||||
|     * ``function`` is the result of ``Functional::IR::fn_to_string(node.fn())`` | ||||
|     * ``args`` are the zero or more arguments passed to the function, most | ||||
|       commonly the name of another node | ||||
|     * wraps ``node.visit()`` with a private visitor with return type | ||||
|       ``std::string`` | ||||
| 
 | ||||
| - ``Functional::IROutput::value()`` and ``Functional::IRState::next_value()`` | ||||
|   represent the outputs of our function | ||||
| 
 | ||||
| Example: Adapting SMT-LIB backend for Rosette | ||||
| --------------------------------------------- | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue