[][src]Module chrysanthemum::verify

Does whatever correctness and type checking necessary to an AST.

Okay, so here's what we need to do... We can make this a one-pass compiler. No recursion, no forward decl. Struct names are capital case, variables are lower case -- does that matter?

  • Declare/define standard library types
  • Enter a function:
    • Add variables to symbol tables -- can enumerate them in the process
    • Type check expressions
    • Make sure patterns/matches are valid
    • Whatever else the AST tells us to do
  • Enter a struct definition and add it to the known types
  • Handle entry point functions -- input and output types will need to go into SPIRV

We can MOSTLY compile things one function at a time: https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html

Each function can just be turned into a known-good AST with whatever other info needs to be attached to it -- local symbol table for enumerated variables, etc. Then we flatten it and break it into basic blocks that do whatever SSA magic necessary. Then we should just be able to emit code?

Module also needs the entry point names and types, the memory model (which can always be Logical addressing and Simple memory model I think), type decl's, constants, extended instruction sets (which can include things like trig, etc), debug info (OpName, OpLine, etc), capabilities, whatever else.

We're going to really want a good test program, and a good set of SPIRV tools (disassembler, validator, GLSL compiler to compare against). And a debugger, --renderdoc should be fine to start with.

Bits that will be tricksy:

  • Structs, and associated pointers
  • Samplers and images

Structs

FunctionDef

A function definition; the AST and whatever other information we care about that can get fed to the actual compiler-y bits.

VContext

Verification context. Contains things like symbol tables, etc.

Enums

TypeDef

A type definition, containing whatever we need for that type.

Functions

verify

Validates whether a program is valid. Returns the Context full of things ready to compile.

verify_expr
verify_program

Validate that whole-program properties are correct, for instance that there are vertex and fragment functions with reasonable types.