/r/Compilers

Photograph via snooOG

This subreddit is all about the theory and development of compilers.

For similar sub-reddits see:

Popular mainstream compilers:

/r/Compilers

18,421 Subscribers

29

Engineering a Compiler vs Dragon Book

I would like to start learning compiler theory (preferrably also with examples) and wanted to know which book would be a better option to start with, considering the up-to-date landscape of compiler engineering. I want to direct myself towards compiler optimisations, codegen, LLVM/MLIR-based compiler back-end projects afterwards. I was stuck between these two books and wanted to ask you guys which could be a better option to start?

Also, if "Engineering a Compiler" is your answer, is there a big difference between the 2nd and 3rd editions of the book? People seem to say the difference is definitely not worth the ~70€, since the former is available online.

Any other recommendation for practical examples, tutorials, books, video series are also welcome :)

13 Comments
2024/04/29
15:45 UTC

28

Careers in low level programming?

I have a cs degree and work in IT as a sys admin.

I recently spent about a year making a compiler and VM with a stack and heap by hand.

I made my own instruction set and my own programming language. It’s a dumbed down version of Java.

I absolutely loved it.

Is there any sort of career path I can take? I’m even considering going to grad school to major in computer engineering.

12 Comments
2024/04/28
19:43 UTC

12

Instruction selection on Sea of Nodes IR

Hi, I'm looking for any information on instruction selection for sea-of-nodes based IR. I've seen many books and papers talk about instruction selection on linear sequences or trees/DAGs, but I couldn't find anything particularly useful about implementing it on a potentially cyclic IR graph. It's my first time actually getting to the stage of writing a backend, so I'm not very experienced and am struggling to come up with a reasonable approach, both in terms of the algorithm and the possibility of implementing it in code. I'd be grateful for any suggestions!

5 Comments
2024/04/27
22:38 UTC

0

IS THERE A WAY TO CHANGE SHADERS COMPILED into ELF TO DXBC?

2 Comments
2024/04/27
15:16 UTC

4

Applying Synchronous Dataflow Graphs to FIFO-based systems

Hi everyone,

Not sure where to post this question, so I chose r/Compilers. Let me know if you think there is a better place to post.

I am working on an architecture that consists of FIFOs and delays nodes. I want to use Synchronous Dataflow Graphs to model the system for calculating backpressure, max throughput etc.

Say I have a system that looks like the below where I can only send data when all receiving FIFOs are not full and only accept data when all sending FIFOs are not empty. The maximum throughput of this would be 1 output every 2 cycles (1/2).

https://preview.redd.it/korsy6ibxvwc1.png?width=750&format=png&auto=webp&s=1bfa1012486e69d71ca86cab84a66312548c3ed5

To model it as an SDF, I would replace each fifo with a node with backpressure like the below figure and this makes sense to me.

https://preview.redd.it/qgk1z26hxvwc1.png?width=1002&format=png&auto=webp&s=bfbdd15f61ab775fa88121f5a6238de07e058cc4

Here the maximum cycle ratio is 2 which matches the maximum throughput. But my issue is I have 6 elements in my circuit but only 4 actors in my SDF. How do I model the delay of each element if they are not all 1?

I think I am missing something when it comes to the nodes that broadcast and merge data.

1 Comment
2024/04/26
20:43 UTC

6

Want to deeply understand Theory of computation

Hey I have studied Theory of computation but i am having difficulty understanding and relating it with compiler so for i want to focus all my atte on Theory of computation and want to make my own grammar for my language so anyone here can suggest me a good resource that is intuitive and really good to understand Theory of computation from ground up to a expert level

6 Comments
2024/04/26
19:39 UTC

5

Decidability proofs.

Hi all.

I am trying to understand the proofs of the decidability problems for regular language, dcfl, CFL CSL RECL REL like membership, subset problem. Emptiness problem, closure in intersection and union etc etc.

Can someone tell me which book or resources can I follow to getting proofs to all these problems? I have already read Michael sipser. And have found it pretty useful. The proofs are complete but it is not having proofs to all the decision problems.

So I need names of resources, or books where I can find these proofs.

Thanksyou.

2 Comments
2024/04/26
07:25 UTC

