Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9from .register import Register 

10 

11 

12class RegisterCodeGenerator: 

13 

14 """ 

15 Common functions for generating register code. 

16 """ 

17 

18 @staticmethod 

19 def _iterate_registers(register_objects): 

20 for register_object in register_objects: 

21 if isinstance(register_object, Register): 

22 yield (register_object, None) 

23 else: 

24 for register in register_object.registers: 

25 yield (register, register_object) 

26 

27 @staticmethod 

28 def _comment(comment, indentation=0): 

29 raise NotImplementedError("Should be overloaded in child class") 

30 

31 def _comment_block(self, text, indentation=0): 

32 """ 

33 Create a comment block from a string with newlines. 

34 """ 

35 text_lines = text.split("\n") 

36 

37 # Very common that the last line is empty. An effect of TOML formatting with 

38 # multi-line strings. Remove to make the output look more clean. 

39 if text_lines[-1] == "": 

40 text_lines.pop() 

41 

42 return "".join(self._comment(line, indentation=indentation) for line in text_lines) 

43 

44 @staticmethod 

45 def _to_pascal_case(snake_string): 

46 """ 

47 Returns e.g., my_funny_string -> MyFunnyString 

48 """ 

49 return snake_string.title().replace("_", "")