Git Product home page Git Product logo

alter-native's Introduction

Alter-Native Build Status

AlterNative is a tool made by Developers for Developers. Its concept is to maximize the idea of happy-coding. It provides a tool to easy port applications from high-level languages such as .NET to native languages like C++.

Most of the actual systems are C++ compatible, thus if the application is ported to this language, it can be executed in several platforms (i.e. smartphones, tablets, embedded systems and computers).

AlterNative's philosophy is to provide the user with a system for taking the advantage of the .NET fast development and also take the advantage of performance of low-level languages. But also, exploit the possibility to run this native code in many systems or in other words, follow the WORA (Write Once, Run Everywhere) philosophy.

Included open-source libraries:

Mono.Cecil: MIT License
AvalonEdit: LGPL
SharpTreeView: LGPL
ILSpy: MIT License
ICSharpCode.Decompiler: MIT License (developed as part of ILSpy)

Alter-Native Contributors:

Alex Albalà (alejandro.albala at upc.edu)
Juan López (Juan.Lopez-Rubio at upc.edu)
Gerard Solé (gerard.sole.castellvi at gmail.com)

Getting the code

git clone https://github.com/AlexAlbala/Alter-Native.git
git submodule init
git submodule update

Compiling

On Windows

  • Install Cmake from http://www.cmake.org/

    • Be sure to add cmake to the PATH
  • Install Boost libraries from http://www.boost.org

    • Unzip to C:\Boost_x_y_z

    • Compile it (NOTE: The current version is working with compiler msvc-11.0 included in Visual Studio 2012)

        cd C:\Boost_x_y_z
        bootstrap.bat
        b2.exe --prefix=<INSTALLATION_DIR> --toolset=msvc-11.0
      
    • Have a coffee or two :)

    • Probably you shohuld set the environment variable BOOST_INCLUDEDIR pointing to the installation directory in order to enable cmake to find the libraries. Check this variable if cmake is not working

  • For use the c++11 features you will need the compiler v120 CTP of November 2012

  • Execute the provided .bat file

      	install.bat
    
  • Or use command line:

    • Initialize environment variables

        alternative-init.bat
      
    • Compile the AlterNative library

        cd Lib/
        alternative-lib-compile.bat
      
    • Compile AlterNative.sln solution (Debug or Release)

        msbuild AlterNative.sln /p:Configuration=net_4_0_Debug
        msbuild AlterNative.sln /p:Configuration=net_4_0_Release
      
    • You also can use the supplied solution on Visual Studio 2012 or higher

      • Be sure to select one of these solution configurations Otherwise it won't compile:

          net_4_0_Debug
          net_4_0_Release
        

