MCPcopy Create free account
hub / github.com/WheretIB/nullc / TranslateToC

Method TranslateToC

NULLC/Compiler.cpp:1410–1755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1408}
1409
1410void Compiler::TranslateToC(const char* fileName, const char *mainName)
1411{
1412#ifdef NULLC_ENABLE_C_TRANSLATION
1413 FILE *fC = fopen(fileName, "wb");
1414
1415 // Save all the types we need to translate
1416 translationTypes.clear();
1417 translationTypes.resize(CodeInfo::typeInfo.size());
1418 for(unsigned int i = 0; i < CodeInfo::typeInfo.size(); i++)
1419 translationTypes[i] = NULL;
1420
1421 // Sort them in their original order of definition
1422 for(unsigned int i = buildInTypes.size(); i < CodeInfo::typeInfo.size(); i++)
1423 translationTypes[CodeInfo::typeInfo[i]->originalIndex] = CodeInfo::typeInfo[i];
1424
1425 for(unsigned int k = 0; k < translationTypes.size(); k++)
1426 {
1427 TypeInfo *type = translationTypes[k];
1428 if(!type || type->arrSize == TypeInfo::UNSIZED_ARRAY || type->refLevel || type->funcType || type->arrLevel)
1429 continue;
1430 TypeInfo::MemberVariable *curr = type->firstVariable;
1431 for(; curr; curr = curr->next)
1432 {
1433 if(curr->type->originalIndex > type->originalIndex)
1434 {
1435 printf("%s (%d) depends on %s (%d), but the latter is defined later\n", type->GetFullTypeName(), type->originalIndex, curr->type->GetFullTypeName(), curr->type->originalIndex);
1436 unsigned index = curr->type->originalIndex;
1437 for(unsigned int i = type->originalIndex + 1; i <= curr->type->originalIndex; i++)
1438 translationTypes[i]->originalIndex--;
1439 type->originalIndex = index;
1440 printf("%s (%d) depends on %s (%d)\n", type->GetFullTypeName(), type->originalIndex, curr->type->GetFullTypeName(), curr->type->originalIndex);
1441 }
1442 }
1443 }
1444 for(unsigned int i = buildInTypes.size(); i < CodeInfo::typeInfo.size(); i++)
1445 translationTypes[CodeInfo::typeInfo[i]->originalIndex] = CodeInfo::typeInfo[i];
1446
1447 ByteCode* runtimeModule = (ByteCode*)BinaryCache::GetBytecode("$base$.nc");
1448
1449 fprintf(fC, "#include \"runtime.h\"\r\n");
1450 fprintf(fC, "// Typeid redirect table\r\n");
1451 fprintf(fC, "static unsigned __nullcTR[%d];\r\n", CodeInfo::typeInfo.size());
1452 fprintf(fC, "// Function pointer table\r\n");
1453 fprintf(fC, "static __nullcFunctionArray* __nullcFM;\r\n");
1454 fprintf(fC, "// Function pointer redirect table\r\n");
1455 fprintf(fC, "static unsigned __nullcFR[%d];\r\n", CodeInfo::funcInfo.size());
1456 fprintf(fC, "// Function pointers, arrays, classes\r\n");
1457 fprintf(fC, "#pragma pack(push, 4)\r\n");
1458 for(unsigned int i = buildInTypes.size(); i < CodeInfo::typeInfo.size(); i++)
1459 {
1460 TypeInfo *type = translationTypes[i];
1461 if(type->funcType)
1462 {
1463 fprintf(fC, "struct __typeProxy_");
1464 type->WriteCNameEscaped(fC, type->GetFullTypeName());
1465 fprintf(fC, "{};\r\n");
1466 continue;
1467 }

Callers 1

nullcTranslateToCFunction · 0.45

Calls 15

strchrFunction · 0.85
GetEscapedNameFunction · 0.85
OutputCFunctionNameFunction · 0.85
strcmpFunction · 0.85
GetCFunctionNameFunction · 0.85
GetFullTypeNameMethod · 0.80
WriteCNameEscapedMethod · 0.80
OutputCTypeMethod · 0.80
EnableMethod · 0.80
DisableMethod · 0.80
GetFullNameHashMethod · 0.80
GetStringHashFunction · 0.70

Tested by

no test coverage detected