Skip to content

Commit 98dfe40

Browse files
authored
Several fixes in signature generation (#41)
1 parent 0c300ce commit 98dfe40

File tree

6 files changed

+61
-20
lines changed

6 files changed

+61
-20
lines changed

source/MetadataProcessor.Core/Tables/nanoSignaturesTable.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public int GetHashCode(byte[] that)
4646

4747
static nanoSignaturesTable()
4848
{
49-
PrimitiveTypes.Add(typeof(void).FullName, nanoCLR_DataType.DATATYPE_VALUETYPE);
49+
PrimitiveTypes.Add(typeof(void).FullName, nanoCLR_DataType.DATATYPE_VOID);
5050

5151
PrimitiveTypes.Add(typeof(sbyte).FullName, nanoCLR_DataType.DATATYPE_I1);
5252
PrimitiveTypes.Add(typeof(short).FullName, nanoCLR_DataType.DATATYPE_I2);
@@ -69,13 +69,6 @@ static nanoSignaturesTable()
6969
PrimitiveTypes.Add(typeof(IntPtr).FullName, nanoCLR_DataType.DATATYPE_VALUETYPE);
7070
//PrimitiveTypes.Add(typeof(UIntPtr).FullName, nanoCLR_DataType.DATATYPE_U4);
7171

72-
PrimitiveTypes.Add("System.DateTime", nanoCLR_DataType.DATATYPE_DATETIME);
73-
PrimitiveTypes.Add("System.TimeSpan", nanoCLR_DataType.DATATYPE_TIMESPAN);
74-
75-
PrimitiveTypes.Add("System.RuntimeTypeHandle", nanoCLR_DataType.DATATYPE_REFLECTION);
76-
PrimitiveTypes.Add("System.RuntimeFieldHandle", nanoCLR_DataType.DATATYPE_REFLECTION);
77-
PrimitiveTypes.Add("System.RuntimeMethodHandle", nanoCLR_DataType.DATATYPE_REFLECTION);
78-
7972
PrimitiveTypes.Add("System.WeakReference", nanoCLR_DataType.DATATYPE_WEAKCLASS);
8073
}
8174

source/MetadataProcessor.Core/Utility/NativeMethodsCrc.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,26 @@ internal static string GetnanoClrTypeName(TypeReference parameterType)
126126
nanoCLR_DataType myType;
127127
if(nanoSignaturesTable.PrimitiveTypes.TryGetValue(parameterType.FullName, out myType))
128128
{
129-
return myType.ToString();
129+
if (myType == nanoCLR_DataType.DATATYPE_LAST_PRIMITIVE)
130+
{
131+
return "DATATYPE_STRING";
132+
}
133+
else if (myType == nanoCLR_DataType.DATATYPE_LAST_NONPOINTER)
134+
{
135+
return "DATATYPE_TIMESPAN";
136+
}
137+
else if (myType == nanoCLR_DataType.DATATYPE_LAST_PRIMITIVE_TO_MARSHAL)
138+
{
139+
return "DATATYPE_TIMESPAN";
140+
}
141+
else if (myType == nanoCLR_DataType.DATATYPE_LAST_PRIMITIVE_TO_PRESERVE)
142+
{
143+
return "DATATYPE_R8";
144+
}
145+
else
146+
{
147+
return myType.ToString();
148+
}
130149
}
131150
else
132151
{

source/MetadataProcessor.Core/Utility/nanoCLR_DataType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum nanoCLR_DataType : byte
3838

3939
// All the above types can be marshaled by assignment.
4040
#if NANOCLR_NO_ASSEMBLY_STRINGS
41-
DATATYPE_LAST_PRIMITIVE_TO_MARSHAL = DATATYPE_STRING,
41+
DATATYPE_LAST_PRIMITIVE_TO_MARSHAL = DATATYPE_STRING,
4242
#else
4343
DATATYPE_LAST_PRIMITIVE_TO_MARSHAL = DATATYPE_TIMESPAN,
4444
#endif

source/MetadataProcessor.Core/Utility/nanoSerializationType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal enum nanoSerializationType : byte
2929
ELEMENT_TYPE_STRING = 0xe,
3030

3131
// every type above PTR will be simple type
32-
ELEMENT_TYPE_PTR = 0xf, // PTR <type>
32+
ELEMENT_TYPE_PTR = 0x0F, // PTR <type>
3333
ELEMENT_TYPE_BYREF = 0x10, // BYREF <type>
3434

3535
// Please use ELEMENT_TYPE_VALUETYPE. ELEMENT_TYPE_VALUECLASS is deprecated.

source/MetadataProcessor.Core/nanoDumperGenerator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,15 @@ private string PrintSignatureForType(TypeReference type)
292292
case nanoCLR_DataType.DATATYPE_U8:
293293
case nanoCLR_DataType.DATATYPE_R4:
294294
case nanoCLR_DataType.DATATYPE_R8:
295-
case nanoCLR_DataType.DATATYPE_STRING:
296295
case nanoCLR_DataType.DATATYPE_BYREF:
297296
case nanoCLR_DataType.DATATYPE_OBJECT:
298297
return dataType.ToString().Replace("DATATYPE_", "");
298+
299+
case nanoCLR_DataType.DATATYPE_LAST_PRIMITIVE:
300+
return "STRING";
301+
302+
case nanoCLR_DataType.DATATYPE_REFLECTION:
303+
return type.FullName.Replace(".", "");
299304
}
300305
}
301306

