Exemplo n.º 1
0
 def createAndAttachGlobalEmitters(self, global_symbols, type_builder):
     
     # Add global variables and their accessors to the class
     for symbol in global_symbols.symbols.values():
     #identifier = ctsIdentifier(symbol)
         identifier = symbol.name
         field_builder = type_builder.DefineField(identifier, cts.symbolType(symbol), FieldAttributes.Private | FieldAttributes.Static)
         print identifier
         assert field_builder is not None
         self.createAndAttachFieldEmitters(field_builder, symbol)
Exemplo n.º 2
0
    def generateMethodBody(self, type_builder, basic_blocks):
        # The first statement of the first basic block is the entry point
        entry_point_node = basic_blocks[0].entryPoint
        try:
            name = entry_point_node.name
            if name == 'Main':
                name = 'FNMain'
            clr_method_name = self.owl_to_clr_method_names[name]
        except KeyError:
            print entry_point_node.name
            print self.owl_to_clr_method_names
            assert 0
        logging.debug("Creating CIL for %s", clr_method_name)
        method_builder = self.method_builders[clr_method_name]
        logging.debug("entry_point_node = %s", entry_point_node)

        # Create the visitor which holds the code generator 
        cv = CilVisitor(self, type_builder, method_builder, self.line_mapper, self.doc)
        
        # Declare LOCAL variables and attach load and store emitters to the symbols
        for node in depthFirstSearch(entry_point_node):
            if isinstance(node, Local):
                symbol_table = node.symbolTable
                for symbol in symbol_table.symbols.values():
                    local_builder = cv.generator.DeclareLocal(cts.symbolType(symbol))
                    local_builder.SetLocalSymInfo(symbol.name) # Provide symbol name for debugger
                    self.createAndAttachLocalEmitters(local_builder, symbol)
        
        # TODO: Declare PRIVATE variables and attach load and store emitters to the symbols
        
        # For each basic block (including the first, if it has an in-degree > 1)
        # define a label, and attach it to the block
        for basic_block in basic_blocks:
            basic_block.label = cv.generator.DefineLabel()
            basic_block.is_label_marked = False

        # Generate the code for blocks and statements in sequence
        for basic_block in basic_blocks:
            for statement in basic_block.statements:
                if statement.startLine and statement.startColumn and statement.endLine and statement.endColumn:
                    cv.generator.MarkSequencePoint(self.doc, statement.startLine, statement.startColumn,
                                                            statement.endLine,   statement.endColumn)
                cv.checkMark(statement) # TODO: Could push this out a level to be per block
                cv.visit(statement)
                assert statement.block.is_label_marked
            self.transferControlToNextBlock(cv.generator, basic_block)
        logging.debug("COMPLETE\n\n\n")