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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
53 views

c# Emit dynamic method to convert DateOnly To Datetime

I am learning IL (intermediate language) for possible applications to a C# application. Using c#, I am trying to generate a dynamic method to convert a DateOnly into a DateTime. In C#, it would just ...
ildanny's user avatar
  • 381
0 votes
0 answers
91 views

C# understanding intermediate language

I am new to c#. I am currently follow some tutorials and try to learn how to read the intermediate language (IL) with ildasm.exe. I wrote this short code in c#: using System; namespace MainApp { ...
Skobo Do's user avatar
1 vote
1 answer
316 views

Will assembly which targets .netstandard2.0 but runs on .NET 7 get all the performance boost from the latest runtime?

I have a choice for the assembly to target .netstandard2.0 or .net7.0. If I do not need latest features of C#, will it eventually make any performance difference when running my application on .NET ? ...
Pavel Voronin's user avatar
1 vote
1 answer
88 views

Unrecoverable IL error, but the IL looks fine

I'm getting errors with the following IL. Any idea why? It looks fine to me! The issue is with the lines stloc.4/ldloc.4 that are highlighted in bold. The syntax highlighting is from Rider, but I ...
Andrew Matthews's user avatar
1 vote
1 answer
211 views

How to compile a .NET Core C# project to raw IL code?

I'm trying to set-up a C# project that outputs raw IL code instead of a .EXE. The output file should either look something like this: IL_0000: nop IL_0001: ldc.i4.5 IL_0002: stloc.0 ...
boooba's user avatar
  • 159
0 votes
1 answer
178 views

Do basic block parameters mean code locality?

Most modern compilers use some form of SSA for internal representation, which needs some notation for variables whose values can come from more than one source. The classic version uses phi nodes. ...
rwallace's user avatar
  • 31.9k
1 vote
1 answer
242 views

Why is callvirt used to call a method on a readonly field of generic type

Consider the following: interface ISomething { void Call(string arg); } sealed class A : ISomething { public void Call(string arg) => Console.WriteLine($"A, {arg}"); } sealed ...
Bogey's user avatar
  • 5,072
0 votes
0 answers
107 views

Using a locally defined class instead of the one provided by a library/package C# IL Weaving

I have seen stuff like Fody and in fact have been using PropertyChanged which reduces the boilerplate code after implementing the INotifyPropertyChanged interface. I believe it is done by 'weaving the ...
Amir Hajiha's user avatar
0 votes
0 answers
45 views

Creating Dymamic Method throws en exception

I want to create some dynamic method whcih has 2 cycles: in first some N values are pushed onto evaluation stack, in second - these N values are popped from stack. But CreateMethod throws ...
Tadeusz's user avatar
  • 6,483
1 vote
0 answers
70 views

Is managed code generated after compilation?

NOTE: Just want to clarify if my current understanding is correct after I came across a MSDN doc which seems to contradicts another MSDN doc. Also I have already been through the following links - Is ...
phougatv's user avatar
  • 921
3 votes
2 answers
1k views

Why does CMake set -no-fat-lto-objects when I enable LTO/IPO?

I'm enabling IPO (inter-procedural optimization) for a C compilation of mine, using CMake: set_property(TARGET foo PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) As expected, this causes an -flto ...
einpoklum's user avatar
  • 121k
0 votes
0 answers
51 views

Get ToString-expression from compiled class using reflection?

I have a class such as: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public override string ToString() => $"{LastName}, {FirstName}&...
Andreas Zita's user avatar
  • 7,282
4 votes
1 answer
161 views

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 ...
Vagaus's user avatar
  • 4,172
0 votes
0 answers
237 views

How to generate LLVM IR code to call C++ STL function?

I want to generate LLVM-IR that contains a call to a C++ STL function. e.g. std::sort(). I think I need to go through following steps to achieve the task. Link std::sort() into the IR Get a reference ...
lonelyjoe's user avatar
  • 115
-1 votes
1 answer
284 views

Why are the variables "i" and "j" considered dead in the control flow graph?

I was going through the topic of induction variable elimination in the red dragon book, where I came across the following example. Consider the control flow graph below : Fig. 1 : Original Control ...
Abhishek Ghosh's user avatar
5 votes
0 answers
941 views

How are "indirect triples" more advantageous than "quadruples" in the intermediate representation of source program

Consider the assignment, a := b*-c + b*-c. Fig. 1 Quadruples for the above statement Below is an excerpt from the red dragon book. Indirect triples can save some space compared with quadruples if ...
Abhishek Ghosh's user avatar
1 vote
1 answer
296 views

