diff --git a/Sources/rxcc/rxcc.swift b/Sources/rxcc/rxcc.swift index 3220caa..0c2e0d5 100644 --- a/Sources/rxcc/rxcc.swift +++ b/Sources/rxcc/rxcc.swift @@ -336,6 +336,9 @@ struct rxcc { .CompoundAssignmentMultiplication: [ .Token(type: .COMPOUND_ASSIGNMENT_MULTIPLICATION), ], + .CompoundAssignmentDivision: [ + .Token(type: .COMPOUND_ASSIGNMENT_DIVISION), + ], .CompoundAssignmentModulo: [ .Token(type: .COMPOUND_ASSIGNMENT_MODULO), ], @@ -820,6 +823,50 @@ struct rxcc { text += " movl\t%eax, \(variables[variable]!)(%ebp)\n" break + case .CompoundAssignmentDivision: + text += " movl\t%eax, %ecx\n" // Move e2 to ecx + text += " movl\t\(variables[variable]!)(%ebp), %eax\n" // Fetch e1 from variable into eax + text += " cdq\n" // Extend eax into edx + text += " idivl\t%ecx\n" // Perform edx:eax / ecx + text += " movl\t%eax, \(variables[variable]!)(%ebp)\n" + + break + + case .CompoundAssignmentModulo: + text += " movl\t%eax, %ecx\n" // Move e2 to ecx + text += " movl\t\(variables[variable]!)(%ebp), %eax\n" // Fetch e1 from variable into eax + text += " cdq\n" // Extend eax into edx + text += " idivl\t%ecx\n" // Perform edx:eax / ecx + text += " movl\t%edx, \(variables[variable]!)(%ebp)\n" + + break + + case .CompoundAssignmentBitwiseShiftLeft: + text += " movl\t%eax, %ecx\n" // Move e2 to ecx + text += " movl\t\(variables[variable]!)(%ebp), %eax\n" // Move e2 to ecx + text += " sal \t%cl, %eax\n" // Perform e1 << e2; result in e1 + text += " movl\t%eax, \(variables[variable]!)(%ebp)\n" // Move e2 to ecx + break + + case .CompoundAssignmentBitwiseShiftRight: + text += " movl\t%eax, %ecx\n" // Move e2 to ecx + text += " movl\t\(variables[variable]!)(%ebp), %eax\n" // Move e2 to ecx + text += " sar \t%cl, %eax\n" // Perform e1 << e2; result in e1 + text += " movl\t%eax, \(variables[variable]!)(%ebp)\n" // Move e2 to ecx + break + + case .CompoundAssignmentBitwiseAnd: + text += " and \t%eax, \(variables[variable]!)(%ebp)\n" + break + + case .CompoundAssignmentBitwiseOr: + text += " or \t%eax, \(variables[variable]!)(%ebp)\n" + break + + case .CompoundAssignmentBitwiseXOR: + text += " xor \t%eax, \(variables[variable]!)(%ebp)\n" + break + default: print("ERROR: Unknown assignment type \"\(node.children[0].variant)\"") break diff --git a/test.c b/test.c index 95233d8..68430eb 100644 --- a/test.c +++ b/test.c @@ -1,8 +1,26 @@ int main() { - int tomas = 1; - int jefferson = 3; - tomas *= jefferson; + int tomas = 8; + tomas /= 2; + tomas *= 3; + tomas %= 7; + tomas <<= 7; + tomas >>= 1; + tomas += 31; + tomas &= 21; + tomas |= 3; + tomas |= 303; + tomas ^= 23; + tomas ^= 27; + tomas &= 302; + tomas ^= 392; + + int jefferson; + jefferson = 3 + tomas / (~3 - 90); + jefferson *= tomas; - return tomas * jefferson; + + int three = tomas | jefferson; + + return three; }