| 1364 | } |
| 1365 | |
| 1366 | void Compiler::SaveListing(const char *fileName) |
| 1367 | { |
| 1368 | #ifdef NULLC_LOG_FILES |
| 1369 | FILE *compiledAsm = fopen(fileName, "wb"); |
| 1370 | char instBuf[128]; |
| 1371 | int line = 0, lastLine = ~0u; |
| 1372 | const char *lastSourcePos = CompilerError::codeStart; |
| 1373 | for(unsigned int i = 0; i < CodeInfo::cmdList.size(); i++) |
| 1374 | { |
| 1375 | while((line < (int)CodeInfo::cmdInfoList.sourceInfo.size() - 1) && (i >= CodeInfo::cmdInfoList.sourceInfo[line + 1].byteCodePos)) |
| 1376 | line++; |
| 1377 | if(CodeInfo::cmdInfoList.sourceInfo.size() && line != lastLine) |
| 1378 | { |
| 1379 | lastLine = line; |
| 1380 | const char *codeStart = CodeInfo::cmdInfoList.sourceInfo[line].sourcePos; |
| 1381 | // Find beginning of the line |
| 1382 | while(codeStart != CodeInfo::cmdInfoList.sourceStart && *(codeStart-1) != '\n') |
| 1383 | codeStart--; |
| 1384 | // Skip whitespace |
| 1385 | while(*codeStart == ' ' || *codeStart == '\t') |
| 1386 | codeStart++; |
| 1387 | const char *codeEnd = codeStart; |
| 1388 | while(*codeEnd != '\0' && *codeEnd != '\r' && *codeEnd != '\n') |
| 1389 | codeEnd++; |
| 1390 | if(codeEnd > lastSourcePos) |
| 1391 | { |
| 1392 | fprintf(compiledAsm, "%.*s\r\n", codeEnd - lastSourcePos, lastSourcePos); |
| 1393 | lastSourcePos = codeEnd; |
| 1394 | }else{ |
| 1395 | fprintf(compiledAsm, "%.*s\r\n", codeEnd - codeStart, codeStart); |
| 1396 | } |
| 1397 | } |
| 1398 | CodeInfo::cmdList[i].Decode(instBuf); |
| 1399 | if(CodeInfo::cmdList[i].cmd == cmdCall) |
| 1400 | fprintf(compiledAsm, "// %d %s (%s)\r\n", i, instBuf, CodeInfo::funcInfo[CodeInfo::cmdList[i].argument]->name); |
| 1401 | else |
| 1402 | fprintf(compiledAsm, "// %d %s\r\n", i, instBuf); |
| 1403 | } |
| 1404 | fclose(compiledAsm); |
| 1405 | #else |
| 1406 | (void)fileName; |
| 1407 | #endif |
| 1408 | } |
| 1409 | |
| 1410 | void Compiler::TranslateToC(const char* fileName, const char *mainName) |
| 1411 | { |
no test coverage detected