On MacOS X

  • Install Mono >= 3.0 and Xamarin Studio >= 4.1, (http://www.mono-project.com/)

  • Install MacPorts (http://www.macports.org/)

  • Install cmake and boost

      sudo port install cmake boost
    
  • Use the provided command:

      source ./install.sh
    
  • Or use command line:

    • Initialize environment variables

        source ./alternative-init.sh
      
    • Compile AlterNative

        ./alternative.core-compile.sh
      
    • Also you can open the AlterNative.Core.sln with Xamarin Studio and compile
    • Compile the AlterNative library

        cd Lib/
        source ./alternative-lib-compile.sh
      

On Linux

Debian Wheezy (Stable)

  • The following software will be installed from the official debian repositories.

    • Install Mono Runtime.

        sudo apt-get install mono-complete
      
    • Install the necessary tools to run AlterNative.

        sudo apt-get install libboost-all-dev cmake build-essential
      
  • If you check your software version, you should have:

      Mono = 2.10.8.1 or higher
      MonoDevelop = 3.0.3.2 or higher
      libboost = 1.49 or higher
    
  • Use the provided command:

      source ./install.sh
    
  • Or use command line:

    • Initialize environment variables

        source ./alternative-init.sh
      
    • Compile AlterNative

        ./alternative.core-compile.sh
      
    • Compile the AlterNative library

        cd Lib/
        source ./alternative-lib-compile.sh
      

Testing

  • Make sure you have a c++11 compatible compiler

  • Make sure you have compiled the C++ AlterNative library before running some test: https://github.com/AlexAlbala/AlterNative-CXX-Lib

      cd AlterNative
      source ./alternative-init.sh
      
      alternative MyExe.exe ./output/
      cd output
      mkdir build
      cd build
      cmake ..
      make
      ./MyExe
    
  • Support for easy testing is being added.

      cd AlterNative
      source ./alternative-init.sh
      alternative new example
      alternative make example
      cd build
      ./Blank
    
  • Finally, you can use the provided testbench at https://github.com/AlexAlbala/AlterNative-Tests. The submodule is configured on Tests/public directory.

alter-native's People

Contributors

alexalbala avatar furtif avatar gerardsoleca avatar jlopezr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alter-native's Issues

Failed to resolve assembly

I am trying to translate a more complex C# program with depdencies. But it fails with failed to resolve assembly. Let me know if you need I can attach the files here. Also is it possible to do partial translation? | am running the command like this: alternative -v -R actions.exe ./output/
This is the output:
Executing alternative command --> translate Loaded Assembly Actions, Version=1.0.5859.41532, Culture=neutral, PublicKeyToken=null Decompiling assembly: Actions, Version=1.0.5859.41532, Culture=neutral, PublicKeyToken=null Output language is C++ Adding /Users/sab/projects/Actions/Actions/bin/Debug to resolver search directories Decompiling assembly: Urho.Desktop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Output language is C++ Adding /Users/sab/projects/Actions/Actions/bin/Debug to resolver search directories Decompiling assembly: Urho, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Output language is C++ Adding /Users/sab/projects/Actions/Actions/bin/Debug to resolver search directories alternative: Failed to resolve assembly: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) <0x7ee3d8 + 0x0022f> in <filename unknown>:0 at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) <0x7ee398 + 0x00038> in <filename unknown>:0 at Mono.Cecil.DefaultAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) <0x7ee248 + 0x0006b> in <filename unknown>:0 at AlterNative.Program.DecompileAssembly (Mono.Cecil.AssemblyDefinition adef, System.String outputDir, System.String location) <0x7ec788 + 0x00221> in <filename unknown>:0 at AlterNative.Program.DecompileAssembly (Mono.Cecil.AssemblyDefinition adef, System.String outputDir, System.String location) <0x7ec788 + 0x00247> in <filename unknown>:0 at AlterNative.Program.DecompileAssembly (Mono.Cecil.AssemblyDefinition adef, System.String outputDir, System.String location) <0x7ec788 + 0x00247> in <filename unknown>:0 at AlterNative.Program.Run () <0x726d38 + 0x00353> in <filename unknown>:0

Compiling X64 Version On Windows

What I tried:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\amd64\MSBuild.exe" AlterNative.sln /p:Configuration=net_4_0_Release /p:Platform=x64

But it fails to build, And if you open it up with visual studio and switch all of them to x64 it will again fail to build.
Is it possible to add possibly a release configuration for x64 builds, please?
I am able to test the platform using ProcessExplorer

Error when building on Ubuntu 20.04 WSL

Hi, I've installed all of the dependencies and cloned the repo, so I go and run install.sh but it ends with this error:
/usr/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets: error : Cannot copy /home/mason/Alter-Native/AlterNative/App.config to /home/mason/Alter-Native/AlterNative.Core.bin/bin/Debug/AlterNative.Core.exe.config, as the source file doesn't exist.
What do I do?
Here's the entire build log:
https://pastebin.com/WY4deUXD
Thank you!

Generic class in another class generates broken c++

Try this c# code

class Foo {
    class Bar<T> { }
}

It will pretty much just go off the rails, generating the below code, which among other things, references type Bar which doesn't exist.

class Foo : public virtual Object{
    public:
    class Bar_T{
        private:
        template<typename T>
        class Bar_T_Base : private virtual Object{
            public:
            Bar::Bar_Base(){
            }
        };

        private:
        template<typename T, bool>
        class Bar_T  {
        };
        private:

        //Basic types template type
        template<typename T>
        class Bar_T<T, true> : private Bar_T_Base<T>{
        };
        private:

