summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2019-07-09 13:59:30 -0400
committerGitHub <noreply@github.com>2019-07-09 13:59:30 -0400
commitf52f5cd4a7b5b71617b949fc62a78abe8c4822b3 (patch)
tree48f636f33e199b3508d779941c034f7be91debc4 /source/slang/slang-ir.cpp
parent691ebae763e29327249735d67fbb231c75b17840 (diff)
WIP: slang to C++ code generation (#997)
* WIP: Emitting Cpp * Added HLSLType instead of using IRInst - because they don't seem to be deduped. * Removed need for lexer to take a String. Added mechansim to lookup intrinsic functions on C++. * A c/c++ cross compilation test. * WIP Cpp output using cloning and slang types. * More work to generate mul funcs. * WIP: Outputting some simple C++. * Expose findOrEmitHoistableInst to IRBuilder to aid cloning, * Simplification for checking for BasicTypes. Test infrastructure compiles output C++ code. * Dot and mat/vec multiplication output. * First pass at swizzling. * First support for binary ops. * Builtin binary and unary functions. * Any and all. * WIP adding support for other functions. Added code to generate function signature. * Add scalar functions to slang-cpp-prelude.h * Support for most built in operations. * Tested first ternary. * Checking the emitting of corner cases functions - normalize, length, any, all, normalize, reflect. * Check asfloat etc work. * Fmod support. * WIP Array handling in C++. * First stage in being able to handl arbitrary type output for CLikeSourceEmitter * Removed Handler/Emitter split - so can implement more easily complex type naming. * Array passing by value first pass. * Rename Array -> FixedArray * Outputs structs in C++. * Emit the thread config. * Dimension -> TypeDimension * SpecializedOperation -> SpecializedIntrinsic Operation -> IntrinsicOp Use shared impl of isNominalOp Commented use of m_uniqueModule etc. * Add code to test slang->cpp when compiled doesn't have errors. Does so by building shared library and exporting the entry point. * Fix linux clang/gcc compile error about override not being specified. * Make sure c-cross-compile is run on linux targets/smoke. * Remove c-cross-compile.slang from smoke. * Fix running tests/cross-compile/c-cross-compile.slang on Ubuntu 16.04 * Only add -std=c++11 for C++ source.
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp27
1 files changed, 9 insertions, 18 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 4975ac824..c5dd5d530 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -1530,8 +1530,7 @@ namespace Slang
}
- IRInst* findOrEmitHoistableInst(
- IRBuilder* builder,
+ IRInst* IRBuilder::findOrEmitHoistableInst(
IRType* type,
IROp op,
UInt operandListCount,
@@ -1544,7 +1543,7 @@ namespace Slang
operandCount += listOperandCounts[ii];
}
- auto& memoryArena = builder->getModule()->memoryArena;
+ auto& memoryArena = getModule()->memoryArena;
void* cursor = memoryArena.getCursor();
// We are going to create a 'dummy' instruction on the memoryArena
@@ -1581,7 +1580,7 @@ namespace Slang
IRInstKey key = { inst };
// Ideally we would add if not found, else return if was found instead of testing & then adding.
- IRInst** found = builder->sharedBuilder->globalValueNumberingMap.TryGetValueOrAdd(key, inst);
+ IRInst** found = sharedBuilder->globalValueNumberingMap.TryGetValueOrAdd(key, inst);
SLANG_ASSERT(endCursor == memoryArena.getCursor());
// If it's found, just return, and throw away the instruction
if (found)
@@ -1600,7 +1599,7 @@ namespace Slang
inst->typeUse.init(inst, type);
}
- maybeSetSourceLoc(builder, inst);
+ maybeSetSourceLoc(this, inst);
IRUse*const operands = inst->getOperands();
for (UInt i = 0; i < operandCount; ++i)
@@ -1613,20 +1612,18 @@ namespace Slang
}
}
- addHoistableInst(builder, inst);
+ addHoistableInst(this, inst);
return inst;
}
- IRInst* findOrEmitHoistableInst(
- IRBuilder* builder,
+ IRInst* IRBuilder::findOrEmitHoistableInst(
IRType* type,
IROp op,
UInt operandCount,
IRInst* const* operands)
{
return findOrEmitHoistableInst(
- builder,
type,
op,
1,
@@ -1634,8 +1631,7 @@ namespace Slang
&operands);
}
- IRInst* findOrEmitHoistableInst(
- IRBuilder* builder,
+ IRInst* IRBuilder::findOrEmitHoistableInst(
IRType* type,
IROp op,
IRInst* operand,
@@ -1646,7 +1642,6 @@ namespace Slang
IRInst* const* lists[] = { &operand, operands };
return findOrEmitHoistableInst(
- builder,
type,
op,
2,
@@ -1661,7 +1656,6 @@ namespace Slang
IRInst* const* operands)
{
return (IRType*) findOrEmitHoistableInst(
- this,
nullptr,
op,
operandCount,
@@ -1806,7 +1800,6 @@ namespace Slang
IRType* resultType)
{
return (IRFuncType*) findOrEmitHoistableInst(
- this,
nullptr,
kIROp_FuncType,
resultType,
@@ -1849,7 +1842,6 @@ namespace Slang
IRType* const* caseTypes)
{
return (IRType*) findOrEmitHoistableInst(
- this,
getTypeKind(),
kIROp_TaggedUnionType,
caseCount,
@@ -1882,7 +1874,6 @@ namespace Slang
}
return (IRType*) findOrEmitHoistableInst(
- this,
getTypeKind(),
kIROp_BindExistentialsType,
baseType,
@@ -3853,7 +3844,7 @@ namespace Slang
return true;
}
- static bool _isNominalOp(IROp op)
+ bool isNominalOp(IROp op)
{
// True if the op identity is 'nominal'
switch (op)
@@ -3892,7 +3883,7 @@ namespace Slang
}
// If the type is nominal - it can only be the same if the pointer is the same.
- if (_isNominalOp(opA))
+ if (isNominalOp(opA))
{
// The pointer isn't the same (as that was already tested), so cannot be equal
return false;