755 switch (ins.opcode) {
769 simulationStack.push(compilerCtx->getShortObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.shortV);
773 simulationStack.push(compilerCtx->getUnsignedObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.unsignedV);
777 simulationStack.push(compilerCtx->getStrObjectType(), {currentCodeBlockIndex, {insIndex}});
781 simulationStack.push(
782 compilerCtx->getCharObjectType(), {currentCodeBlockIndex, {insIndex}},
static_cast<char>(ins.operands[0].value.character));
786 auto value = simulationStack.peek(0);
787 simulationStack.pop();
788 if (
value.hasPossibleValue) {
789 switch (
value.type->type) {
791 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.deciValue);
794 value.possibleValue.charValue =
value.possibleValue.boolValue ? 1 : 0;
797 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.intValue);
800 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.shortValue);
803 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.unsignedValue);
808 value.type = compilerCtx->getCharObjectType();
809 insIndex = reduce(
value.contributedInstructions, insIndex);
811 insIndex = generatePushOp(value, insIndex);
813 simulationStack.push(compilerCtx->getCharObjectType(),
814 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
815 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
820 auto value = simulationStack.peek(0);
821 simulationStack.pop();
823 if (
value.hasPossibleValue) {
824 switch (
value.type->type) {
826 value.possibleValue.boolValue =
value.possibleValue.intValue != 0;
829 value.possibleValue.boolValue =
value.possibleValue.deciValue != 0.0;
832 value.possibleValue.boolValue =
value.possibleValue.charValue != 0;
835 value.possibleValue.boolValue =
value.possibleValue.shortValue != 0;
838 value.possibleValue.boolValue =
value.possibleValue.unsignedValue != 0;
843 value.type = compilerCtx->getBoolObjectType();
844 insIndex = reduce(
value.contributedInstructions, insIndex);
846 insIndex = generatePushOp(value, insIndex);
848 simulationStack.push(compilerCtx->getBoolObjectType(),
849 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
850 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
855 auto value = simulationStack.peek(0);
856 simulationStack.pop();
857 if (
value.hasPossibleValue) {
858 switch (
value.type->type) {
860 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.deciValue);
863 value.possibleValue.intValue =
value.possibleValue.boolValue ? 1 : 0;
866 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.charValue);
869 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.shortValue);
872 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.unsignedValue);
877 value.type = compilerCtx->getIntObjectType();
878 insIndex = reduce(
value.contributedInstructions, insIndex);
880 insIndex = generatePushOp(value, insIndex);
882 simulationStack.push(compilerCtx->getIntObjectType(),
883 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
884 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
889 auto value = simulationStack.peek(0);
890 simulationStack.pop();
892 if (
value.hasPossibleValue) {
893 switch (
value.type->type) {
895 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.intValue);
898 value.possibleValue.deciValue =
value.possibleValue.boolValue ? 1.0 : 0.0;
901 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.charValue);
904 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.unsignedValue);
907 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.shortValue);
912 value.type = compilerCtx->getDeciObjectType();
913 insIndex = reduce(
value.contributedInstructions, insIndex);
915 insIndex = generatePushOp(value, insIndex);
917 simulationStack.push(compilerCtx->getDeciObjectType(),
918 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
919 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
924 auto value = simulationStack.peek(0);
925 simulationStack.pop();
927 if (
value.hasPossibleValue) {
928 switch (
value.type->type) {
930 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.intValue);
933 value.possibleValue.shortValue =
value.possibleValue.boolValue;
936 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.charValue);
939 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.unsignedValue);
942 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.deciValue);
947 value.type = compilerCtx->getShortObjectType();
948 insIndex = reduce(
value.contributedInstructions, insIndex);
950 insIndex = generatePushOp(value, insIndex);
952 simulationStack.push(compilerCtx->getShortObjectType(),
953 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
954 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
959 auto value = simulationStack.peek(0);
960 simulationStack.pop();
962 if (
value.hasPossibleValue) {
963 switch (
value.type->type) {
965 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.intValue);
968 value.possibleValue.unsignedValue =
value.possibleValue.boolValue;
971 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.charValue);
974 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.shortValue);
977 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.deciValue);
982 value.type = compilerCtx->getUnsignedObjectType();
983 insIndex = reduce(
value.contributedInstructions, insIndex);
985 insIndex = generatePushOp(value, insIndex);
987 simulationStack.push(compilerCtx->getUnsignedObjectType(),
988 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
989 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
994 auto right = simulationStack.peek(0);
995 auto left = simulationStack.peek(1);
996 simulationStack.pop();
997 simulationStack.pop();
999 auto result = add(left, right);
1002 if (result.hasPossibleValue) {
1003 insIndex = reduce(left.contributedInstructions, insIndex);
1004 insIndex = reduce(right.contributedInstructions, insIndex);
1006 insIndex = generatePushOp(result, insIndex);
1009 simulationStack.push(
1011 left.contributedInstructions + right.contributedInstructions +
1012 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1017 auto right = simulationStack.peek(0);
1018 auto left = simulationStack.peek(1);
1019 simulationStack.pop();
1020 simulationStack.pop();
1022 auto result = sub(left, right);
1025 if (result.hasPossibleValue) {
1026 insIndex = reduce(left.contributedInstructions, insIndex);
1027 insIndex = reduce(right.contributedInstructions, insIndex);
1029 insIndex = generatePushOp(result, insIndex);
1032 simulationStack.push(
1034 left.contributedInstructions + right.contributedInstructions +
1035 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1040 auto right = simulationStack.peek(0);
1041 auto left = simulationStack.peek(1);
1042 simulationStack.pop();
1043 simulationStack.pop();
1045 auto result = mul(left, right);
1048 if (result.hasPossibleValue) {
1049 insIndex = reduce(left.contributedInstructions, insIndex);
1050 insIndex = reduce(right.contributedInstructions, insIndex);
1052 insIndex = generatePushOp(result, insIndex);
1055 simulationStack.push(
1057 left.contributedInstructions + right.contributedInstructions +
1058 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1063 auto right = simulationStack.peek(0);
1064 auto left = simulationStack.peek(1);
1065 simulationStack.pop();
1066 simulationStack.pop();
1068 auto result = div(left, right);
1071 if (result.hasPossibleValue) {
1072 insIndex = reduce(left.contributedInstructions, insIndex);
1073 insIndex = reduce(right.contributedInstructions, insIndex);
1075 insIndex = generatePushOp(result, insIndex);
1078 simulationStack.push(
1080 left.contributedInstructions + right.contributedInstructions +
1081 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1086 auto right = simulationStack.peek(0);
1087 auto left = simulationStack.peek(1);
1088 simulationStack.pop();
1089 simulationStack.pop();
1091 auto result = mod(left, right);
1092 if (result.hasPossibleValue) {
1093 insIndex = reduce(left.contributedInstructions, insIndex);
1094 insIndex = reduce(right.contributedInstructions, insIndex);
1096 insIndex = generatePushOp(result, insIndex);
1099 simulationStack.push(
1101 left.contributedInstructions + right.contributedInstructions +
1102 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1107 auto value = simulationStack.peek(0);
1108 simulationStack.pop();
1110 auto result = negate(value);
1111 if (result.hasPossibleValue) {
1112 insIndex = reduce(
value.contributedInstructions, insIndex);
1114 insIndex = generatePushOp(result, insIndex);
1117 simulationStack.push(result.type,
1118 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
1119 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1124 auto right = simulationStack.peek(0);
1125 auto left = simulationStack.peek(1);
1126 simulationStack.pop();
1127 simulationStack.pop();
1129 auto result = bitwiseAnd(left, right);
1130 if (result.hasPossibleValue) {
1131 insIndex = reduce(left.contributedInstructions, insIndex);
1132 insIndex = reduce(right.contributedInstructions, insIndex);
1134 insIndex = generatePushOp(result, insIndex);
1137 simulationStack.push(
1139 left.contributedInstructions + right.contributedInstructions +
1140 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1145 auto right = simulationStack.peek(0);
1146 auto left = simulationStack.peek(1);
1147 simulationStack.pop();
1148 simulationStack.pop();
1150 auto result = bitwiseOr(left, right);
1151 if (result.hasPossibleValue) {
1152 insIndex = reduce(left.contributedInstructions, insIndex);
1153 insIndex = reduce(right.contributedInstructions, insIndex);
1155 insIndex = generatePushOp(result, insIndex);
1158 simulationStack.push(
1160 left.contributedInstructions + right.contributedInstructions +
1161 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1166 auto right = simulationStack.peek(0);
1167 auto left = simulationStack.peek(1);
1168 simulationStack.pop();
1169 simulationStack.pop();
1171 auto result = bitwiseXor(left, right);
1172 if (result.hasPossibleValue) {
1173 insIndex = reduce(left.contributedInstructions, insIndex);
1174 insIndex = reduce(right.contributedInstructions, insIndex);
1176 insIndex = generatePushOp(result, insIndex);
1179 simulationStack.push(
1181 left.contributedInstructions + right.contributedInstructions +
1182 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1187 auto value = simulationStack.peek(0);
1188 simulationStack.pop();
1190 auto result = bitwiseNot(value);
1191 if (result.hasPossibleValue) {
1192 insIndex = reduce(
value.contributedInstructions, insIndex);
1193 insIndex = generatePushOp(result, insIndex);
1196 simulationStack.push(result.type,
1197 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
1198 currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1203 auto shift = simulationStack.peek(0);
1204 auto value = simulationStack.peek(1);
1205 simulationStack.pop();
1206 simulationStack.pop();
1208 auto result = bitwiseShiftLeft(value, shift);
1209 if (result.hasPossibleValue) {
1210 insIndex = reduce(
value.contributedInstructions, insIndex);
1211 insIndex = reduce(shift.contributedInstructions, insIndex);
1213 insIndex = generatePushOp(result, insIndex);
1216 simulationStack.push(
1218 value.contributedInstructions + shift.contributedInstructions +
1219 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1224 auto shift = simulationStack.peek(0);
1225 auto value = simulationStack.peek(1);
1226 simulationStack.pop();
1227 simulationStack.pop();
1229 auto result = bitwiseShiftRight(value, shift);
1230 if (result.hasPossibleValue) {
1231 insIndex = reduce(
value.contributedInstructions, insIndex);
1232 insIndex = reduce(shift.contributedInstructions, insIndex);
1234 insIndex = generatePushOp(result, insIndex);
1237 simulationStack.push(
1239 value.contributedInstructions + shift.contributedInstructions +
1240 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1245 auto right = simulationStack.peek(0);
1246 auto left = simulationStack.peek(1);
1247 simulationStack.pop();
1248 simulationStack.pop();
1250 auto result = lessThan(left, right);
1251 if (result.hasPossibleValue) {
1252 insIndex = reduce(left.contributedInstructions, insIndex);
1253 insIndex = reduce(right.contributedInstructions, insIndex);
1255 insIndex = generatePushOp(result, insIndex);
1258 simulationStack.push(
1260 left.contributedInstructions + right.contributedInstructions +
1261 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1266 auto right = simulationStack.peek(0);
1267 auto left = simulationStack.peek(1);
1268 simulationStack.pop();
1269 simulationStack.pop();
1271 auto result = greaterThan(left, right);
1272 if (result.hasPossibleValue) {
1273 insIndex = reduce(left.contributedInstructions, insIndex);
1274 insIndex = reduce(right.contributedInstructions, insIndex);
1276 insIndex = generatePushOp(result, insIndex);
1279 simulationStack.push(
1281 left.contributedInstructions + right.contributedInstructions +
1282 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1287 auto right = simulationStack.peek(0);
1288 auto left = simulationStack.peek(1);
1289 simulationStack.pop();
1290 simulationStack.pop();
1292 auto result = greaterThanOrEqual(left, right);
1293 if (result.hasPossibleValue) {
1294 insIndex = reduce(left.contributedInstructions, insIndex);
1295 insIndex = reduce(right.contributedInstructions, insIndex);
1297 insIndex = generatePushOp(result, insIndex);
1300 simulationStack.push(
1302 left.contributedInstructions + right.contributedInstructions +
1303 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1308 auto right = simulationStack.peek(0);
1309 auto left = simulationStack.peek(1);
1310 simulationStack.pop();
1311 simulationStack.pop();
1313 auto result = greaterThanOrEqual(left, right);
1314 if (result.hasPossibleValue) {
1315 insIndex = reduce(left.contributedInstructions, insIndex);
1316 insIndex = reduce(right.contributedInstructions, insIndex);
1318 insIndex = generatePushOp(result, insIndex);
1321 simulationStack.push(
1323 left.contributedInstructions + right.contributedInstructions +
1324 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1329 auto right = simulationStack.peek(0);
1330 auto left = simulationStack.peek(1);
1331 simulationStack.pop();
1332 simulationStack.pop();
1334 auto result = equal(left, right);
1335 if (result.hasPossibleValue) {
1336 insIndex = reduce(left.contributedInstructions, insIndex);
1337 insIndex = reduce(right.contributedInstructions, insIndex);
1339 insIndex = generatePushOp(result, insIndex);
1342 simulationStack.push(
1344 left.contributedInstructions + right.contributedInstructions +
1345 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1350 auto right = simulationStack.peek(0);
1351 auto left = simulationStack.peek(1);
1352 simulationStack.pop();
1353 simulationStack.pop();
1355 auto result = notEqual(left, right);
1356 if (result.hasPossibleValue) {
1357 insIndex = reduce(left.contributedInstructions, insIndex);
1358 insIndex = reduce(right.contributedInstructions, insIndex);
1360 insIndex = generatePushOp(result, insIndex);
1363 simulationStack.push(
1365 left.contributedInstructions + right.contributedInstructions +
1366 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, std::set{yoi::indexT{insIndex}}});
1371 if (
auto it = variablesExtraInfo.find(ins.operands[0].value.symbolIndex); it != variablesExtraInfo.end()) {
1373 if (it->second.hasPossibleValue && it->second.possibleValue.contributedInstructions.codeBlockIndex == currentCodeBlockIndex) {
1375 simulationStack.push(it->second.possibleValue.type,
1376 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
1377 it->second.isReadAfterStore =
false;
1381 auto type = targetFunction->getVariableTable().get(ins.operands[0].value.symbolIndex);
1382 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
1383 it->second.isReadAfterStore =
true;
1388 auto type = targetFunction->getVariableTable().get(ins.operands[0].value.symbolIndex);
1389 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
1390 variablesExtraInfo[ins.operands[0].value.symbolIndex] = {
false,
true, {}};
1400 auto definitionType = targetFunction->getVariableTable().get(ins.operands[0].value.symbolIndex);
1401 auto value = simulationStack.peek(0);
1403 if (
value.type->isForeignBasicType()) {
1404 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
1409 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::reduceRedundantConstantExpr(): store_local: type mismatch");
1412 simulationStack.pop();
1413 if (
auto it = variablesExtraInfo.find(ins.operands[0].value.symbolIndex);
1414 it != variablesExtraInfo.end() && it->second.hasPossibleValue && !it->second.isReadAfterStore &&
1415 it->second.possibleValue.contributedInstructions.codeBlockIndex == currentCodeBlockIndex) {
1417 insIndex = reduce(it->second.possibleValue.contributedInstructions, insIndex);
1418 variablesExtraInfo[ins.operands[0].value.symbolIndex] = {
value.hasPossibleValue,
false,
value};
1420 value.contributedInstructions =
1421 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}};
1422 variablesExtraInfo[ins.operands[0].value.symbolIndex] = {
value.hasPossibleValue,
false,
value};
1428 auto moduleIndex = ins.operands[0].value.symbolIndex;
1429 auto type = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
1430 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
1435 auto moduleIndex = ins.operands[0].value.symbolIndex;
1436 auto definitionType = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
1437 auto value = simulationStack.peek(0);
1439 if (
value.type->isForeignBasicType()) {
1440 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
1446 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::reduceRedundantConstantExpr(): store_global: type mismatch");
1449 simulationStack.pop();
1454 auto value = simulationStack.peek(0);
1455 auto type =
value.type->typeIndex;
1456 auto targetModule = compilerCtx->getImportedModule(
value.type->typeAffiliateModule);
1457 auto structDef = targetModule->structTable[type];
1458 auto memberIndex = ins.operands[0].value.symbolIndex;
1459 auto memberDef =
managedPtr(*structDef->fieldTypes[memberIndex]);
1460 simulationStack.pop();
1461 simulationStack.push(memberDef,
1462 value.contributedInstructions +
1463 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
1468 auto value = simulationStack.peek(1);
1469 auto type = simulationStack.peek(0).type->typeIndex;
1470 auto structDef = compilerCtx->getImportedModule(simulationStack.peek(0).type->typeAffiliateModule)->structTable[type];
1471 auto memberIndex = ins.operands[0].value.symbolIndex;
1472 auto memberDef = structDef->fieldTypes[memberIndex];
1474 if (
value.type->isForeignBasicType()) {
1475 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
1481 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::reduceRedundantConstantExpr(): store_member: type mismatch");
1484 simulationStack.pop();
1485 simulationStack.pop();
1492 auto moduleIndex = ins.operands[0].value.symbolIndex;
1493 auto function = compilerCtx->getImportedModule(moduleIndex)->functionTable[ins.operands[1].value.symbolIndex];
1495 auto argTypes = function->argumentTypes;
1496 auto argCount = function->argumentTypes.size();
1497 SimulationStack::Item::ContributedInstructionSet contributedInstructions = {currentCodeBlockIndex, {insIndex},
false};
1498 for (
int i = 0; i < argCount; i++) {
1499 contributedInstructions = contributedInstructions + simulationStack.peek(0).contributedInstructions;
1500 simulationStack.pop();
1502 simulationStack.push(returnType, contributedInstructions);
1506 auto function = compilerCtx->getIRFFITable()
1507 ->importedLibraries[ins.operands[0].value.symbolIndex]
1508 .importedFunctionTable[ins.operands[1].value.symbolIndex];
1509 auto returnType = function->returnType;
1510 auto argTypes = function->argumentTypes;
1511 auto argCount = function->argumentTypes.size();
1512 for (
int i = 0; i < argCount; i++) {
1513 simulationStack.pop();
1515 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
1519 auto argCount = ins.operands[3].value.symbolIndex;
1520 for (
int i = 0; i < argCount - 1; i++) {
1521 simulationStack.pop();
1523 auto returnType = compilerCtx->getImportedModule(ins.operands[0].value.symbolIndex)
1524 ->interfaceTable[ins.operands[1].value.symbolIndex]
1525 ->methodMap[ins.operands[2].value.symbolIndex]
1528 simulationStack.pop();
1529 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
1533 auto moduleIndex = ins.operands[0].value.symbolIndex;
1534 auto structDef = compilerCtx->getImportedModule(moduleIndex)->structTable[ins.operands[1].value.symbolIndex];
1535 simulationStack.push(
1537 {currentCodeBlockIndex, {insIndex},
false});
1541 auto moduleIndex = ins.operands[0].value.symbolIndex;
1542 auto interfaceImplDef =
1543 compilerCtx->getImportedModule(moduleIndex)->interfaceImplementationTable[ins.operands[1].value.symbolIndex];
1545 interfaceImplDef->implInterfaceIndex.first,
1546 interfaceImplDef->implInterfaceIndex.second});
1547 simulationStack.pop();
1548 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
1552 auto condition = simulationStack.peek(0);
1553 simulationStack.pop();
1554 if (condition.hasPossibleValue) {
1555 if (condition.possibleValue.boolValue) {
1558 insIndex = reduce(condition.contributedInstructions, insIndex);
1562 insIndex = reduce(condition.contributedInstructions, insIndex);
1563 insIndex = reduce(SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}}, insIndex);
1573 auto condition = simulationStack.peek(0);
1574 simulationStack.pop();
1575 if (condition.hasPossibleValue) {
1576 if (!condition.possibleValue.boolValue) {
1579 insIndex = reduce(condition.contributedInstructions, insIndex);
1583 insIndex = reduce(condition.contributedInstructions, insIndex);
1584 insIndex = reduce(SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}}, insIndex);
1595 simulationStack.pop();
1607 std::shared_ptr<IRValueType> baseType;
1608 switch (ins.opcode) {
1610 baseType = compilerCtx->getIntObjectType();
1613 baseType = compilerCtx->getBoolObjectType();
1616 baseType = compilerCtx->getCharObjectType();
1619 baseType = compilerCtx->getDeciObjectType();
1622 baseType = compilerCtx->getStrObjectType();
1625 baseType = compilerCtx->getShortObjectType();
1628 baseType = compilerCtx->getUnsignedObjectType();
1637 for (
auto i = 1; i < ins.operands.size(); i++) {
1638 size *= ins.operands[i].value.symbolIndex;
1639 dims.push_back(ins.operands[i].value.symbolIndex);
1641 for (
yoi::indexT i = 0; i < ins.operands[0].value.symbolIndex; i++) {
1642 simulationStack.pop();
1644 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
1649 auto moduleIndex = ins.operands[0].value.symbolIndex;
1650 auto typeIndex = ins.operands[1].value.symbolIndex;
1659 for (
yoi::indexT i = 3; i < ins.operands.size(); i++) {
1660 size *= ins.operands[i].value.symbolIndex;
1661 dims.push_back(ins.operands[i].value.symbolIndex);
1663 for (
yoi::indexT i = 0; i < ins.operands[2].value.symbolIndex; i++) {
1664 simulationStack.pop();
1666 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
1671 auto index = simulationStack.peek(0);
1672 auto array = simulationStack.peek(1);
1673 simulationStack.pop();
1674 simulationStack.pop();
1676 array.contributedInstructions + index.contributedInstructions +
1677 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
1682 auto index = simulationStack.peek(0);
1683 auto value = simulationStack.peek(1);
1684 auto array = simulationStack.peek(2);
1685 simulationStack.pop();
1686 simulationStack.pop();
1687 simulationStack.pop();
1691 auto rhs = simulationStack.peek(0);
1692 auto lhs = simulationStack.peek(1);
1693 simulationStack.pop();
1694 simulationStack.pop();
1695 simulationStack.push(lhs.type,
1696 lhs.contributedInstructions + rhs.contributedInstructions +
1697 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
1701 auto array = simulationStack.peek(0);
1702 simulationStack.pop();
1703 if (
array.type->isArrayType()) {
1705 for (
auto &dim :
array.type->dimensions) {
1709 insIndex = reduce(
array.contributedInstructions, insIndex);
1712 insIndex = generatePushOp({compilerCtx->getIntObjectType(),
true,
static_cast<int64_t
>(size)}, insIndex);
1714 }
else if (
array.type->isDynamicArrayType()) {
1716 simulationStack.push(compilerCtx->getIntObjectType(),
1717 array.contributedInstructions +
1718 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
1723 auto rhs = simulationStack.peek(0);
1724 if (rhs.contributedInstructions.optimizable) {
1725 insIndex = reduce(rhs.contributedInstructions, insIndex);
1728 simulationStack.pop();
1733 ins.operands[1].value.symbolIndex,
1734 ins.operands[2].value.symbolIndex,
1735 ins.operands[3].value.symbolIndex
1738 simulationStack.pop();
1739 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
1743 simulationStack.pop();
1760 std::shared_ptr<IRValueType> baseType;
1761 switch (ins.opcode) {
1763 baseType = compilerCtx->getIntObjectType();
1766 baseType = compilerCtx->getBoolObjectType();
1769 baseType = compilerCtx->getCharObjectType();
1772 baseType = compilerCtx->getDeciObjectType();
1775 baseType = compilerCtx->getShortObjectType();
1778 baseType = compilerCtx->getUnsignedObjectType();
1781 baseType = compilerCtx->getStrObjectType();
1796 simulationStack.pop();
1798 simulationStack.push(
managedPtr(baseType->getDynamicArrayType()), {currentCodeBlockIndex, {insIndex},
false});
1803 auto interfaceType = simulationStack.peek(0).type;
1804 auto objectType = simulationStack.peek(1).type;
1805 simulationStack.pop();
1806 simulationStack.pop();
1807 simulationStack.push(compilerCtx->getBoolObjectType(), {currentCodeBlockIndex, {insIndex},
false});
1811 simulationStack.push(compilerCtx->getIntObjectType(), {currentCodeBlockIndex, {insIndex},
false});
1815 handleInstruction(ins, insIndex, currentCodeBlockIndex);
3488 simulationStack.push(compilerCtx->getDeciObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.decimal);
3492 simulationStack.push(compilerCtx->getShortObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.shortV);
3496 simulationStack.push(compilerCtx->getUnsignedObjectType(), {currentCodeBlockIndex, {insIndex}}, ins.operands[0].value.unsignedV);
3500 simulationStack.push(compilerCtx->getStrObjectType(), {currentCodeBlockIndex, {insIndex}});
3504 simulationStack.push(
3505 compilerCtx->getCharObjectType(), {currentCodeBlockIndex, {insIndex}},
static_cast<char>(ins.operands[0].value.character));
3509 auto value = simulationStack.peek(0);
3510 simulationStack.pop();
3512 if (
value.hasPossibleValue) {
3513 switch (
value.type->type) {
3515 value.possibleValue.boolValue =
value.possibleValue.intValue != 0;
3518 value.possibleValue.boolValue =
value.possibleValue.unsignedValue != 0;
3521 value.possibleValue.boolValue =
value.possibleValue.shortValue != 0;
3524 value.possibleValue.boolValue =
value.possibleValue.deciValue != 0.0;
3527 value.possibleValue.boolValue =
value.possibleValue.charValue != 0;
3532 value.type = compilerCtx->getBoolObjectType();
3533 simulationStack.push(value);
3535 simulationStack.push(compilerCtx->getBoolObjectType(),
3536 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3537 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3542 auto value = simulationStack.peek(0);
3543 simulationStack.pop();
3544 if (
value.hasPossibleValue) {
3545 switch (
value.type->type) {
3547 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.deciValue);
3550 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.unsignedValue);
3553 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.shortValue);
3556 value.possibleValue.intValue =
value.possibleValue.boolValue ? 1 : 0;
3559 value.possibleValue.intValue =
static_cast<int64_t
>(
value.possibleValue.charValue);
3564 value.type = compilerCtx->getIntObjectType();
3565 simulationStack.push(value);
3567 simulationStack.push(compilerCtx->getIntObjectType(),
3568 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3569 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3574 auto value = simulationStack.peek(0);
3575 simulationStack.pop();
3577 if (
value.hasPossibleValue) {
3578 switch (
value.type->type) {
3580 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.intValue);
3583 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.unsignedValue);
3586 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.shortValue);
3589 value.possibleValue.deciValue =
value.possibleValue.boolValue ? 1.0 : 0.0;
3592 value.possibleValue.deciValue =
static_cast<double>(
value.possibleValue.charValue);
3597 value.type = compilerCtx->getDeciObjectType();
3598 simulationStack.push(value);
3600 simulationStack.push(compilerCtx->getDeciObjectType(),
3601 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3602 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3607 auto value = simulationStack.peek(0);
3608 simulationStack.pop();
3609 if (
value.hasPossibleValue) {
3610 switch (
value.type->type) {
3612 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.intValue);
3615 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.unsignedValue);
3618 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.deciValue);
3621 value.possibleValue.shortValue =
value.possibleValue.boolValue ? 1 : 0;
3624 value.possibleValue.shortValue =
static_cast<short>(
value.possibleValue.charValue);
3629 value.type = compilerCtx->getShortObjectType();
3630 simulationStack.push(value);
3632 simulationStack.push(compilerCtx->getShortObjectType(),
3633 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3634 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3639 auto value = simulationStack.peek(0);
3640 simulationStack.pop();
3641 if (
value.hasPossibleValue) {
3642 switch (
value.type->type) {
3644 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.intValue);
3647 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.shortValue);
3650 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.deciValue);
3653 value.possibleValue.unsignedValue =
value.possibleValue.boolValue ? 1 : 0;
3656 value.possibleValue.unsignedValue =
static_cast<uint64_t
>(
value.possibleValue.charValue);
3661 value.type = compilerCtx->getUnsignedObjectType();
3662 simulationStack.push(value);
3664 simulationStack.push(compilerCtx->getUnsignedObjectType(),
3665 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3666 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3671 auto value = simulationStack.peek(0);
3672 simulationStack.pop();
3673 if (
value.hasPossibleValue) {
3674 switch (
value.type->type) {
3676 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.deciValue);
3679 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.unsignedValue);
3682 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.shortValue);
3685 value.possibleValue.charValue =
value.possibleValue.boolValue ? 1 : 0;
3688 value.possibleValue.charValue =
static_cast<char>(
value.possibleValue.intValue);
3693 value.type = compilerCtx->getCharObjectType();
3694 simulationStack.push(value);
3696 simulationStack.push(compilerCtx->getCharObjectType(),
3697 value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{
3698 currentCodeBlockIndex, std::set{
yoi::indexT{insIndex}}});
3704 auto array = simulationStack.peek(0);
3705 simulationStack.pop();
3706 for (
auto i = 0; i < ins.operands[0].value.symbolIndex; ++i) {
3708 array.contributedInstructions +
3709 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
3715 auto structVal = simulationStack.peek(0);
3716 simulationStack.pop();
3717 auto structDef = compilerCtx->getImportedModule(structVal.type->typeAffiliateModule)->structTable[structVal.type->typeIndex];
3720 yoi::indexT endPos = startPos + ins.operands[0].value.symbolIndex;
3721 for (
auto i = startPos; i < endPos; ++i) {
3722 auto fieldType = structDef->fieldTypes[i];
3723 simulationStack.push(fieldType,
3724 structVal.contributedInstructions +
3725 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
3730 auto right = simulationStack.peek(0);
3731 auto left = simulationStack.peek(1);
3732 simulationStack.pop();
3733 simulationStack.pop();
3735 auto result = add(left, right);
3738 simulationStack.push(result);
3742 auto right = simulationStack.peek(0);
3743 auto left = simulationStack.peek(1);
3744 simulationStack.pop();
3745 simulationStack.pop();
3747 auto result = sub(left, right);
3748 simulationStack.push(result);
3752 auto right = simulationStack.peek(0);
3753 auto left = simulationStack.peek(1);
3754 simulationStack.pop();
3755 simulationStack.pop();
3757 auto result = mul(left, right);
3758 simulationStack.push(result);
3762 auto right = simulationStack.peek(0);
3763 auto left = simulationStack.peek(1);
3764 simulationStack.pop();
3765 simulationStack.pop();
3767 auto result = div(left, right);
3770 simulationStack.push(result);
3774 auto right = simulationStack.peek(0);
3775 auto left = simulationStack.peek(1);
3776 simulationStack.pop();
3777 simulationStack.pop();
3779 auto result = mod(left, right);
3780 simulationStack.push(result);
3784 auto value = simulationStack.peek(0);
3785 simulationStack.pop();
3787 auto result = negate(value);
3788 simulationStack.push(result);
3792 auto right = simulationStack.peek(0);
3793 auto left = simulationStack.peek(1);
3794 simulationStack.pop();
3795 simulationStack.pop();
3797 auto result = bitwiseAnd(left, right);
3798 simulationStack.push(result);
3802 auto right = simulationStack.peek(0);
3803 auto left = simulationStack.peek(1);
3804 simulationStack.pop();
3805 simulationStack.pop();
3807 auto result = bitwiseOr(left, right);
3808 simulationStack.push(result);
3812 auto right = simulationStack.peek(0);
3813 auto left = simulationStack.peek(1);
3814 simulationStack.pop();
3815 simulationStack.pop();
3817 auto result = bitwiseXor(left, right);
3818 simulationStack.push(result);
3822 auto value = simulationStack.peek(0);
3823 simulationStack.pop();
3825 auto result = bitwiseNot(value);
3827 simulationStack.push(result.type,
value.contributedInstructions);
3831 auto shift = simulationStack.peek(0);
3832 auto value = simulationStack.peek(1);
3833 simulationStack.pop();
3834 simulationStack.pop();
3836 auto result = bitwiseShiftLeft(value, shift);
3837 simulationStack.push(result);
3841 auto shift = simulationStack.peek(0);
3842 auto value = simulationStack.peek(1);
3843 simulationStack.pop();
3844 simulationStack.pop();
3846 auto result = bitwiseShiftRight(value, shift);
3847 simulationStack.push(result);
3851 auto right = simulationStack.peek(0);
3852 auto left = simulationStack.peek(1);
3853 simulationStack.pop();
3854 simulationStack.pop();
3856 auto result = lessThan(left, right);
3857 simulationStack.push(result);
3861 auto right = simulationStack.peek(0);
3862 auto left = simulationStack.peek(1);
3863 simulationStack.pop();
3864 simulationStack.pop();
3866 auto result = greaterThan(left, right);
3867 simulationStack.push(result);
3871 auto right = simulationStack.peek(0);
3872 auto left = simulationStack.peek(1);
3873 simulationStack.pop();
3874 simulationStack.pop();
3876 auto result = greaterThanOrEqual(left, right);
3877 simulationStack.push(result);
3881 auto right = simulationStack.peek(0);
3882 auto left = simulationStack.peek(1);
3883 simulationStack.pop();
3884 simulationStack.pop();
3886 auto result = greaterThanOrEqual(left, right);
3887 simulationStack.push(result);
3891 auto right = simulationStack.peek(0);
3892 auto left = simulationStack.peek(1);
3893 simulationStack.pop();
3894 simulationStack.pop();
3896 auto result = equal(left, right);
3897 simulationStack.push(result);
3901 auto right = simulationStack.peek(0);
3902 auto left = simulationStack.peek(1);
3903 simulationStack.pop();
3904 simulationStack.pop();
3906 auto result = notEqual(left, right);
3907 simulationStack.push(result);
3911 auto varIndex = ins.operands[0].value.symbolIndex;
3912 auto varType = targetFunction->getVariableTable().get(varIndex);
3914 if (
auto it = variablesExtraInfo.find(varIndex); it != variablesExtraInfo.end() && it->second.hasPossibleValue) {
3915 simulationStack.push(it->second.possibleValue);
3917 simulationStack.push(varType, {currentCodeBlockIndex, {insIndex}});
3920 if (
auto it = variablesExtraInfo.find(varIndex); it != variablesExtraInfo.end()) {
3921 it->second.isReadAfterStore =
true;
3923 variablesExtraInfo[varIndex] = {
false,
true, {}};
3928 auto varIndex = ins.operands[0].value.symbolIndex;
3929 auto value = simulationStack.peek(0);
3930 simulationStack.pop();
3932 variablesExtraInfo[varIndex] = {
value.hasPossibleValue,
false,
value};
3937 auto moduleIndex = ins.operands[0].value.symbolIndex;
3938 auto type = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
3939 simulationStack.push(type, {currentCodeBlockIndex, {insIndex}});
3944 auto moduleIndex = ins.operands[0].value.symbolIndex;
3945 auto definitionType = compilerCtx->getImportedModule(moduleIndex)->globalVariables[ins.operands[1].value.symbolIndex];
3946 auto value = simulationStack.peek(0);
3948 if (
value.type->isForeignBasicType()) {
3949 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
3955 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::analyzeBlock(): store_global: type mismatch");
3958 simulationStack.pop();
3963 auto value = simulationStack.peek(0);
3964 auto type =
value.type->typeIndex;
3965 auto targetModule = compilerCtx->getImportedModule(
value.type->typeAffiliateModule);
3966 auto structDef = targetModule->structTable[type];
3967 auto memberIndex = ins.operands[0].value.symbolIndex;
3968 auto memberDef =
managedPtr(*structDef->fieldTypes[memberIndex]);
3969 if (memberDef->metadata.hasMetadata(L
"STRUCT_DATAFIELD")) {
3972 simulationStack.pop();
3973 simulationStack.push(
3974 memberDef,
value.contributedInstructions + SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}});
3979 auto value = simulationStack.peek(1);
3980 auto type = simulationStack.peek(0).type->typeIndex;
3981 auto structDef = compilerCtx->getImportedModule(simulationStack.peek(0).type->typeAffiliateModule)->structTable[type];
3982 auto memberIndex = ins.operands[0].value.symbolIndex;
3983 auto memberDef = structDef->fieldTypes[memberIndex];
3985 if (
value.type->isForeignBasicType()) {
3986 *
value.type = compilerCtx->normalizeForeignBasicType(
value.type);
3992 panic(ins.debugInfo.line, ins.debugInfo.column,
"IROptimizer::analyzeBlock(): store_member: type mismatch");
3995 simulationStack.pop();
3996 simulationStack.pop();
4003 auto moduleIndex = ins.operands[0].value.symbolIndex;
4004 auto function = compilerCtx->getImportedModule(moduleIndex)->functionTable[ins.operands[1].value.symbolIndex];
4005 auto returnType = function->returnType;
4006 auto argTypes = function->argumentTypes;
4007 auto argCount = function->argumentTypes.size();
4008 SimulationStack::Item::ContributedInstructionSet contributedInstructions = {currentCodeBlockIndex, {insIndex},
false};
4009 for (
int i = 0; i < argCount; i++) {
4010 contributedInstructions = contributedInstructions + simulationStack.peek(0).contributedInstructions;
4011 simulationStack.pop();
4013 simulationStack.push(returnType, contributedInstructions);
4017 auto function = compilerCtx->getIRFFITable()
4018 ->importedLibraries[ins.operands[0].value.symbolIndex]
4019 .importedFunctionTable[ins.operands[1].value.symbolIndex];
4020 auto returnType = function->returnType;
4021 auto argTypes = function->argumentTypes;
4022 auto argCount = function->argumentTypes.size();
4023 for (
int i = 0; i < argCount; i++) {
4024 simulationStack.pop();
4026 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
4030 auto argCount = ins.operands[3].value.symbolIndex;
4031 for (
int i = 0; i < argCount - 1; i++) {
4032 simulationStack.pop();
4034 auto returnType = compilerCtx->getImportedModule(ins.operands[0].value.symbolIndex)
4035 ->interfaceTable[ins.operands[1].value.symbolIndex]
4036 ->methodMap[ins.operands[2].value.symbolIndex]
4038 simulationStack.pop();
4039 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
4043 auto moduleIndex = ins.operands[0].value.symbolIndex;
4044 auto structDef = compilerCtx->getImportedModule(moduleIndex)->structTable[ins.operands[1].value.symbolIndex];
4046 {currentCodeBlockIndex, {insIndex},
false});
4050 auto moduleIndex = ins.operands[0].value.symbolIndex;
4051 auto interfaceImplDef = compilerCtx->getImportedModule(moduleIndex)->interfaceImplementationTable[ins.operands[1].value.symbolIndex];
4053 interfaceImplDef->implInterfaceIndex.first,
4054 interfaceImplDef->implInterfaceIndex.second});
4055 simulationStack.pop();
4056 simulationStack.push(returnType, {currentCodeBlockIndex, {insIndex},
false});
4062 simulationStack.pop();
4074 std::shared_ptr<IRValueType> baseType;
4075 switch (ins.opcode) {
4077 baseType = compilerCtx->getIntObjectType();
4080 baseType = compilerCtx->getBoolObjectType();
4083 baseType = compilerCtx->getCharObjectType();
4086 baseType = compilerCtx->getDeciObjectType();
4089 baseType = compilerCtx->getStrObjectType();
4092 baseType = compilerCtx->getShortObjectType();
4095 baseType = compilerCtx->getUnsignedObjectType();
4103 for (
auto i = 1; i < ins.operands.size(); i++) {
4104 size *= ins.operands[i].value.symbolIndex;
4105 dims.push_back(ins.operands[i].value.symbolIndex);
4107 for (
yoi::indexT i = 0; i < ins.operands[0].value.symbolIndex; i++) {
4108 simulationStack.pop();
4110 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
4115 auto moduleIndex = ins.operands[0].value.symbolIndex;
4116 auto typeIndex = ins.operands[1].value.symbolIndex;
4125 for (
yoi::indexT i = 3; i < ins.operands.size(); i++) {
4126 size *= ins.operands[i].value.symbolIndex;
4127 dims.push_back(ins.operands[i].value.symbolIndex);
4129 for (
yoi::indexT i = 0; i < ins.operands[2].value.symbolIndex; i++) {
4130 simulationStack.pop();
4132 simulationStack.push(
managedPtr(baseType->getArrayType(dims)), {currentCodeBlockIndex, {insIndex},
false});
4144 std::shared_ptr<IRValueType> baseType;
4145 switch (ins.opcode) {
4147 baseType = compilerCtx->getIntObjectType();
4150 baseType = compilerCtx->getBoolObjectType();
4153 baseType = compilerCtx->getCharObjectType();
4156 baseType = compilerCtx->getDeciObjectType();
4159 baseType = compilerCtx->getShortObjectType();
4162 baseType = compilerCtx->getUnsignedObjectType();
4165 baseType = compilerCtx->getStrObjectType();
4180 simulationStack.pop();
4182 simulationStack.pop();
4183 simulationStack.push(
managedPtr(baseType->getDynamicArrayType()), {currentCodeBlockIndex, {insIndex},
false});
4188 auto index = simulationStack.peek(0);
4189 auto array = simulationStack.peek(1);
4190 simulationStack.pop();
4191 simulationStack.pop();
4193 array.contributedInstructions + index.contributedInstructions +
4194 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
4199 auto index = simulationStack.peek(0);
4200 auto value = simulationStack.peek(1);
4201 auto array = simulationStack.peek(2);
4202 simulationStack.pop();
4203 simulationStack.pop();
4204 simulationStack.pop();
4208 simulationStack.pop();
4212 auto rhs = simulationStack.peek(0);
4213 auto lhs = simulationStack.peek(1);
4215 if (rhs.type->isForeignBasicType()) {
4216 *rhs.type = rhs.type->getNormalizedForeignBasicType();
4218 yoi_assert(*lhs.type == *rhs.type, 0, 0,
"IROptimizer::analyzeBlock(): direct_assign: type mismatch");
4219 simulationStack.pop();
4220 simulationStack.pop();
4221 simulationStack.push(lhs.type,
4222 lhs.contributedInstructions + rhs.contributedInstructions +
4223 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
4228 ins.operands[1].value.symbolIndex,
4229 ins.operands[2].value.symbolIndex,
4233 simulationStack.pop();
4234 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
4238 simulationStack.pop();
4247 auto array = simulationStack.peek(0);
4248 simulationStack.pop();
4249 if (
array.type->isArrayType()) {
4251 for (
auto dim :
array.type->dimensions) {
4254 simulationStack.push(compilerCtx->getIntObjectType(),
4255 array.contributedInstructions +
4256 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex}},
4257 static_cast<int64_t
>(size));
4258 }
else if (
array.type->isDynamicArrayType()) {
4259 simulationStack.push(compilerCtx->getIntObjectType(),
4260 array.contributedInstructions +
4261 SimulationStack::Item::ContributedInstructionSet{currentCodeBlockIndex, {insIndex},
false});
4267 auto interfaceType = simulationStack.peek(0).type;
4268 auto objectType = simulationStack.peek(1).type;
4269 simulationStack.pop();
4270 simulationStack.pop();
4271 simulationStack.push(compilerCtx->getBoolObjectType(), {currentCodeBlockIndex, {insIndex},
false});
4275 simulationStack.push(compilerCtx->getIntObjectType(), {currentCodeBlockIndex, {insIndex},
false});
4279 auto typeMod = ins.operands[0].value.symbolIndex;
4280 auto typeIndex = ins.operands[1].value.symbolIndex;
4282 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
4286 for (
yoi::indexT i = 0; i < ins.operands[0].value.symbolIndex; i++) {
4287 simulationStack.pop();
4292 simulationStack.pop();
4293 simulationStack.pop();
4297 auto type = simulationStack.peek(0).type;
4298 simulationStack.pop();
4299 for (
auto &operand : ins.operands) {
4300 auto def = compilerCtx->getImportedModule(type->typeAffiliateModule)->dataStructTable[type->typeIndex];
4301 type = def->fieldTypes[operand.value.symbolIndex];
4303 simulationStack.push(type, {currentCodeBlockIndex, {insIndex},
false});
4307 simulationStack.pop();
4308 simulationStack.pop();
4312 simulationStack.pop();
4316 simulationStack.pop();