summaryrefslogtreecommitdiffstats
path: root/source/slang/emit.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-11-07 10:22:53 -0800
committerTim Foley <tfoley@nvidia.com>2017-11-07 11:00:02 -0800
commitccea5702442a7a8303e6735a038be86939c1ce7a (patch)
treea892b31bbd5e03296b3e5d4627e2a11613fb1194 /source/slang/emit.cpp
parented29b2994e99e0531488a0d46ff82348b62b070e (diff)
Emit pointer-type parameters as out params
The IR encodes `out` and `in out` function parameters as pointer types, so the emit logic needs to handle it. We had code to handle translation of pointers types into `out` declarations for function *declarations* but weren't handling it for function *definitions*. This change unifies the logic so that it is shared by function definitions and decalrations. This change does *not* deal with the following issues that need to be addressed sometime soon-ish: - We currently always translate pointers into `out`, even if they should be `in out`. This is obviously wrong. - If/when we eventually have targets that support true pointers (e.g., CUDA, NVIDIA OpenGL, etc.) we'll need a way to tell the difference between an `in` pointer parameter, and an `out` parameter. Both of these issues are meant to be addressed by having a few special cases of pointer types, for the `out` and `in out` cases, and only translating those (not all pointers). We need to plumb those through the IR more completely, but I'm not dealing with that here.
Diffstat (limited to 'source/slang/emit.cpp')
-rw-r--r--source/slang/emit.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp
index c67bb7b29..617e25d71 100644
--- a/source/slang/emit.cpp
+++ b/source/slang/emit.cpp
@@ -5698,7 +5698,8 @@ emitDeclImpl(decl, nullptr);
emit(", ");
auto paramName = getIRName(pp);
- emitIRType(ctx, pp->getType(), paramName);
+ auto paramType = pp->getType();
+ emitIRParamType(ctx, paramType, paramName);
emitIRSemantics(ctx, pp);
}
@@ -5724,6 +5725,33 @@ emitDeclImpl(decl, nullptr);
}
}
+ void emitIRParamType(
+ EmitContext* ctx,
+ Type* type,
+ String const& name)
+ {
+ // An `out` or `inout` parameter will have been
+ // encoded as a parameter of pointer type, so
+ // we need to decode that here.
+ //
+ if( auto ptrType = type->As<PtrType>() )
+ {
+ // TODO: we need a way to distinguish `out`
+ // from `inout`. The easiest way to do
+ // that might be to have each be a distinct
+ // sub-case of `IRPtrType` - this would also
+ // ensure that they can be distinguished from
+ // real pointers when the user means to use
+ // them.
+
+ emit("out ");
+
+ type = ptrType->getValueType();
+ }
+
+ emitIRType(ctx, type, name);
+ }
+
void emitIRFuncDecl(
EmitContext* ctx,
IRFunc* func)
@@ -5771,26 +5799,7 @@ emitDeclImpl(decl, nullptr);
paramName.append(pp);
auto paramType = funcType->getParamType(pp);
- // An `out` or `inout` parameter will have been
- // encoded as a parameter of pointer type, so
- // we need to decode that here.
- //
- if( auto ptrType = paramType->As<PtrType>() )
- {
- // TODO: we need a way to distinguish `out`
- // from `inout`. The easiest way to do
- // that might be to have each be a distinct
- // sub-case of `IRPtrType` - this would also
- // ensure that they can be distinguished from
- // real pointers when the user means to use
- // them.
-
- emit("out ");
-
- paramType = ptrType->getValueType();
- }
-
- emitIRType(ctx, paramType, paramName);
+ emitIRParamType(ctx, paramType, paramName);
}
emit(");\n");
}