import ast def process(node): dest = ast.nextPRegister() compareOperation = node.ops[0][0] ast.outputInBlock( "%s = new %s" % ( dest, "PyBoolean" ) ) label1 = ast.nextLabel() label2 = ast.nextLabel() if compareOperation == "==": ast.outputInBlock( "ne %s, %s, %s" % ( ast.evaluate(node.expr), ast.evaluate(node.ops[0][1]), label1 ) ) ast.outputInBlock( "%s = %s" % ( dest, "1" ) ) ast.outputInBlock( "branch %s" % ( label2 ) ) ast.outputLabel( label1 ) ast.outputInBlock( "%s = %s" % ( dest, "0" ) ) ast.outputLabel( label2 ) elif compareOperation == "!=": ast.outputInBlock( "ne %s, %s, %s" % ( ast.evaluate(node.expr), ast.evaluate(node.ops[0][1]), label1 ) ) ast.outputInBlock( "%s = %s" % ( dest, "0" ) ) ast.outputInBlock( "branch %s" % ( label2 ) ) ast.outputLabel( label1 ) ast.outputInBlock( "%s = %s" % ( dest, "1" ) ) ast.outputLabel( label2 ) elif compareOperation == ">": ast.outputInBlock( "gt %s, %s, %s" % ( ast.evaluate(node.expr), ast.evaluate(node.ops[0][1]), label1 ) ) ast.outputInBlock( "%s = %s" % ( dest, "0" ) ) ast.outputInBlock( "branch %s" % ( label2 ) ) ast.outputLabel( label1 ) ast.outputInBlock( "%s = %s" % ( dest, "1" ) ) ast.outputLabel( label2 ) elif compareOperation == "<": ast.outputInBlock( "ge %s, %s, %s" % ( ast.evaluate(node.expr), ast.evaluate(node.ops[0][1]), label1 ) ) ast.outputInBlock( "%s = %s" % ( dest, "1" ) ) ast.outputInBlock( "branch %s" % ( label2 ) ) ast.outputLabel( label1 ) ast.outputInBlock( "%s = %s" % ( dest, "0" ) ) ast.outputLabel( label2 ) elif compareOperation == ">=": ast.outputInBlock( "ge %s, %s, %s" % ( ast.evaluate(node.expr), ast.evaluate(node.ops[0][1]), label1 ) ) ast.outputInBlock( "%s = %s" % ( dest, "0" ) ) ast.outputInBlock( "branch %s" % ( label2 ) ) ast.outputLabel( label1 ) ast.outputInBlock( "%s = %s" % ( dest, "1" ) ) ast.outputLabel( label2 ) elif compareOperation == "<=": ast.outputInBlock( "gt %s, %s, %s" % ( ast.evaluate(node.expr), ast.evaluate(node.ops[0][1]), label1 ) ) ast.outputInBlock( "%s = %s" % ( dest, "1" ) ) ast.outputInBlock( "branch %s" % ( label2 ) ) ast.outputLabel( label1 ) ast.outputInBlock( "%s = %s" % ( dest, "0" ) ) ast.outputLabel( label2 ) return dest