5,872 questions
4
votes
2
answers
172
views
How to manage ownership of recursive AST nodes with std::unique_ptr in C++17?
I’m writing a small C compiler front-end in C++17 as a learning project.
My parser builds an AST for expressions, and I’m not sure about the best way to handle ownership for child nodes.
Here is a ...
Advice
3
votes
5
replies
89
views
How are loops that modify a state implemented in SSA form?
If I, for example, create my own strlen as such:
unsigned strlen(char *str) {
unsigned len = 0;
while (*str++) len++;
return len;
}
How would this get converted into an SSA form? I've ...
0
votes
0
answers
38
views
Getting "error: No instructions defined!" while building an LLVM backend based on GlobalISel
I am writing an LLVM backend from scratch for a RISC style target architecture, so far I have mostly been able to understand the high level flow of how LLVM IR is converted to MIR, MC and finally to ...
-3
votes
1
answer
131
views
Is the GCC bootstrapping 'chain' improved / simplified relative to 2021?
In 2021, this post here on StackOverflow:
How are GCC and g++ bootstrapped? -> Andrius Strikonas' answer
explained how GCC can be bootstrapped beginning with a tiny assembler taking just a hex dump ...
0
votes
0
answers
84
views
Why is the printk Function Not Visible in /proc/kallsyms on WSL2, But _printk Is Present?
I'm working with WSL2 on Windows, running Ubuntu (and I've tried Arch as well), and I'm encountering some odd behavior with the Linux kernel symbols, specifically around the printk function. It feels ...
1
vote
1
answer
66
views
Superfluous Phi Functions in Self-Loop Converted to SSA
Consider the following statements
10: a = 1
20: b = a
30: a = 2
40: goto 20
This breaks down into two basic blocks: the entry point
# Block 1
10: a = 1
and an infinite loop
Block 2
20: b = a
30: a = ...
1
vote
0
answers
67
views
Bison precedence is behaving unexpectedly with %prec for non operator precedence
I'm trying to remove shift reduce errors in a grammar which just recognizes if-else constructs, using the %nonassoc and %prec. I know there are other ways to solve this, but I'm just trying for my own ...
0
votes
0
answers
81
views
Custom programming language offside rule implementation using Flex/Bison
I am developing a compiler for a custom programming language. The initial parsing is done using Flex and Bison tools. The language supports statement blocks that are implemented in two different ways. ...
1
vote
0
answers
80
views
How does the lexer handle tokens that are concatenated together?
Let me give you an example. In a language like Java, we have code like this:
class className {
}
In this example, if className is concatenated to class, and also className is concatenated to {, how ...
1
vote
1
answer
68
views
Is it possible to make Bison utilize external token definitions?
I am working on building a compiler using Flex/Bison, and tried to utilize a tokens.h file to define the tokens used by the parser and lexer.
#ifndef TOKENS_H
#define TOKENS_H
enum TokenType {
...
1
vote
1
answer
108
views
To what extent can I expect the original FIRRTL compiler to optimize?
For now I am still using the final release of the original FIRRTL compiler that was archived in 2024.
I am using to software compilers going to great lengths to optimize code, performing constant ...
1
vote
1
answer
102
views
Is LR(0) GOTO different from LR(1) GOTO?
I'm writing an LALR(1) parser generator, and am getting a bit confused about the use of the GOTO function in creating the parsing table. I've been following the dragon book. The grammar I have been ...
1
vote
1
answer
338
views
What are the proper conventions for x64 assembly functions on Windows?
I've been messing around with assembly and compilers & have gotten a lot of conflicting information in how I should be using registers, the stack / spill over registers, and to what extent ...
1
vote
0
answers
69
views
Compiler Design - Question on third-order recursion in relation to expression grammar
In the "Compiler Design in C" book, below is a table on a simple expression grammar.
According to the below excerpts:
Note that the grammar is recursive. For example, Production 2 has ...
1
vote
0
answers
53
views
LALR Parser Shift/Reduce Conflict
I am writing a microJava compiler and I am currently implementing class logic. So far I have implemented field logic but I am struggling with method access. The code bellow is working properly (for ...