12 votes
Accepted

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

In the case of LLVM IR, I think the point here is not backpatching an address, but backpatching a label. If the label is "created" at the point where it is in the code, any forward jumps to ...
Pseudonym's user avatar
  • 21.6k
5 votes

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

Update Based on your comment, I'm not concerned so much about switch statement being inefficient as I am by the fact that the switch statement exists at all. , I think that I understand the ...
Nat's user avatar
  • 1,341
4 votes

How to generate branch tables from SSA form?

The book "A Retargetable C Compiler: Design and Implementation" by Christopher Fraser and David Hanson gives some detail on how they lower switch statements to a ...
Tim Foley's user avatar
4 votes
Accepted

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

In general when we talk about code generation (or model-to-model transformation in general), clearly defined semantics is quite important, since such transformations usually make sense when both the ...
ivcha's user avatar
  • 540
4 votes
Accepted

Implementing a Compiler with Macros

Yes and no. Yes, you could structure a compiler this way, but most of the benefits you are hoping for would not materialize. There may be some benefits, such as a powerful compile-time meta-language. ...
Derek Elkins left SE's user avatar
3 votes
Accepted

How to Identify which instructions are represented by this microcode

Microcode instruction sets typically have more fields than ordinary instruction sets. Sometimes this is called wide word, as a very long instruction can offer access to multiple hardware components ...
Erik Eidt's user avatar
  • 451
3 votes

Why do compilers produce assembly code?

Usually compilers work internally with sequences of instructions. Each instruction will be represented by a data structure representing it's operation name, operands and so-on. When the operands are ...
Peter Green's user avatar
3 votes

Why do compilers produce assembly code?

Even platforms that use the same instruction set may have different relocatable object file formats. I can think of "a.out" (early UNIX), OMF, MZ (MS-DOS EXE), NE (16-bit Windows), COFF (UNIX System V)...
Damian Yerrick's user avatar
2 votes

Is there a described algorithm converting _from_ Continuation Passing Style?

From "Back to Direct Style" by Oliver Danvy: Much work has been devoted to transforming programs into continuation-passing style (CPS). ... By contrast, programs that are not in CPS (e.g., ...
Mike Samuel's user avatar
  • 1,194
2 votes

How are codes like 5421 and 2421 unique?

Codes like 5421 and 2421 are not unique, and this is one of their advantages. For example, 2421 is self-complementing: computing the 9-complement of a digit is the same as negating its bits. In ...
Yuval Filmus's user avatar
2 votes

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

It is reasonably common nowadays that code is recompiled on occasion. For example, a JVM compiler will initially assume that some function call is not virtual (but can be proved wrong). It will then ...
gnasher729's user avatar
  • 28.4k
2 votes

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

Unroll the loop. Instead of while true: switch on var: 1 => branch1 2 => branch2 default => branch3 replace that with an unrolled version:...
D.W.'s user avatar
  • 156k
2 votes
Accepted

How to build 4 codewords with a code distance of 5?

0000000000 1111100000 0000011111 1111111111
Yuval Filmus's user avatar
2 votes
Accepted

What makes a nested function in gcc so complicated?

I don't see any obvious reason why the compiler could not inline the call to list_traverse, assuming that it is a simple and that its definition is available in the ...
rici's user avatar
  • 11.9k
2 votes
Accepted

Generate code from automata

A simple way to do it is to just write an interpreter that follows the transition table. I.e., do something like (in C): ...
vonbrand's user avatar
  • 13.9k
2 votes
Accepted

Can algorithms of arbitrarily worse complexity be systematically created?

Yes, of course. $2^{f(n)}$ is asymptotically larger than $f(n)$, so you can come up with an unending sequence of larger and larger running times. The answer to your other questions are also yes, by ...
D.W.'s user avatar
  • 156k
2 votes

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

When emitting textual assembly code, backpatching is not strictly necessary, as long as you can predict what the label of a destination is going to be even if that destination is in the future. There ...
harold's user avatar
  • 2,018
2 votes

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

I haven't seen anything on this but the closest I could find is Evolving Algebras: Evolving Algebras: An Attempt to Discover Semantics Evolving Algebras: Mini-Course Communicating Evolving Algebras ...
Lance's user avatar
  • 2,163
2 votes

time complexity of loops

Conside Geometric progression $1+2+4+8+...+n=2n-1$. So time complexity is $O(n)$.
Jxb's user avatar
  • 318
1 vote

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

I realize that Java bytecode uses (absolute/relative) address offset instead of (symbolic) labels in its jumping instructions such as goto. Then I know that ...
hengxin's user avatar
  • 9,501
1 vote
Accepted

Is there a computer science theory behind automatic source code generation

I don't know anything about it but the field as a whole is called "automatic programming", which should give you pointers of where to look.
David Richerby's user avatar
1 vote

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

I'm going to simplify your question, considering that a specific encoding for a universal Turing machine will necessarily include a method for the encoding of its programs. I'll also assume that the ...
André Souza Lemos's user avatar
1 vote

How to generate (Java) source code in academically acceptable way - using abstract syntax tree?

It highly depends on what is the domain you are working on, i.e. why do you need to generate Java Source code anyway?. Can you explain better what knowledge do you have stored in your knowledge base?....
bones.felipe's user avatar
1 vote

How to represent software code for code generation / automatic programming? How to integrate procedural and declarative knowledge?

Use some form of metamodelling : The outputs are represented as abstract syntax trees (ASTs): and constructed by a decoder with a dynamically-determined modular structure paralleling the ...
Paul Sweatte's user avatar
1 vote
Accepted

What is the quickest way to allocate a set of points to a fixed number groups based on Euclidean distances from a point in each group?

This looks very much like the Nearest neighbor problem. The asymptotically most efficient approach is probably computing a k-d-tree on the points in B. Constructing the tree takes $O(|B| \log |B|)$ ...
adrianN's user avatar
  • 5,931
1 vote

Why do compilers produce assembly code?

A compiler should be able to produce an assembler output in addition to the normal relocatable code is for the benefit of the programmer. One time I just not find the bug in a C program running on ...
Robert Pearson's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible