def visitRelationalExpr(self, ctx):
     c = Condition(ctx.myop.type)
     tmp0=self.visit(ctx.expr(0))
     tmp1=self.visit(ctx.expr(1))
     tmp4=self._current_function.new_tmp()
     if self._debug:
         print("relational expression:")
         print(Trees.toStringTree(ctx, None, self._parser))
         print("Condition:", c)
     endrl = self._current_function.new_label("endrl")
     self._current_function.addInstructionLI(tmp4,0)
     self._current_function.addInstructionCondJUMP(endrl,tmp0,c.negate(),tmp1)
     self._current_function.addInstructionLI(tmp4,1)
     self._current_function.addLabel(endrl)
     return tmp4
Example #2
0
 def visitRelationalExpr(self, ctx):
     c = Condition(ctx.myop.type)
     if self._debug:
         print("relational expression:")
         print(Trees.toStringTree(ctx, None, self._parser))
         print("Condition:", c)
     raise NotImplementedError()
 def visitRelationalExpr(self, ctx):
     c = Condition(ctx.myop.type)
     if self._debug:
         print("relational expression:")
         print(Trees.toStringTree(ctx, None, self._parser))
         print("Condition:", c)
     tmpl = self.visit(ctx.expr(0))
     tmpr = self.visit(ctx.expr(1))
     dest = self._current_function.new_tmp()
     end_relational = self._current_function.new_label('end_relational')
     self._current_function.addInstructionLI(dest, 0)
     self._current_function.addInstructionCondJUMP(end_relational, tmpl,
                                                   c.negate(), tmpr)
     self._current_function.addInstructionLI(dest, 1)
     self._current_function.addLabel(end_relational)
     return dest
 def visitNotExpr(self, ctx):
     lval = self.visit(ctx.expr())
     dr=self._current_function.new_tmp()
     lendnot1 = self._current_function.new_label("lendnot")
     lendmid1 = self._current_function.new_label("lendmid")
     self._current_function.addInstructionCondJUMP(lendmid1,lval,Condition(MiniCParser.EQ),0)
     self._current_function.addInstructionLI(dr, 0)
     self._current_function.addInstructionJUMP(lendnot1)
     self._current_function.addLabel(lendmid1)
     self._current_function.addInstructionLI(dr, 1)
     self._current_function.addLabel(lendnot1)
     return dr
 def visitNotExpr(self, ctx):
     reg = self.visit(ctx.expr())
     dr = self._current_function.new_tmp()
     # there is no boolean not :-(
     labelneg, labelend = self._current_function.new_label_cond()
     self._current_function.addInstructionCondJUMP(labelneg, reg,
                                                   Condition("beq"), 0)
     self._current_function.addInstructionLI(dr, 0)
     self._current_function.addInstructionJUMP(labelend)
     self._current_function.addLabel(labelneg)
     self._current_function.addInstructionLI(dr, 1)
     self._current_function.addLabel(labelend)
     return dr
 def visitWhileStat(self, ctx):
     if self._debug:
         print("while statement, condition is:")
         print(Trees.toStringTree(ctx.expr(), None, self._parser))
         print("and block is:")
         print(Trees.toStringTree(ctx.stat_block(), None, self._parser))
     ltest1 = self._current_function.new_label("ltest1")
     lendwhile1 = self._current_function.new_label("lendwhile")
     self._current_function.addLabel(ltest1)
     tmp4=self.visit(ctx.expr())
     self._current_function.addInstructionCondJUMP(lendwhile1,tmp4,Condition(MiniCParser.EQ),0)
     self.visit(ctx.stat_block())
     self._current_function.addInstructionJUMP(ltest1)
     self._current_function.addLabel(lendwhile1)
 def visitCondBlock(self, ctx):
     if self._debug:
         print("condblockstatement, condition is:")
         print(Trees.toStringTree(ctx.expr(), None, self._parser))
         print("and block is:")
         print(Trees.toStringTree(ctx.stat_block(), None, self._parser))
     tmp4=self.visit(ctx.expr())
     lendif1 = self._current_function.new_label("lendif")
     self._current_function.addInstructionCondJUMP(lendif1,tmp4,Condition(MiniCParser.EQ),0)
     self.visit(ctx.stat_block())
     end_if=self.ctx_stack[-1]
     self._current_function.addInstructionJUMP(end_if)
     self._current_function.addLabel(lendif1)
     return tmp4
 def visitWhileStat(self, ctx):
     if self._debug:
         print("while statement, condition is:")
         print(Trees.toStringTree(ctx.expr(), None, self._parser))
         print("and block is:")
         print(Trees.toStringTree(ctx.stat_block(), None, self._parser))
     labelbegin, labelend = self._current_function.new_label_while()
     self._current_function.addLabel(labelbegin)
     reg = self.visit(ctx.expr())
     self._current_function.addInstructionCondJUMP(labelend, reg,
                                                   Condition("beq"), 0)
     self.visit(ctx.stat_block())
     self._current_function.addInstructionJUMP(labelbegin)
     self._current_function.addLabel(labelend)
 def visitCondBlock(self, ctx):
     if self._debug:
         print("condblockstatement, condition is:")
         print(Trees.toStringTree(ctx.expr(), None, self._parser))
         print("and block is:")
         print(Trees.toStringTree(ctx.stat_block(), None, self._parser))
     end_if = self.ctx_stack[-1]  # get the label for the end!
     next_cond = self._current_function.new_label('end_cond')
     cond = self.visit(ctx.expr())
     self._current_function.addInstructionCondJUMP(next_cond, cond,
                                                   Condition("beq"), 0)
     self.visit(ctx.stat_block())
     self._current_function.addInstructionJUMP(end_if)
     self._current_function.addLabel(next_cond)