        //Generic template type
        template<typename T>
        class Bar_T<T, false> : private virtual Bar_T_Base<Object>{
        };
    };
};

I tried a non-generic nested type and it worked OK

Handling of Double[]

Tthe C# Array "Double[]" of double type is treated as pointers to array of pointers to double. For example, a[i] (in C#) would be converted to *(a->GetData(i)) instead of a->GetData(i). After adding "double" as a fundamental type in Lib/src/public/System/support/internal/TypeTraits.h, only some of the cases are handled correctly while others are still not correct.

C# Code Example:
...
// Initialize Gaussian data lists
gauss_h = new Double[fit.num_gauss];
gauss_h_cross = new Double[fit.num_gauss];
gauss_p = new Double[fit.num_gauss];
gauss_p_init = new Double[fit.num_gauss];
for (i = 0; i < fit.num_gauss; i++)
{
vec.error_position[i] = Math.Abs(gauss_p_init[i] - gauss_p[i]) >= extend.peak_diff_cutoff;
}

        // Determine the cross-normalized peak heights
        for (i = 0; i < fit.num_gauss; i++)
        {
            vec.normalized_cross_height[i]  = (CROSS_COEFF * metric_cross * Math.Abs(gauss_h[i])) + (metric * Math.Abs(gauss_h_cross[i]));
            vec.normalized_cross_height[i] /= (CROSS_COEFF * metric_cross) + metric;
        }

...
C++ output:
...
Array* array = new Array((int)(fit->num_gauss));
Array* array2 = new Array((int)(fit->num_gauss));
Array* array3 = new Array((int)(fit->num_gauss));
Array* array4 = new Array((int)(fit->num_gauss));
for (uint num = 0u; num < (uint)(fit->num_gauss); num += 1u) {
vec->error_position->SetData((int)(num), Math::Abs(*(array4->GetData((int)(num))) - *(array3->GetData((int)(num)))) >= extend->peak_diff_cutoff);
}
for (uint num = 0u; num < (uint)(fit->num_gauss); num += 1u) {
vec->normalized_cross_height->SetData((int)(num), ((5.0 * metric_cross) * Math::Abs(array->GetData((int)(num)))) + (metric * Math::Abs(array2->GetData((int)(num)))));
vec->normalized_cross_height->SetData((int)(num), (5.0 * metric_cross) + metric);
}
...

'isnan' function is failing in linux

isnan function is failing in Linux due to latest c++ standard in compiler. I am using Lubuntu 16.04.
The following error message is coming while building 'Lib'.
error: ‘isnan’ was not declared in this scope.
isnan was used in Lib/src/public/System/support/valuetypes.h file at two places(Line no: 60 & 75).
I changed isnan to std::isnan to get rid of this error.
could you please fix this.

RuntimeHelpers::InitializeArray isn't handled (used for arrays of >=3 constants)

This c# will crash AlterNative: class foo { float[] bar = { 1,2,3 }; };
It's easier to see why that might be when you try this:

class foo {
    void baz() {
        float[] bar = { 1, 2, 3 };
    }
};

which results in

void foo::baz(){
    RuntimeHelpers::InitializeArray(new Array<float>(3), fieldof(<PrivateImplementationDetails>{169D9E6B-C4D0-4476-851A-DD23AA0A2F9B}::$$method0x6000001-1)->FieldHandle);
}

For 1 or 2 elements, the c# compiler will emit array stores. For the 3rd element it begins emitting that ugly hacky approach.

Simple .NET C# Hello World Doesn't Translate.

Hi,

I've been looking at this project to see how well it works but it seems to fail with almost any of our .NET 2.0 assemblies we tried it with.

After some debugging I narrowed it down to Nullable types. As an example, this simple program will not translate:

public class Hello1
{
public static void Main()
{
bool? foobar;
foobar = true;
System.Console.WriteLine("Hello, World! The nullable is: " + foobar);
}
}

