Пример #1
0
class AssemblyGenerator(object):
    """used to create Assembly from an Syntax Tree (AST)"""
    def __init__(self):
        self.Assembly = Assembly()

    def WorkFromAST(self, ast):
        print("getting global Variables")
        gblVisit = GlobalVarVisitor()
        gblVisit.visit(ast)
        global KnownGlobalVariables

        print("getting Functions")
        funcVisit = FunctionVisitor(gblVisit.Variables)
        funcVisit.visit(ast)

        print('appending default starting Assembly')
        self.Assembly.AppendDirective(Directive('instructionsize 16'))

        print('working through syntax tree ...')
        for func in KnownFunctions:
            self.Assembly.AppendAssembly(func.GetAssembly())

        print('appending DataSegment')
        self.Assembly.AppendAssembly(gblVisit.GetAssemblyForAll())

    def GetInTextform(self):
        return self.Assembly.ToString()
Пример #2
0
 def GetAssemblyForAll(self):
     ret = Assembly()
     for el in self.Variables:
         ret.AppendAssembly(self.GetAssemblyForSpecific(el))
     return ret