Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make my own JIT\Interpreter\Compiler for C# and use it in Visual Studio?

I am currently writing a compiler that produces JIT-like EXE from C# (rewrites itself), is there anyway to make Visual Studio and it's debugger recognize the way I want to build it (with my compiler) and debug the output?

My compiler's output is EXE, but it doesn't contain MSIL, it contains my intermediate language, and the rest of the content is the JIT written in C++. (The C++ reads itself\EXE and executes)

I am well-aware it's not magic to make it compatible; I am here to get a straight answer whatever it's possible and hints to start; e.g. write a C++ DLL with such functions and parameters and give the DLL path to Visual Studio's debugger parameters, or just point me to reference at MSDN. (I got zero promising results from Google)

like image 931
LyingOnTheSky Avatar asked Oct 26 '15 17:10

LyingOnTheSky


People also ask

What is JIT compiler in C?

In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is a way of executing computer code that involves compilation during execution of a program (at run time) rather than before execution.

What compiler can be used for C?

(Actually we will use the Gnu C++ compiler, but all C programs compile using this compiler). The g++ compiler is open source, meaning you can use it for free on any project you want, including "for profit" projects.

What languages use just-in-time compilation?

Newer programs will make use of JIT compilers, which generate code while the program is running. Two common uses of JIT compilers include Java Virtual Machine (JVM) which is used in Java, as well as CLR (Common Language Runtime) which is used in C#.

Do you need a compiler to run C?

C is a mid-level language and it needs a compiler to convert it into an executable code so that the program can be run on our machine.


1 Answers

It appears that what you want to do is possible. The relevant sections of MSDN would be :

  • Extending Visual Studio

The Visual Studio integrated development environment (IDE) provides the user interface (UI) for standard components, such as compilers, editors, and debuggers. Features like Visual C++ and Visual Basic that are included with Visual Studio are themselves extensions of the IDE. The Visual Studio SDK provides tools, samples, wizards, designers, and documentation that helps you develop your own applications that extend the IDE and integrate seamlessly with it.

Pay particular attention to :

  • Visual Studio Debugger Extensibility

Visual Studio includes a fully interactive source code debugger, providing a powerful and easy-to-use tool for tracking down bugs in your program. The debugger has complete support Visual Basic, C#, C/C++, and JavaScript. However, with the Visual Studio SDK, that is available from the Microsoft Download Center,, other programming languages can be supported in the debugger with the same rich features.

Also take note of the Language Services section - this describes means to add support for a new language to visual studio. In particular, you can also add debug support for the language.

see : Language Service Support For Debugging

The type of compiler determines what you need to do to implement debugging for your language. If your compiler targets the Windows operating system and writes a .pdb file, you can debug programs with the native code debugging engine that is integrated into Visual Studio. If your compiler produces Microsoft intermediate language (MSIL), you can debug programs with the managed code debugging engine, which is also integrated into Visual Studio. If your compiler targets a proprietary operating system or a different runtime environment, you need to write your own debugging engine.

Emphasis mine - ie: you can debug anything you want, but you will need to write the debugger yourself.

You'll probably want to download the Visual Studio SDK.

like image 123
J... Avatar answered Sep 30 '22 04:09

J...