Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I whant to know, how the C++/CLI compiler works, I generate 5 tree dumps of one simple code in C++/CLI

3 tree dumps I generate with this simple code ( pure, safe CLR):


C++
using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");
    return 0;
}


so, but, when I compile the code with a ' printf '... the code generate of CLR and PURE use this instruction:

|___[STM] printf : vararg int32 modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl)(int8 modopt([mscorlib]System.Runtime.CompilerServices.IsSignUnspecifiedByte) modopt([mscorlib]System.Runtime.CompilerServices.IsConst)*)


The IL code generate is this:

//000008: 	printf("Ola mundo\n");
  IL_000a:  /* 7F   | (04)000001       */ ldsflda    valuetype '<CppImplementationDetails>'.$ArrayType$$$BY0L@$$CBD/*02000002*/ modopt([mscorlib/*23000001*/]System.Runtime.CompilerServices.IsConst/*01000002*/) '?A0x1af50272.unnamed-global-0' /* 04000001 */
  IL_000f:  /* 28   | (0A)000004       */ call       vararg int32 modopt([mscorlib/*23000001*/]System.Runtime.CompilerServices.CallConvCdecl/*01000001*/) printf(int8 modopt([mscorlib/*23000001*/]System.Runtime.CompilerServices.IsSignUnspecifiedByte/*01000006*/) modopt([mscorlib/*23000001*/]System.Runtime.CompilerServices.IsConst/*01000002*/)*) /* 0A000004 */
  IL_0014:  /* 26   |                  */ pop



So, In my attempt of development of one compiler with this style, I found one compiler called pnetC, of NetGnu, this compile mix C Native code with MSIL,but, the compiler use one dll with all .h files...

So, I would like techniques information of this compiler style, how I can generate this mixed code ?

So, basically, I need ideias for this, and technical informations of this...

Thanks
Alexandre
Posted
Updated 3-Jul-12 1:54am
v2

1 solution

Compiler -> IR (intermediate representation) -> Optimizer -> Optimized Intermediate Representation -> Assembler -> Binary Code -> Linker -> Application Code.

Native Application Code -> Native CPU
Managed Application Code -> Virtual Machine with Logical CPU -> Native CPU

Short answer:
When you user printf, CLR must prepare a stub(using managed code instructions) for calling unmanaged code (native instructions).
 
Share this answer
 
Comments
Alexandre Bencz 3-Jul-12 8:31am    
Ok, but, in my simple compiler, how I can mix this ?
for example, I have one header with a function:

void thisFnc(const char*, ...)

like printf... how I can create this in CLR, for my simple language ?
how is the best form, to mix this with CLR technolog ?
Sergey Alexandrovich Kryukov 3-Jul-12 14:15pm    
Your simple compiler? What do you mean?
--SA
Alexandre Bencz 3-Jul-12 14:18pm    
It's my project....
I can create a system, when I can use the C/C++ headers on the code of my compiler... (:
So, and, I want to know more and more about c++/cli technology (:
Sergey Alexandrovich Kryukov 3-Jul-12 14:14pm    
This is explained with impressive detail, but, if explained on this level, makes it not quite clear, how .NET application code works, so you also need to mention JIT compiler and explain what it does (I voted 4).
--SA
Mihai Vrinceanu 4-Jul-12 8:18am    
JIT is not related to compiler development. Useful to know, nevertheless. He should read the "Dragon Book", understand it and then work on a C++/C#/CLI compilers. 10-12 months and he will be on the right track. We are talking about WRITING compilers, aren't we!? :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900