Пример #1
0
    def _set_bool(self, spotmap, get_reg, asm_code):
        """Emit code for SET command if arg is boolean type."""
        # When any scalar value is converted to _Bool, the result is 0 if the
        # value compares equal to 0; otherwise, the result is 1

        # If arg_asm is a LITERAL or conflicts with output, move to register.
        if (isinstance(spotmap[self.arg], LiteralSpot)
                or spotmap[self.arg] == spotmap[self.output]):
            r = get_reg([], [spotmap[self.output]])
            asm_code.add(
                asm_cmds.Mov(r, spotmap[self.arg], self.arg.ctype.size))
            arg_spot = r
        else:
            arg_spot = spotmap[self.arg]

        label = asm_code.get_label()
        output_spot = spotmap[self.output]

        zero = LiteralSpot("0")
        one = LiteralSpot("1")

        asm_code.add(asm_cmds.Mov(output_spot, zero, self.output.ctype.size))
        asm_code.add(asm_cmds.Cmp(arg_spot, zero, self.arg.ctype.size))
        asm_code.add(asm_cmds.Je(label))
        asm_code.add(asm_cmds.Mov(output_spot, one, self.output.ctype.size))
        asm_code.add(asm_cmds.Label(label))
Пример #2
0
    def make_asm(self, spotmap, home_spots, get_reg, asm_code):  # noqa D102
        regs = []

        result = get_reg([spotmap[self.output]],
                         [spotmap[self.arg1], spotmap[self.arg2]])
        regs.append(result)

        out_size = self.output.ctype.size
        eq_val_spot = LiteralSpot(1)
        asm_code.add(asm_cmds.Mov(result, eq_val_spot, out_size))

        arg1_spot, arg2_spot = self._fix_both_literal_or_mem(
            spotmap[self.arg1], spotmap[self.arg2], regs, get_reg, asm_code)
        arg1_spot, arg2_spot = self._fix_either_literal64(
            arg1_spot, arg2_spot, regs, get_reg, asm_code)
        arg1_spot, arg2_spot = self._fix_literal_wrong_order(
            arg1_spot, arg2_spot)

        arg_size = self.arg1.ctype.size
        neq_val_spot = LiteralSpot(0)
        label = asm_code.get_label()

        asm_code.add(asm_cmds.Cmp(arg1_spot, arg2_spot, arg_size))
        asm_code.add(self.cmp_command()(label))
        asm_code.add(asm_cmds.Mov(result, neq_val_spot, out_size))
        asm_code.add(asm_cmds.Label(label))

        if result != spotmap[self.output]:
            asm_code.add(asm_cmds.Mov(spotmap[self.output], result, out_size))
Пример #3
0
    def make_asm(self):
        """Generate ASM code."""

        #print("\nSymbol table:")
        #pprint.pprint(self.symbol_table.__dict__)
        #print()

        global_spotmap = self._get_global_spotmap()

        #pprint.pprint(self.il_code.__dict__)

        for func in self.il_code.commands:
            #print(func)
            self.asm_code.add(asm_cmds.Label(func))

            #for i in self.il_code.commands[func]:
            #print(i, i.__dict__)

            self._make_asm(self.il_code.commands[func], global_spotmap)
Пример #4
0
    def make_asm(self, spotmap, home_spots, get_reg, asm_code):  # noqa D102

        arg1_spot = spotmap[self.arg1]
        arg2_spot = spotmap[self.arg2]
        output_spot = spotmap[self.output]
        r12_spot = spots.RegSpot("r12")
        r13_spot = spots.RegSpot("r13")
        label = asm_code.get_label()

        # this stays here until I removed size from all functions
        size = None

        # start with setting the output reg to 1, in case of success
        asm_code.add(asm_cmds.Load(LiteralSpot(1), output_spot, size))

        self.move(arg1_spot, r12_spot, asm_code)
        self.move(arg2_spot, r13_spot, asm_code)

        # swap args when using less than instructions (to convert to gte's)
        if self.reverse_less_cmd:
            asm_code.add(self.cmp_command()(r12_spot, r13_spot,
                                            LiteralSpot(2)))
        else:
            asm_code.add(self.cmp_command()(r13_spot, r12_spot,
                                            LiteralSpot(2)))
        #not bgt r12 r0 2 -> bge r0 r12 2
        #not bge r12 r0 2 -> bgt r0 r12 2

        #not beq r12 r0 2 -> bne r0 r12 2
        #not bne r12 r0 2 -> beq r0 r12 2

        asm_code.add(asm_cmds.Jump(label))

        # in case the comparison was unsuccessful, set output reg to 0
        asm_code.add(asm_cmds.Load(LiteralSpot(0), output_spot, size))

        asm_code.add(asm_cmds.Label(label))
Пример #5
0
 def make_asm(self, spotmap, home_spots, get_reg, asm_code):  # noqa D102
     asm_code.add(asm_cmds.Label(self.label))
Пример #6
0
 def make_asm(self):
     """Generate ASM code."""
     global_spotmap = self._get_global_spotmap()
     for func in self.il_code.commands:
         self.asm_code.add(asm_cmds.Label(func))
         self._make_asm(self.il_code.commands[func], global_spotmap)