Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions src/ILToNative/reproNative/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,38 @@ void __register_module(SimpleModuleHeader* pModule)
#endif // USE_MRT
}

namespace System { class Object {
public:
EEType * get_EEType() { return *(EEType **)this; }
}; };
namespace mscorlib { namespace System {

class Object {
public:
EEType * get_EEType() { return *(EEType **)this; }
};

class Array : public Object {
public:
int32_t GetArrayLength() {
return *(int32_t *)((void **)this + 1);
}
void * GetArrayData() {
return (void **)this + 2;
}
};

class String : public Object { public:
static MethodTable * __getMethodTable();
};

class String__Array : public Object { public:
static MethodTable * __getMethodTable();
};

class EETypePtr { public:
intptr_t m_value;
};

namespace System { class Array : public System::Object {
public:
int32_t GetArrayLength() {
return *(int32_t *)((void **)this + 1);
}
void * GetArrayData() {
return (void **)this + 2;
}
}; };

namespace System { class String : public System::Object { public:
static MethodTable * __getMethodTable();
}; };

namespace System { class EETypePtr { public:
intptr_t m_value;
}; }
using namespace mscorlib;

//
// The fast paths for object allocation and write barriers is performance critical. They are often
Expand Down Expand Up @@ -147,6 +157,8 @@ extern "C" Object * __allocate_object(MethodTable * pMT)

Object * __allocate_string(int32_t len)
{
#ifdef CPPCODEGEN

#if !USE_MRT
alloc_context * acontext = GetThread()->GetAllocContext();
Object * pObject;
Expand Down Expand Up @@ -178,6 +190,10 @@ Object * __allocate_string(int32_t len)
#else
return RhNewArray(System::String::__getMethodTable(), len);
#endif

#else
throw 42;
#endif
}

extern "C" Object * __allocate_array(MethodTable * pMT, size_t elements)
Expand Down Expand Up @@ -291,11 +307,7 @@ void __range_check(void * a, size_t elem)
ThrowRangeOverflowException();
}

namespace System { class String__Array : public System::Object { public:
static MethodTable * __getMethodTable();
}; };


#ifdef CPPCODEGEN
Object * __get_commandline_args(int argc, char * argv[])
{
System::Array * p = (System::Array *)__allocate_array(System::String__Array::__getMethodTable(), argc);
Expand All @@ -308,6 +320,7 @@ Object * __get_commandline_args(int argc, char * argv[])

return (Object *)p;
}
#endif

// FCalls

Expand Down Expand Up @@ -523,17 +536,17 @@ extern "C" intptr_t RhGetModuleFromEEType(System::EETypePtr)
throw 42;
}

#if 0
#ifndef CPPCODEGEN
SimpleModuleHeader __module = { NULL, NULL /* &__gcStatics, &__gcStaticsDescs */ };

extern "C" int Program__Main();
extern "C" int repro_Program__Main();

int main(int argc, char * argv[]) {
if (__initialize_runtime() != 0) return -1;
__register_module(&__module);
ReversePInvokeFrame frame; __reverse_pinvoke(&frame);

Program::Main((System::String__Array*)__get_commandline_args(argc - 1, argv + 1));
repro_Program__Main();

__reverse_pinvoke_return(&frame);
__shutdown_runtime();
Expand Down
4 changes: 2 additions & 2 deletions src/ILToNative/reproNative/reproNativeCpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CPPCODEGEN;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\..\Native\gc;..\..\Native\gc\env</AdditionalIncludeDirectories>
Expand All @@ -71,7 +71,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>CPPCODEGEN;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>..\gc;..\..\Native\gc\env</AdditionalIncludeDirectories>
Expand Down
2 changes: 2 additions & 0 deletions src/ILToNative/reproNative/stubs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using namespace mscorlib;

//
// BoundsChecking
//
Expand Down
11 changes: 6 additions & 5 deletions src/ILToNative/src/Compiler/AsmWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ void OutputCode()

foreach (var t in _registeredTypes.Values)
{
RegisteredMethod m = t.Methods;
while (m != null)
if (t.Methods != null)
{
if (m.MethodCode != null)
OutputMethodCode(m);
m = m.Next;
foreach (var m in t.Methods)
{
if (m.MethodCode != null)
OutputMethodCode(m);
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/ILToNative/src/Compiler/Compilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,23 @@ public void AddMethod(MethodDesc method)
return;
reg.IncludedInCompilation = true;

RegisteredType regType = GetRegisteredType(method.OwningType);
if (regType.Methods == null)
regType.Methods = new List<RegisteredMethod>();
regType.Methods.Add(reg);

if (_methodsThatNeedsCompilation == null)
_methodsThatNeedsCompilation = new List<MethodDesc>();
_methodsThatNeedsCompilation.Add(method);

NameMangler.GetMangledMethodName(method);

if (_options.IsCppCodeGen)
{
// Precreate name to ensure that all types referenced by signatures are present
NameMangler.GetMangledTypeName(method.OwningType);
GetRegisteredType(method.OwningType);
var signature = method.Signature;
NameMangler.GetMangledTypeName(signature.ReturnType);
GetRegisteredType(signature.ReturnType);
for (int i = 0; i < signature.Length; i++)
NameMangler.GetMangledTypeName(signature[i]);
GetRegisteredType(signature[i]);
}
}

Expand Down Expand Up @@ -352,8 +355,8 @@ public void AddField(FieldDesc field)
if (_options.IsCppCodeGen)
{
// Precreate name to ensure that all types referenced by signatures are present
NameMangler.GetMangledTypeName(field.OwningType);
NameMangler.GetMangledTypeName(field.FieldType);
GetRegisteredType(field.OwningType);
GetRegisteredType(field.FieldType);
}
}

Expand Down
Loading