public void TestOpenGlExe() { Il2Converter.Convert( Path.GetFullPath(CompilerHelper.OpenGlExePath), CompilerHelper.OutputPath, CompilerHelper.GetConverterArgs(true)); }
public static bool ConvertAll(string fileName, string source = SourcePath) { Trace.WriteLine(string.Empty); Trace.WriteLine("=========================================================================="); Trace.WriteLine("Generating LLVM BC(ll) for " + fileName); Trace.WriteLine("=========================================================================="); Trace.WriteLine(string.Empty); var sources = Directory.GetFiles(source, string.Format("{0}-*.cs", fileName)).ToList(); var filePath = Path.Combine(source, string.Format("{0}.cs", fileName)); if (File.Exists(filePath)) { sources.Insert(0, filePath); } if (!sources.Any()) { Trace.WriteLine(string.Empty); Trace.WriteLine("=========================================================================="); Trace.WriteLine("MISSING! " + fileName); Trace.WriteLine("=========================================================================="); Trace.WriteLine(string.Empty); return(false); } Il2Converter.Convert( sources.ToArray(), OutputPath, GetConverterArgs(true)); return(true); }
public void TestOpenGlLib() { // todo: // 1) class Condition method _getEffectiveTarget when it is returning Object it does not cast Interface to an Object, to replicate the issue change returning type to Object // 2) the same as 1) but in InterpolateValueAction when saving value 'value = this._target[this._property]' Il2Converter.Convert(Path.GetFullPath(OpenGlLibPath), OutputPath, GetConverterArgs(true)); }
/// <summary> /// </summary> /// <param name="number"> /// </param> /// <param name="source"> /// </param> /// <param name="fileName"> /// </param> /// <param name="format"> /// </param> private static void Convert(string fileName, string source = SourcePath) { Il2Converter.Convert( string.Concat(source, string.Format("{0}.cs", fileName)), OutputPath, GetConverterArgs(true)); }
/// <summary> /// </summary> /// <param name="args"> /// </param> private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("C# Native, https://csnative.codeplex.com/"); Console.WriteLine("MSIL to LLVM ByteCode compiler"); Console.WriteLine(string.Empty); Console.WriteLine("Usage: Il2Bc [options] file..."); Console.WriteLine("file:"); Console.WriteLine(" .cs C# source file"); Console.WriteLine(" .dll MSIL dll file"); Console.WriteLine("Options:"); Console.WriteLine(" /corelib:<file> Reference standard library (CoreLib.dll)"); Console.WriteLine(" /roslyn Compile C# source file with Roslyn Compiler"); Console.WriteLine(" /target:<target> LLVM target, ex: i686-pc-win32, armv7-none-linux-androideabi, asmjs-unknown-emscripten"); Console.WriteLine(" /gc- Disable Boehm garbage collector"); Console.WriteLine(" /gctors- Disable using global constructors"); Console.WriteLine(" /llvm35 Enable support LLVM 3.5 (otherwise 3.6)"); Console.WriteLine(" /llvm34 Enable support LLVM 3.4 or lower version (otherwise 3.6)"); Console.WriteLine(" /debug Generate debug information"); Console.WriteLine(" /multi Use all CPU cores"); Console.WriteLine(" /android Set recommended settings for Android platform"); Console.WriteLine(" /emscripten Set recommended settings for Emscripten platform"); return; } var processedArgs = args.Select(arg => (arg.StartsWith("/") || arg.StartsWith("-")) ? arg.Substring(1) : arg).ToArray(); Il2Converter.Convert(args.First(arg => (!arg.StartsWith("/") && !arg.StartsWith("-"))), Environment.CurrentDirectory, processedArgs); }
public void TestAndroid() { Il2Converter.Convert( Path.GetFullPath(CompilerHelper.AndroidPath), CompilerHelper.OutputPath, CompilerHelper.GetConverterArgs(true)); }
/// <summary> /// </summary> /// <param name="args"> /// </param> private static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine("C# Native, https://csnative.codeplex.com/"); Console.WriteLine("C# to C++ transpiler"); Console.WriteLine(string.Empty); Console.WriteLine("Usage: CS2CPP [options] file"); Console.WriteLine(string.Empty); Console.WriteLine("file: Specifies the file or files to be compiled"); Console.WriteLine(" .cs C# source file"); Console.WriteLine(" .csproj C# project file"); Console.WriteLine(string.Empty); Console.WriteLine("Options:"); Console.WriteLine(" /release Release mode"); Console.WriteLine(" /corelib:<file> Reference standard library (CoreLib.dll)"); Console.WriteLine(" /ref:<file|assembly>[;<file|assembly>..]"); Console.WriteLine(" Reference assembly by name or file"); Console.WriteLine(string.Empty); Console.WriteLine("When .CSPROJ provided:"); Console.WriteLine(" /property:<name>=<value>"); Console.WriteLine(" /p:<name>=<value> Set or override the specified project-level properties"); Console.WriteLine(string.Empty); Console.WriteLine("Example:"); Console.WriteLine(" Cs2Cpp file1.cs Compiles one C# file"); Console.WriteLine(" Cs2Cpp proj1.csproj Compiles C# project"); Console.WriteLine(" Cs2Cpp /ref:System.Core file1.cs file2.cs"); Console.WriteLine(" Compiles two C# files using Roslyn compiler"); Console.WriteLine(" Cs2Cpp proj1.csproj /p:Configuration=netstandard2.0-Windows_NT-Release"); Console.WriteLine(" Compiles C# project with Configuration 'netstandard2.0-Windows_NT-Release'"); return(0); } var processedArgs = args.Where(arg => arg.StartsWith("/") || arg.StartsWith("-")).Select(arg => arg.Substring(1)).ToArray(); var sources = args.Where(arg => (!arg.StartsWith("/") && !arg.StartsWith("-"))).ToArray(); var fileExtension = Path.GetExtension(sources.First()); if (!sources.All(f => Path.GetExtension(f).Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase))) { Console.WriteLine("WARNING!"); Console.WriteLine("You can use only one type of files at a time."); return(1); } if (fileExtension.Equals("csproj", StringComparison.InvariantCultureIgnoreCase) && sources.Count() > 1) { Console.WriteLine("WARNING!"); Console.WriteLine("You can use only one CSPROJ file at a time."); return(1); } Console.WriteLine("Generating C++ files..."); Il2Converter.Convert(sources, Environment.CurrentDirectory, processedArgs); Console.WriteLine("Done."); return(0); }
/// <summary> /// </summary> /// <param name="args"> /// </param> private static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine("NativeSharp, https://github.com/0xFireball/NativeSharp"); Console.WriteLine("Based on Cs2Cpp, https://github.com/ASDAlexander77/cs2cpp.git"); Console.WriteLine("C# to C++ transpiler"); Console.WriteLine(string.Empty); Console.WriteLine("Usage: CS2CPP [options] file"); Console.WriteLine(string.Empty); Console.WriteLine("file: Specifies the file or files to be compiled"); Console.WriteLine(" .cs C# source file"); Console.WriteLine(" .csproj C# project file"); Console.WriteLine(string.Empty); Console.WriteLine("Options:"); Console.WriteLine(" /release Release mode"); Console.WriteLine(" /corelib:<file> Reference standard library (CoreLib.dll)"); Console.WriteLine(" /ref:<file|assembly>[;<file|assembly>..]"); Console.WriteLine(" Reference assembly by name or file"); Console.WriteLine(string.Empty); Console.WriteLine("Example:"); Console.WriteLine(" Il2C file1.cs Compiles one C# file"); Console.WriteLine(" Il2C proj1.csproj Compiles C# project"); Console.WriteLine(" Il2C /ref:System.Core file1.cs file2.cs"); Console.WriteLine(" Compiles two C# files using Roslyn compiler"); return(0); } var processedArgs = args.Select(arg => (arg.StartsWith("/", StringComparison.InvariantCulture) || arg.StartsWith("-", StringComparison.InvariantCulture)) ? arg.Substring(1) : arg).ToArray(); var sources = args.Where(arg => (!arg.StartsWith("/", StringComparison.InvariantCulture) && !arg.StartsWith("-", StringComparison.InvariantCulture))).ToArray(); var fileExtension = Path.GetExtension(sources.First()); if (!sources.All(f => Path.GetExtension(f).Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase))) { Console.WriteLine("WARNING!"); Console.WriteLine("You can use only one type of files at a time."); return(1); } if (fileExtension.Equals("csproj", StringComparison.InvariantCultureIgnoreCase) && sources.Count() > 1) { Console.WriteLine("WARNING!"); Console.WriteLine("You can use only one CSPROJ file at a time."); return(1); } Console.WriteLine("Building target \"Generate C++ files\"..."); Il2Converter.Convert(sources, Environment.CurrentDirectory, processedArgs); Console.WriteLine("Done."); return(0); }
public void TestMscorlibCompile_TypeTest() { // Do not forget to set MSCORLIB variable Il2Converter.Convert( Path.GetFullPath( @"C:\Windows\Microsoft.NET\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll"), CompilerHelper.OutputPath, CompilerHelper.GetConverterArgs(false), new[] { "System.Diagnostics.Tracing.EventProvider" }); }
private static void CompileExeTarget(string[] sources, string[] processedArgs) { var corelibSwitch = "corelib:"; var findCoreLibSwitch = processedArgs.FirstOrDefault(arg => arg.StartsWith(corelibSwitch)); if (findCoreLibSwitch == null) { Console.WriteLine("It is needed to provide CoreLib using /corelib:<file.dll> switch"); return; } Console.Write("Generating LLVM IR file for CoreLib..."); var coreLib = findCoreLibSwitch.Substring(corelibSwitch.Length); Il2Converter.Convert( new[] { coreLib }, Environment.CurrentDirectory, processedArgs.Where(p => !p.StartsWith(corelibSwitch)).ToArray()); Console.WriteLine("Done."); // you need to get target var llvmDummyWriter = new LlvmWriter(string.Empty, string.Empty, string.Empty, processedArgs); var target = llvmDummyWriter.Target; // next step compile CoreLib Console.Write("Compiling LLVM IR file for CoreLib..."); var coreLibNameNoExt = Path.GetFileNameWithoutExtension(coreLib); ExecCmd("llc", string.Format("-filetype=obj -mtriple={1} {0}.ll", coreLibNameNoExt, target)); Console.WriteLine("Done."); // compile generated dll Console.Write("Compiling LLVM IR file..."); var targetFileNameNoExt = Path.GetFileNameWithoutExtension(sources.First()); ExecCmd("llc", string.Format("-filetype=obj -mtriple={1} {0}.ll", targetFileNameNoExt, target)); Console.WriteLine("Done."); // detect OBJ extention var objExt = ".obj"; var targetObjFile = Directory.GetFiles(Environment.CurrentDirectory, targetFileNameNoExt + ".o*").FirstOrDefault(); if (targetObjFile != null) { objExt = Path.GetExtension(targetObjFile); } Console.Write("Compiling target exe. file..."); // finally generate EXE output ExecCmd("g++", string.Format("-o {0}.exe {0}{2} {1}{2} -lstdc++ -lgc-lib -march=i686 -L .", targetFileNameNoExt, coreLibNameNoExt, objExt)); Console.WriteLine("Done."); }
/// <summary> /// </summary> /// <param name="number"> /// </param> /// <param name="source"> /// </param> /// <param name="fileName"> /// </param> /// <param name="format"> /// </param> public static void Convert(string fileName, string source = SourcePath) { Trace.WriteLine(string.Empty); Trace.WriteLine("=========================================================================="); Trace.WriteLine("Generating C for " + fileName); Trace.WriteLine("=========================================================================="); Trace.WriteLine(string.Empty); Il2Converter.Convert( string.Concat(source, string.Format("{0}.cs", fileName)), OutputPath, GetConverterArgs(true)); }
public void TestCoreLib() { Il2Converter.Convert(Path.GetFullPath(CoreLibPath), OutputPath, GetConverterArgs(false)); if (CompileWithOptimization) { ExecCmd("opt", "CoreLib.ll -o CoreLib.bc -O2"); ExecCmd("llc", string.Format("-filetype=obj -mtriple={0} CoreLib.bc", Target)); } else { ExecCmd("llc", string.Format("-filetype=obj -mtriple={0} CoreLib.ll", Target)); } }
public void TestMscorlibCompile_ReducedBuild() { // Do not forget to set MSCORLIB variable Il2Converter.Convert( //Path.GetFullPath(@"C:\Windows\Microsoft.NET\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll"), CompilerHelper.MscorlibPath, CompilerHelper.OutputPath, CompilerHelper.GetConverterArgs(false), new[] { "System.Object", }); }
public static void BuildCoreLib() { var testOutput = Path.Combine(Environment.CurrentDirectory, OutputPath); var buildCoreLibFolderPath = Path.Combine(testOutput, "CoreLib"); if (!Directory.Exists(buildCoreLibFolderPath)) { AssertUiEnabled(true); Debug.Assert(false, "This will generate and build CoreLib which will take time"); AssertUiEnabled(false); Il2Converter.Convert( "../../../CoreLib/CoreLib.csproj", testOutput, new[] { "/release" }); ExecCmd("build_prerequisite_vs2017_release.bat", "", buildCoreLibFolderPath); ExecCmd("build_vs2017_release.bat", "", buildCoreLibFolderPath); } }
public static bool ConvertAll(string fileName, string source = SourcePath, string additionalFilesFolder = "", string[] additionalFilesPattern = null) { Trace.WriteLine(string.Empty); Trace.WriteLine("=========================================================================="); Trace.WriteLine("Generating C for " + fileName); Trace.WriteLine("=========================================================================="); Trace.WriteLine(string.Empty); var sources = Directory.GetFiles(source, string.Format("{0}-*.cs", fileName)).ToList(); var filePath = Path.Combine(source, string.Format("{0}.cs", fileName)); if (File.Exists(filePath)) { sources.Insert(0, filePath); } if (!string.IsNullOrEmpty(additionalFilesFolder)) { foreach (var pattern in additionalFilesPattern) { sources = Directory.GetFiles(additionalFilesFolder, pattern).Union(sources).ToList(); } } if (!sources.Any()) { Trace.WriteLine(string.Empty); Trace.WriteLine("=========================================================================="); Trace.WriteLine("MISSING! " + fileName); Trace.WriteLine("=========================================================================="); Trace.WriteLine(string.Empty); return(false); } Il2Converter.Convert( sources.ToArray(), OutputPath, GetConverterArgs(true)); return(true); }
public void TestMscorlibCompile() { // TODO: if you have undefined symbols, remove all linkodr_once and see which symbol is not defined // Do not forget to set MSCORLIB variable // you need to compile it with optimization, otherwise it will not be compiled as being to big /* * IF NOT EXIST mscorlib.obj opt mscorlib.ll -o mscorlib.bc -O2 * IF NOT EXIST mscorlib.obj llc -filetype=obj -mtriple=i686-w64-mingw32 mscorlib.bc * opt test-1.ll -o test-1.bc -O3 * llc -filetype=obj -mtriple=i686-w64-mingw32 test-1.bc * g++.exe -o test-1.exe mscorlib.obj test-1.obj -lstdc++ -lgc-lib -march=i686 -L . * del test-1.obj * del test-1.bc */ // alternative way to compile /* * llvm-link -o=test-1.bc test-1.ll mscorlib.ll * llc -filetype=obj -mtriple=i686-w64-mingw32 test-1.bc * g++.exe -o test-1.exe test-1.obj -lstdc++ -lgc-lib -march=i686 -L . * del test-1.o */ // WHAT TODO here // remove static dependancy on count of interfaces // adjust creating string as MSCORLIB does // adjust creating RuntimeType as MSCORLIB does Il2Converter.Convert( Path.GetFullPath( @"C:\Windows\Microsoft.NET\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll"), CompilerHelper.OutputPath, CompilerHelper.GetConverterArgs(false, stubs: true)); }
public void TestMscolibCSNative() { // TODO: if you have undefined symbols, remove all linkodr_once and see which symbol is not defined Il2Converter.Convert( Path.GetFullPath(CompilerHelper.MscorlibPath), CompilerHelper.OutputPath, CompilerHelper.GetConverterArgs(false, stubs: true)); ////if (CompilerHelper.CompileWithOptimization) ////{ //// CompilerHelper.ExecCmd("opt", "CoreLib.ll -o CoreLib.bc -O2"); //// CompilerHelper.ExecCmd( //// "llc", //// string.Format("-filetype=obj -mtriple={0} mscorlib.bc", CompilerHelper.Target)); ////} ////else ////{ //// CompilerHelper.ExecCmd( //// "llc", //// string.Format("-filetype=obj -mtriple={0} mscorlib.ll", CompilerHelper.Target)); ////} }
public void TestMscorlibCompile() { //Debug.Listeners.Clear(); Il2Converter.Convert(Path.GetFullPath(@"C:\Windows\Microsoft.NET\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll"), OutputPath, GetConverterArgs(false)); }
/// <summary> /// </summary> /// <param name="index"> /// </param> /// <param name="fileName"> /// </param> /// <param name="format"> /// </param> /// <param name="justCompile"> /// </param> private static void ExecCompile(string fileName, bool justCompile = false, bool opt = false) { /* * call vcvars32.bat * llc -mtriple i686-pc-win32 -filetype=obj corelib.ll * llc -mtriple i686-pc-win32 -filetype=obj test-%1.ll * link -defaultlib:libcmt -nodefaultlib:msvcrt.lib -nodefaultlib:libcd.lib -nodefaultlib:libcmtd.lib -nodefaultlib:msvcrtd.lib corelib.obj test-%1.obj /OUT:test-%1.exe * del test-%1.obj */ // to test working try/catch with g++ compilation // http://mingw-w64.sourceforge.net/download.php // Windows 32 DWARF i686 - use this config to test exceptions on windows // GC - http://www.hboehm.info/gc/ (use git and cmake to compile libgc-lib.a file /* * llc -mtriple i686-pc-mingw32 -filetype=obj corelib.ll * llc -mtriple i686-pc-mingw32 -filetype=obj test-%1.ll * g++.exe -o test-%1.exe corelib.o test-%1.o -lstdc++ -march=i686 * del test-%1.o */ // if GC Enabled /* * llc -mtriple i686-pc-mingw32 -filetype=obj corelib.ll * llc -mtriple i686-pc-mingw32 -filetype=obj test-%1.ll * g++.exe -o test-%1.exe corelib.o test-%1.o -lstdc++ -lgc-lib -march=i686 -L . * del test-%1.o */ // if GC Enabled with optimization /* * opt corelib.ll -o corelib.bc -O2 * opt test-%1.ll -o test-%1.bc -O2 * llc -mtriple i686-pc-mingw32 -filetype=obj corelib.bc * llc -mtriple i686-pc-mingw32 -filetype=obj test-%1.bc * g++.exe -o test-%1.exe corelib.o test-%1.o -lstdc++ -lgc-lib -march=i686 -L . * del test-%1.o */ // Android target - target triple = "armv7-none-linux-androideabi" // compile CoreLib if (!File.Exists(Path.Combine(OutputPath, string.Concat("CoreLib.", OutputObjectFileExt)))) { if (!File.Exists(Path.Combine(OutputPath, "CoreLib.ll"))) { Il2Converter.Convert(Path.GetFullPath(CoreLibPath), OutputPath, GetConverterArgs(false)); } if (opt) { ExecCmd("opt", "CoreLib.ll -o CoreLib.bc -O2"); ExecCmd("llc", string.Format("-filetype=obj -mtriple={0} CoreLib.bc", Target)); } else { ExecCmd("llc", string.Format("-filetype=obj -mtriple={0} CoreLib.ll", Target)); } } // file obj if (opt) { ExecCmd("opt", string.Format("{0}.ll -o {0}.bc -O2", fileName)); ExecCmd("llc", string.Format("-filetype=obj -mtriple={1} {0}.bc", fileName, Target)); } else { ExecCmd("llc", string.Format("-filetype=obj -mtriple={1} {0}.ll", fileName, Target)); } if (!justCompile) { // file exe ExecCmd("g++", string.Format("-o {0}.exe {0}.{1} CoreLib.{1} -lstdc++ -lgc-lib -march=i686 -L .", fileName, OutputObjectFileExt)); // test execution ExecCmd(string.Format("{0}.exe", fileName)); } else { Assert.IsTrue(File.Exists(Path.Combine(OutputPath, string.Format("{0}{1}.{2}", OutputPath, fileName, OutputObjectFileExt)))); } }
public void TestAndroid() { Il2Converter.Convert(Path.GetFullPath(AndroidPath), OutputPath, GetConverterArgs(true)); }
public void TestOpenGlExe() { Il2Converter.Convert(Path.GetFullPath(OpenGlExePath), OutputPath, GetConverterArgs(true)); }
/// <summary> /// </summary> /// <param name="args"> /// </param> private static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine("C# Native, https://csnative.codeplex.com/"); Console.WriteLine("MSIL to LLVM ByteCode compiler"); Console.WriteLine(string.Empty); Console.WriteLine("Usage: Il2Bc [options] file"); Console.WriteLine(string.Empty); Console.WriteLine("file: Specifies the file or files to be compiled"); Console.WriteLine(" .cs C# source file"); Console.WriteLine(" .dll MSIL dll file"); Console.WriteLine(string.Empty); Console.WriteLine("Options:"); Console.WriteLine(" /exe Output file"); Console.WriteLine(" /corelib:<file> Reference standard library (CoreLib.dll)"); Console.WriteLine(" /roslyn Compile C# source file with Roslyn Compiler"); Console.WriteLine( " /target:<target> LLVM target, ex: i686-pc-win32, armv7-none-linux-androideabi, asmjs-unknown-emscripten"); Console.WriteLine(" /gc- Disable Boehm garbage collector"); Console.WriteLine(" /gctors- Disable using global constructors"); Console.WriteLine(" /llvm35 Enable support LLVM 3.5 (otherwise 3.6)"); Console.WriteLine(" /llvm34 Enable support LLVM 3.4 or lower version (otherwise 3.6)"); Console.WriteLine(" /debug Generate debug information, can be combined with /llvm37"); Console.WriteLine(" /verbose Verbose output"); Console.WriteLine(" /multi Use all CPU cores"); Console.WriteLine(" /android Set recommended settings for Android platform"); Console.WriteLine(" /emscripten Set recommended settings for Emscripten platform"); Console.WriteLine(string.Empty); Console.WriteLine("Example:"); Console.WriteLine(" Il2Bc file1.cs Compiles one C# file"); Console.WriteLine(" Il2Bc /roslyn file1.cs file2.cs"); Console.WriteLine(" Compiles two C# files using Roslyn compiler"); Console.WriteLine(" Il2Bc file1.dll Converts one DLL file"); return(0); } var processedArgs = args.Select(arg => (arg.StartsWith("/") || arg.StartsWith("-")) ? arg.Substring(1) : arg).ToArray(); var sources = args.Where(arg => (!arg.StartsWith("/") && !arg.StartsWith("-"))).ToArray(); var isCompilingTargetExe = processedArgs.Any(s => s == "exe"); var fileExtension = Path.GetExtension(sources.First()); if (!sources.All(f => Path.GetExtension(f).Equals(fileExtension, StringComparison.InvariantCultureIgnoreCase))) { Console.WriteLine("WARNING!"); Console.WriteLine("You can use only one type of files at a time."); return(1); } if (fileExtension.Equals("dll", StringComparison.InvariantCultureIgnoreCase) && sources.Count() > 1) { Console.WriteLine("WARNING!"); Console.WriteLine("You can use only one DLL file at a time."); return(1); } // if version is not provided, detect it your self if (isCompilingTargetExe && !processedArgs.Any(p => p.StartsWith("llvm"))) { processedArgs = AppendLlvmVersionToParams(processedArgs); } Console.Write("Generating LLVM IR file..."); Il2Converter.Convert(sources, Environment.CurrentDirectory, processedArgs); Console.WriteLine("Done."); if (isCompilingTargetExe) { CompileExeTarget(sources, processedArgs); } return(0); }