Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI .NET compiler Unmanaged , +
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):
 

    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 3-Jul-12 2:38am
Edited 3-Jul-12 2:54am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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).
  Permalink  
Comments
Alexandre Bencz at 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 at 3-Jul-12 14:15pm
   
Your simple compiler? What do you mean?
--SA
Alexandre Bencz at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 274
1 Shweta N Mishra 216
2 PIEBALDconsult 210
3 Sergey Alexandrovich Kryukov 185
4 BillWoodruff 174
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100