From ad19484792dcc5a1fb90720614830c66c4b9712d Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 17 Aug 2017 13:40:50 -0700 Subject: Add some dummy logic to print IR to HLSL - Change IR instructions to just hold an integer opcode instead of a pointer to the "info" structure - Externalize definition of IR instructions to a header file, and use the "X macro" approach to allow generating different definitions - Add notion of function types to the IR, so that we can easily query the result type of a function - Add some convenience accesors to allow walking the IR in a strongly-typed manner (e.g., iterate over the parameters of a function) - TODO: these should really be changed to assert the type of things, as least in debug builds - Add very basic logic to `emit.cpp` so that it can walk the generated IR and start printing it back as HLSL - This isn't meant to be usable as-is, but it is a step toward where we need to go --- source/slang/lower-to-ir.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source/slang/lower-to-ir.cpp') diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index a01279f2e..ed8ed3318 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -608,9 +608,13 @@ struct DeclLoweringVisitor : DeclVisitor // set up sub context for generating our new function + List paramTypes; + for( auto paramDecl : decl->GetParameters() ) { IRType* irParamType = lowerSimpleType(context, paramDecl->getType()); + paramTypes.Add(irParamType); + IRParam* irParam = subBuilder->emitParam(irParamType); DeclRef paramDeclRef = makeDeclRef(paramDecl.Ptr()); @@ -620,8 +624,13 @@ struct DeclLoweringVisitor : DeclVisitor subContext->shared->declValues.Add(paramDeclRef, irParamVal); } - auto irResultType = lowerType(context, decl->ReturnType); + auto irResultType = lowerSimpleType(context, decl->ReturnType); + auto irFuncType = getBuilder()->getFuncType( + paramTypes.Count(), + ¶mTypes[0], + irResultType); + irFunc->type.init(irFunc, irFuncType); lowerStmt(subContext, decl->Body); -- cgit v1.2.3