Questions tagged [intermediate-language]

An intermediate language, in compiler design, is a low-level language that typically resembles an idealized assembly language, often a textual representation of bytecode for a virtual machine. For .NET's CIL, use the [cil] tag.

An intermediate language, in compiler design, is a translation stage after the syntax tree and before the machine code. The term is usually used for final stages of the translation, after high-level optimizations have been performed, but at a stage when the translation is still independent of the target machine.

In particular, “intermediate language” often means a low-level, assembly-like language for a virtual machine such as the JVM, .NET, Prolog's WAM, etc.

For example, the .NET Common Intermediate Language is the assembly language for the virtual machine that is the target of and other compilers.

144 questions
4
votes
1 answer

Why casting double to double emits conv.r8 IL instruction

Is there any reason for the C# compiler to emit a conv.r8 when casting from double -> double ? This looks to be completely unnecessary (casting from int -> int, char -> char, etc) does not emit equivalent conversion instructions (as you can see in…
Vagaus
  • 4,174
  • 20
  • 31
4
votes
3 answers

Static analysis for partial C++ programs

I'm thinking about doing some static analysis project over C++ code samples, as opposed to entire programs. In general static analysis requires some simpler intermediate representation, but such a representation cannot be accurately created without…
Oak
  • 26,231
  • 8
  • 93
  • 152
4
votes
1 answer

Question about how the C# Compiler emits TypeRef information

I found this interesting thing when I was trying out the new feature “optional parameters” in C# 4.0. I know that there are two ways to use “optional parameters” in C# 4.0: static void TestMethod(int parameter = 5) { } static void…
4
votes
1 answer

Generate correct IL to call a virtual method with a parameter with the new "in" modifier on a generic class

I am writing a serialization/deserialization framework around the new System.IO.Pipelines package in .NET Core 2.1. I've run into an issue when generating IL to call a virtual method with a parameter with the new "in" modifier on a generic class.…
smoyer
  • 7,932
  • 3
  • 17
  • 26
4
votes
1 answer

C# unit tests and code in same folder: strip out tests from compiled binary

I have read the answers to Do you put unit tests in same project or another project? and the consensus back then (almost 10 years ago) is to put unit tests in a separate project from the code they are testing. The main reason given is to avoid…
Mike Chamberlain
  • 39,692
  • 27
  • 110
  • 158
4
votes
4 answers

How is this virtual method call faster than the sealed method call?

I am doing some tinkering on the performance of virtual vs sealed members. Below is my test code. The output is virtual total 3166ms per call virtual 3.166ns sealed total 3931ms per call sealed 3.931ns I must be doing something wrong because…
Simon
  • 33,714
  • 21
  • 133
  • 202
4
votes
2 answers

Tool for editing .IL files?

Currently I use Notepad for this purpose. Is there any specific tool intended for editing .NET Intermediate Language files? Dotnet IL Editor (DILE) disassembles files before editing them, I don't need that functionality - only actual editing is…
SharpAffair
  • 5,558
  • 13
  • 78
  • 158
4
votes
1 answer

Modify IL code on the fly

I want to modify .Net IL code of an existing class on the fly. Is that possible somehow? I found some references to the .Net Profiling API, but according to the documentation it does not support self modifying applications. The main purpose would be…
Achim
  • 15,415
  • 15
  • 80
  • 144
4
votes
5 answers

Programmatically compare IL of two methods

I have a compiled assembly. I want to programmatically compare the method implementation of one of the methods in that assembly with something I expect. Is there a way I can compare their ILs? Even if I can get a byte array representation of any…
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
4
votes
0 answers

Can Intel's icc compiler produce AST, CFG, and/or IR?

When using clang, I've found it useful to examine the abstract syntax tree (AST), control-flow graph (CFG), and LLVM IR that it produces. I've started looking at Intel's icc compiler (version 15.0.2), and I can't find any documentation that tells me…
4
votes
1 answer

Intermediate representation for FPGA compilers

When writing compilers for standard computers, one can target an existing intermediate representation (like LLVM IR) and not have to worry about tricky architectural differences between systems. Does something like this exist for FPGAs?
Dan
  • 12,409
  • 3
  • 50
  • 87
4
votes
1 answer

Options for invoking methods dynamically in C#

I've seen quite a few questions related to how do I invoke a method like this and that. What I haven't found is a listing of the different options of how to invoke a method via reflection or any other means in csharp. Can someone explain in detail…
Sean Chambers
  • 8,572
  • 7
  • 41
  • 55
4
votes
2 answers

C# compiling to MSIL code

Does the Microsoft C# compiler (CSC.exe) have an option to output the Intermediate Language files? Kind of like the -S switch does in GCC?
Icemanind
  • 47,519
  • 50
  • 171
  • 296
3
votes
2 answers

C# Call and return an object from a static method in IL

This is an extension to the solutions offered here. I've created a static method that returns me an object. My goal, is the write a dynamic method for a type I define at runtime to return me the object that this static method is returning. My code…
OnResolve
  • 4,016
  • 3
  • 28
  • 50
3
votes
0 answers

Spilling a symbol doesn't improve colorability

Say I have this intermediate representation of some code: t1 = 1 t2 = 2 t3 = 3 t4 = t1 + t2 t5 = t3 + t4 use t5 The ultimate goal is to do register assignment using only two ARM registers, r0 and r1, and possibly spill some symbols. The first…
ForceBru
  • 43,482
  • 10
  • 63
  • 98
1 2
3
9 10