| 57 | } |
| 58 | |
| 59 | void CLikeCodeGen::PrintOp(CodeGenContext & ctx, ILOperand * op, bool forceExpression) |
| 60 | { |
| 61 | auto makeFloat = [](float v) |
| 62 | { |
| 63 | String rs(v, "%.12e"); |
| 64 | if (!rs.Contains('.') && !rs.Contains('e') && !rs.Contains('E')) |
| 65 | rs = rs + ".0"; |
| 66 | if (rs.StartsWith("-")) |
| 67 | rs = "(" + rs + ")"; |
| 68 | return rs; |
| 69 | }; |
| 70 | |
| 71 | if (auto c = dynamic_cast<ILConstOperand*>(op)) |
| 72 | { |
| 73 | auto type = c->Type.Ptr(); |
| 74 | if (type->IsFloat()) |
| 75 | ctx.Body << makeFloat(c->FloatValues[0]); |
| 76 | else if (type->IsInt()) |
| 77 | ctx.Body << (c->IntValues[0]); |
| 78 | else if (type->IsBool()) |
| 79 | ctx.Body << ((c->IntValues[0] != 0) ? "true" : "false"); |
| 80 | else if (auto baseType = dynamic_cast<ILBasicType*>(type)) |
| 81 | { |
| 82 | PrintType(ctx.Body, baseType); |
| 83 | ctx.Body << "("; |
| 84 | |
| 85 | if (baseType->Type == ILBaseType::Float2) |
| 86 | ctx.Body << makeFloat(c->FloatValues[0]) << ", " << makeFloat(c->FloatValues[1]); |
| 87 | else if (baseType->Type == ILBaseType::Float3) |
| 88 | ctx.Body << makeFloat(c->FloatValues[0]) << ", " << makeFloat(c->FloatValues[1]) << ", " << makeFloat(c->FloatValues[2]); |
| 89 | else if (baseType->Type == ILBaseType::Float4) |
| 90 | ctx.Body << makeFloat(c->FloatValues[0]) << ", " << makeFloat(c->FloatValues[1]) << ", " << makeFloat(c->FloatValues[2]) << ", " << makeFloat(c->FloatValues[3]); |
| 91 | else if (baseType->Type == ILBaseType::Float3x3) |
| 92 | { |
| 93 | ctx.Body << "mat3("; |
| 94 | for (int i = 0; i < 9; i++) |
| 95 | { |
| 96 | ctx.Body << makeFloat(c->FloatValues[i]); |
| 97 | if (i != 8) |
| 98 | ctx.Body << ", "; |
| 99 | } |
| 100 | ctx.Body; |
| 101 | } |
| 102 | else if (baseType->Type == ILBaseType::Float4x4) |
| 103 | { |
| 104 | for (int i = 0; i < 16; i++) |
| 105 | { |
| 106 | ctx.Body << makeFloat(c->FloatValues[i]); |
| 107 | if (i != 15) |
| 108 | ctx.Body << ", "; |
| 109 | } |
| 110 | } |
| 111 | else if (baseType->Type == ILBaseType::Int2) |
| 112 | ctx.Body << c->IntValues[0] << ", " << c->IntValues[1]; |
| 113 | else if (baseType->Type == ILBaseType::Int3) |
| 114 | ctx.Body << c->IntValues[0] << ", " << c->IntValues[1] << ", " << c->IntValues[2]; |
| 115 | else if (baseType->Type == ILBaseType::Int4) |
| 116 | ctx.Body << c->IntValues[0] << ", " << c->IntValues[1] << ", " << c->IntValues[2] << ", " << c->IntValues[3]; |
no test coverage detected