{"id":21420877,"url":"https://github.com/lord-turmoil/tomicompiler","last_synced_at":"2026-05-18T03:32:07.891Z","repository":{"id":194026943,"uuid":"689948550","full_name":"Lord-Turmoil/ToMiCompiler","owner":"Lord-Turmoil","description":"A shabby compiler for BUAA 2023 Autumn Compiler Technology course.","archived":false,"fork":false,"pushed_at":"2023-12-18T12:00:57.000Z","size":2451,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T06:32:14.942Z","etag":null,"topics":["buaa","buaa-compiler","compiler","cpp","llvm","mips"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lord-Turmoil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-11T08:37:25.000Z","updated_at":"2024-01-02T13:35:16.000Z","dependencies_parsed_at":"2023-12-25T16:50:57.673Z","dependency_job_id":"b6d23622-4235-4145-bda7-cbaeab07941e","html_url":"https://github.com/Lord-Turmoil/ToMiCompiler","commit_stats":null,"previous_names":["lord-turmoil/tcompiler","lord-turmoil/tomicompiler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lord-Turmoil%2FToMiCompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lord-Turmoil%2FToMiCompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lord-Turmoil%2FToMiCompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lord-Turmoil%2FToMiCompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lord-Turmoil","download_url":"https://codeload.github.com/Lord-Turmoil/ToMiCompiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243926071,"owners_count":20369910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buaa","buaa-compiler","compiler","cpp","llvm","mips"],"created_at":"2024-11-22T20:23:04.277Z","updated_at":"2026-05-18T03:32:07.806Z","avatar_url":"https://github.com/Lord-Turmoil.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ToMiCompiler\n\nA shabby compiler for BUAA 2023 Autumn Compiler Technology course.\n\n\u003e \"Shabby\" means that it is not a complete compiler, but a toy compiler that can only compile a small subset of C language.\n\n_\"Past the point of no return, the final threshold.\"_\n\n---\n\n[![Build](https://github.com/Lord-Turmoil/ToMiCompiler/actions/workflows/cmake-multi-platform.yml/badge.svg?branch=main)](https://github.com/Lord-Turmoil/ToMiCompiler/actions/workflows/cmake-multi-platform.yml)\n\n## DISCLAIMER \n\nDO NOT COPY IT DIRECTLY! Study purposes is welcomed, but don't copy any parts to your projects.\n\n---\n\n## Overview\n\n### Basic Structure\n\nThe primary idea of this compiler is using Inverse of Control to manage all processes in compilation. To achieve this, I used [MinIoC](https://github.com/Lord-Turmoil/MinIoC) as my IoC container.\n\nThe structure of this compiler confoms the classic 5 parts: Lexical Parsing, Syntactical Parsing, Semantic Parsing, Intermediate Code Generation (LLVM) and Target Code Generation (MIPS).\n\nLexical parser will read the source code, and return all tokens in it. It is the simplest, so I merged it with syntax parser. Here, all errors with tokens will be discovered and reported.\n\nThe syntax parser will call lexical parser, and generate a basic AST. Here, all syntax errors will be reported.\n\n\u003e Although I use \"AST\", this thing is in fact not strictly an Abstract Syntax Tree. Instead, it is a top-down derivation tree.\n\nThe semantic parser will then use this AST to do attribute analysis, and construct the symbol table. At the same time, it will add more information to the AST, making it \"complete\". All errors will be reported here, and the compilation process will end up here if any error exists.\n\nThen, the intermediate code generator will use the \"complete\" AST to generate LLVM. After generation, it will output a LLVM `Module`.\n\n\u003e The generator is called `IAsmGenerator`, following the name in LLVM source.\n\nAt last, the MIPS generator will take the LLVM `Module`, and output MIPS assemply code.\n\n### Details\n\nThe compiler is highly configurable, you can use command-line arguments to choose what to be injected as implementation. For example, the `IAstPrinter` can allow you to output XML format AST when debugging locally.\n\nFor AST, I mimicked [TinyXML2](https://github.com/leethomason/tinyxml2), thus my AST is in fact a XML document. It empowers the AST with incredible flexibility, and makes it easier for semantic parsing, which uses Attribute Translation Grammar (ATG).\n\nFor the intermediate code, I chose LLVM, and refered to a relatively old version of it, see [LLVM](https://github.com/llvm-mirror/llvm). The two main concepts in LLVM are [Value](https://llvm.org/doxygen/classllvm_1_1Value.html) and [Type](https://llvm.org/doxygen/classllvm_1_1Type.html), for which I implemented my own version.\n\n## Epilogue\n\nDue to some iresistable factors, this project was forced to halt. However, it was not ended, as I re-implemented it with Java. You can find the final project here: [ToMiCompiler4J](https://github.com/Lord-Turmoil/ToMiCompiler4J).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flord-turmoil%2Ftomicompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flord-turmoil%2Ftomicompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flord-turmoil%2Ftomicompiler/lists"}