{"id":16170460,"url":"https://github.com/corentinth/pld-comp","last_synced_at":"2025-04-07T07:29:20.390Z","repository":{"id":90229612,"uuid":"270654690","full_name":"CorentinTh/pld-comp","owner":"CorentinTh","description":"Bare C to ASM compiler in CPP (school project).","archived":false,"fork":false,"pushed_at":"2020-07-02T15:31:37.000Z","size":494,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-13T11:35:38.719Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CorentinTh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-08T12:10:28.000Z","updated_at":"2023-09-08T18:08:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"77ca2461-045d-483d-bbb5-825539de8694","html_url":"https://github.com/CorentinTh/pld-comp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Fpld-comp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Fpld-comp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Fpld-comp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CorentinTh%2Fpld-comp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CorentinTh","download_url":"https://codeload.github.com/CorentinTh/pld-comp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247611211,"owners_count":20966493,"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":[],"created_at":"2024-10-10T03:18:50.647Z","updated_at":"2025-04-07T07:29:20.369Z","avatar_url":"https://github.com/CorentinTh.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PLD Compilateur\n![C/C++ CI](https://github.com/CorentinTh/pld-comp/workflows/C/C++%20CI/badge.svg)\nBare C to ASM compiler in CPP (school project).\n\n## Description\n\nThis project has been made during our fourth year at INSA Lyon\nThe goal of the project was to make a compiler for a subset of the C language using C++ and Antlr4\n\nFor now our compilator supports the following features :\n * Arithmetic operations \n   * Binary operators: `*`, `/`, `+`, `-`, `%`, `\u0026`, `|`, `^`\n   * Bool operators: `==`, `!=`, `\u003e`, `\u003c`, `\u003e=`, `\u003c=`\n   * Unary operators: `-`, `+`, `!` (not bool), `~` (not bitwise)\n * Multiple variable declaration and affectation\n * IF / ELSE (with or without block body)\n * WHILE / DO-WHILE (with or without block body)\n * Procedure and functions up to 6 arguments\n * `getchar` / `putchar`\n\nThe project also uses unit testing and continuous integration to prevent regressions.\n\n## Team and Organisation\n\nThis is a group project made by :\n - Balthazar Frolin\n - Bastien Marsaud\n - Marc Meillac\n - Corentin Thomasset\n - Lucca Paffi\n\nWe mostly work with pair/group programming doing iterative works and building our compiler step by step.\nWe use Github Projects to track bugs and features status. The fact that it is fully integrated with Github allow us to work faster with one single account.\n\n## User Manual\n\nIn order to use our compiler follow these steps :\n* Write your own program using the basic C grammar (for the implemented features)\n* Compile our compiler (see \"[Using command line](#using-command-line)\")\n\nNow you can run against any C program .\n```\n$ ./pld-comp myFile.c -o myResult.s\n```\n\nCli usage :\n```\n$ ./pld-comp -h\nA compiler for a subset of the C language using C++ and Antlr4.\nUsage : ./pld-comp \u003cinputFileName\u003e \u003coption\u003e [\u003cargs\u003e]\n\nCommandes:\n        -h, --help      show this message\n        -o              specifie a file to write the output\n```\n\nA set of demo of complex working C programs is available in the [demo](./demo) folder.\n\n## Links\n * **Source code**: https://github.com/CorentinTh/pld-comp  \n * **Project management kanban**: https://github.com/CorentinTh/pld-comp/projects/1  \n * **CI pipeline**: https://github.com/CorentinTh/pld-comp/actions  \n * **UT framework**: https://github.com/CorentinTh/comest  \n\n## Code Description\n\n### Project Structure\n\n#### Grammar\n\nThe grammar is written for antlr4, you can find the describing file under antlr4 folder with `.g4` extension ([here](./src/antlr/IFCC.g4)).\n\n#### Modules\n\n* **Variable Manager** used to simplify variable management during compilation process\n\n* **ASSM** utility class that simplifies assembly code generation\n\n* **Logger** used to provide informations during compilation process\n\n#### Visitors\n\nFor each of our grammars entries we generate a visitor in C++ that will be used for syntax validation and assembly conversion. You can find our visitors in file `CompVisitor.cpp`.\n\nWe also use an AST tree to process arithmetics.\n\n\u003e For now our assembly code is generated at differents places, we know it's not a really clean solution but we are waiting for the IR implemtation to refactor this solution.\n\n### IC Explaination\n\nTo ensure we do not create regression while implementing features, we've setup continuous integration thanks to Github Actions. The pipeline configuration file is located in [.github/workflows/c-cpp.yml](./.github/workflows/c-cpp.yml). To do so, we've create a small node.js framework called [comest](https://github.com/CorentinTh/comest) that allows execution of shell commands and checks stdout, stderr and the result code of the command thanks to `yaml` files. Here is an example of a test file :\n\n```yaml\nname: Simple multiplication\ncommand: ./cmake-build-debug/pld-comp {file1}\nassets:\n  - type: file\n    name: file1\n    content: |-\n      int main() {\n          int a = 8 * 8;\n          return a;\n      }\nexpect:\n  status: 0\n  stdout: |-\n    .text\n    .global main\n    main:\n      pushq %rbp\n      movq %rsp, %rbp\n      movl $8, %eax\n      movl $8, %ebx\n      imull %ebx, %eax\n      movl %eax, -4(%rbp)\n      movl -4(%rbp), %eax\n      popq %rbp\n      ret\n```\n\n## Build\n\nThis project uses Cmake to build. \n\n### Prerequisites\nThe packages `uuid-dev` and `pkg-config` have to be installed.\n\n```shell\nsudo apt-get install uuid-dev pkg-config\n```\n\n### Using command line\n```shell\n# Compile\ncmake . -B cmake-build-debug\ncd cmake-build-debug\nmake\n\n# Execute\n./pld-comp myFile.c\n```\n\n### Using Clion\nOpen it with CLion as a CMake project and the magic will show !\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorentinth%2Fpld-comp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorentinth%2Fpld-comp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorentinth%2Fpld-comp/lists"}