Dagon
github.com/samuel-malec/dagon · Blog post
Overview
Cthulhu is a low-level, statically typed, functional intermediate representation, designed to be suitable for program transformation, testing, and verification. This project is a compiler toolchain that connects JavaScript to Cthulhu, and it consists of two separate compilers:
- js2ct compiles JavaScript into Cthulhu.
- ct2qjs lowers Cthulhu into QuickJS bytecode.
Why I built it
You may wonder why both ends of the compilation pipeline are such exotic choices. It's a fair question, but the choice is deliberate. At FI MUNI, where I study, a Jaculus Machine is developed. It an embeddable JavaScript runtime built on QuickJS and aimed at embedded devices. My goal is to make code running on such devices analyzable. The idea is to use Cthulhu to analyze JavaScript applications before they run, and eventually to help establish properties such as bounded memory use for the QuickJS bytecode produced from them. Which analyses to support is still open.
How it works
I haven't implemented the entire JavaScript language. Instead, I restricted myself to a subset of it, which I compile to Cthulhu and then to QuickJS bytecode. Since the supported subset is rapidly changing, I want to reffer interested readers to the project repository in github, where the docs are being updated regularly.