A Linux command line compiler explorer script inspired by this article by Matt Godbolt. See the repo that generated this page.
sudo apt update
sudo apt install g++ curl entr gedit
git clone git@gitlab.com:germs-dev/explore
cd explore/
Below I’m splitting my terminal with tmux
and running
the main script when the source changes using entr
.
ls main.cxx | entr -c bash explore.sh
But you can also use this wrapper script to edit in
gedit
.
bash run.sh
explore.sh
This command really is the core of godbolt.org, edit your compiler flags here.
readonly CXXFLAGS="-std=c++23 -O1"
g++ main.cxx $CXXFLAGS -S -o - \
| c++filt \
| grep -vE "\s+\.|^[0-9]:"
main.cxx
#include <cmath>
#include <cstddef>
int func(const size_t max) {
int sum = 0;
for (auto i = 0uz; i < max; ++i)
+= i;
sum
return sum;
}
int main() {
const auto param = std::pow(2, 13);
return func(param * 3);
}
Note the call to std::pow
has been optimised out even at
-O1
.
(unsigned long):
func.LFB1178:
endbr64%rdi, %rdi
testq $0, %eax
movl $0, %edx
movl .L3:
%eax, %edx
addl $1, %rax
addq %rax, %rdi
cmpq .L1:
%edx, %eax
movl ret
.L4:
$0, %edx
movl .LFE1178:
main:
.LFB1179:
endbr64$24576, %edi
movl call func(unsigned long)
ret
.LFE1179: