Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
GoでCコンパイラを作った話
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
repunit11
July 21, 2026
Technology
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GoでCコンパイラを作った話
repunit11
July 21, 2026
More Decks by repunit11
See All by repunit11
パーソナライズPodcastを作った話
repunit11
0
120
Goから始める低レイヤ
repunit11
0
48
-共通テストから学ぶ- ネットワークにDeep Dive
repunit11
0
37
技術カンファレンスはただの学び場ではない「最高の遊び場だ」
repunit11
0
42
Other Decks in Technology
See All in Technology
HacobuにおけるFDEとは/登壇資料(戸井田 裕貴)
hacobu
PRO
1
770
FinTech 1-2 : Overview of FinTech
ks91
PRO
0
140
メルペイ 会計システム概要と歴史
mewuto
0
150
個別開発で終わらせない。 現場の課題をプロダクトの強さに変える StockmarkのFDE
ktkrhr
0
580
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
350
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
3
680
2026-10-01_MagicPod_QAハーネスエンジニアリングとQA組織の未来像
ynisqa1988
1
520
Codex概要
ymiya55
0
350
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
490
Futexes the good, the bad, the ugly
ennael
PRO
0
120
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.4k
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
120
Featured
See All Featured
WCS-LA-2024
lcolladotor
0
840
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
550
Designing for Timeless Needs
cassininazir
1
520
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Visualization
eitanlees
153
17k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Code Review Best Practice
trishagee
74
20k
A better future with KSS
kneath
240
18k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
600
Transcript
GoでCコンパイラを 作った話 Fukuoka.go #23
自己紹介 レプ # seccamp 26 # Go言語 @repunit11 # 分散アルゴリズム
# システムプログラミング # マジック # アニメ # ステッカー帳 2
目次 01 自作Cコンパイラの紹介 02 printの実装 3
自作Cコンパイラ の紹介 4
コンパイラとは ソースコードを別の言語や形式に変換するプログラム Cプログラム アセンブリ コード コ ン パ イ ル
自作Cコンパイラの紹介 オブジェクト ファイル ア セ ン ブ ル 実行 ファイル リ ン ク 5
コンパイラとは ソースコードを別の言語や形式に変換するプログラム 今回:C言語からLinuxx86-64アセンブリへの変換 Cプログラム アセンブリ コード コ ン パ イ
ル 自作Cコンパイラの紹介 オブジェクト ファイル ア セ ン ブ ル 実行 ファイル リ ン ク 6
コンパイルの流れ シンプルなコンパイラのステップ 字句解析 構文解析 トークン AST 抽象構文木 自作Cコンパイラの紹介 意味解析 最適化
コード生成 型システム 中間表現 IR アセンブリ 7
実際にコンパイルできるもの 自作Cコンパイラの紹介 8
Cコンパイラを作ろうと思った理由 去年の12月ごろ:低レイヤ開発に興味が出てきた CコンパイラをC言語で書く教科書はあるのでそれをやってみる Goが好きなのでGoで実装してみる この登壇を機にprintを実装した 自作Cコンパイラの紹介 参考にした教科書:低レイヤを知りたい人のためのCコンパイラ作成入門 9
printの実装 10
実装したprintの内容 printの実装 11
printの仕組み print:メモリ上の文字列を標準出力へ書き出す処理 ~処理の流れ~ 文字列を用意する アドレスと長さを指定する writeシステムコールを呼ぶ ファイルディスクリプタ、配置されているメモリアドレス、文字数 (0:標準入力、1:標準出力、2:エラー出力) printの実装 12
システムコールとは printの実装 13
アセンブリでHello Worldする方法 x86-64 上のLinux printの実装 引用:『Goならわかるシステムプログラミング 第2版』 14
Goパッケージのシステムコールの実装 システムコールをアセンブリから呼び出したいとき 使いたいシステムコールの番号、引数をネットやmanを使って調べる syscallパッケージを読もう printの実装 15
Goパッケージのシステムコールの実装 syscallパッケージ:GoからOSのシステムコールを呼びだすためのパッケージ Goはlibcを経由せずにシステムコールを呼べる システムコールがOSまで届く流れをGoのソースコードだけで追いやすい 今回参考にした実装:syscall/zsyscall_linux_amd64.go ※ syscallパッケージは現在は更新されていないので、新しく使いたい場合は golang.org/x/sys/unix を使うべき printの実装
詳しくは:https://go.googlesource.com/proposal/+/refs/heads/master/design/freeze-syscall.md 16
まとめ 17
まとめ CコンパイラをGoで実装してみた アセンブリでシステムコールを呼びだす方法 システムコールの使い方はsyscallパッケージに書いてあるので助かる まとめ 18