2 # KLL Compiler - Kiibohd Backend
4 # Backend code generator for the Kiibohd Controller firmware.
6 # Copyright (C) 2014 by Jacob Alexander
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.
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.
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/>.
27 # Modifying Python Path, which is dumb, but the only way to import up one directory...
28 sys.path.append( os.path.expanduser('..') )
30 from kll_lib.containers import *
35 ## Print Decorator Variables
36 ERROR = '\033[5;1;31mERROR\033[0m:'
44 # Looks for template file and builds list of fill tags
45 def __init__( self, templatePath ):
46 # Does template exist?
47 if not os.path.isfile( templatePath ):
48 print ( "{0} '{1}' does not exist...".format( ERROR, templatePath ) )
51 self.templatePath = templatePath
52 self.fill_dict = dict()
54 # Generate list of fill tags
56 with open( templatePath, 'r' ) as openFile:
58 match = re.findall( '<\|([^|>]+)\|>', line )
60 self.tagList.append( item )
63 # USB Code Capability Name
64 def usbCodeCapability( self ):
68 # Processes content for fill tags and does any needed dataset calculations
69 def process( self, capabilities ):
71 self.fill_dict['CapabilitiesList'] = "const Capability CapabilitiesList[] = {\n"
74 for key in capabilities.keys():
75 funcName = capabilities.funcName( key )
76 argByteWidth = capabilities.totalArgBytes( key )
77 self.fill_dict['CapabilitiesList'] += "\t{{ {0}, {1} }},\n".format( funcName, argByteWidth )
79 self.fill_dict['CapabilitiesList'] += "};"
81 print( self.fill_dict['CapabilitiesList'] )
84 # Generates the output keymap with fill tags filled
85 def generate( self, filepath ):
86 print("My path: {0}".format( filepath) )