- 
                Notifications
    
You must be signed in to change notification settings  - Fork 996
 
Add association-list-based helper functions into Rosette backend #5128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            gussmith23
  wants to merge
  16
  commits into
  YosysHQ:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
gussmith23:gussmith23-rosette-backend-updates
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      fd5918c
              
                get_field_names for structs
              
              
                gussmith23 7b4c9c5
              
                Add optional keyword-based constructor
              
              
                gussmith23 10b8fdd
              
                Rename argument
              
              
                gussmith23 1fdfba2
              
                Add helper for accessing by base name
              
              
                gussmith23 c1111f1
              
                Add output helper as well
              
              
                gussmith23 a55dc80
              
                Rename parameter
              
              
                gussmith23 af51097
              
                Convert to 'assoc list helpers'
              
              
                gussmith23 8ec9de0
              
                Use ir.inputs()/ir.outputs()
              
              
                gussmith23 d8b27d4
              
                Bugfix
              
              
                gussmith23 9faa61d
              
                Remove gate on smt and rkt tests
              
              
                gussmith23 51560b0
              
                Start adding Rosette simulation facilties
              
              
                gussmith23 8a9d724
              
                Finish up functions and tests, TODO: CLI
              
              
                gussmith23 a1d68fe
              
                Add option for using assoc list helpers in tests
              
              
                gussmith23 3c54d8a
              
                tests/functional: Auto parallelize
              
              
                KrystalDelusion 108a4ed
              
                tests/functional: Reduce CI to 100 steps
              
              
                KrystalDelusion dcf72ff
              
                Document tests/functional prereqs
              
              
                KrystalDelusion File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -188,12 +188,14 @@ struct SmtrModule { | |
| Functional::IR ir; | ||
| SmtrScope scope; | ||
| std::string name; | ||
| 
     | 
||
| std::optional<std::string> input_helper_name; | ||
| std::optional<std::string> output_helper_name; | ||
| 
     | 
||
| SmtrStruct input_struct; | ||
| SmtrStruct output_struct; | ||
| SmtrStruct state_struct; | ||
| 
     | 
||
| SmtrModule(Module *module) | ||
| SmtrModule(Module *module, bool assoc_list_helpers) | ||
| : ir(Functional::IR::from_module(module)) | ||
| , scope() | ||
| , name(scope.unique_name(module->name)) | ||
| 
        
          
        
         | 
    @@ -202,6 +204,12 @@ struct SmtrModule { | |
| , state_struct(scope.unique_name(module->name.str() + "_State"), scope) | ||
| { | ||
| scope.reserve(name + "_initial"); | ||
| if (assoc_list_helpers) { | ||
| input_helper_name = scope.unique_name(module->name.str() + "_inputs_helper"); | ||
| scope.reserve(*input_helper_name); | ||
| output_helper_name = scope.unique_name(module->name.str() + "_outputs_helper"); | ||
| scope.reserve(*output_helper_name); | ||
| } | ||
| for (auto input : ir.inputs()) | ||
| input_struct.insert(input->name, input->sort); | ||
| for (auto output : ir.outputs()) | ||
| 
          
            
          
           | 
    @@ -257,6 +265,43 @@ struct SmtrModule { | |
| w.pop(); | ||
| } | ||
| 
     | 
||
| void write_assoc_list_helpers(SExprWriter &w) | ||
| { | ||
| // Input struct keyword-based constructor. | ||
| w.push(); | ||
| w.open(list("define")); | ||
| const auto inputs_name = "inputs"; | ||
| w.open(list(*input_helper_name, inputs_name)); | ||
| w.close(); | ||
| w.open(list(input_struct.name)); | ||
| for (auto input : ir.inputs()) { | ||
| w.push(); | ||
| w.open(list("let")); | ||
| w.push(); | ||
| w.open(list()); | ||
| w.open(list("assoc-result")); | ||
| w << list("assoc", "\"" + RTLIL::unescape_id(input->name) + "\"", inputs_name); | ||
| w.pop(); | ||
| w.open(list("if", "assoc-result")); | ||
| w << list("cdr", "assoc-result"); | ||
| w.open(list("begin")); | ||
| w << list("fprintf", list("current-error-port"), "\"%s not found in inputs\""); | ||
| w << "'not-found"; | ||
| w.pop(); | ||
| } | ||
| w.pop(); | ||
| // Output struct keyword-based destructor. | ||
| w.push(); | ||
| w.open(list("define")); | ||
| const auto outputs_name = "outputs"; | ||
| w << list(*output_helper_name, outputs_name); | ||
| w.open(list("list")); | ||
| for (auto output : ir.outputs()) { | ||
| w << list("cons", "\"" + RTLIL::unescape_id(output->name) + "\"", output_struct.access("outputs", output->name)); | ||
| } | ||
| w.pop(); | ||
| } | ||
| 
     | 
||
| void write(std::ostream &out) | ||
| { | ||
| SExprWriter w(out); | ||
| 
        
          
        
         | 
    @@ -265,6 +310,12 @@ struct SmtrModule { | |
| output_struct.write_definition(w); | ||
| state_struct.write_definition(w); | ||
| 
     | 
||
| if (input_helper_name) { | ||
| if (!output_helper_name) | ||
| log_error("if keyword helpers are enabled, both input and output helper names are expected"); | ||
| 
         
      Comment on lines
    
      +314
     to 
      +315
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible for this error to occur?  | 
||
| write_assoc_list_helpers(w); | ||
| } | ||
| 
     | 
||
| write_eval(w); | ||
| write_initial(w); | ||
| } | ||
| 
        
          
        
         | 
    @@ -282,12 +333,16 @@ struct FunctionalSmtrBackend : public Backend { | |
| log("\n"); | ||
| log(" -provides\n"); | ||
| log(" include 'provide' statement(s) for loading output as a module\n"); | ||
| log(" -assoc-list-helpers\n"); | ||
| log(" provide helper functions which convert inputs/outputs from/to association lists\n"); | ||
| log(" \n"); | ||
| log("\n"); | ||
| } | ||
| 
     | 
||
| void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override | ||
| { | ||
| auto provides = false; | ||
| auto assoc_list_helpers = false; | ||
| 
     | 
||
| log_header(design, "Executing Functional Rosette Backend.\n"); | ||
| 
     | 
||
| 
        
          
        
         | 
    @@ -296,6 +351,8 @@ struct FunctionalSmtrBackend : public Backend { | |
| { | ||
| if (args[argidx] == "-provides") | ||
| provides = true; | ||
| else if (args[argidx] == "-assoc-list-helpers") | ||
| assoc_list_helpers = true; | ||
| else | ||
| break; | ||
| } | ||
| 
        
          
        
         | 
    @@ -308,7 +365,7 @@ struct FunctionalSmtrBackend : public Backend { | |
| 
     | 
||
| for (auto module : design->selected_modules()) { | ||
| log("Processing module `%s`.\n", module->name.c_str()); | ||
| SmtrModule smtr(module); | ||
| SmtrModule smtr(module, assoc_list_helpers); | ||
| smtr.write(*f); | ||
| } | ||
| } | ||
| 
          
            
          
           | 
    ||
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| #!/usr/bin/env bash | ||
| pytest -v -m "not smt and not rkt" "$@" | ||
| pytest -v -n auto "$@" --steps 100 | 
  
    
      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
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Python utilities for simulating Rosette code.""" | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I'm missing it, this file isn't used anywhere (and has nothing in it).  | 
||
  
    
      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
    
  
  
    
              
  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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes this a destructor?