Add chibicc

This program popped up on Hacker News recently. It's the only modern
compiler I've ever seen that doesn't have dependencies and is easily
modified. So I added all of the missing GNU extensions I like to use
which means it might be possible soon to build on non-Linux and have
third party not vendor gcc binaries.
This commit is contained in:
Justine Tunney 2020-12-05 12:20:41 -08:00
parent e44a0cf6f8
commit 8da931a7f6
298 changed files with 19493 additions and 11950 deletions

View file

@ -168,7 +168,7 @@
"hasatleast"
"nodebuginfo"
"frownedupon"
"noreturn"
"wontreturn"
"initarray"
"mayalias"
"noinstrument"
@ -190,7 +190,7 @@
"thatispacked"
"strlenesque"
"textwindows"
"aligned"
"forcealign"
"typeof"
"textreal"
"autotype"

View file

@ -4,6 +4,10 @@
"__LINE__"
"__DATE__"))
(defconst cosmo-cpp-constants-chibicc
'("__cosmo__"
"__chibicc__"))
(defconst cosmo-cpp-constants-gcc-412
'("__BASE_FILE__"
"__CHAR_BIT__"
@ -21,6 +25,8 @@
"__SHRT_MAX__"
"__DBL_MIN__"
"__DBL_MAX__"
"__LDBL_MIN__"
"__LDBL_MAX__"
"__FLT_MIN__"
"__FLT_MAX__"
"__WCHAR_MAX__"
@ -156,6 +162,7 @@
(append cosmo-cpp-constants-c11
cosmo-cpp-constants-gcc-92
cosmo-cpp-constants-gcc-412
cosmo-cpp-constants-chibicc
cosmo-cpp-constants-cosmopolitan))
(defconst cosmo-cpp-constants-regex

View file

@ -137,6 +137,7 @@
;; M-3 C-c C-c Compile w/ MODE=rel
;; M-4 C-c C-c Compile w/ MODE=dbg
;; M-5 C-c C-c Compile w/ MODE=""
;; M-9 C-c C-c Compile w/ chibicc
(defun cosmo-intest (&optional file-name)
(let (path root pkg)
@ -155,7 +156,15 @@
((cosmo-intest) "dbg")
(t "")))
(defun cosmo--compile-command (this root kind mode)
(defun cosmo--make-suffix (arg)
(cond ((eq arg 9) ".chibicc")
(t "")))
(defun cosmo--make-objdump-flags (arg)
(cond ((eq arg 9) "-x")
(t "")))
(defun cosmo--compile-command (this root kind mode suffix objdumpflags)
(let* ((ext (file-name-extension this)) ;; e.g. "c"
(dir (file-name-directory this)) ;; e.g. "/home/jart/daisy/libc/"
(dots (file-relative-name root dir)) ;; e.g. "../"
@ -170,20 +179,21 @@
(directory-file-name
(file-name-directory
(file-relative-name this root)))))
((cosmo-contains "_test." (buffer-file-name))
((and (equal suffix "")
(cosmo-contains "_test." (buffer-file-name)))
(format "m=%s; make -j8 -O MODE=$m %s"
mode runs))
((file-exists-p (format "%s" buddy))
((and (equal suffix "")
(file-exists-p (format "%s" buddy)))
(format (cosmo-join
" && "
'("m=%s; n=%s; make -j8 -O o/$m/%s.o MODE=$m SILENT=0"
"make -j8 -O MODE=$m %s"
'("m=%s; n=%s; make -j8 -O o/$m/$n%s.o MODE=$m SILENT=0"
;; "bloat o/$m/%s.o | head"
;; "nm -C --size o/$m/%s.o | sort -r"
"echo"
"size -A o/$m/$n.o | grep '^[.T]' | grep -v 'debug\\|command.line\\|stack' | sort -rnk2"
"objdump -wzCd o/$m/$n.o"))
mode name name buns))
"objdump %s -wzCd o/$m/$n%s.o"))
mode name suffix objdumpflags suffix))
((eq kind 'run)
(format
(cosmo-join
@ -199,13 +209,13 @@
(format
(cosmo-join
" && "
`("m=%s; f=o/$m/%s.o"
`("m=%s; f=o/$m/%s%s.o"
,(concat "make -j8 -O $f MODE=$m SILENT=0")
;; "nm -C --size $f | sort -r"
"echo"
"size -A $f | grep '^[.T]' | grep -v 'debug\\|command.line\\|stack' | sort -rnk2"
"objdump -wzCd $f"))
mode name)))))
"objdump %s -wzCd $f"))
mode name suffix objdumpflags)))))
(defun cosmo-compile (arg)
(interactive "P")
@ -213,9 +223,11 @@
(root (locate-dominating-file this "Makefile")))
(when root
(let* ((mode (cosmo--make-mode arg))
(suffix (cosmo--make-suffix arg))
(objdumpflags (cosmo--make-objdump-flags arg))
(compilation-scroll-output nil)
(default-directory root)
(compile-command (cosmo--compile-command this root nil mode)))
(compile-command (cosmo--compile-command this root nil mode suffix objdumpflags)))
(compile compile-command)))))
(defun cosmo-compile-hook ()
@ -554,7 +566,7 @@
(format "./%s" file))))
((memq major-mode '(c-mode c++-mode asm-mode fortran-mode))
(let* ((mode (cosmo--make-mode arg))
(compile-command (cosmo--compile-command this root 'run mode)))
(compile-command (cosmo--compile-command this root 'run mode "" "")))
(compile compile-command)))
((eq major-mode 'sh-mode)
(compile (format "sh %s" file)))
@ -590,7 +602,7 @@
(next (file-name-sans-extension name))
(exec (format "o/%s/%s.com.dbg" mode next))
(default-directory root)
(compile-command (cosmo--compile-command this root nil mode)))
(compile-command (cosmo--compile-command this root nil mode "" "")))
(compile compile-command)
(gdb (format "gdb -q -nh -i=mi %s -ex run" exec))))))

View file

@ -348,7 +348,7 @@ cosmo_kws = frozenset([
"nointerpose",
"nooptimize",
"noprune",
"noreturn",
"wontreturn",
"nosideeffect",
"nothrow",
"nothrow",
@ -411,7 +411,7 @@ cosmo_kws = frozenset([
"nointerpose",
"nooptimize",
"noprune",
"noreturn",
"wontreturn",
"nosideeffect",
"nothrow",
"nothrow",