| 162 | } |
| 163 | |
| 164 | void CLikeCodeGen::PrintBinaryInstrExpr(CodeGenContext & ctx, BinaryInstruction * instr) |
| 165 | { |
| 166 | if (instr->Is<StoreInstruction>()) |
| 167 | { |
| 168 | auto op0 = instr->Operands[0].Ptr(); |
| 169 | auto op1 = instr->Operands[1].Ptr(); |
| 170 | ctx.Body << "("; |
| 171 | PrintOp(ctx, op0); |
| 172 | ctx.Body << " = "; |
| 173 | PrintOp(ctx, op1); |
| 174 | ctx.Body << ")"; |
| 175 | return; |
| 176 | } |
| 177 | auto op0 = instr->Operands[0].Ptr(); |
| 178 | auto op1 = instr->Operands[1].Ptr(); |
| 179 | if (instr->Is<StoreInstruction>()) |
| 180 | { |
| 181 | throw InvalidOperationException("store instruction cannot appear as expression."); |
| 182 | } |
| 183 | if (instr->Is<MemberLoadInstruction>()) |
| 184 | { |
| 185 | PrintOp(ctx, op0); |
| 186 | bool printDefault = true; |
| 187 | if (op0->Type->GetVectorSize() <= 4 && op0->Type->IsVector()) |
| 188 | { |
| 189 | if (auto c = dynamic_cast<ILConstOperand*>(op1)) |
| 190 | { |
| 191 | switch (c->IntValues[0]) |
| 192 | { |
| 193 | case 0: |
| 194 | ctx.Body << ".x"; |
| 195 | break; |
| 196 | case 1: |
| 197 | ctx.Body << ".y"; |
| 198 | break; |
| 199 | case 2: |
| 200 | ctx.Body << ".z"; |
| 201 | break; |
| 202 | case 3: |
| 203 | ctx.Body << ".w"; |
| 204 | break; |
| 205 | default: |
| 206 | throw InvalidOperationException("Invalid member access."); |
| 207 | } |
| 208 | printDefault = false; |
| 209 | } |
| 210 | } |
| 211 | else if (auto structType = dynamic_cast<ILStructType*>(op0->Type.Ptr())) |
| 212 | { |
| 213 | if (auto c = dynamic_cast<ILConstOperand*>(op1)) |
| 214 | { |
| 215 | ctx.Body << "." << structType->Members[c->IntValues[0]].FieldName; |
| 216 | } |
| 217 | printDefault = false; |
| 218 | } |
| 219 | if (printDefault) |
| 220 | { |
| 221 | ctx.Body << "["; |
nothing calls this directly
no test coverage detected