1

Migration from python

I created a simple compiler for a language in python and I am just wondering when I should rewrite the compiler in the language itself or should I rewrite in a language like c++ first?

7 Comments
2024/04/26
04:25 UTC

24

Good first book to learn how to build a compiler for a beginner

Hello everyone, (thanks to anyone who's reading this)
Context -> I am freshman at UIUC(will become a sophomore in this coming fall sem)who wants to learn more about how computer systems and programming in general work beneath the hood and I thought learning how to build a compiler will be a hard but rewarding challenge to take up in this summer break.
I looked into the dragon book but i am confused cause some people were saying that it is too academic and less practical, I also looked into Crafting Interpreters but I am not able to decide on which book should I follow.

21 Comments
2024/04/25
18:27 UTC

2

Instruction Pointer relative addressing vs Page relative addressing

I was toying around with Compiler Explorer and tried running this program. One difference between the x86 and aarch64 architectures I noticed was the Instruction Pointer relative addressing to load the strings that are arguments to the levenshtein_distance function. Arm on the other hand uses the adrp instruction and then adds the offset via normal add instructions. Is there a logical reason why the architectures deviate in this regard? Does this have something to do with ARM having 32 bit fixed length instructions? Also does this have anything to do with clang/gcc generating PIEs?

1 Comment
2024/04/24
04:27 UTC

4

Torben mogensen introduction to compiler design

I'm looking for assistance with solutions to exercises from Torben Mogensen's 'Introduction to Compiler Design' (2nd edition). Could someone help me with this?"

0 Comments
2024/04/24
04:25 UTC

8

Can ambiguity be useful?

I remember seeing someone saying that an ambiguous grammar could be useful in some scenarios. I'm still learning basic concepts about compilers so I can't think of how ambiguity could be useful in compiler design. Is this a real thing? If so, can someone give me an example?

8 Comments
2024/04/23
23:16 UTC

0

Cross Compiling Apache- TVM runtime for QNX SDP 7.0.0

What are the steps to cross compile model to QNX OS, what compilers or gnu need to be installed on host machine? also to install the tvm runtime for QNX what should be the cmake instructions? also the hardware I am using is ARM cpu with neon processor so what should be the target device for cross compilation?

0 Comments
2024/04/23
11:35 UTC

4

A question about implementing custom syntax for functions

Hey everyone, I am starting to develop my language and thought of faking for loops using while loop as a custom function For this purpose I am trying to enable users to declare custom syntax for functions so everything else is much easier to implement and modify in the long run But thinking about this, though giving me some ideas about how to approach this, really didn't seem too intuitive for a language that's easy to read and write so any suggestions or another idea for implementation! any good suggestions are welcome and thanks for all the support given by all.

25 Comments
2024/04/23
07:23 UTC

24

Speed of Bytecode Compilers

There was a throwaway compiler test I used to do, which went something like this, obviously varying by language:

a=1
b=2
c=3
d=4

a=b+c*d

print(a)

It was simple enough to be easy to write in any language after you'd managed to run Hello World. Once this worked, the a=b+c*d line was repeated up to 2M times.

As a test, it was not highly regarded, especially when all the code had to be in a single function - not exactly typical real-life code. Nevertheless, I was curious as to how a language implementation would cope when presented with such a stress test. Maybe it would show up weaknesses not apparent in smaller tests.

I repeated some of those tests today, but concentrated on bytecode compilers and dynamic languages, using 2M lines of code.

Here are some results run on a Windows PC. The code is outside a function unless stated. Figures shown are elapsed time from submitting source code until the result (14) is displayed. They will include any extra passes, like fixups, that are needed, and they include executing those 2M lines, but that is usually insignificant:

CLox       0.5 seconds (inside func; 2 seconds unoptimised)
Pascal-S   0.7 seconds (1.1s unoptimised; port of a tiny-Pascal compiler, statically typed)
LuaJIT     1.0 
QQ         1.0         (my product; 1.3 seconds unoptimised)
Lua        1.7         (3.8 seconds unoptimised; updated to use locally built version) 
Ruby      14   
CLisp     16   
Perl      30           (Showed output in 20 seconds, finally terminated in 30)   
CPython   35   
PyPy     150           (JIT product)
A68G       -   failed  (10K lines took 0.5 seconds; statically typed language)

I included CLox to show the possibilities, although it is not a full spec language and is a little fragile.

My own 'QQ' product uses multiple passes. I did have a cut-down version that was much faster, but I had to make too many concesssions so I dropped it.

These languages are generally run from source code so compile-times matter. While programs tend not to be huge, a slow bytecode compiler can still introduce noticeable delays. Here there is usually no reason for it to be too slow, unlike compiled, statically typed languages.

(I did one more test, which was for Basic via my own Basic interpreter. That couldn't be included above as it doesn't conform: lines are parsed each time they are executed; there is no separate compile step and no bytecode.

Still, it finished the test in 14 seconds which has to include parsing those 2M lines. But the Basic interpreter was itself run under my QQ interpreter mentioned above).

Conclusion: I think some products could do better. The 2m30s of PyPy might be partly justified, in needing to set the scene for a complex tracing-JIT process, but LuaJIT doesn't seem to let that hold it back!

20 Comments
2024/04/21
23:04 UTC

1

Creating the parser tree while SLR parsing

Hello people, i'm making a SLR parser in C++ for arithmetic expressions ─ using +, -, /, * and (), aside the numbers ─ for a project. The lexing is pretty easy to do, but i can't think in a good way of creating the parsing tree while i run the algorithm. I tried to put the created nodes in a stack and poping them when a reduce occurs, but i can't generalize because of the different types of nodes i have to create, leading for various stacks and a ugly code flow. What are the best ways to do this tree creation? And sorry for any english mistakes, not my first language.

5 Comments
2024/04/21
15:01 UTC

57

How do I get into ML compilers?

Hello! C++ dev here and I'm getting a little bored of mucking around in embedded. My big bet is that ML compilers (as in, compiling models to run efficiently on target hardware, not using machine learning to optimize code compilation) is gonna get exponentially more important as compute needs for LLMs get bigger.

I also just think this field sounds super sick.

So how do I get into it? So far I've thought of:

  • actually understand how neural nets work (my knowledge is pretty hand wavy)
  • find OSS projects to contribute to (I'd love a list of good ones that are friendly to contribute to)
  • learn general programming language compiler knowledge (LLVM kaleidescope tutorial, crafting interpreters)

Thoughts? Am I going down the right path?

9 Comments
2024/04/21
01:47 UTC

16

Toy python to x86 compiler now works with libc calls -- simple example shown

I fork/modded BenHoyt's python to x86 compiler to also work with C library calls and strings on Linux:
https://github.com/HPCguy/pyast64

def main():
   fp = fopen('myfile', 'w')
   fputs(r'hello world!\n', fp)
   fclose(fp)

.section .text
#
.globl main
main:
pushq   $0
pushq   %rbp
movq    %rsp, %rbp
movq    $str1, %rsi
movq    $str0, %rdi
call    fopen
movq    %rax, 8(%rbp)
movq    8(%rbp), %rsi
movq    $str2, %rdi
call    fputs
movq    8(%rbp), %rdi
call    fclose
movq    $0, %rax
popq    %rbp
leaq    8(%rsp),%rsp
ret

#
.section .data
str0:
.asciz "myfile"
str1:
.asciz "w"
str2:
.asciz "hello world!\n"

Upvote1Downvote0comments

21 Comments
2024/04/20
10:23 UTC

17

Was skimming Interpreter Book by Thorsten Ball, are those shots fired at Crafting Interpreters?

16 Comments
2024/04/20
03:52 UTC

24

Fun language called Occult

Over the past 8-9 months (with some breaks) I wrote a programming language which cross-compiles to C

Its basically stripped down rust + c like components and a garbage collection for dynamic arrays as the base array type

To be fair, this is my first big project, and I went into it knowing nothing, still working on it for fun, I want to complete it and then do a second version with a revised code-base because the current one isn't that good

FYI please don't judge the code, I mean I would like feedback, I know a huge portion of it is spaghetti!

If anyone wants to check it out, here https://github.com/occultlang/occult

0 Comments
2024/04/18
03:20 UTC

Back To Top