Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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
  • 22.2k
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,351
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
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
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
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
  • 30.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
  • 161k
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,204
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

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,243
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
  • 12k
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
  • 14.1k
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
  • 161k
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 ...
user555045's user avatar
  • 2,053
2 votes

Creating an executable after code generation - compiler design

Assembly language is basically meant to be a 1:1 representation of the underlying CPU machine code. (Yes I'm aware there are a few exceptions, especially with modern assemblers) The difference is you ...
Caleb Fuller's user avatar
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,561
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
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

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
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,951

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