Skip to content

Commit c3a27c0

Browse files
author
Tim Foley
authored
Fix up name mangling/unmangling for extensions (shader-slang#493)
* Fix up name mangling/unmangling for extensions This is required for the unmangling we do on some builtin function names. The work here is mostly just a band-aid, and a more comprehensive pass over the name mangling/unmangling code is required to make any of this robust. * fixup: UNREACHABLE_RETURN argument
1 parent 0450ca6 commit c3a27c0

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

source/slang/emit.cpp

+51-4
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,28 @@ struct EmitVisitor
23552355
}
23562356
}
23572357

2358+
2359+
UnownedStringSlice readRawStringSegment()
2360+
{
2361+
// Read the length part
2362+
UInt count = readCount();
2363+
if(count > UInt(end_ - cursor_))
2364+
{
2365+
SLANG_UNEXPECTED("bad name mangling");
2366+
UNREACHABLE_RETURN(UnownedStringSlice());
2367+
}
2368+
2369+
auto result = UnownedStringSlice(cursor_, cursor_ + count);
2370+
cursor_ += count;
2371+
return result;
2372+
}
2373+
2374+
void readNamedType()
2375+
{
2376+
// TODO: handle types with more complicated names
2377+
readRawStringSegment();
2378+
}
2379+
23582380
void readType()
23592381
{
23602382
int c = peek();
@@ -2378,16 +2400,30 @@ struct EmitVisitor
23782400
break;
23792401

23802402
default:
2381-
// TODO: need to read a named type
2382-
// here...
2403+
readNamedType();
23832404
break;
23842405
}
23852406
}
23862407

23872408
void readVal()
23882409
{
2389-
// TODO: handle other cases here
2390-
readType();
2410+
switch(peek())
2411+
{
2412+
case 'k':
2413+
get();
2414+
readCount();
2415+
break;
2416+
2417+
case 'K':
2418+
get();
2419+
readRawStringSegment();
2420+
break;
2421+
2422+
default:
2423+
readType();
2424+
break;
2425+
}
2426+
23912427
}
23922428

23932429
void readGenericArg()
@@ -2405,6 +2441,12 @@ struct EmitVisitor
24052441
}
24062442
}
24072443

2444+
void readExtensionSpec()
2445+
{
2446+
expect("X");
2447+
readType();
2448+
}
2449+
24082450
UnownedStringSlice readSimpleName()
24092451
{
24102452
UnownedStringSlice result;
@@ -2422,6 +2464,11 @@ struct EmitVisitor
24222464
readGenericArgs();
24232465
continue;
24242466
}
2467+
else if(c == 'X')
2468+
{
2469+
readExtensionSpec();
2470+
continue;
2471+
}
24252472

24262473
if(!isDigit((char)c))
24272474
return result;

source/slang/mangle.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ namespace Slang
170170
// (both types and values) to be mangled in terms of their
171171
// "depth" (how many outer generics) and "index" (which
172172
// parameter are they at the specified depth).
173+
emitRaw(context, "K");
173174
emitName(context, genericParamIntVal->declRef.GetName());
174175
}
175176
else if( auto constantIntVal = dynamic_cast<ConstantIntVal*>(val) )

0 commit comments

Comments
 (0)