Beispiel #1
0
    def __init__(self, file, show_comments=0):
        """Constructor.  'file' is the file object to output the
        resulting code to.  If 'show_comments' is true, then annotated
        comments are produced for the generated assembly code."""

        Visitor.__init__(self)

        # The current label number we're on, for generating
        # jump labels in the assembly code (e.g., 'LO', 'L1', etc).
        self.__label = 0

        # Current label number for generating string literal labels.
        self.__str_literal_label = 0

        # Current assembly code for string literals.
        self.__str_literal_str = ""

        # Whether we should show comments or not.
        self.show_comments = show_comments

        # The file we're outputting the generated code to.
        self.file = file

        # A hashtable of binary operators and the assembly
        # instructions corresponding to them.  Certain instructions
        # are just the 'base' instruction and require a suffix
        # corresponding to the size of the operands; for instance,
        # addition can be accomplished with the 'addl' instruction
        # for 32-bit integers and 'addb' for 8-bit integers.
        #
        # In such cases, the code adds the appropriate suffixes on its
        # own.
        self.binop_instructions = \
                                { '==' : 'sete',
                                  '!=' : 'setne',
                                  '>=' : 'setge',
                                  '<=' : 'setle',
                                  '>'  : 'setg',
                                  '<'  : 'setl',
                                  '+'  : 'add',
                                  '-'  : 'sub',
                                  '*'  : 'imul',
                                  '='  : 'mov'
                                  }

        # Windows' C linkage prepends a '_' before symbol
        # names, whereas Unix doesn't.  This is particularly
        # critical if the source file is linking to external
        # libraries that we're not compiling.  Figure out
        # which one to use here.
        import sys
        if sys.platform == 'win32':
            self.symbol_prepend = "_"
        else:
            self.symbol_prepend = ""
Beispiel #2
0
    def __init__(self, file, show_comments=0):
        """Constructor.  'file' is the file object to output the
        resulting code to.  If 'show_comments' is true, then annotated
        comments are produced for the generated assembly code."""
        
        Visitor.__init__(self)

        # The current label number we're on, for generating
        # jump labels in the assembly code (e.g., 'LO', 'L1', etc).
        self.__label = 0

        # Current label number for generating string literal labels.
        self.__str_literal_label = 0

        # Current assembly code for string literals.
        self.__str_literal_str = ""

        # Whether we should show comments or not.
        self.show_comments = show_comments

        # The file we're outputting the generated code to.
        self.file = file

        # A hashtable of binary operators and the assembly
        # instructions corresponding to them.  Certain instructions
        # are just the 'base' instruction and require a suffix
        # corresponding to the size of the operands; for instance,
        # addition can be accomplished with the 'addl' instruction
        # for 32-bit integers and 'addb' for 8-bit integers.
        #
        # In such cases, the code adds the appropriate suffixes on its
        # own.
        self.binop_instructions = \
                                { '==' : 'sete',
                                  '!=' : 'setne',
                                  '>=' : 'setge',
                                  '<=' : 'setle',
                                  '>'  : 'setg',
                                  '<'  : 'setl',
                                  '+'  : 'add',
                                  '-'  : 'sub',
                                  '*'  : 'imul',
                                  '='  : 'mov'
                                  }

        # Windows' C linkage prepends a '_' before symbol
        # names, whereas Unix doesn't.  This is particularly
        # critical if the source file is linking to external
        # libraries that we're not compiling.  Figure out
        # which one to use here.
        import sys
        if sys.platform == 'win32':
            self.symbol_prepend = "_"
        else:
            self.symbol_prepend = ""
Beispiel #3
0
 def __init__(self):
     Visitor.__init__(self)
     self.liveness_at_inst = {}
Beispiel #4
0
 def __init__(self):
     Visitor.__init__(self)
     self.liveness_at_inst = {}