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
Cコンパイラ自作はじめてみた
Search
mikiken
September 17, 2022
Programming
280
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Cコンパイラ自作はじめてみた
セキュリティ・キャンプ全国大会2022アフターイベント LT発表
mikiken
September 17, 2022
More Decks by mikiken
See All by mikiken
ライフゲームの製作
mikiken
0
280
簡単な4bitCPUの作成
mikiken
0
1.6k
Webブラウザでページが表示されるまで
mikiken
0
97
seccamp2022 成果発表
mikiken
0
60
Other Decks in Programming
See All in Programming
R8 の設定見直しでアプリサイズ削減
andpad
0
230
Vue Fes Japan の “作る側”に関わってみて
naokihaba
1
200
phperだってパンチカードでコーディングしたい
o0h
PRO
0
480
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.8k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3k
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
200
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
480
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
190
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
3
600
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
130
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
240
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
120
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
620
Six Lessons from altMBA
skipperchong
29
4.5k
Believing is Seeing
oripsolob
1
250
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
47k
From π to Pie charts
rasagy
1
420
The World Runs on Bad Software
bkeepers
PRO
72
12k
Skip the Path - Find Your Career Trail
mkilby
1
260
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Transcript
セキュリティ・キャンプ全国大会2022アフターイベント
• 神戸大学 工学部 電気電子工学科 2年生 • セキュリティキャンプ全国大会 2022 L3 Cコンパイラゼミ
参加 • 多少プログラミングを触ったことはあったが、 本格的にやったことはなかった mikiken @mikikeen
• 去年、大学の授業でほぼ初めてC言語に触れた • セキュキャン応募時点(5月)では、ポインタがあまり理解できて いなかった()
• C(のサブセット)言語のコンパイラを作った • 現在も作っている
• 変数・1次元配列・関数定義までは実装済 • まだchar型がない https://github.com/mikiken/9cc
C言語のプログラム アセンブラ 機械語のプログラム コンパイル アセンブル・リンク
• • • • 中間コード生成 (やってない) • 最適化 (やってない) •
C言語のプログラム アセンブラ コンパイル
入力プログラムを意味のあるトークンに分ける
字句解析したトークンをもとに構文木を構築する
• 構文上正しいが間違っているプログラムを弾く は構文上正しいが、どうみてもおかしい • 型の情報を付与したり • キャストもここで行ったり
ここまでで生成した構文木を、再帰的に辿って アセンブラを出力する
None
• if・else・while・forといった制御構文はラベルとジャンプを 用いて実現されている
• if・else・while・forといった制御構文はラベルとジャンプを 用いて実現されている • ifやwhileをネストするとバグる
• ラベルのカウントにグローバル変数を用いていた • 関数が再帰的に呼ばれた際に、label_countがインクリメント され、ラベルに一貫した値を使えていなかった
• ここで初めてコンパイラに型を導入する必要が生じる • Compiler bookの解説が割とサラッとしていたので 実装方針が中々分からなかった • Discordでみなさんに教えてもらい、なんとか突破
他にも色々あるが、割愛
• Compiler bookを読了する • グローバル変数 • char型 • 文字列リテラル •
構造体 ︙
• フィボナッチ数列のn項目の値を求めるプログラムぐらいなら 意外と簡単にコンパイルできることが分かった。 • セキュキャン期間中、デバッグに手間取っていたところ、 深夜(というか翌朝)まで多くの方に手伝ってもらった。 ありがとうございました。
None