Skip to content

Toy Codegen as example for `semantic-analyzer-rs` library.

License

Notifications You must be signed in to change notification settings

mrLSD/toy-codegen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Toy Codegen

Toy Codegen is the example compiler for semantic-analyzer-rs.

As Codegen backend used LLVM, with inkwell.

Basic design

There is a basic implementation of code-generation. The Semantic AST structure is used as a basic data source. This means that any subset of programming languages can be represented, the main criterion for which is representability in a finite AST structure of Semantic Analyzer, which is used in the semantic-analyzer library.

Codegen implementation

The codege is focused only on those instructions that are presented as an AST sample. And it is not intended to cover all possible complex cases of code generation based on a complete set of SemanticStateContext instructions. However, the end result is a fully functional binary code.

The basic parts is:

  • Function declarations
    • Functions parameters initializations
  • Types declarations
  • Constants declarations
  • Function body implementation
    • Let-binding
      • Codegen variables state
    • Binding
    • Expressions
      • Codegen type conversions
    • If conditions flow
    • Loop conditions flow
    • Function return flow
  • Target triple initialization (LLVM backend)
  • LLVM IR source code generation (and store to file)
  • Binary code generation (and store to file)
  • Code generation error flow with custom error types

LICENCE: MIT

About

Toy Codegen as example for `semantic-analyzer-rs` library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published