From a2e9eaa837bde1d0a35f8c18b8e31f7e5398f3bc Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 9 Dec 2011 15:22:48 +0000 Subject: Fix value of logical not (!) expression --- pp2cc.py | 4 ++-- tests/not.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/not.c diff --git a/pp2cc.py b/pp2cc.py index 7249ca3..ac00ffd 100755 --- a/pp2cc.py +++ b/pp2cc.py @@ -568,9 +568,9 @@ class Parse(object): # assume that the status words of the registers describes the value # of the expression lines.append(self.asm.branch_op("BEQ", lbl_false)) - lines.append(self.asm.binary_op("LOAD", reg, 1, label=lbl_true)) + lines.append(self.asm.binary_op("LOAD", reg, 0, label=lbl_true)) lines.append(self.asm.branch_op("BRA", lbl_end)) - lines.append(self.asm.binary_op("LOAD", reg, 0, label=lbl_false)) + lines.append(self.asm.binary_op("LOAD", reg, 1, label=lbl_false)) lines.append(self.asm.noop(lbl_end, register=reg)) elif op == "sizeof": self.logger.error("Sizeof operator 'sizeof' is not supported.", diff --git a/tests/not.c b/tests/not.c new file mode 100644 index 0000000..b7c7682 --- /dev/null +++ b/tests/not.c @@ -0,0 +1,3 @@ +int main() { + return !0; // 1 +} -- cgit v1.2.1