It kicks out an error...
Executing alternative command --> translate
Loaded Assembly HelloNullable, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
foobar/ does not exists. Created
Decompiling assembly: HelloNullable, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Output language is C++
alternative:
bool?
at ICSharpCode.NRefactory.Cpp.Resolver.GetTypeName (ICSharpCode.NRefactory.Cpp.Ast.AstType type) <0x41728b20 + 0x002d7> in :0
at ICSharpCode.NRefactory.Cpp.Visitors.CSharpToCppConverterVisitor.ICSharpCode.NRefactory.CSh
:
:
at AlterNative.Program.DecompileAssembly (Mono.Cecil.AssemblyDefinition adef, System.String outputDir, System.String location) <0x41608ed0 + 0x0049e> in :0
at AlterNative.Program.Run () <0x415fee20 + 0x0040b> in :0

Dale

fatal error: Queue.h: No such file or directory

I get the following error, when trying to compile my output-files:

fatal error: Queue.h: No such file or directory

Do I have to install additional packages/header files to be able to compile? Could only find the Standford C++ library that indeed has this file. I am not sure, but I thought it is a kind of standard C++ header.

How Alter-Native can transpile 'Go' to 'C'/'C++' ?

Hi, it appears helpful (as i can see many users have Starred it).

How do i transpile Go source into C or C++ source code with it ?
is there a transpiler that can convert Go src into C or C++ src, with (almost all) high level structures used in source, kept fairly same/accurate in output source ?

if this project can keep C# (csharp) source code's high-level structures fairly/accurately same in C++ output source code, then i can use go2cs first.

i have Starred this project too.



EXTRA INFO : BTW , i have mentioned it in a Transpiler List here in SO(StackOverflow) site , would you please UPVOTE it here ( or vote to UNDELETE it ) ? please upvote my Question+Answer, both, if you find it useful or if you think it will be helpful for other users related to this type of transpiler projects . By the way, Transpiler-List can be seen from here or here or find it under my repo(s) here.
( and please downvote user Caleb's answer, as that is incorrect answer . Correct-answer must answer my questions first , My question is about "Transpiler" tools & which "transpiler" tool can keep high-level algorithms/structures intact , Question/article is NOT about language learning, when to transpile & when-not, etc.
In SO site, user Flimzy (and Caleb) doesn't give advice When "C/C++",etc to "Go" conversion related question is posted or when "C/C++" is criticized , But when "Go"-to-"C/C++",etc conversion Question is posted or when Google based products (like "Go"-language) are criticized , then those users, especially Flimzy "Close" the question & downvotes, & gives many un-asked advices, etc, Because those users are Google PUSHERS & google based product (like "Go", Google-Advertisements,etc) PUSHERS . Flimzy edited-out important text from my post criticizing Advertisements . Google Crimes1, 2, 3, 4, 5, 6. Problems in "Go"1, 2, 3, 4, 5, 6, 7. )

EDIT : added links (created new page for Transpiler List).
EDIT : added links ('Go'-problems).

Is Alter-Native support p/invoke?

I have question before trying out this project.
I developed game based on OpenTK and it uses AutoGenerated attributes

and it calls OpenGL native functions via p/invoke.
The question is, is this project support with binaries that uses p/invoke feature?

problem in translating an assembly - Length cannot be less than zero.

I tried to translate an assembly with the following command:
alternative "D:\Hakan Documents\Visual Studio 2012\Projects\CsharpConsole\CsharpConsole\bin\Debug\CsharpConsole.exe" D:\output

but i got an error:
Length cannot be less than zero.

I traced program and i found where this error occured, Program.cs:313.

So, i changed those lines with mine, and it works fine now.

Take a look at what i wrote:

//string fullPath = "";
//if (Config.Extra[0].Replace('\\', '/').Contains('/'))
//    fullPath = Config.Extra[0].Substring(0, Config.Extra[0].Replace('\\', '/').LastIndexOf("/"));
//else
//    fullPath = Path.Combine(Environment.CurrentDirectory, Config.Extra[0]);

//assemblyLocation = fullPath.Substring(0, fullPath.LastIndexOf('/'));

//Hakan648 - fixed: Length cannot be less than zero.
bool isTargetInADir = Config.Extra[0].Contains('\\');

if (isTargetInADir)
    assemblyLocation = Path.GetDirectoryName(Config.Extra[0]);
else
    assemblyLocation = Path.Combine(Environment.CurrentDirectory, Config.Extra[0]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.