Using nvdisasm to generate control flow image of PTX code

I have a single file of CUDA code compiled to intermediate language PTX code, example.ptx. I would be interested to start poking around with this short file, trying to understand how it works. I don't ...
Toothery's user avatar
  • 155
2 votes
1 answer
197 views

ECMA CLI spec: initobj instruction description for value types

The ECMA CLI spec has the following statement in the description for the initobj CLI instruction: "If typeTok is a value type, then after this instruction is executed, the instance is ready for a ...
Wizard Brony's user avatar
5 votes
0 answers
372 views

How does the "ThrowHelper" .Net Framework class help lessen the generated IL code?

I was looking at this and it its starting comments it says it exists because throw new ArgumentNullException("key", Environment.GetResourceString("ArgumentNull_Key")); generates ...
user14092802's user avatar
1 vote
1 answer
877 views

Change C# code inside DLL programmatically

I got .net dll (originally, written in C#) which is being updated / released from time to time. There's a small part of code I need to modify inside this dll which suits my usage needs. I'm able to do ...
WhiteAngel's user avatar
  • 2,624
1 vote
0 answers
167 views

How to design an intermediate representation for language with a nested functions?

I am writing a compiler for language with nested functions. I decided to use display to access local variables of outer functions from inner ones, I don't know how to represent writing of activation ...
cyberfined's user avatar
0 votes
0 answers
339 views

Delete part of IL language condition

I am working on reverse engineering, Now I have I condition line of while statement while (!flag && \u0003\u001A\u0007.\u0001(this.\u0001, 0, false)) That it is meets these lines in IL ...
JustMe's user avatar
  • 6,075
2 votes
1 answer
263 views

Efficiency of load-value instructions versus load-address instructions for fields of structs

Consider the following C# struct definitions: public struct A { public B B; } public struct B { public int C; } Also consider the following static method: public static int Method(A a) =&...
Wizard Brony's user avatar
0 votes
1 answer
199 views

GCC flags to get LTO bitcode

I have been using LLVM/Clang and its Intermediate Representation(IR) for a while now. I have recently started working with GCC. I want to dump IR bitcode to a file, similar to (-flto -save-temps flag)...
kshh23's user avatar
  • 36
1 vote
1 answer
110 views

ECMA CLI spec: stack transition diagram notation for CIL instructions

I have been reading the ECMA CLI spec: http://www.ecma-international.org/publications/standards/Ecma-335.htm and I'm puzzled by the use of commas within the stack transition diagrams for some of the ...
Wizard Brony's user avatar
0 votes
0 answers
226 views

Same method body, different GetILAsByteArray result

I am looking for a way to check at runtime which overrides of GetHashCode do nothing else than to simply call a particular static method. I'm close, but there are minor differences that I cannot ...
Timo's user avatar
  • 8,180
3 votes
0 answers
70 views

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 ...
ForceBru's user avatar
  • 43.8k
0 votes
1 answer
2k views

How can I create a class at runtime in c#? I want the class to be created physically in my file system

I am developing an extension that must create classes with just the user giving class name and property info and some more which i will be extending later. I also want to add necessary namespaces. I ...
Naresh_drake's user avatar
0 votes
0 answers
74 views

How do compilers implement dataflow analysis for arrays and pointers due to aliasing related to array indices and pointer addresses

I have looked online through google search for the above question but didn't find a easy to understand high-level idea of the approach for it. I have read through the Engineering-a-Compiler Textbook ...
Joe Black's user avatar
  • 635
1 vote
0 answers
964 views

Expected relocatable expression

I'm trying to compile a sample from Multiboot 2 specification on MacOS using LLVM but I failed at the start. I want to create an object file from boot.S with included multiboot2.h so I call gcc -m32 ...
Denis Steinman's user avatar
2 votes
0 answers
673 views

Generate IL-Code / DLL and persistently save it

Currently I am developing a programming language and a compiler. I use antlr as a parser generator and I am implementing everything in C# targeting .Net Core 3.1 At the moment I am compiling my ...
Lars Behl's user avatar
  • 253
1 vote
1 answer
325 views

Where can I find QEMU (TCG)'s / LLVM IR operational semantics?

Is anyone aware pf any public QEMU's TCG operational semantics description? I rather found something about LLVM, but I'm not sure if these two are quite similar? especially that TCGs use sometimes ...
noureddine-as's user avatar
0 votes
1 answer
233 views

debug low level gcc intermediate code representations

In connection with this question I have another question. I managed to reproduce it and I do not copy paste the code here again, as you can find the code. I paste only the output of compilation on my ...
alinsoar's user avatar
  • 15.4k
1 vote
1 answer
703 views

how to use mono.cecil to inject a function call having optional parameters?

I am trying to weave an assembly by using mono.cecil library. I am injecting a function call at a place in the assembly. The function call has some optional parameters. But when I inject without ...
Ankit Choudhary's user avatar
0 votes
0 answers
107 views

How to ILEmit a function from another DLL?

I'm trying to create a .exe file and this file has to call a function that is allocated in another DLL. I can load the DLL correctly and the type and the method are referenced correctly but it gives ...
Manuel Dias's user avatar
0 votes
2 answers
109 views

Field initializer is in constructor in IL, but not when debugging in Visual Studio

In IL code,the field initialization is in constructor. Field initialization in Constructor But in VS2017 debug ,the field initialization is not in constructor, but in class. Field initialization ...
MUYA's user avatar
  • 37
1 vote
1 answer
221 views

System Field Acess Exception from Reflection.Emit derived class

I have a dynamically generated class that needs to access a field from the base class. I keep getting this exception: Exception System.FieldAccessException: 'Attempt by method 'AutoGenRelay....
Bercovici Adrian's user avatar
2 votes
1 answer
481 views

How to use conditional in Reflection.Emit

Hello i am generating a class using Reflection.Emit and i want to know how do you use brfalse command for conditionals. Specifically i do not know how do i translate the IL to OPCODES for the brfalse....
Bercovici Adrian's user avatar
4 votes
1 answer
171 views

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 ...
smoyer's user avatar
  • 7,992
0 votes
0 answers
41 views

Casting errors with conversion operators

I am getting an Invalid Cast Exception when doing Bar = IFoo but not when Bar = Foo even though that during run time the IFoo object is of Type Foo. The issue here is that the assemblies that work ...
user avatar
3 votes
1 answer
574 views

Intermediate Code Generation on Functions

I am following Compiler design and I found the following problem. int fact(int n){ if(n==0) return 1; else return (n*fact(n-l)) } for the above code, following was given as the intermediate ...
Klaus's user avatar
  • 1,641
3 votes
1 answer
442 views

Modifying IL code causing InvalidProgramException at runtime

Im trying to remove the subscription to the Tick event in IL Code so that it wont ever fire. Here is the IL Code: IL_0e19: ldftn instance void App.Framework.MainForm::mTimer_Tick(object, ...
CathalMF's user avatar
  • 9,807
2 votes
1 answer
500 views

Pros and cons of graphical and linear intermediate representation in compiler design?

There are two kinds of intermediate representation (IR) in compiler design, briefly introduced here: graphical (e.g. abstract syntax tree) and linear (e.g. LLVM IR). What are the pros and cons of the ...
Leedehai's user avatar
  • 3,740
0 votes
1 answer
655 views

Backpatch to flow-of-control of FOR LOOP

I am looking for Backpatching in FOR-LOOP. I know this approach at IF-THEN-ELSE is in this way: IF '(' expr M ')' stmt N ELSE L stmt L { backpatch($4, $9 - $4); backpatch($7, $11 - $7); } You ...
Mohsen's user avatar
  • 11
1 vote
1 answer
693 views

Why does SPIR-V use a "4 byte" code, or "Word code"?

According to the SPIR-V 1.3 specification, as I understand it, all instructions are segmented in 4 byte words. This is different from traditional byte code IR languages like Pythons byte code and Java'...
Krupip's user avatar
  • 4,476
4 votes
1 answer
1k views

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 ...
Mike Chamberlain's user avatar
1 vote
1 answer
71 views

Automatically convert code from one representation to another?

Is there a way to convert code from one high-level representation to another? For example, in Javascript, a popular way of maintaining state is with a third-party library called Redux. VueJS on the ...
U Avalos's user avatar
  • 6,608
0 votes
1 answer
793 views

Performance and compilation of null propagation operator

This is specifically referring to some C# properties I want to rewrite. Example of one of the original properties: public double? PartQuantity { get { if( MaintenanceRequestPart != ...
Jmaurier's user avatar
  • 777
1 vote
0 answers
41 views

Consume Scala syntax-trees from external tool

I would like to develop a tool that would consume scala syntax-trees (as the title suggests). More specifically it would be great if I could consume the trees after each compilation phase. My ...
Than21's user avatar
  • 321
3 votes
1 answer
122 views

Scala compiler output after cleanup phase

I would like to develop a tool that post-processes a scala program once all the heavy lifting has been completed by the Scala compiler. From what I understand the different phases of the Scala ...
Than21's user avatar
  • 321