| 1238 | m_gen.Function.SetAddress(goto_ref, m_gen.Function.GetCurrentAddress()); |
| 1239 | } |
| 1240 | void HLSLCompiler::translateForStatement(M4::HLSLForStatement* forStmt) |
| 1241 | { |
| 1242 | m_breaks.push(std::vector<size_t>()); |
| 1243 | |
| 1244 | if (forStmt->initialization) |
| 1245 | translateDeclaration(forStmt->initialization); |
| 1246 | |
| 1247 | int first_test = -1; |
| 1248 | int reg_test = -1; |
| 1249 | int rewind_adr = -1; |
| 1250 | |
| 1251 | if (forStmt->condition) { |
| 1252 | translateExpression(forStmt->condition); |
| 1253 | first_test = m_gen.Function.If(); |
| 1254 | } |
| 1255 | |
| 1256 | // on first iteration skip update() and regular condition() |
| 1257 | size_t body_start = m_gen.Function.Goto(); |
| 1258 | m_continueAddr.push(m_gen.Function.GetCurrentAddress()); |
| 1259 | |
| 1260 | // the third part of the for loop |
| 1261 | if (forStmt->increment) |
| 1262 | translateExpression(forStmt->increment); |
| 1263 | |
| 1264 | if (forStmt->condition) { |
| 1265 | translateExpression(forStmt->condition); |
| 1266 | reg_test = m_gen.Function.If(); |
| 1267 | } |
| 1268 | |
| 1269 | m_gen.Function.SetAddress(body_start, m_gen.Function.GetCurrentAddress()); |
| 1270 | translateStatements(forStmt->statement); |
| 1271 | |
| 1272 | // go to top (m_continueAddr == top) where top is where loop -> condition -> body starts |
| 1273 | size_t rewind_ref = m_gen.Function.Goto(); |
| 1274 | m_gen.Function.SetAddress(rewind_ref, m_continueAddr.top()); |
| 1275 | |
| 1276 | // address to which vm should go if condition result is false |
| 1277 | if (reg_test != -1) |
| 1278 | m_gen.Function.SetAddress(reg_test, m_gen.Function.GetCurrentAddress()); |
| 1279 | if (first_test != -1) |
| 1280 | m_gen.Function.SetAddress(first_test, m_gen.Function.GetCurrentAddress()); |
| 1281 | |
| 1282 | for (size_t i = 0; i < m_breaks.top().size(); i++) |
| 1283 | m_gen.Function.SetAddress(m_breaks.top()[i], m_gen.Function.GetCurrentAddress()); |
| 1284 | |
| 1285 | m_continueAddr.pop(); |
| 1286 | m_breaks.pop(); |
| 1287 | } |
| 1288 | |
| 1289 | void HLSLCompiler::translateDeclaration(M4::HLSLDeclaration* declr) |
| 1290 | { |