ã¾ãã«ä½ã¬ã¤ã¤ã®ãã¨ãåãã£ã¦ãããã以åããæ°ã«ãªã£ã¦ãããã®æ¬ãåãæãã£ã¦ã¿ãã¨ããæãã®ã»ãã¹ã¤ã¹ã¤é²ãããã¦ãå¢ãã«ä¹ã£ã¦ã»ã«ããã¹ãï¼èªåãæ¸ããã³ã³ãã¤ã©ã§èªåèªèº«ãã³ã³ãã¤ã«ããã¨ããï¼ã¾ã§ãããã®ã§è¨å¿µã«æ¸ãã¦ãããæ£ç¢ºã«ã¯ C ã³ã³ãã¤ã©ã®ãµãã»ããã§ãã
å ¨ä½çãªé²ãæ¹ã¯ã
- ä¸è¨ã®æ¬ã®éãã«é²ãã¦ããã
- ãã以éã¯èªä½ã® 8queen ãæ®éã«æ¸ããããã«æ©è½ãå¼·åã
- ãã以éã¯ã»ã«ããã¹ããç®æ¨ã«é²ããã
- ããªããã»ããµããªã³ã«ã¯ä½ãããC ããã¢ã»ã³ããªã¾ã§ã
ã¨ããæããèªåã¯æãåãããªãã¨é²ãã§ãæ°ãããªãã®ã§ãã¾ãã¯æ¸ãã¦ã¿ã¤ã¤ããããªãæãããã°èª¿ã¹ããã¨ããã¹ã¿ã³ã¹ã§ããã
ãã¨ããã£ãããªã®ã§ RISC-V ã®åå¼·ããããã£ãã®ã§ããåãã«æ¸ãããªã®ã§å®è¡ã¯ã¨ãã¥ã¬ã¼ã¿ä¸ã¨ãããã¨ã«ãªã£ã¦ãããæ©æ¢°ã¨ä¼è©±ã§ãã¦ãæã¯çµå±å°ãªãã®ã§ãå®æ©ãã»ããã¨ããã ã
ããåèã«ããã®ã¯:
- riscv-elf-psabi-doc/riscv-cc.adoc
- N1570 April 12, 2011 ISO/IEC 9899:201x
- https://inst.eecs.berkeley.edu/~cs61c/fa17/img/riscvcard.pdf
- https://www.cs.cornell.edu/courses/cs3410/2019sp/schedule/slides/10-calling-notes.pdf
ã¨ãã
ã¡ãªã¿ã« GitHub Copilot ãæå¹ã«ãããè£å®ããã¾ãã£ã¦ã¢ãªã¢ãªæ¸ããã®ã ããããã¯ãã¶ãæ¬å®¶ã® 9cc ã chibicc ç±æ¥ã®ã³ã¼ããªã®ã§ç´°ãããã¯ã¯èªåã§ã¯æ¸ãã¦ãªãã®ã§ãã£ãã
ä¸æ¹ã§ãã¿ãã¬ã¯ãããããªãã¨æã£ã¦ããã£ã¦ããéã¯ãã¾ãä»ã®ææ¦è ã®è¨é²ãèªãã§ãªãã£ãã®ã ãã©ãã»ã«ããã¹ãCã³ã³ãã¤ã©aqcc éçºè¨ãã¨ã¦ãé¢ç½ãã£ãã®ã§èªåããã°ãæãåºããã¶ãã ãæ¸ãã¦ãããã¨ã«ãããæåã®æ¹ã¯ Scrapbox ã«ã¡ã¢ãåãã¤ã¤ãã£ã¦ãã®ã ãã©ããªãã¨ãªãã©ãé²ããã°ãããããããããã«ãªã£ã¦ããã¯ã³ã¼ããæ¸ãæ¹ã«éä¸ãã¦ããã®ã§ãã¾ããã°ããªããã³ããããã°ããæãåºãã¤ã¤æ¸ãã
2022-10-XX (day 0)
- ã¾ã RISC-V ã®éçºç°å¢ãç¨æãããDocker 㧠Linux ç°å¢ãç¨æããã¤ããã ã£ããã³ã³ãã¤ã«ã«æéããããããã¦è©¦è¡é¯èª¤ãã¾ã¾ãªãããçµå± macOS ã« Homebrew ã§ã¤ã³ã¹ãã¼ã«ãããã¨ã«ãã: https://github.com/riscv-software-src/homebrew-riscvããªããããããã¨æ¥½ã¡ãã§ããã
spike /opt/homebrew/opt/riscv-pk/riscv64-unknown-elf/bin/pk <program>
ã®ããã«ããã¨å®è¡ã§ããã- ãã®éã©ãã stderr ã¸ã®åºåã stdout ã«åºã¦ãæ°ãããã
- ãã¨æåã« "bbl loader" ã¨åºãã®ãæ¶ããªãããªãã§ãªãã¨ãããã
- ãªãã ããã ã§ãã¡ãã Ubuntu ã® devcontainer ãç¨æãããã©ãçµå± macOS ã§ããã®ãæ©ãã¦ãã¡ãã§ããæ¸ãã¦ãªããä»ãå£ãã¦ããã
2022-10-27 (day 1)
- ã¨ããããã³ã¼ã 42 ã§çµäºããããã°ã©ã ãä½ããããã
- ãªãã»ã©ã³ã³ãã¤ã©ãä½ãã£ã¦ Hello, world ããããã®ãã¨æã£ã¦ãããã©æåã¯ãããããªã®ããã¨éç¨ãæã£ã¦è奮ããã
- ã¨ã¯ããããããã¢ã»ã³ããªãã¾ãããããªãã®ã§ã³ã³ãã¤ã«çµæãã°ããã¨ããããå§ãããgcc -S ã§ã¢ã»ã³ããªãåºåã§ãããã¨ãç¥ãããã®ã¨ãã¯ä½¿ãããªãã¦ãªãã£ããã©ãã®ã¡ã®ã¡ Compiler Explorer ãå¤ç¨ããããã«ãªã£ãã
- ããã¦ã¹ã¿ãã¯ãããããªããæ£ç¢ºã«ã¯ã¢ã»ã³ããªã§ã©ãæ¸ãã®ããããããªãããã®ã¸ãã¯æçµçã« Calling Convention ããã¼ã¯ã¼ãã«ã大å¦ã®è¬ç¾©è³æãªã©ãããã£ã¦ãªãã¨ãªãæ´ãã§ãã£ãã
- RISC-V ã® ISA (Instruction set architecture) ã«ã¯
pop
ãpush
ã¿ãããªä¾¿å©ãªãã®ã¯ãªãã®ã§èªåã§æ¸ãã - ã¨ããããã¹ã¿ãã¯ãã·ã³ãã§ããã°ã¹ã ã¼ãºã§ããã®æ¥ã¯ æ¯è¼æ¼ç®å ãããã¾ã§é²ãã
- æåã®æ°ã³ãããã ããã£ãã¤ãã¦è±èªã§æ¸ãã¦ãããèªåã®ããã®ããã¸ã§ã¯ããªã®ã§æ¥æ¬èªã§æ¸ããã¨ã«ããã
2022-10-28 (day 2)
- ãã¼ã«ã«å¤æ°ãå®è£ ãã¹ã¿ãã¯ããªãã¨ãªãããã£ã¦ãããããããã¡ã¢ãªã«å¤ãæ¸ãè¾¼ããã¨ãªãã¨ä¸æè°ãªæãã ã
- å¶å¾¡æ§é ãå®è£
ã
j
ã§ã¸ã£ã³ãã¨ãããã¨ã¢ã»ã³ããªæ¸ãã¦ãæãããããæ§é åãããããã°ã©ã ããã©ããã«ãã¦ããéç¨ãªã®ãã - é¢æ°å¼ã³åºããä½ã£ã¡ãããå帰ãã¨ããªãéä¹ã¾ã§æ¸ãã¦ææ¿ããã
- ã¹ã¿ãã¯ã« push ãããã®ã pop ãå¿ãããã¨ã§å®è¡æã«ä¾å¤ãèµ·ãã¦ãã¦ã¡ãã£ã¨ããã£ããããããã¨ãã¯ã¢ã»ã³ããªãä¸è¡ä¸è¡èªãã§ããä½æ¥â¦â¦ã
- é¢æ°ã¨ãã¼ã«ã«å¤æ° ã¾ã§å°éã
2022-10-31 (day 3)
- ãã¤ã³ã¿ã®å®è£ ãããã¾ã§ã«å·¦è¾ºå¤ãæ±ã£ã¦ããã®ã§ãã®å»¶é·ã§ã¢ãã¬ã¹ãåå¾ã§ããã®ã¯ãªãã»ã©ã
mov rax, [rax]
ã RISC-V ã§ã©ãæ¸ãã®ãåãããªãã£ããã©ãld t0, 0(t0)
ã®ããã ã£ãã- é
åã«ããã©ã¤ãC ã®é
åã£ã¦è¦ã¯ãã¤ã³ã¿ã®ãã¨ã§ããï¼ ã¨ããéãªç解ããã¦ãããå®è£
ãã¦ã¿ãã¨é£ãããæ§æ解ææã«
a
ãé åå¤æ°ã ã£ãã&a
ã§ããã¨ãã¦ã¿ããã¨ã«ããããã®ã³ã¼ãã¯ãã¨ã§æ¨ã¦ãã - é åå¨ãã§ãªãã ãã¢ãããã¯ãªã³ã¼ããå¢ãã¦ãã¦å«ã«ãªã£ã¦ããã
- ãã¼ã«ã«å¤æ°ãããã°ã©ã å ¨ä½ã®ã¹ã³ã¼ããæã£ã¦ããã®ãé¢æ°ã¹ã³ã¼ãã«ããã
2022-11-01 (day 4)
- ãã¹ããä¸ã¤ã§ã失æãããæ®ãã®ãã¹ããèµ°ããªãããã«ãªã£ã¦ãããã©ãããã ã¨ã¨ã³ãã°ãã¦ããç®æãã²ã¨ã¤ããè¦ã¤ããããªãã®ã§å
¨ã¦èµ°ãããããã«å¤æ´ãå
·ä½çã«ã¯ TAP ãåãã¦
prove
ã«é£ãããããã«ããã使ãæ £ããæãã ã - é
åã®å®è£
ãå¤æ´ã
a
ã&a
ã«ããã¨ãã«ããã¡ãã®é½åã§çæããæ¬ä¼¼çãªãã¼ãã§ãããã¨ããã¼ã¯ããããã®ã³ã¼ããæ¨ã¦ãã - çµå±å¤æ°ã®è©ä¾¡æã«é åã ã£ããç¹å¥ãªæ±ããããããã«ãããããã
2022-11-02 (day 5)
- ã°ãã¼ãã«å¤æ°ãå®è£ ãLVar ã¨ã»ã¨ãã©åã GVar ãç»å ´ããã¼ã¿æ§é ãæä½ã®é¢æ°ãã³ããã§ä½ããããã¦ãªã¹ãã®æä½ã ãã§ãåä¸ã«ãããã¨æããããã¾ãè¾¼ã¿å ¥ã£ããã¨ãããã¨ã»ã«ããã¹ããé ã®ãããã§ã§ããªãï¼çµå±ãã¾ãã§ãã¦ããªãï¼ã
- é¢æ°ã®å®£è¨ã¨ã°ãã¼ãã«å¤æ°ã®å®£è¨ã®æ§æ解æãæ··ãã£ã¦èªã¿ã«ãããªã£ãã
- æååãªãã©ã«ãå®è£ ãã¨ã¹ã±ã¼ãã·ã¼ã±ã³ã¹ã¨ãã解éããã«ã¢ã»ã³ããªã«åãåºãã¦ãåãã£ã¦ããããããã§çåã«æã£ããã©ã¢ã»ã³ããªã®æååãªãã©ã«ã®ä»æ§ã¯ã©ãã«ãããã ï¼
- ãã¡ã¤ã«ããã®èªã¿è¾¼ã¿ãå®è£ ãããã¯ã³ããã
- ã¹ããã26: å ¥åããã¡ã¤ã«ããèªã ã¾ã§å°éã
2022-11-03 (day 6)
- ã¹ããã27: è¡ã³ã¡ã³ãã¨ãããã¯ã³ã¡ã³ã ã¾ã§å°éãããããå ã¯èªåã§ç®æ¨ãæã£ã¦ãã£ã¦ããã8queen ã¨ãã»ã«ããã¹ãã§ããã
- 8queen ãåãããã¨ã«ã¯ãã£ããæåãfor ã®ä¸ã§å¤æ°å®£è¨ã§ããªãããå¤æ°å®£è¨ã¨åæã«ä»£å
¥ãã§ããªãããæåãªãã©ã«ããªãã®ã§
putchar()
ã«æ°åã渡ããªãããããªãããã¨ã²ã©ãããã ãã¡ããã¨åãã¦ããããªããªãæçã湧ãã¦ããã
2022-11-04 (day 7)
- 1ãã¹ããã¤ã³ã³ãã¤ã«âå®è¡ãã¦ãã test.sh ãã²ã¨ã¤ã®ããã°ã©ã ã§ãã test/test.c ã«ç§»è¡ãèªåã®ã³ã³ãã¤ã©ãããç¨åº¦ã¯ä¿¡é ¼ã§ããããã«ãªã£ã¦ããã®ã§ãããããã¨ãã§ãããã©ããå£ãã¦ããããããªãã®ã«ãã¹ããã²ã¨ã¤ã®ããã°ã©ã ã«ã¾ã¨ãããã¨ãªãã¦ã§ããªãã§ãããã¨æåã¯æã£ã¦ãããã®ã ãã©ã
- ããã TAP ã§ãã¹ãçµæãåºåãããã®ã§ããã
- 8queen ãéã£ã¦ããã¨ããã®ã§ãã¡ãã£ã¨ãªãã¡ã¯ã¿ãªã³ã°ããã
- å¤æ°ãã¹ã³ã¼ãã¨ãã¦é¢æ°åãæã£ã¦ããã®ããNode ã«ãã¼ã«ã«å¤æ°ãæãããããã«å¤æ´ãã¹ã³ã¼ãã¨ããæ¦å¿µãããã§ã¾ã¨ããªå½¢ã§ç»å ´ããã
- ã»ã«ããã¹ãã«å¿ è¦ãªé ç®ãæ¸ãåºãã
2022-11-06 (day 8)
- ã°ãã¼ãã«å¤æ°ãåæåå¯è½ã«ãå®æ°å¤ã®è¨ç®ã®ã³ã¼ããæ¸ãã®ã¯é¢åã ãªï¼
- ãã¼ã«ã«å¤æ°ãåæåããã¡ãã¯ä»£å ¥ããªããããã®ããã«ãã¼ããçæããã
break
ãå®è£ ã親 while ã«å¯¾å¿ããã©ãã«ã«j
ãããbreak LABEL
ããã£ãããã£ã¨é¢åã ã£ãã«éããªãã- ãããã¦ãæ§æ解ææã«ã¹ã³ã¼ãã push/pop ããããã«ãªãã
2022-11-07 (day 9)
continue
ãå®è£ ã- èªåèªèº«ãã³ã³ãã¤ã«ããããã¨ããã¨æåã«å¼ã£ãããã¨ããã ããã ã¨æãããæ§é ä½ã«æãä»ãã¦ãããparse_type() ããã¡ããã¡ãã«ãªã£ã¦ããâ¦â¦ã
- æ§é ä½ã®ã¡ã³ã㯠LVar ãåå©ç¨ã§ãããããªãã»ããã®è¨ç®ãã¡ãã£ã¨éãããã ãã
- ã¨ãããæ§é ä½ã®ã¡ã³ãã®ã¢ã©ã¤ã³ã¡ã³ã㯠ABI ã§å®ãããã¦ããªãã®ï¼
2022-11-08 (day 10)
- 9cv ã¨ããååã mocc ã«å¤æ´ãããæåã®é«ããæã£ã¦ãå¯æãããã
- LVar, GVar ã Var ã«ä¸æ¬åã
struct A;
ã¿ãããªã®ã許ãã- åé
!
ã«å¯¾å¿ã for (int i = 0;;)
ã¨å®£è¨ãã§ããããã«ãããfor ãã¹ã³ã¼ããæã¤ããã«ãªã£ãã- ãããã¦ãcodegen æã« for ãå§ã¾ã£ãã¨ãã«ã¹ã¿ãã¯ãç©ãããã«ãªã£ããããã¯å¤±æã ã£ãã®ã§ãã¨ã§ãããã
2022-11-09..11 (day 11..13)
enum
ã«å¯¾å¿ãenum ã§å®£è¨ãããã¢ã¤ãã ã¯ããã®å¾ã®ç»å ´ã§ã¯å®æ°å¤ã«ç½®ãæãããããªå®è£ ãtypedef
ã«å¯¾å¿ãTY_INT ã TY_ARRAYãTY_STRUCT ã¨ä¸¦ã㧠TY_TYPEDEF ã¨ããé¡ãä½ãã- å¯å¤é·å¼æ°ã«å¯¾å¿ã
va_start
ã®åå¨ãè¬ããã¦å®è£ ã§ããæ°ãããªãã£ãããç°¡åãªå ´åã«ã¤ãã¦ã¯ãªãã¨ãªãåãã£ããã¹ã¿ãã¯ã®æ ¹æ¬ã®ã»ãã«å¼æ°ãã¡ãç©ãã§ãããva_list ap
ã¯ããã¸ã®ãã¤ã³ã¿ã«ãªã£ã¦ããã¨ããããã ãva_start
ã®å¼ã³åºãã ãç¹å¥ã«å¦çããããã¨ã«ããã switch
ãå®è£ ãã¦ã¿ããswitch ã®å´ããcase
ãè¦ã¤ãã«è¡ã£ã¦ãããããéã®ã»ãããããªããextern
ã«å¯¾å¿ã
2022-11-16..17 (day 14..15)
++
ã«å¯¾å¿ãå¾ç½®ã¯ããé¢åãextern
ã Type ã®æ§è³ªã®ããã«å®è£ ãã¦ããã®ã Var ã®ãã®ã«å¤æ´ã- ãã¼ã«ã«å¤æ°ã®ã¹ã³ã¼ãã®ç®¡çã®ãããã¹ã³ã¼ããã¨ã«ã¹ã¿ãã¯ãã¤ã³ã¿ã移åãã¦ãã (day 10) ã®ã break ãªã©ã¨çµ¡ãã¨è¤éã«ãªããããã®ã§ãæ§æ解ææã«ã¹ã³ã¼ããé¢æ°ã®ã¹ã³ã¼ãã«ãã¼ã¸ããããå¤æ´ã
- break ãªã©ã®ã¸ã£ã³ãå ããã³ã¼ãçææã«è¡ã£ã¦ããã®ãæ§æ解ææã«ããããã«å¤æ´ãã¦ã³ã¼ãçæã§ã¯ã¹ã³ã¼ããã»ã¨ãã©æèããªãã¦ããããã«ããã
- 空ã®
return;
ã«å¯¾å¿ã - ä¸ç®æã§ãã使ã£ã¦ããªãã£ãåãã£ã¹ãã®å®è£ ãããããããã¨ã«ãã¦ãã½ã¼ã¹ã³ã¼ãããé¤ããã
- æ§é ä½ã®åæåãå¢ãã§å®è£ ããã
2022-11-18 (day 16)
- é¢æ°ã®è¿ãå¤ã®åããããããã§ãã¯ããããã«ã
- ããããã¡ã¤ã«ã«ã»ã«ããã¹ãåãã®é¢æ°ãå¤æ°å®£è¨ãç¡çããæ¸ãã¦ããã
-D__mocc_self__
ããã¨ã㯠#include ãããã«èªåã®å®ç¾©ã使ããããªå½¢ã ã - ãã®æç¹ã§ã»ã«ããã¹ããéæã§ãã¦ããããclang ã§ã³ã³ãã¤ã«ãã mocc (stage1) ã§ã³ã³ãã¤ã«ãã mocc (stage2) ã§ãã¹ããéãããã«ãªã£ãã
2022-11-20 (day 17)
- ãã®ã¨ã³ããªãæ¸ãã¦ããã break ã®å®è£ ãããããã£ãã®ãçºè¦ããã®ã§ä¿®æ£ã
- ãã㧠clang ã§ã³ã³ãã¤ã«ãã mocc (stage1) ã§ã³ã³ãã¤ã«ãã mocc (stage2) ã¨ãããã§ã³ã³ãã¤ã«ãã mocc (stage3) ãã¾ã£ããä¸è´ããããã«ãªã£ã!!!
ãã£ã¦ã¿ã¦
- ãã®æ¬ã§ã¯ã¨ã«ããã¾ãã¯ãã°ããæçµçãªçµæãåºããã¨ãç®æããæ©ãããæ½è±¡åãããã«é²ãã¦ããã¹ã¿ã¤ã«ã強調ãã¦ãã¦ããã®éãã«ããã¨ã»ãã¨ãã«é²ãã®ã§ãã¡ããã¡ãæ°æã¡ãããã
- é¢æ°ãã¤ã³ã¿ã¯æªå®è£ ããã®å¥æªãªå宣è¨ãã©ããã¼ãºããã®ããèããã¨ãããããããªã®ã§ãã£ã¦ã¿ããããªã
- åçµæåãå¤ãã§ããªã端æããªããã§ã¯ãã£ããã©ããªããªãéææãããããåå¼·ã«ãªã£ããèªåã¯æ触ãããªãã¨ããç解ã§ããªãã¿ããªã®ã ãã©ãABI (Application Binary Interface) ããªããªã®ãã¨ãããã¨ãèã§ããã£ãé¨åã¯å¤§ããããã¨é¢æ°å¼ã³åºãã®å¼æ°ãå¾ãããè©ä¾¡ããå¦çç³»ãããæ°æã¡ãããã£ãâ¦â¦ã
- ã¡ãã£æã« JavaScript ã®å¦çç³»ãæ¸ããã¨ãã¯ãé©å½ã«ä½ã£ãããã¤ãããã¯ã¹ã³ã¼ããçãã¦ãã¾ã£ã¦ãã«ããã¨æã£ããã®ã ãã©ããã£ã¦ã¿ãªãã¨ããããªãã¨ããã®ã¯ãããããã¨ã ã
- ã㨠VSCode + clangd ã®ããã㧠C ãæ¸ãä½é¨ã¯ããªãå¿«é©ã ã£ãã15å¹´åã«ãã¤ãã§æ¸ãã¦ãããã¨ã¯ããããéãã
- ãã®ãã¨ã¯ã¼ã¡ã¼ã¡ã³ã¼ãã綺éºã«ãã¦ãããã¨ããã¤ã¤ä½çãéããããã