source/native/Tools.Parser/AssemblyParserDump.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,36 +493,60 @@ void MetaData::Parser::Dump_EnumTypeDefs( bool fNoByteCode )
493493
const CLR_UINT8* IP = il.Code;
494494
const CLR_UINT8* IPend = IP + il.GetCodeSize();
495495

496+
CLR_UINT16 ilCount = 0;
497+
498+
// 1st pass: count the number of instructions
496499
while(IP < IPend)
497500
{
498501
CLR_OPCODE op = CLR_ReadNextOpcode( IP );
499502

500-
fwprintf( m_output, L" %-12S", c_CLR_RT_OpcodeLookup[op].m_name );
501-
502503
if(IsOpParamToken( c_CLR_RT_OpcodeLookup[op].m_opParam ))
503504
{
504505
CLR_UINT32 arg; NANOCLR_READ_UNALIGNED_UINT32( arg, IP );
505-
506-
fwprintf( m_output, L"[%08x]", arg );
507506
}
508507
else
509508
{
510509
IP = CLR_SkipBodyOfOpcode( IP, op );
511510
}
512511

513-
fwprintf( m_output, L"\n" );
512+
ilCount++;
514513
}
514+
515+
fwprintf(m_output, L" IL count: %d\n", ilCount);
516+
517+
IP = il.Code;
518+
IPend = IP + il.GetCodeSize();
519+
520+
// 2nd pass: output the instructions
521+
while (IP < IPend)
522+
{
523+
CLR_OPCODE op = CLR_ReadNextOpcode(IP);
524+
525+
fwprintf(m_output, L" %-12S", c_CLR_RT_OpcodeLookup[op].m_name);
526+
527+
if (IsOpParamToken(c_CLR_RT_OpcodeLookup[op].m_opParam))
528+
{
529+
CLR_UINT32 arg; NANOCLR_READ_UNALIGNED_UINT32(arg, IP);
530+
531+
fwprintf(m_output, L"[%08x]", arg);
532+
}
533+
else
534+
{
535+
IP = CLR_SkipBodyOfOpcode(IP, op);
536+
}
537+
538+
fwprintf(m_output, L"\n");
539+
}
540+
515541
}
516542
}
517-
518-
fwprintf( m_output, L"\n" );
519543
}
520544

521545
for(mdInterfaceImplListIter it3 = td.m_interfaces.begin(); it3 != td.m_interfaces.end(); it3++)
522546
{
523547
InterfaceImpl& ii = m_mapDef_Interface[*it3];
524548

525-
fwprintf( m_output, L" InterfaceImplProps [%08x]: Itf: %08x\n", ii.m_td, ii.m_itf );
549+
fwprintf( m_output, L" InterfaceImplProps [%08x]: Itf: %08x\n", *it3, ii.m_itf );
526550
}
527551

528552
fwprintf( m_output, L"\n" );

0 commit comments

Comments
 (0)