Last active
January 16, 2019 14:44
-
-
Save olofk/b700a338a8fa054de432632feae2bcbd to your computer and use it in GitHub Desktop.
Web Enabled Edalize example
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
| { | |
| "files": [ | |
| { | |
| "file_type": "verilogSource", | |
| "is_include_file": false, | |
| "logical_name": "", | |
| "name": "../src/fusesoc_utils_blinky_0/blinky.v" | |
| }, | |
| { | |
| "file_type": "cppSource", | |
| "is_include_file": false, | |
| "logical_name": "", | |
| "name": "../src/fusesoc_utils_blinky_0/bench/blinky_tb.cpp" | |
| }, | |
| { | |
| "file_type": "user", | |
| "is_include_file": false, | |
| "logical_name": "", | |
| "name": "../src/fusesoc_utils_blinky_0/bench/testb.h" | |
| } | |
| ], | |
| "hooks": {}, | |
| "name": "fusesoc_utils_blinky_0", | |
| "parameters": { | |
| "clk_freq_hz": { | |
| "datatype": "int", | |
| "default": 10000, | |
| "description": "Clock frequency in Hz", | |
| "paramtype": "vlogparam" | |
| }, | |
| "vcd": { | |
| "datatype": "bool", | |
| "paramtype": "plusarg" | |
| } | |
| }, | |
| "tool_options": { | |
| "verilator": { | |
| "verilator_options": [ | |
| "--trace" | |
| ] | |
| } | |
| }, | |
| "toplevel": "blinky", | |
| "version": "0.2.0", | |
| "vpi": [] | |
| } |
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
| Install edalize (pip install edalize) | |
| Set up server with python weedalize.py [port] | |
| Call it with curl using curl -i -X POST -H 'Content-Type: application/json' -d @path/to/json_file.json http://localhost:8000/verilator --output file_to_save.zip | |
| verilator can be exchanged with any other edalize-compatible tool (ghdl, icarus, icestorm, ise, isim, modelsim, quartus, rivierapro, spyglass, trellis, vcs, verilator, vivado, xsim) |
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
| try: | |
| import http.server as BaseHTTPServer # Python 3.x | |
| except ImportError: | |
| import BaseHTTPServer # Python 2.x | |
| import os | |
| import shutil | |
| import sys | |
| import json | |
| import tempfile | |
| from edalize import get_edatool | |
| class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
| def do_POST(self): | |
| tool = self.path.rsplit('/', 1)[1] | |
| content_length = int(self.headers['Content-Length']) | |
| file_content = self.rfile.read(content_length) | |
| eda_api = json.loads(file_content) | |
| work_root = tempfile.mkdtemp() | |
| backend = get_edatool(tool)(eda_api=eda_api, | |
| work_root=work_root) | |
| backend.configure([]) | |
| (h, outfile) = tempfile.mkstemp() | |
| shutil.make_archive(outfile, 'zip', work_root) | |
| with open(outfile+'.zip', 'rb') as f: | |
| self.send_response(200) | |
| self.send_header("Content-Type", 'application/octet-stream') | |
| self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(tool+'.zip')) | |
| fs = os.fstat(f.fileno()) | |
| self.send_header("Content-Length", str(fs.st_size)) | |
| self.end_headers() | |
| shutil.copyfileobj(f, self.wfile) | |
| def test(HandlerClass=SimpleHTTPRequestHandler, | |
| ServerClass=BaseHTTPServer.HTTPServer, | |
| protocol="HTTP/1.0"): | |
| if sys.argv[1:]: | |
| port = int(sys.argv[1]) | |
| else: | |
| port = 8000 | |
| server_address = ('', port) | |
| HandlerClass.protocol_version = protocol | |
| httpd = BaseHTTPServer.HTTPServer(server_address, HandlerClass) | |
| sa = httpd.socket.getsockname() | |
| httpd.serve_forever() | |
| if __name__ == '__main__': | |
| test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment