Skip to content

Commit

Permalink
Merge branch 'c_write_single_process' of https://alexdevhouse.visuals…
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDAlexander77 committed Jun 2, 2016
2 parents caca201 + 66010a2 commit 493fecd
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ StyleCop.Cache
/PdbReader/obj
/PdbReader/bin
/Il2Native.Logic/Resources/Impl.zip
/mscorlib/bin/Debug
/mscorlib/obj/Debug
/mscorlib/obj/Release
/mscorlib/bin/Release
/Il2Native.VC.db
/Il2Native.VC.VC.opendb
Binary file added .vs/Il2Native/v14/.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions Il2Native.Logic/CCodeFilesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void WriteBuildFiles(AssemblyIdentity identity, ISet<AssemblyIdentity> re
set(CMAKE_EXE_LINKER_FLAGS ""${CMAKE_EXE_LINKER_FLAGS} /ignore:4006 /ignore:4049 /ignore:4217"")
else()
if (CMAKE_SYSTEM_NAME STREQUAL ""Android"")
SET(EXTRA_CXX_FLAGS ""-std=gnu++11 -fexceptions -frtti -fshort-wchar"")
SET(EXTRA_CXX_FLAGS ""-std=gnu++11 -fexceptions -frtti"")
SET(BUILD_ARCH ""vs_android"")
else()
SET(EXTRA_CXX_FLAGS ""-std=gnu++14 -march=native"")
Expand Down Expand Up @@ -273,7 +273,7 @@ cd __build_win32_<%build_type_lowercase%>_bdwgc
if not exist bdwgc/libatomic_ops (git clone git://github.com/ivmai/libatomic_ops.git bdwgc/libatomic_ops)
md __build_vs_android_<%build_type_lowercase%>_bdwgc
cd __build_vs_android_<%build_type_lowercase%>_bdwgc
cmake -f ../bdwgc -G ""Visual Studio 14"" -Denable_threads:BOOL=ON -Denable_parallel_mark:BOOL=ON -Denable_cplusplus:BOOL=ON -Denable_gcj_support:BOOL=ON -DCMAKE_BUILD_TYPE=<%build_type%> -DCMAKE_SYSTEM_NAME=Android -Wno-dev
cmake -f ../bdwgc -G ""Visual Studio 14"" -Denable_threads:BOOL=ON -Denable_parallel_mark:BOOL=ON -Denable_cplusplus:BOOL=OFF -Denable_gcj_support:BOOL=ON -DCMAKE_BUILD_TYPE=<%build_type%> -DCMAKE_SYSTEM_NAME=Android -Wno-dev
call ""%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat"" amd64_x86
MSBuild ALL_BUILD.vcxproj /m:8 /p:Configuration=<%build_type%> /p:Platform=""Win32"" /toolsversion:14.0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void WriteTo(CCodeWriterBase c)
{
c.TextSpan("GC_set_bit(bitmap, GC_WORD_OFFSET(__type,");
c.WhiteSpace();
c.WriteName(field);
c.WriteFieldAccessAsStaticField(field);
c.TextSpanNewLine("));");
}

Expand Down
2 changes: 1 addition & 1 deletion Il2Native.Logic/DOM2/Literal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static string UnicodeChar(char c)
return c.ToString();
}

if (char.IsHighSurrogate(c) || char.IsLowSurrogate(c))
if (c == 0 || char.IsHighSurrogate(c) || char.IsLowSurrogate(c))
{
return string.Format("\\x{0:X4}", (uint)c);
}
Expand Down
91 changes: 88 additions & 3 deletions Il2Native.Logic/Resources/c_declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ template <typename T, int32_t RANK> class __multi_array : public CoreLib::System
auto length = 1;
for (auto rank = 0; rank < RANK; rank++)
{
length *= _data[rank];
length *= (_upperBoundries[rank] - _lowerBoundries[rank]);
}

auto instance = allocate_multiarray(length);
Expand All @@ -593,6 +593,91 @@ template <typename T, int32_t RANK> class __multi_array : public CoreLib::System
virtual int32_t get_Rank() override;
};

// allocator
template<class T>
class gc_allocator_with_realloc {
public:
typedef T value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;

typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;

gc_allocator_with_realloc() {}
gc_allocator_with_realloc(const gc_allocator_with_realloc&) {}
~gc_allocator_with_realloc() {}

pointer address(reference r) const { return &r; }
const_pointer address(const_reference r) const { return &r; }

pointer allocate(size_type n, const_pointer = 0)
{
return static_cast<pointer>(GC_MALLOC_UNCOLLECTABLE(n * sizeof(value_type)));
}

void deallocate(pointer p, size_type)
{
GC_FREE(p);
}

pointer reallocate(pointer p, size_type n)
{
return static_cast<pointer>(GC_REALLOC(p, n * sizeof(value_type)));
}

size_type max_size() const
{
return static_cast<size_type>(-1) / sizeof(value_type);
}

void construct(pointer p, const value_type& val)
{
new(p) value_type(val);
}
void destroy(pointer p) { p->~value_type(); }

template <class U>
gc_allocator_with_realloc(const gc_allocator_with_realloc<U>&) {}

template<class U>
struct rebind
{
typedef gc_allocator_with_realloc<U> other;
};
};

// gc_allocator_with_realloc<void> specialization.
template<>
class gc_allocator_with_realloc<void> {
public:
typedef void value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;

template<class U>
struct rebind
{
typedef gc_allocator_with_realloc<U> other;
};
};

template<class T>
inline bool operator==(const gc_allocator_with_realloc<T>&, const gc_allocator_with_realloc<T>&)
{
return true;
}

template<class T>
inline bool operator!=(const gc_allocator_with_realloc<T>&, const gc_allocator_with_realloc<T>&)
{
return false;
}

