From 97d67c978678ea6009212ec2b868ebc7bc543585 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 7 Dec 2011 08:27:15 +0000 Subject: Proper fix for calculating negative constants --- pp2cc.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pp2cc.py b/pp2cc.py index 81f6a79..b270191 100755 --- a/pp2cc.py +++ b/pp2cc.py @@ -1315,13 +1315,11 @@ class Parse(object): else: operand = self.determineConstValue(LinkedNode(node.expr, linked_node)) - if op == "-": - # negating a value in PP2 is flipping the WORDSIZE-th bit - value = -operand - #(operand ^ (pow(2, self.WORDSIZE) - 1)) + 1 - elif op == "~": - # invert all bits + if op in ("-", "~"): value = operand ^ (pow(2, self.WORDSIZE) - 1) + # negating a value in PP2 is inverting the bits and adding 1 + if op == "-": + value += 1 else: value = int(getattr(operator, op)(operand)) elif linked_node.type == "BinaryOp": -- cgit v1.2.1