summaryrefslogtreecommitdiffstats
path: root/source/slang/bytecode.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-04 18:07:09 -0400
committerYong He <yonghe@outlook.com>2017-11-04 18:07:09 -0400
commitd1009d1a5ac7463dc74169ed7c6e1e692b3541d7 (patch)
treeb21cd74ca6daabd655f5a2625c2698de16a92dd1 /source/slang/bytecode.cpp
parent1f9686ce87573efdd4ad56040deb2d424fe51929 (diff)
parent784bd914cface6e5837ef0da7aee0df2e16c4999 (diff)
merge with fixWarnings branch
Diffstat (limited to 'source/slang/bytecode.cpp')
-rw-r--r--source/slang/bytecode.cpp66
1 files changed, 36 insertions, 30 deletions
diff --git a/source/slang/bytecode.cpp b/source/slang/bytecode.cpp
index ee055a01f..e3cd9e74e 100644
--- a/source/slang/bytecode.cpp
+++ b/source/slang/bytecode.cpp
@@ -156,7 +156,7 @@ BCPtr<void>::RawVal allocateRaw(
for(size_t ii = currentOffset; ii < endOffset; ++ii)
context->shared->bytecode.Add(0);
- return (BCPtr<void>::RawVal)beginOffset;
+ return beginOffset;
}
template<typename T>
@@ -241,10 +241,11 @@ BCConst getGlobalValue(
BytecodeGenerationContext* context,
IRValue* value)
{
- BCConst bcConst;
- if( context->shared->mapValueToGlobal.TryGetValue(value, bcConst) )
- return bcConst;
-
+ {
+ BCConst bcConst;
+ if (context->shared->mapValueToGlobal.TryGetValue(value, bcConst))
+ return bcConst;
+ }
// Next we need to check for things that can be mapped to
// global IDs on the fly.
@@ -255,8 +256,9 @@ BCConst getGlobalValue(
UInt constID = context->shared->constants.Count();
context->shared->constants.Add(value);
+ BCConst bcConst;
bcConst.flavor = kBCConstFlavor_Constant;
- bcConst.id = (uint32_t)constID;
+ bcConst.id = constID;
context->shared->mapValueToGlobal.Add(value, bcConst);
@@ -268,10 +270,13 @@ BCConst getGlobalValue(
break;
}
- bcConst.flavor = (uint32_t) -1;
- bcConst.id = (uint32_t)-9999;
SLANG_UNEXPECTED("no ID for inst");
- //return bcConst;
+ {
+ UNREACHABLE(BCConst bcConst);
+ UNREACHABLE(bcConst.flavor = (BCConstFlavor)-1);
+ UNREACHABLE(bcConst.id = -9999);
+ UNREACHABLE_RETURN(bcConst);
+ }
}
Int getLocalID(
@@ -389,17 +394,17 @@ void generateBytecodeForInst(
case kIROp_FloatLit:
{
- auto ii = (IRConstant*) inst;
- encodeUInt(context, ii->op);
- encodeOperand(context, ii->getType());
+ auto cInst = (IRConstant*) inst;
+ encodeUInt(context, cInst->op);
+ encodeOperand(context, cInst->getType());
static const UInt size = sizeof(IRFloatingPointValue);
unsigned char buffer[size];
- memcpy(buffer, &ii->u.floatVal, sizeof(buffer));
+ memcpy(buffer, &cInst->u.floatVal, sizeof(buffer));
- for(UInt i = 0; i < size; ++i)
+ for(UInt ii = 0; ii < size; ++ii)
{
- encodeUInt8(context, buffer[i]);
+ encodeUInt8(context, buffer[ii]);
}
// destination:
@@ -476,7 +481,7 @@ BytecodeGenerationPtr<BCType> emitBCType(
auto bcArgs = (bcType + 1).bitCast<BCPtr<uint8_t>>();
bcType->op = op;
- bcType->argCount = (uint32_t)argCount;
+ bcType->argCount = argCount;
for(UInt aa = 0; aa < argCount; ++aa)
{
@@ -486,7 +491,7 @@ BytecodeGenerationPtr<BCType> emitBCType(
UInt id = context->shared->bcTypes.Count();
context->shared->mapTypeToID.Add(type, id);
context->shared->bcTypes.Add(bcType);
- bcType->id = (uint32_t)id;
+ bcType->id = id;
return bcType;
}
@@ -574,6 +579,7 @@ BytecodeGenerationPtr<BCType> emitBCTypeImpl(
SLANG_UNEXPECTED("unimplemented");
+ UNREACHABLE_RETURN(BytecodeGenerationPtr<BCType>());
}
BytecodeGenerationPtr<BCType> emitBCType(
@@ -699,7 +705,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 = (uint32_t)blockCount;
+ bcFunc->blockCount = blockCount;
bcFunc->blocks = bcBlocks;
// Now loop through the blocks again, and allocate the storage
@@ -746,7 +752,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
}
}
- bcBlocks[blockID].paramCount = (uint32_t)paramCount;
+ bcBlocks[blockID].paramCount = paramCount;
}
// Okay, we've counted how many registers we need for each block,
@@ -754,7 +760,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
UInt regCount = regCounter;
auto bcRegs = allocateArray<BCReg>(context, regCount);
- bcFunc->regCount = (uint32_t)regCount;
+ bcFunc->regCount = regCount;
bcFunc->regs = bcRegs;
// Now we will loop over things again to fill in the information
@@ -782,7 +788,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
#if 0
bcRegs[localID].name = tryGenerateNameForSymbol(context, pp);
#endif
- bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID;
+ bcRegs[localID].previousVarIndexPlusOne = localID;
bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, pp);
}
@@ -804,7 +810,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
#if 0
bcRegs[localID].name = tryGenerateNameForSymbol(context, ii);
#endif
- bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID;
+ bcRegs[localID].previousVarIndexPlusOne = localID;
bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, ii);
}
break;
@@ -824,11 +830,11 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
#if 0
bcRegs[localID].name = tryGenerateNameForSymbol(context, ii);
#endif
- bcRegs[localID].previousVarIndexPlusOne = (uint32_t)localID;
+ bcRegs[localID].previousVarIndexPlusOne = localID;
bcRegs[localID].typeID = getTypeIDForGlobalSymbol(context, ii);
bcRegs[localID+1].op = ii->op;
- bcRegs[localID+1].previousVarIndexPlusOne = (uint32_t)localID+1;
+ bcRegs[localID+1].previousVarIndexPlusOne = localID+1;
bcRegs[localID+1].typeID = getTypeID(context,
(ii->getType()->As<PtrType>())->getValueType());
}
@@ -899,7 +905,7 @@ BytecodeGenerationPtr<BCSymbol> generateBytecodeSymbolForInst(
UInt constCount = subContext->remappedGlobalSymbols.Count();
auto bcConsts = allocateArray<BCConst>(context, constCount);
- bcFunc->constCount = (uint32_t)constCount;
+ bcFunc->constCount = constCount;
bcFunc->consts = bcConsts;
for( UInt cc = 0; cc < constCount; ++cc )
@@ -965,7 +971,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule(
// Ensure that local code inside functions can see these symbols
BCConst bcConst;
bcConst.flavor = kBCConstFlavor_GlobalSymbol;
- bcConst.id = (uint32_t)globalID;
+ bcConst.id = globalID;
context->shared->mapValueToGlobal.Add(gv, bcConst);
// In the global scope, global IDs are also the local IDs
@@ -974,7 +980,7 @@ BytecodeGenerationPtr<BCModule> generateBytecodeForModule(
auto bcSymbols = allocateArray<BCPtr<BCSymbol>>(context, symbolCount);
- bcModule->symbolCount = (uint32_t)symbolCount;
+ bcModule->symbolCount = symbolCount;
bcModule->symbols = bcSymbols;
for( auto gv = irModule->getFirstGlobalValue(); gv; gv = gv->getNextValue() )
@@ -994,7 +1000,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 = (uint32_t)constantCount;
+ bcModule->constantCount = constantCount;
bcModule->constants = bcConstants;
for(UInt cc = 0; cc < constantCount; ++cc)
@@ -1022,7 +1028,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 = (uint32_t)typeCount;
+ bcModule->typeCount = typeCount;
bcModule->types = bcTypes;
for(UInt tt = 0; tt < typeCount; ++tt)
@@ -1059,7 +1065,7 @@ void generateBytecodeContainer(
}
UInt bcModuleCount = bcModulesList.Count();
- header->moduleCount = (uint32_t)bcModuleCount;
+ header->moduleCount = bcModuleCount;
auto bcModules = allocateArray<BCPtr<BCModule>>(context, bcModuleCount);
header->modules = bcModules;