Skip to content

Proof of concept C to C# and C# to C code transpiler using LLVM and Roslyn

License

Notifications You must be signed in to change notification settings

Cryru/SeaSharpener

Repository files navigation

SeaSharpener

A C to C# and C# to C code transpiler using LLVM's Clang and Roslyn. It's more of a proof of concept, but it works.

For information on usage and the APIs check the ExecTest project.

C to C#

Sadly the current C# featureset doesn't allow for a full conversion, as some logic has no equivalent.

One example is that structs with function pointers or multidimensional arrays have to be converted to classes, which are reference types and won't be copied when passed into a function. It's possible these problems have solutions, but I haven't really put much work or thought into this project.

Supports

Check the test files in the ExecTest project for examples. This list is a bit funny, but to fully translate everything you need to manually handle every CXCursorKind case.

  • Structs
  • Enums
    • Nameless enums
  • Type aliases
  • Includes
  • Unions
    • Unions nested in structs
  • Function pointers
  • Most of the stdlib.h implemented
  • If/Else
  • For loops
  • Goto
  • Conditional ternary operator ?:
  • Accessing struct members expressions
  • Numerical and string literals
  • Primitive and sturct variable declaration
  • Static variable declaration
  • Array indexing
  • Break/Continue
  • Simple binary operators
  • CStyle casts

Unsupported/ToDo

  • Integral literal enum values
  • Expression enum values
  • Enums nested within structs
  • Fixed arrays in structs
  • Global variables
  • Do/While
  • Array variable declaration and initialization
  • Prettify output

C# to C

This was a quickly put together functionality which inverts the roles of Clang and Roslyn, showcasing the latter's syntax analysis functionality.

Supports

Check the test files in the ExecTest project for examples.

  • Simple hello world function

Dependencies

https://github.com/dotnet/roslyn

https://github.com/dotnet/ClangSharp/

Inspired, and some code referenced from https://github.com/rds1983/Sichem

About

Proof of concept C to C# and C# to C code transpiler using LLVM and Roslyn

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published