#ifdef NO_TIMED_MUTEX
#ifndef GC_PTHREADS
struct __monitor
Expand Down Expand Up @@ -813,7 +898,7 @@ class __object_extras_storage
{
public:

typedef std::unordered_map<object*, __object_extras*> map;
typedef std::unordered_map<object*, __object_extras*, std::hash<const object*>, std::equal_to<const object*>, gc_allocator_with_realloc<std::pair<const object*, __object_extras*> > > map;

__object_extras* operator[] (object* obj)
{
Expand Down Expand Up @@ -859,7 +944,7 @@ class __strings_storage
{
public:

typedef std::unordered_map<const char16_t*, string*> map;
typedef std::unordered_map<const char16_t*, string*, std::hash<const char16_t*>, std::equal_to<const char16_t*>, gc_allocator_with_realloc<std::pair<const char16_t*, string*> > > map;

string* operator() (const char16_t* str, size_t length)
{
Expand Down
35 changes: 34 additions & 1 deletion Il2Native.Logic/Resources/c_definitions.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
__object_extras_storage* __object_extras_storage_instance = nullptr;
__strings_storage* __strings_storage_instance = nullptr;

/*
void* operator new (size_t _size)
{
return GC_MALLOC_UNCOLLECTABLE(size);
}
void operator delete (void* obj);
{
GC_FREE(obj);
}
void* operator new[] (size_t _size);
{
return GC_MALLOC_UNCOLLECTABLE(size);
}
void operator delete[] (void* obj);
{
GC_FREE(obj);
}
*/

void* operator new (size_t _size, GCNormal)
{
return __new_set0(_size, GCNormal::Default);
Expand Down Expand Up @@ -138,14 +160,20 @@ void __shutdown()

void __startup()
{
/*
#if (defined(PLATFORM_ANDROID) || defined(__ANDROID__))
struct GC_stack_base sb;
#endif
*/
atexit(__shutdown);
GC_set_all_interior_pointers(1);
GC_INIT();
/*
#if (defined(PLATFORM_ANDROID) || defined(__ANDROID__))
GC_allow_register_threads();
struct GC_stack_base sb;
GC_register_my_thread(&sb);
#endif
*/
__object_extras_storage_instance = new __object_extras_storage();
__strings_storage_instance = new __strings_storage();
}
Expand All @@ -162,3 +190,8 @@ __array<string*>* __get_arguments(int32_t argc, char* argv[])

return args;
}

void throw_out_of_memory()
{
throw __new<CoreLib::System::OutOfMemoryException>();
}
39 changes: 39 additions & 0 deletions Il2Native.Logic/Resources/c_forward_declarations.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,18 @@ template <typename T> struct is_pointer_type : std::integral_constant<bool, std:

extern void GC_CALLBACK __finalizer(void * obj, void * client_data);

void throw_out_of_memory();

inline void* __new_set0(size_t _size)
{
auto mem = _size > 102400
? GC_MALLOC_IGNORE_OFF_PAGE(_size)
: GC_MALLOC(_size);
if (!mem)
{
throw_out_of_memory();
}

return mem;
}

Expand All @@ -105,6 +112,11 @@ inline void* __new_set0(size_t _size, GCAtomic)
auto mem = _size > 102400
? GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(_size)
: GC_MALLOC_ATOMIC(_size);
if (!mem)
{
throw_out_of_memory();
}

std::memset(mem, 0, _size);
return mem;
}
Expand All @@ -114,6 +126,11 @@ inline void* __new_set0(size_t _size, GC_descr _type_descr)
auto mem = _size > 102400
? GC_malloc_explicitly_typed_ignore_off_page(_size, _type_descr)
: GC_MALLOC_EXPLICITLY_TYPED(_size, _type_descr);
if (!mem)
{
throw_out_of_memory();
}

return mem;
}

Expand Down Expand Up @@ -152,6 +169,11 @@ inline void* __new_set0(size_t _size, const char* _file, int _line)
auto mem = _size > 102400
? GC_debug_malloc_ignore_off_page(_size, GC_ALLOC_PARAMS)
: GC_debug_malloc(_size, GC_ALLOC_PARAMS);
if (!mem)
{
throw_out_of_memory();
}

return mem;
#else
return __new_set0(_size);
Expand All @@ -173,6 +195,11 @@ inline void* __new_set0(size_t _size, GCAtomic, const char* _file, int _line)
auto mem = _size > 102400
? GC_debug_malloc_atomic_ignore_off_page(_size, GC_ALLOC_PARAMS)
: GC_debug_malloc_atomic(_size, GC_ALLOC_PARAMS);
if (!mem)
{
throw_out_of_memory();
}

return mem;
#else
return __new_set0(_size, GCAtomic::Default);
Expand All @@ -185,6 +212,11 @@ inline void* __new_set0(size_t _size, GC_descr _type_descr, const char* _file, i
auto mem = _size > 102400
? GC_debug_malloc_ignore_off_page(_size, GC_ALLOC_PARAMS)
: GC_debug_malloc(_size, GC_ALLOC_PARAMS);
if (!mem)
{
throw_out_of_memory();
}

return mem;
#else
return __new_set0(_size, _type_descr);
Expand Down Expand Up @@ -219,6 +251,13 @@ inline void* __new_set0_with_finalizer(size_t _size, GC_descr _type_descr, const
return mem;
}

/*
void* operator new (size_t _size);
void* operator delete (void* obj);
void* operator new[] (size_t _size);
void* operator delete[] (void* obj);
*/

void* operator new (size_t _size, GCNormal);
void* operator new (size_t _size, GCNormal, const char* _file, int _line);
void* operator new (size_t _size, int32_t _customSize, GCNormal);
Expand Down
2 changes: 1 addition & 1 deletion Il2Native.Logic/Resources/c_template_definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ int32_t __multi_array<T, RANK>::get_Length()
auto length = 1;
for (auto rank = 0; rank < RANK; rank++)
{
length *= _data[rank];
length *= (_upperBoundries[rank] - _lowerBoundries[rank]);
}

return length;
Expand Down
5 changes: 3 additions & 2 deletions Ll2NativeTests/CompilerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class CompilerHelper
public const string CoreLibCSProjPath = @"C:\Dev\Temp\Il2Native\CoreLib\CoreLib.csproj";
public const string CoreLibDllPath = @"C:\Dev\Temp\Il2Native\CoreLib\bin\Release\CoreLib.dll";
public const string CoreLibPdbPath = @"C:\Dev\Temp\Il2Native\CoreLib\bin\Release\CoreLib.pdb";
public const string MscorlibCSProjPath = @"C:\Dev\Temp\Il2Native\mscorlib\mscorlib.csproj";
public static string MscorlibDllPath = @"C:\Dev\Temp\Il2Native\mscorlib\bin\Release\mscorlib.dll";
public const string MscorlibPdbPath = @"C:\Dev\Temp\Il2Native\mscorlib\bin\Release\mscorlib.pdb";
public const string SscliSourcePath = @"C:\Dev\Unzipped\sscli20\tests\bcl\system\";
Expand All @@ -31,7 +32,7 @@ public static class CompilerHelper
#if _DISK_D_
public const string SourcePath = @"D:\Temp\CSharpTranspilerExt\Mono-Class-Libraries\mcs\tests\";
public const string SourcePathCustom = @"D:\Temp\tests\";
public const string OutputPath = @"M:\";
public const string OutputPath = @"D:\Temp\IlCTests\";
public const string CoreLibCSProjPath = @"..\..\..\CoreLib\CoreLib.csproj";
public const string CoreLibDllPath = @"..\..\..\CoreLib\bin\Release\CoreLib.dll";
public const string CoreLibPdbPath = @"..\..\..\CoreLib\bin\Release\CoreLib.pdb";
Expand Down Expand Up @@ -188,7 +189,7 @@ public static void ExecCmd(
Trace.WriteLine(output);
}

Assert.AreEqual(returnCode, process.ExitCode);
Assert.AreEqual(returnCode, process.ExitCode, string.Format("File: {0}, Arguments: {1}, Working Dir: {2}", fileName, arguments, workingDir));
}

/// <summary>
Expand Down
9 changes: 5 additions & 4 deletions Ll2NativeTests/MSTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,7 @@ static int Test ()

skip.Add(930); // throwing exception in finally block - BUG! check if you can fix it

////foreach (var index in Enumerable.Range(1, 907).Where(n => !skip.Contains(n)))
foreach (var index in Enumerable.Range(36, 2).Where(n => !skip.Contains(n)))
foreach (var index in Enumerable.Range(1, 934).Where(n => !skip.Contains(n)))
{
CompilerHelper.CompileAndRun(string.Format("test-{0}", index));
}
Expand Down Expand Up @@ -895,7 +894,7 @@ public void TestCoreLib()
// you need to compile GC property to include GC_pthread_create etc.
// read Readme.win32 how to compile it for MinGW

CompilerHelper.GcDebugEnabled = true;
CompilerHelper.GcDebugEnabled = false;

Il2Converter.Convert(
Path.GetFullPath(CompilerHelper.CoreLibCSProjPath),
Expand Down Expand Up @@ -1008,8 +1007,10 @@ public void TestGameLogicForll()
//[Ignore]
public void TestMscolibCSNative()
{
CompilerHelper.GcDebugEnabled = false;

Il2Converter.Convert(
Path.GetFullPath(CompilerHelper.MscorlibDllPath),
Path.GetFullPath(CompilerHelper.MscorlibCSProjPath),
CompilerHelper.OutputPath,
CompilerHelper.GetConverterArgs(false, stubs: true));
}
Expand Down
3 changes: 0 additions & 3 deletions mscorlib/mscorlib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,6 @@
<ItemGroup>
<None Include="src\System\Globalization\Tables\CharInfo.nlp" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down

0 comments on commit 493fecd

Please sign in to comment.