def main(): logger.basicConfig(level=logger.DEBUG) logBanner() # mainThread = Thread.currentThread() st = stats_tracker.StatsTracker() stats = st.getInstance() opts = options.parseOptions() try: arch = Architecture.Architecture(opts.sslFilename) except OSError as e: logger.critical('Unable to open SSL file!', e) return except: logger.critical('Error parsing SSL file!', e) return overallStartTime = time.time() _program = program.create_program(arch) mainfile = os.path.abspath(opts.mainFilename) basefilename = None try: logger.warning("Parsing " + opts.mainFilename + "...") _program.load_main_module(mainfile) if basefilename == None: basefilename = get_base_filename(mainfile) except OSError as e: logger.critical('File not found: ', e) return except IOError as e: logger.critical('IOException while parsing executable!', e) return except Exception as e: logger.critical('Error during parsing', e) return logger.info('Finished parsing executable') if opts.startAddress > 0: logger.log("Setting start address to 0x" + hex(opts.startAddress)) _program.set_entry_address( absolute_address(opt.startAddress.getValue()))
class Shemas: ipgen = Architecture() shema1 = [["1", "2"]] shema2 = [["1", "3"], ["3", "2"]] shema3 = [["1", "2", "4"], ["2", "3", "5"], ["4", "5", "6", "7"]] shema4 = [["1", "2", "4"], ["2", "3", "6"], ["4", "5", "7"], ["8", "5", "6"]] shemaIp1 = ipgen.architecture("192.168.0.0/24", "300,25") shemaIp2 = ipgen.architecture("192.168.0.0/24","200,30,2") shemaIp3 = ipgen.architecture("192.168.0.0/24", "500,400,350,200,2,2,2") shemaIp4 = ipgen.architecture("192.168.0.0/24", "1000,700,300,80,2,2,2,2")
def setUp(self): self.arch1 = Architecture("AVR8") self.arch2 = Architecture("AVR8") self.arch3 = Architecture("x86") self.arch1.setCompiler("gcc")
from Architecture import * if __name__ == '__main__': process = Architecture() process.start()
def __init__(self): self.ImmediateCode = [] # unoptimized immediate code self.ImmediateCodeOptimized = [] # optimized immediate code self.Variables = [] self.ArchOutput = Architecture() # type: # while begin of a while loop # statement statement of the header # body the body of the while loop (is a list) # number (statement) only a number # value the value of the number # TODO< remove this > # assigment asign a new value to a number # variable the name of the target variable # statement a statement for the assigment of a new value # assigment2 assign the right side to the left # left leftside # right rightside # minusAssigment -= # left leftside # right rightside # variable access a variable # name the name of the variable # mul multiplication # left leftside # right rightside # div division # left leftside # right rightside # add addition # left leftside # right rightside # sub subtraction # left leftside # right rightside # if if thing # statement the statement # block the contained block # else None or another block with the else part # true (statement) # false (statement) # greaterEqual (statement) # left leftside # right rightside # TODO< smallerEqual, Equal, Unequal, Smaller, Greater > # break break expression # postinc (statement) # statement # preinc (statement) # statement # postdec (statement) # statement # preinc (statement) # statement # return (statement) # expression is the expression that have to be avaluated, can also be not set (None) # expressionSet was the Expression set (True or False) # newConstArray creates a new constant unchangable array # name is the name of the array # info Typeinformation, is a 'Datatype' Object # newVar2 allocates space for a new (scoped) variable # name is the Variablename # info Typeinformation, is a 'Datatype' Object # constantFloat is a contant float # value is the floatingpoint value """ self.Root = [ {"type":"newVar", "name":"Counter", "dataType":0,"bits":32}, {"type":"assigment2", "left":{"type":"variable", "name":"Counter"}, "right":{"type":"number", "value":20}}, {"type":"newVar", "name":"Xn", "dataType":0, "bits":32}, {"type":"assigment2", "left":{"type":"variable", "name":"Xn"}, "right":{"type":"number", "value":5}}, {"type":"newVar", "name":"Number", "dataType":0, "bits":32}, {"type":"assigment2", "left":{"type":"variable", "name":"Number"}, "right":{"type":"number", "value":500}}, {"type":"while", "statement":{"type":"number", "value":1}, "body":[ {"type":"minusAssignment", "left":{"type":"variable", "name":"Counter"}, "right":{"type":"number", "value":1}}, {"type":"assigment2", "left":{"type":"variable", "name":"Xn"}, "right":{ "type":"div", "left":{"type":"add", "left":{"type":"variable", "name":"Xn"}, "right":{"type":"div", "left":{"type":"variable", "name":"Number"}, "right":{"type":"variable", "name":"Xn"}}}, "right":{"type":"number", "value":2} }} ]} ]""" # algorithm for calculating of the sqrt # (examples/calc my sqrt) # (is a serial code) # works """ Type1 = Datatype(Datatype.EnumBasetype.UNSIGNED) Type1.Bits = 32 Type2 = Datatype(Datatype.EnumBasetype.UNSIGNED) Type2.Bits = 32 Type3 = Datatype(Datatype.EnumBasetype.UNSIGNED) Type3.Bits = 32 self.Root = [ {"type":"newVar2", "name":"Input", "info":Type1}, {"type":"assigment2", "left":{"type":"variable", "name":"Input"}, "right":{"type":"number", "value":29}}, {"type":"newVar2", "name":"Counter", "info":Type2}, {"type":"assigment2", "left":{"type":"variable", "name":"Counter"}, "right":{"type":"number", "value":0}}, {"type":"newVar2", "name":"Old", "info":Type3}, {"type":"assigment2", "left":{"type":"variable", "name":"Old"}, "right":{"type":"number", "value":0}}, {"type":"while", "statement":{"type":"true"}, "body":[ {"type":"assigment2", "left":{"type":"variable", "name":"Old"}, "right":{ "type":"add", "left":{"type":"variable", "name":"Old"}, "right":{ "type":"add", "left":{"type":"mul", "left":{"type":"number", "value":2}, "right":{"type":"variable", "name":"Counter"}}, "right":{"type":"number", "value":1} } }}, { "type":"if", "statement":{"type":"greaterEqual", "left":{"type":"variable", "name":"Old"}, "right":{"type":"variable", "name":"Input"}}, "block":[ {"type":"break"} ] }, { "type":"postinc", "statement":{"type":"variable", "name":"Counter"} } ]} ] """ # cordic algorithm """ const fixed6p12 ATanTable[1] = [0.7853981633974483 , 0.4636476090008061, 0.24497866312686414, 0.12435499454676144, 0.06241880999595735, 0.031239833430268277, 0.015623728620476831]; """ """ Type1 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype Type1.PrePointBits = 6 Type1.PostPointBits = 12 Type1.IsArray = True Type1.IsConst = True Type1.ArrayValues = [0.7853981633974483 , 0.4636476090008061, 0.24497866312686414, 0.12435499454676144, 0.06241880999595735, 0.031239833430268277, 0.015623728620476831] Type2 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype Type2.PrePointBits = 6 Type2.PostPointBits = 12 Type3 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype Type3.PrePointBits = 6 Type3.PostPointBits = 12 Type4 = Datatype(Datatype.EnumBasetype.FIXEDPOINT) # fixedpoint Datatype Type4.PrePointBits = 6 Type4.PostPointBits = 12 self.Root = [ {"type":"newConstArray", "name":"ATanTable", "info":Type1}, {"type":"newVar2", "name":"X", "info":Type2}, {"type":"assigment2", "left":{"type":"variable", "name":"X"}, "right":{"type":"constantFloat", "value":4.0}}, {"type":"newVar2", "name":"Y", "info":Type3}, {"type":"assigment2", "left":{"type":"variable", "name":"Y"}, "right":{"type":"constantFloat", "value":1.0}}, {"type":"newVar2", "name":"Phi", "info":Type4}, {"type":"assigment2", "left":{"type":"variable", "name":"Phi"}, "right":{"type":"constantFloat", "value":0.907571}} ] """ # Testcode for the parallelistation code Type1 = Datatype(Datatype.EnumBasetype.UNSIGNED) Type1.Bits = 32 Type2 = Datatype(Datatype.EnumBasetype.UNSIGNED) Type2.Bits = 32 Type3 = Datatype(Datatype.EnumBasetype.UNSIGNED) Type3.Bits = 32 self.Root = [ {"type":"newVar2", "name":"A", "info":Type1}, {"type":"newVar2", "name":"B", "info":Type2}, {"type":"newVar2", "name":"C", "info":Type3}, {"type":"assigment2", "left":{"type":"variable", "name":"A"}, "right":{ "type":"add", "left":{"type":"variable", "name":"A"}, "right":{"type":"add", "left":{"type":"variable", "name":"B"}, "right":{"type":"variable", "name":"C"}} #}} }} ] self.ImmediateCodeObj = ImmediateCode()