Questions tagged [code-generation]

Questions about the parts of a compiler that select assembly instructions or machine code specific to a specific target computer architecture.

31 questions
19
votes
6 answers

Why do compilers produce assembly code?

Assembly language is converted in to machine language by assembler. Why would a compiler convert high-level language to assembly? Can't it directly convert from the high-level language to machine code?
CODERSAM
  • 293
  • 1
  • 2
  • 4
6
votes
1 answer

How to generate branch tables from SSA form?

Branch tables are usually described as an efficient way a compiler can implement a switch statement, and that actually seems how GCC and Clang do it (and LLVM even has an opcode just for that). If a sequence of if statements is used (instead of a…
paulotorrens
  • 731
  • 3
  • 11
6
votes
3 answers

Is there a described algorithm converting _from_ Continuation Passing Style?

Continuation Passing Style (CPS) is a form of code where the control is passed explicitly, by passing the continuation of the code at each call point, unlike direct style. There are many descriptions in the literature for how to convert from direct…
John Källén
  • 245
  • 1
  • 6
5
votes
1 answer

Implementing a Compiler with Macros

I've been thinking about embedded languages (domain-specific or otherwise), and in particular the approach where we define a datatype to represent terms of the embedded language, e.g. (in Haskell): data Expr = Numeral Int | Apply Expr…
Warbo
  • 642
  • 3
  • 13
5
votes
1 answer

The importance of the language semantics for code generation and frameworks for code generation in model-driven development

I am implementing worflow where the code in industrial programming languages (JavaScript and Java) should be generated from the formal (formally verified) expressions (from ontologies as objects and rule formulas as behaviors). What is the best…
5
votes
6 answers

Why is backpatching needed during intermediate code generation? For what purposes?

I understand how backpatching works during intermediate code generation, but I do not understand why it is needed. A common argument for using backpatching during intermediate code generation is as follows: Suppose the intermediate code generated…
hengxin
  • 9,671
  • 3
  • 37
  • 75
3
votes
1 answer

Is there a computer science theory behind automatic source code generation

The OpenAPI specification aims at standardizing the representation of REST based systems in json and yaml formats. A short version of the petstore is below: { "swagger": "2.0", "info": {}, "host": "petstore.swagger.io", "basePath": "/v2", …
SyCode
  • 133
  • 5
3
votes
1 answer

About codes over $\mathbb{F}_2$

I was looking through these notes but I am not sure I can locate the answer to these questions of mine - it would be great if someone can just even point out what to look for! So any set of binary vectors can be seen as "code"? Let $M$ be a…
2
votes
1 answer

How are codes like 5421 and 2421 unique?

For the number 6, if I need to represent it in 5421 code form, should I code it as 1001 or 0110? Why should I choose the one over the other? Similarly for the number 5 in 2421, is it 1011 or 0101? Edit 1: In a weighted binary code, the name of the…
Anupama
  • 21
  • 1
  • 3
2
votes
0 answers

Codes for correcting a single deletion and re-ranking of a permutation

I was struggling with this paper about codes which can correct single deletion and re-ranking in permutations, http://ieeexplore.ieee.org/xpl/articleDetails.jsp?tp=&arnumber=6875337 [Published in: Information Theory (ISIT), 2014 IEEE International…
user6818
  • 1,165
  • 8
  • 13
2
votes
1 answer

Assigning one variable to another in 3 address code?

3 address code is a very common topic in many of the CS theories. I encountered it while studying Compiler Design. According to the Wikipedia article, it says - Each TAC instruction has at most three operands and is typically a combination of…
lethal
  • 21
  • 3
1
vote
2 answers

Can I program a universal Turing machine to accept arbitrary input encodings?

I've been reading about building Turing machines for specific purposes, and some sources talk about input encodings and some talk about programming specific machines, but I've been unable to find anything that discusses both. Here's a specific…
1
vote
1 answer

Software code generation from the (operational) semantics - reference request for automatic programming

Are there research trends that try to research code generation directly from the (operational or some other kind of) semantics? One can imagine cognitive architecture that discovers and reasons about the tasks that the software should do and…
1
vote
1 answer

How to Identify which instructions are represented by this microcode

I'm having issues with a question how to identify which instruction are represented by this microcode. The pc starts at 5000 and 7000 and 7001 have values 31 and 64 - I'm really confused how to approach this wouldn't each line be an instruction? …
1
vote
3 answers

Is it possible to define branches which, once taken once, will become the default forever?

Assuming I have a very simple branching: switch on var: 1 => branch1 2 => branch2 default => branch3 And I wish to implement a program that will forever take "branch2" when entering this sequence of instructions once branch2 is taken. This…
1
2 3