From f52f5cd4a7b5b71617b949fc62a78abe8c4822b3 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 9 Jul 2019 13:59:30 -0400 Subject: 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. --- source/slang/slang-ir.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'source/slang/slang-ir.cpp') 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; -- cgit v1.2.3