diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-03 09:38:02 -0400 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2017-11-03 09:38:02 -0400 |
| commit | a0458266d7cd5d802b8c51e6a997b4bf0d9beb82 (patch) | |
| tree | 39f16538178907240e59b8e531ae153391805833 /source/slang/bytecode.cpp | |
| parent | d5e2319c33115d0241dd9d2047c0a5f029553dde (diff) | |
in-progress work
Diffstat (limited to 'source/slang/bytecode.cpp')
| -rw-r--r-- | source/slang/bytecode.cpp | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp index f1b23849d..ee055a01f 100644 --- a/source/slang/bytecode.cpp +++ b/source/slang/bytecode.cpp @@ -77,7 +77,6 @@ struct BytecodeGenerationPtr BytecodeGenerationPtr<T> operator+(Int index) const { - UInt size = sizeof(T); Int delta = index * sizeof(T); UInt newOffset = offset + delta; return BytecodeGenerationPtr<T>( @@ -157,7 +156,7 @@ BCPtr<void>::RawVal allocateRaw( for(size_t ii = currentOffset; ii < endOffset; ++ii) context->shared->bytecode.Add(0); - return beginOffset; + return (BCPtr<void>::RawVal)beginOffset; } template<typename T> @@ -196,7 +195,7 @@ void encodeUInt( { if( value < 128 ) { - encodeUInt8(context, value); + encodeUInt8(context, (uint8_t)value); return; } @@ -256,9 +255,8 @@ BCConst getGlobalValue( UInt constID = context->shared->constants.Count(); context->shared->constants.Add(value); - BCConst bcConst; bcConst.flavor = kBCConstFlavor_Constant; - bcConst.id = constID; + bcConst.id = (uint32_t)constID; context->shared->mapValueToGlobal.Add(value, bcConst); @@ -270,10 +268,10 @@ BCConst getGlobalValue( break; } + bcConst.flavor = (uint32_t) -1; + bcConst.id = (uint32_t)-9999; SLANG_UNEXPECTED("no ID for inst"); - bcConst.flavor = (BCConstFlavor) -1; - bcConst.id = -9999; - return bcConst; + //return bcConst; } Int getLocalID( @@ -348,7 +346,6 @@ void generateBytecodeForInst( // auto argCount = inst->getArgCount(); - auto type = inst->getType(); encodeUInt(context, inst->op); encodeOperand(context, inst->getType()); encodeUInt(context, argCount); @@ -400,9 +397,9 @@ void generateBytecodeForInst( unsigned char buffer[size]; memcpy(buffer, &ii->u.floatVal, sizeof(buffer)); - for(UInt ii = 0; ii < size; ++ii) + for(UInt i = 0; i < size; ++i) { - encodeUInt8(context, buffer[ii]); + encodeUInt8(context, buffer[i]); } // destination: @@ -479,7 +476,7 @@ BytecodeGenerationPtr<BCType> emitBCType( auto bcArgs = (bcType + 1).bitCast<BCPtr<uint8_t>>(); bcType->op = op; - bcType->argCount = argCount; + bcType->argCount = (uint32_t)argCount; for(UInt aa = 0; aa < argCount; ++aa) { @@ -489,7 +486,7 @@ BytecodeGenerationPtr<BCType> emitBCType( UInt id = context->shared->bcTypes.Count(); context->shared->mapTypeToID.Add(type, id); context->shared->bcTypes.Add(bcType); - bcType->id = id; + bcType->id = (uint32_t)id; return bcType; } @@ -577,7 +574,6 @@ BytecodeGenerationPtr<BCType> emitBCTypeImpl( SLANG_UNEXPECTED("unimplemented"); - return BytecodeGenerationPtr<BCType>(); } BytecodeGenerationPtr<BCType> emitBCType( @@ -703,7 +699,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( // Allocate the array of block objects to be stored in the // bytecode file. auto bcBlocks = allocateArray<BCBlock>(context, blockCount); - bcFunc->blockCount = blockCount; + bcFunc->blockCount = (uint32_t)blockCount; bcFunc->blocks = bcBlocks; // Now loop through the blocks again, and allocate the storage @@ -750,7 +746,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( } } - bcBlocks[blockID].paramCount = paramCount; + bcBlocks[blockID].paramCount = (uint32_t)paramCount; } // Okay, we've counted how many registers we need for each block, @@ -758,7 +754,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( UInt regCount = regCounter; auto bcRegs = allocateArray<BCReg>(context, regCount); - bcFunc->regCount = regCount; + bcFunc->regCount = (uint32_t)regCount; bcFunc->regs = bcRegs; // Now we will loop over things again to fill in the information @@ -786,7 +782,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( #if 0 bcRegs[localID].name = tryGenerateNameForSymbol(context, pp); #endif - bcRegs[localID].previousVarIndexPlusOne = localID; + bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID; bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, pp); } @@ -808,7 +804,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( #if 0 bcRegs[localID].name = tryGenerateNameForSymbol(context, ii); #endif - bcRegs[localID].previousVarIndexPlusOne = localID; + bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID; bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, ii); } break; @@ -828,11 +824,11 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( #if 0 bcRegs[localID].name = tryGenerateNameForSymbol(context, ii); #endif - bcRegs[localID].previousVarIndexPlusOne = localID; + bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID; bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, ii); bcRegs[localID+1].op = ii->op; - bcRegs[localID+1].previousVarIndexPlusOne = localID+1; + bcRegs[localID+1].previousVarIndexPlusOne = (uint32_t)localID+1; bcRegs[localID+1].typeID = getTypeID(context, (ii->getType()->As<PtrType>())->getValueType()); } @@ -840,7 +836,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( } } } - assert(regCounter == regCount); + assert((UInt)regCounter == regCount); // Now that we've allocated our blocks and our registers // we can go through the actual process of emitting instructions. Hooray! @@ -851,7 +847,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( List<UInt> blockOffsets; for( auto bb = irFunc->getFirstBlock(); bb; bb = bb->getNextBlock() ) { - UInt blockID = blockCounter++; + blockCounter++; // Get local bytecode offset for current block. UInt blockOffset = subContext->currentBytecode.Count(); @@ -903,7 +899,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst( UInt constCount = subContext->remappedGlobalSymbols.Count(); auto bcConsts = allocateArray<BCConst>(context, constCount); - bcFunc->constCount = constCount; + bcFunc->constCount = (uint32_t)constCount; bcFunc->consts = bcConsts; for( UInt cc = 0; cc < constCount; ++cc ) @@ -969,7 +965,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule( // Ensure that local code inside functions can see these symbols BCConst bcConst; bcConst.flavor = kBCConstFlavor_GlobalSymbol; - bcConst.id = globalID; + bcConst.id = (uint32_t)globalID; context->shared->mapValueToGlobal.Add(gv, bcConst); // In the global scope, global IDs are also the local IDs @@ -978,7 +974,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule( auto bcSymbols = allocateArray<BCPtr<BCSymbol>>(context, symbolCount); - bcModule->symbolCount = symbolCount; + bcModule->symbolCount = (uint32_t)symbolCount; bcModule->symbols = bcSymbols; for( auto gv = irModule->getFirstGlobalValue(); gv; gv = gv->getNextValue() ) @@ -998,7 +994,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule( // At this point we should have identified all the literals we need: UInt constantCount = context->shared->constants.Count(); auto bcConstants = allocateArray<BCConstant>(context, constantCount); - bcModule->constantCount = constantCount; + bcModule->constantCount = (uint32_t)constantCount; bcModule->constants = bcConstants; for(UInt cc = 0; cc < constantCount; ++cc) @@ -1026,7 +1022,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule( // At this point we should have collected all the types we need: UInt typeCount = context->shared->bcTypes.Count(); auto bcTypes = allocateArray<BCPtr<BCType>>(context, typeCount); - bcModule->typeCount = typeCount; + bcModule->typeCount = (uint32_t)typeCount; bcModule->types = bcTypes; for(UInt tt = 0; tt < typeCount; ++tt) @@ -1055,8 +1051,6 @@ void generateBytecodeContainer( // TODO: Need to dump BC representation of compiled kernel codes // for each specified code-generation target. - UInt translationUnitCount = compileReq->translationUnits.Count(); - List<BytecodeGenerationPtr<BCModule>> bcModulesList; for (auto translationUnitReq : compileReq->translationUnits) { @@ -1065,7 +1059,7 @@ void generateBytecodeContainer( } UInt bcModuleCount = bcModulesList.Count(); - header->moduleCount = bcModuleCount; + header->moduleCount = (uint32_t)bcModuleCount; auto bcModules = allocateArray<BCPtr<BCModule>>(context, bcModuleCount); header->modules = bcModules; |
