void WriteModuleHeader(std::ostream& os, IRModuleEmitter& moduleEmitter) { auto pModule = moduleEmitter.GetLLVMModule(); // Header comment std::string moduleName = pModule->getName(); os << "//\n// ELL header for module " << moduleName << "\n//\n\n"; os << "#include <stdint.h>\n\n"; { DeclareExternC externC(os); // preprocessor definitions auto defines = moduleEmitter.GetPreprocessorDefinitions(); if (defines.size() > 0) { for (const auto& def : defines) { os << "#define " << def.first << " " << def.second << "\n"; } os << "\n"; } // First write out type definitions os << "//\n// Types\n//\n\n"; // Look for the module-level "declare in header" tag if (moduleEmitter.HasMetadata("", c_declareInHeaderTagName)) { auto typeNames = GetModuleTagValues(moduleEmitter, c_declareInHeaderTagName); auto structTypes = pModule->getIdentifiedStructTypes(); for (const auto& t : structTypes) { if (t->hasName() && (typeNames.cend() != typeNames.find(t->getName()))) { WriteStructDefinition(os, t); os << "\n\n"; } } } os << "\n"; os << "//\n// Functions\n//\n\n"; // Now write out function signatures auto tagValues = GetFunctionsWithTag(moduleEmitter, c_declareInHeaderTagName); for (auto& tv : tagValues) { WriteFunction(os, moduleEmitter, *(tv.function)); os << "\n\n"; } } }
void JSFunctionWriter::GenerateSource(String& sourceOut) { String source = ""; if (function_->IsConstructor()) { WriteConstructor(source); } else { WriteFunction(source); } sourceOut += source; }
void GFGClass::WriteProtected ( ostream& os, const JBoolean interface ) { const JSize count = GetElementCount(); for (JIndex i = 1; i <= count; i++) { GFGMemberFunction* fn = NthElement(i); if (fn->IsUsed() && fn->IsProtected()) { WriteFunction(os, fn, interface); } } }
int asCRestore::Save() { unsigned long i, count; // Store everything in the same order that the builder parses scripts // Store enums count = (asUINT)module->enumTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; i++ ) { WriteObjectTypeDeclaration(module->enumTypes[i], false); WriteObjectTypeDeclaration(module->enumTypes[i], true); } // Store type declarations first count = (asUINT)module->classTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; i++ ) { // Store only the name of the class/interface types WriteObjectTypeDeclaration(module->classTypes[i], false); } // Now store all interface methods for( i = 0; i < count; i++ ) { if( module->classTypes[i]->IsInterface() ) WriteObjectTypeDeclaration(module->classTypes[i], true); } // Then store the class methods, properties, and behaviours for( i = 0; i < count; ++i ) { if( !module->classTypes[i]->IsInterface() ) WriteObjectTypeDeclaration(module->classTypes[i], true); } // Store typedefs count = (asUINT)module->typeDefs.GetLength(); WRITE_NUM(count); for( i = 0; i < count; i++ ) { WriteObjectTypeDeclaration(module->typeDefs[i], false); WriteObjectTypeDeclaration(module->typeDefs[i], true); } // scriptGlobals[] count = (asUINT)module->scriptGlobals.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteGlobalProperty(module->scriptGlobals[i]); // scriptFunctions[] count = 0; for( i = 0; i < module->scriptFunctions.GetLength(); i++ ) if( module->scriptFunctions[i]->objectType == 0 ) count++; WRITE_NUM(count); for( i = 0; i < module->scriptFunctions.GetLength(); ++i ) if( module->scriptFunctions[i]->objectType == 0 ) WriteFunction(module->scriptFunctions[i]); // globalFunctions[] count = (int)module->globalFunctions.GetLength(); WRITE_NUM(count); for( i = 0; i < count; i++ ) { WriteFunction(module->globalFunctions[i]); } // bindInformations[] count = (asUINT)module->bindInformations.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteFunction(module->bindInformations[i]->importedFunctionSignature); WriteString(&module->bindInformations[i]->importFromModule); } // usedTypes[] count = (asUINT)usedTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectType(usedTypes[i]); } // usedTypeIds[] WriteUsedTypeIds(); // usedFunctions[] WriteUsedFunctions(); // usedGlobalProperties[] WriteUsedGlobalProps(); // usedStringConstants[] WriteUsedStringConstants(); // TODO: Store script section names return asSUCCESS; }
int asCRestore::Save() { unsigned long i, count; // structTypes[] count = module->structTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectTypeDeclaration(module->structTypes[i]); } // usedTypeIndices[] count = module->usedTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectType(module->usedTypes[i]); } // scriptGlobals[] count = module->scriptGlobals.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteProperty(module->scriptGlobals[i]); // globalMem size (can restore data using @init()) count = module->globalMem.GetLength(); WRITE_NUM(count); // globalVarPointers[] WriteGlobalVarPointers(); // initFunction WriteFunction(&module->initFunction); // scriptFunctions[] count = module->scriptFunctions.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteFunction(module->scriptFunctions[i]); // stringConstants[] count = module->stringConstants.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteString(module->stringConstants[i]); // importedFunctions[] and bindInformations[] count = module->importedFunctions.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteFunction(module->importedFunctions[i]); WRITE_NUM(module->bindInformations[i].importFrom); } // usedTypeIds[] WriteUsedTypeIds(); return asSUCCESS; }
int lame_decoder(lame_global_flags * gfp, FILE * outf, int skip, char *inPath, char *outPath) { short int Buffer[2][1152]; int iread; double wavsize; int i; void (*WriteFunction) (FILE * fp, char *p, int n); int tmp_num_channels = lame_get_num_channels( gfp ); if (silent < 10) fprintf(stderr, "\rinput: %s%s(%g kHz, %i channel%s, ", strcmp(inPath, "-") ? inPath : "<stdin>", strlen(inPath) > 26 ? "\n\t" : " ", lame_get_in_samplerate( gfp ) / 1.e3, tmp_num_channels, tmp_num_channels != 1 ? "s" : ""); switch (input_format) { case sf_mp3: if (skip==0) { if (enc_delay>-1) skip = enc_delay + 528+1; else skip=lame_get_encoder_delay(gfp)+528+1; }else{ /* user specified a value of skip. just add for decoder */ skip += 528+1; /* mp3 decoder has a 528 sample delay, plus user supplied "skip" */ } if (silent < 10) fprintf(stderr, "MPEG-%u%s Layer %s", 2 - lame_get_version(gfp), lame_get_out_samplerate( gfp ) < 16000 ? ".5" : "", "III"); break; case sf_mp2: skip += 240 + 1; if (silent < 10) fprintf(stderr, "MPEG-%u%s Layer %s", 2 - lame_get_version(gfp), lame_get_out_samplerate( gfp ) < 16000 ? ".5" : "", "II"); break; case sf_mp1: skip += 240 + 1; if (silent < 10) fprintf(stderr, "MPEG-%u%s Layer %s", 2 - lame_get_version(gfp), lame_get_out_samplerate( gfp ) < 16000 ? ".5" : "", "I"); break; case sf_raw: if (silent < 10) fprintf(stderr, "raw PCM data"); mp3input_data.nsamp = lame_get_num_samples( gfp ); mp3input_data.framesize = 1152; skip = 0; /* other formats have no delay *//* is += 0 not better ??? */ break; case sf_wave: if (silent < 10) fprintf(stderr, "Microsoft WAVE"); mp3input_data.nsamp = lame_get_num_samples( gfp ); mp3input_data.framesize = 1152; skip = 0; /* other formats have no delay *//* is += 0 not better ??? */ break; case sf_aiff: if (silent < 10) fprintf(stderr, "SGI/Apple AIFF"); mp3input_data.nsamp = lame_get_num_samples( gfp ); mp3input_data.framesize = 1152; skip = 0; /* other formats have no delay *//* is += 0 not better ??? */ break; default: if (silent < 10) fprintf(stderr, "unknown"); mp3input_data.nsamp = lame_get_num_samples( gfp ); mp3input_data.framesize = 1152; skip = 0; /* other formats have no delay *//* is += 0 not better ??? */ assert(0); break; } if (silent < 10) { fprintf(stderr, ")\noutput: %s%s(16 bit, Microsoft WAVE)\n", strcmp(outPath, "-") ? outPath : "<stdout>", strlen(outPath) > 45 ? "\n\t" : " "); if (skip > 0) fprintf(stderr, "skipping initial %i samples (encoder+decoder delay)\n", skip); } if ( 0 == disable_wav_header ) WriteWaveHeader(outf, 0x7FFFFFFF, lame_get_in_samplerate( gfp ), tmp_num_channels, 16); /* unknown size, so write maximum 32 bit signed value */ wavsize = -skip; WriteFunction = swapbytes ? WriteBytesSwapped : WriteBytes; mp3input_data.totalframes = mp3input_data.nsamp / mp3input_data.framesize; assert(tmp_num_channels >= 1 && tmp_num_channels <= 2); do { iread = get_audio16(gfp, Buffer); /* read in 'iread' samples */ mp3input_data.framenum += iread / mp3input_data.framesize; wavsize += iread; if (silent <= 0) decoder_progress(gfp, &mp3input_data); skip -= (i = skip < iread ? skip : iread); /* 'i' samples are to skip in this frame */ for (; i < iread; i++) { if ( disable_wav_header ) { WriteFunction(outf, (char *) &Buffer[0][i], sizeof(short)); if (tmp_num_channels == 2) WriteFunction(outf, (char *) &Buffer[1][i], sizeof(short)); } else { Write16BitsLowHigh(outf, Buffer[0][i]); if (tmp_num_channels == 2) Write16BitsLowHigh(outf, Buffer[1][i]); } } } while (iread); i = (16 / 8) * tmp_num_channels; assert(i > 0); if (wavsize <= 0) { if (silent < 10) fprintf(stderr, "WAVE file contains 0 PCM samples\n"); wavsize = 0; } else if (wavsize > 0xFFFFFFD0 / i) { if (silent < 10) fprintf(stderr, "Very huge WAVE file, can't set filesize accordingly\n"); wavsize = 0xFFFFFFD0; } else { wavsize *= i; } if ( 0 == disable_wav_header ) if (!fseek(outf, 0l, SEEK_SET)) /* if outf is seekable, rewind and adjust length */ WriteWaveHeader(outf, (int)wavsize, lame_get_in_samplerate( gfp ), tmp_num_channels, 16); fclose(outf); if (silent <= 0) decoder_progress_finish(gfp); return 0; }
int main(int argc, char* argv[]) { struct dirent *pDirent; DIR *pDir; char *dirName; char inputFilename[128]; FILE *inP, *outP; // input and output file Command *vmCommands; // all VM Commands int count=0; // count of instructions int i; // loop index Command *currentCommand = NULL; if(argc != 2) { printf("Usage : VMTranslator <directory>"); return -1; } dirName = argv[1]; // open directory pDir = opendir (dirName); if(pDir == NULL) { printf("Can not open directory '%s'\n", dirName); } vmCommands = (Command*)malloc(sizeof(Command) * MAX_COMMAND_NUM); // create the output file outP = Open(dirName, basename(dirName)); if(!outP) { printf("File open failed!\n"); goto failed; } WriteInit(outP); while ((pDirent = readdir(pDir)) != NULL) { // only open the *.vm files in directory if( CheckFileExtension(pDirent->d_name) ) { sprintf(inputFilename, "%s/%s", dirName, pDirent->d_name); // open the input file inP = fopen(inputFilename, "r"); if(!inP) { printf("File '%s' open failed!\n", inputFilename); continue; } SetFileName(basename(inputFilename)); memset(vmCommands, 0, MAX_COMMAND_NUM); count = Parse(inP, &vmCommands); for( i = 0; i < count; i++) { currentCommand = vmCommands + i; switch(currentCommand->commandType){ case C_ARITHMETIC: WriteArithmetic(outP, currentCommand->arg1); break; case C_LABEL: WriteLabel(outP, currentCommand->arg1); break; case C_GOTO: WriteGoTo(outP, currentCommand->arg1); break; case C_IF: WriteIf(outP, currentCommand->arg1); break; case C_PUSH: case C_POP: WritePushPop(outP, currentCommand->commandType, currentCommand->arg1, currentCommand->arg2); break; case C_FUNCTION: WriteFunction(outP, currentCommand->arg1, currentCommand->arg2); break; case C_CALL: WriteCall(outP, currentCommand->arg1, currentCommand->arg2); break; case C_RETURN: WriteReturn(outP); break; default: break; } } fclose(inP); } } closedir (pDir); Close(outP); failed: free(vmCommands); return 0; }
bool CSave::WriteFields( const char *pname, void *pBaseData, const DataMap_t& dataMap, const TYPEDESCRIPTION *pFields, int fieldCount ) { int i, j; const TYPEDESCRIPTION *pTest; int entityArray[ MAX_ENTITYARRAY ]; // Precalculate the number of empty fields int actualCount = 0; for( i = 0; i < fieldCount; i++ ) { pTest = &pFields[ i ]; void *pOutputData; pOutputData = ( ( char * ) pBaseData + pTest->fieldOffset ); if( ( pTest->flags & TypeDescFlag::SAVE ) && !DataEmpty( ( const char * ) pOutputData, pTest->fieldSize * g_SaveRestoreSizes[ pTest->fieldType ] ) ) ++actualCount; } // Empty fields will not be written, write out the actual number of fields to be written WriteInt( pname, &actualCount, 1 ); for( i = 0; i < fieldCount; i++ ) { void *pOutputData; pTest = &pFields[ i ]; pOutputData = ( ( char * ) pBaseData + pTest->fieldOffset ); // UNDONE: Must we do this twice? //TODO: update CSaveRestoreBuffer to allow seeking to write to earlier locations. - Solokiller if( !( pTest->flags & TypeDescFlag::SAVE ) || DataEmpty( ( const char * ) pOutputData, pTest->fieldSize * g_SaveRestoreSizes[ pTest->fieldType ] ) ) continue; switch( pTest->fieldType ) { case FIELD_FLOAT: WriteFloat( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize ); break; case FIELD_TIME: WriteTime( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize ); break; case FIELD_MODELNAME: case FIELD_SOUNDNAME: case FIELD_STRING: WriteString( pTest->fieldName, ( int * ) pOutputData, pTest->fieldSize ); break; case FIELD_CLASSPTR: case FIELD_EVARS: case FIELD_EDICT: case FIELD_ENTITY: case FIELD_EHANDLE: if( pTest->fieldSize > MAX_ENTITYARRAY ) ALERT( at_error, "Can't save more than %d entities in an array!!!\n", MAX_ENTITYARRAY ); for( j = 0; j < pTest->fieldSize; j++ ) { switch( pTest->fieldType ) { case FIELD_EVARS: entityArray[ j ] = EntityIndex( ( ( entvars_t ** ) pOutputData )[ j ] ); break; case FIELD_CLASSPTR: entityArray[ j ] = EntityIndex( ( ( CBaseEntity ** ) pOutputData )[ j ] ); break; case FIELD_EDICT: entityArray[ j ] = EntityIndex( ( ( edict_t ** ) pOutputData )[ j ] ); break; case FIELD_ENTITY: entityArray[ j ] = EntityIndex( ( ( EOFFSET * ) pOutputData )[ j ] ); break; case FIELD_EHANDLE: entityArray[ j ] = EntityIndex( ( CBaseEntity * ) ( ( ( EHANDLE * ) pOutputData )[ j ] ) ); break; } } WriteInt( pTest->fieldName, entityArray, pTest->fieldSize ); break; case FIELD_POSITION_VECTOR: WritePositionVector( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize ); break; case FIELD_VECTOR: WriteVector( pTest->fieldName, ( float * ) pOutputData, pTest->fieldSize ); break; case FIELD_BOOLEAN: //TODO: should be written as a bit perhaps? - Solokiller WriteBoolean( pTest->fieldName, ( bool* ) pOutputData, pTest->fieldSize ); break; case FIELD_INTEGER: WriteInt( pTest->fieldName, ( int * ) pOutputData, pTest->fieldSize ); break; case FIELD_SHORT: WriteData( pTest->fieldName, 2 * pTest->fieldSize, ( ( char * ) pOutputData ) ); break; case FIELD_CHARACTER: WriteData( pTest->fieldName, pTest->fieldSize, ( ( char * ) pOutputData ) ); break; case FIELD_FUNCPTR: WriteFunction( pTest->fieldName, ( void ** ) pOutputData, pTest->fieldSize, dataMap, *pTest ); break; default: ALERT( at_error, "Bad field type\n" ); } } return true; }
void asCRestore::WriteObjectTypeDeclaration(asCObjectType *ot, bool writeProperties) { if( !writeProperties ) { // name WriteString(&ot->name); // size int size = ot->size; WRITE_NUM(size); // flags asDWORD flags = ot->flags; WRITE_NUM(flags); } else { if( ot->flags & asOBJ_ENUM ) { // enumValues[] int size = (int)ot->enumValues.GetLength(); WRITE_NUM(size); for( int n = 0; n < size; n++ ) { WriteString(&ot->enumValues[n]->name); WRITE_NUM(ot->enumValues[n]->value); } } else if( ot->flags & asOBJ_TYPEDEF ) { eTokenType t = ot->templateSubType.GetTokenType(); WRITE_NUM(t); } else { WriteObjectType(ot->derivedFrom); // interfaces[] int size = (asUINT)ot->interfaces.GetLength(); WRITE_NUM(size); asUINT n; for( n = 0; n < ot->interfaces.GetLength(); n++ ) { WriteObjectType(ot->interfaces[n]); } // properties[] size = (asUINT)ot->properties.GetLength(); WRITE_NUM(size); for( n = 0; n < ot->properties.GetLength(); n++ ) { WriteObjectProperty(ot->properties[n]); } // behaviours if( !ot->IsInterface() && ot->flags != asOBJ_TYPEDEF && ot->flags != asOBJ_ENUM ) { WriteFunction(engine->scriptFunctions[ot->beh.construct]); WriteFunction(engine->scriptFunctions[ot->beh.destruct]); WriteFunction(engine->scriptFunctions[ot->beh.factory]); size = (int)ot->beh.constructors.GetLength() - 1; WRITE_NUM(size); for( n = 1; n < ot->beh.constructors.GetLength(); n++ ) { WriteFunction(engine->scriptFunctions[ot->beh.constructors[n]]); WriteFunction(engine->scriptFunctions[ot->beh.factories[n]]); } } // methods[] size = (int)ot->methods.GetLength(); WRITE_NUM(size); for( n = 0; n < ot->methods.GetLength(); n++ ) { WriteFunction(engine->scriptFunctions[ot->methods[n]]); } // virtualFunctionTable[] size = (int)ot->virtualFunctionTable.GetLength(); WRITE_NUM(size); for( n = 0; n < (asUINT)size; n++ ) { WriteFunction(ot->virtualFunctionTable[n]); } } } }