pythoncode.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ###########################################
  2. # Project: CMSIS DSP Library
  3. # Title: pythoncode.py
  4. # Description: Generation of Python code for the static scheduler
  5. #
  6. # $Date: 29 July 2021
  7. # $Revision: V1.10.0
  8. #
  9. # Target Processor: Cortex-M and Cortex-A cores
  10. # -------------------------------------------------------------------- */
  11. #
  12. # Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. #
  14. # SPDX-License-Identifier: Apache-2.0
  15. #
  16. # Licensed under the Apache License, Version 2.0 (the License); you may
  17. # not use this file except in compliance with the License.
  18. # You may obtain a copy of the License at
  19. #
  20. # www.apache.org/licenses/LICENSE-2.0
  21. #
  22. # Unless required by applicable law or agreed to in writing, software
  23. # distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. # See the License for the specific language governing permissions and
  26. # limitations under the License.
  27. ############################################
  28. from jinja2 import Environment, PackageLoader, select_autoescape
  29. import os.path
  30. import pathlib
  31. from .config import *
  32. def gencode(sched,directory,config):
  33. env = Environment(
  34. loader=PackageLoader("cmsisdsp.sdf.scheduler"),
  35. autoescape=select_autoescape(),
  36. trim_blocks=True
  37. )
  38. template = env.get_template("code.py")
  39. cfile=os.path.join(directory,"sched.py")
  40. with open(cfile,"w") as f:
  41. nbFifos = len(sched._graph._allFIFOs)
  42. print(template.render(fifos=sched._graph._allFIFOs,
  43. nbFifos=nbFifos,
  44. nodes=sched.nodes,
  45. schedule=sched.schedule,
  46. config=config,
  47. sched=sched
  48. ),file=f)