KLL Compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

kiibohd.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. # KLL Compiler - Kiibohd Backend
  3. #
  4. # Backend code generator for the Kiibohd Controller firmware.
  5. #
  6. # Copyright (C) 2014 by Jacob Alexander
  7. #
  8. # This file is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This file is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this file. If not, see <http://www.gnu.org/licenses/>.
  20. ### Imports ###
  21. import os
  22. import sys
  23. import re
  24. # Modifying Python Path, which is dumb, but the only way to import up one directory...
  25. sys.path.append( os.path.expanduser('..') )
  26. from kll_lib.containers import *
  27. ### Decorators ###
  28. ## Print Decorator Variables
  29. ERROR = '\033[5;1;31mERROR\033[0m:'
  30. ### Classes ###
  31. class Backend:
  32. # Initializes backend
  33. # Looks for template file and builds list of fill tags
  34. def __init__( self, templatePath ):
  35. # Does template exist?
  36. if not os.path.isfile( templatePath ):
  37. print ( "{0} '{1}' does not exist...".format( ERROR, templatePath ) )
  38. sys.exit( 1 )
  39. self.templatePath = templatePath
  40. self.fill_dict = dict()
  41. # Generate list of fill tags
  42. self.tagList = []
  43. with open( templatePath, 'r' ) as openFile:
  44. for line in openFile:
  45. match = re.findall( '<\|([^|>]+)\|>', line )
  46. for item in match:
  47. self.tagList.append( item )
  48. # Processes content for fill tags and does any needed dataset calculations
  49. def process( self, capabilities ):
  50. ## Capabilities ##
  51. self.fill_dict['CapabilitiesList'] = "const Capability CapabilitiesList[] = {\n"
  52. # Keys are pre-sorted
  53. for key in capabilities.keys():
  54. funcName = capabilities.funcName( key )
  55. argByteWidth = capabilities.totalArgBytes( key )
  56. self.fill_dict['CapabilitiesList'] += "\t{{ {0}, {1} }},\n".format( funcName, argByteWidth )
  57. self.fill_dict['CapabilitiesList'] += "};"
  58. print( self.fill_dict['CapabilitiesList'] )
  59. # Generates the output keymap with fill tags filled
  60. def generate( self, filepath ):
  61. print("My path: {0}".format( filepath) )