File tree Expand file tree Collapse file tree 2 files changed +35
-34
lines changed
Expand file tree Collapse file tree 2 files changed +35
-34
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (C) 2025 HDLtools Project
3+ #
4+ # SPDX-License-Identifier: GPL-3.0-or-later
5+ #
6+
7+ """
8+ Generates and writes the output HDL code based on templates.
9+ """
10+
11+ from pathlib import Path
12+ from jinja2 import Environment , FileSystemLoader
13+
14+
15+ class HDLWriter :
16+ """Generates and writes the output HDL code."""
17+
18+ def __init__ (self ):
19+ tdir = Path (__file__ ).parent .joinpath ('templates' )
20+ self .env = Environment (loader = FileSystemLoader (str (tdir )))
21+ self .code = ''
22+
23+ def render (self , tempname , context ):
24+ """Render the specified template."""
25+ template = self .env .get_template (f'{ tempname } .jinja' )
26+ self .code = template .render (context )
27+
28+ def write_file (self , path ):
29+ """Writes the generated HDL code to the specified file."""
30+ with open (path , 'w' , encoding = 'utf-8' ) as fobj :
31+ fobj .write (self .code )
32+
33+ def get_code (self ):
34+ """Get the generated code."""
35+ return self .code
You can’t perform that action at this time.
0 commit comments