示例#1
0
    def bake(self):
        oplen = toBase27(self.word_len())
        assert len(oplen) == 1
        head = bakers.Baked("{opcode}{len}_".format(opcode=self.opcode,
                                                    len=oplen))

        return bakers.BakerSequence([head] +
                                    [opr.bake() for opr in self.operands])
示例#2
0
 def bake(self):
     flagstr = "{s:_>2}".format(s=''.join(self.flags))
     if SMALL_OPERANDS and isinstance(self.payload.bake(), bakers.Baked):
         small = smallify(self.payload.bake().s)
         if small:
             return bakers.Baked("{type}{flags}{payload}".format(
                 type=self.type, flags=flagstr, payload=small))
     head = "_{flags}{type}".format(type=self.type, flags=flagstr)
     return bakers.BakerSequence([bakers.Baked(head), self.payload.bake()])
示例#3
0
 def bake(self):
     elems = []
     ins = Instruction('FN',
                       [Operand('C', [], RefWord(self.fname))] + self.args)
     elems.append(ins)
     if self.to:
         elems.append(
             Instruction('MV', [Operand('S', [], ConstWord('V')), self.to]))
     return bakers.BakerSequence([e.bake() for e in elems])
示例#4
0
 def bake(self):
     name = 'top_' + bakers.uniqueID()
     elems = []
     elems.append(Label(name).bake())
     elems.append(Label('@continue').bake())
     elems.extend([b.bake() for b in self.pieces])
     jumpback = Instruction('JP', [Operand('C', [], RefWord(name))])
     elems.append(jumpback.bake())
     elems.append(Label('@break').bake())
     return bakers.CaptureScopeBaker(bakers.BakerSequence(elems),
                                     pretty_name='loop')
示例#5
0
 def bake(self):
     elems = []
     label = Label(self.name).bake()  # Function label
     if self.preserves:
         preserves = Instruction(
             'PU', [Operand('S', [], ConstWord('P'))] +
             [Operand('R', [], ConstWord(reg))
              for reg in self.preserves]).bake()
         elems.append(preserves)
     elems.extend([b.bake() for b in self.pieces])  # Actual body
     elems.append(Label("@return").bake())
     if self.preserves:
         restores = Instruction('PL', [Operand('S', [], ConstWord('P'))] + [
             Operand('R', [], ConstWord(reg))
             for reg in reversed(self.preserves)
         ]).bake()
         elems.append(restores)
     elems.append(Instruction('RT', []).bake())
     return bakers.BakerSequence([
         label,
         bakers.CaptureScopeBaker(bakers.BakerSequence(elems),
                                  pretty_name='func_' + self.name)
     ])
示例#6
0
    def bake(self):
        elems = []
        cond = copy.copy(self.cond)
        cond.append(Instruction('JP', [Operand('C', [], RefWord('@endif'))]))
        then = copy.copy(self.then)
        then.insert(0, Label('@true'))
        then.append(Label('@endif'))
        then.append(Label('@false'))
        elems += cond
        elems += then

        if self.otherwise:
            log(type(self.otherwise))
            elems += self.otherwise

        log("Elems is {} ".format(elems))
        return bakers.CaptureScopeBaker(
            bakers.BakerSequence([b.bake() for b in elems]))
示例#7
0
 def bake(self):
     return bakers.BakerSequence([bakers.LabelBaker(self.label)] +
                                 [b.bake() for b in self.datas])
示例#8
0
 def bake(self):
     end_label = Label("@end").bake()
     return bakers.BakerSequence([b.bake()
                                  for b in self.pieces] + [end_label])