{"id":20835676,"url":"https://github.com/cla7aye15i4nd/pymx","last_synced_at":"2025-09-05T20:41:12.541Z","repository":{"id":130367661,"uuid":"247875519","full_name":"cla7aye15I4nd/Pymx","owner":"cla7aye15I4nd","description":"Pymx is a compiler written in Python 3 for the M* language which is a toy language. The compiler is intended to support to generate rv32im code from a java-like language.","archived":false,"fork":false,"pushed_at":"2020-05-26T05:03:54.000Z","size":619,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T09:38:26.043Z","etag":null,"topics":["compiler","compiler-optimization","llvm-ir","python","riscv32"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cla7aye15I4nd.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-17T04:00:57.000Z","updated_at":"2023-09-21T01:08:02.000Z","dependencies_parsed_at":"2023-03-30T06:52:58.960Z","dependency_job_id":null,"html_url":"https://github.com/cla7aye15I4nd/Pymx","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/cla7aye15I4nd%2FPymx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cla7aye15I4nd%2FPymx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cla7aye15I4nd%2FPymx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cla7aye15I4nd%2FPymx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cla7aye15I4nd","download_url":"https://codeload.github.com/cla7aye15I4nd/Pymx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248200351,"owners_count":21063880,"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":["compiler","compiler-optimization","llvm-ir","python","riscv32"],"created_at":"2024-11-18T00:27:00.971Z","updated_at":"2025-04-10T10:43:42.885Z","avatar_url":"https://github.com/cla7aye15I4nd.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pymx\n\n### A hapy compiler created in Python\n\n---\n\nPymx is a compiler written in Python 3 for the M* language, M* is a toy language in course Compiler 2020 at ACM Class, Shanghai Jiao Tong University. The compiler is intended to support to generate rv32im code. \n\n### Usage\n\n```\n$ pymx -h\nusage: run.py [-h] [-d] [-c] [-l IR_FILE] [-s ASM_FILE] files [files ...]\n\nPymx is a Mx compiler created in Python\n\npositional arguments:\n  files        Source file\n\noptional arguments:\n  -h, --help   show this help message and exit\n  -d           Developer option\n  -c           Syntax check only\n  -l IR_FILE   Intermediate code file\n  -s ASM_FILE  Target file\n```\n\n## Implementation Overview\n\n### Stage\n\n#### Lexer\n\nLexer is implemented in [`lexer`](pymx/lexer), It will generate a Token List. [`tokens.py`](pymx/lexer/tokens.py) defines token classes and keywords table, and [`lexer.py`](pymx/lexer/lexer.py) matches the source code greedily.\n\n#### Parser\n\nThe Parser will parse the token list to AST and do the semantic check, [`tree`](pymx/tree) contains the definitions of the syntax tree. Parse instance is implemented in [`parser`](pymx/parser), it is a **recursive descent parser**. \n\n#### IR generation\n\nPymx traverses the syntax tree to generate linear intermediate code called TypeLess LL. The commands' format looks like LLVM IR but just keep partial instructions and without type system. TypeLess LL only care the size of each data. It is defined in [`inst.py`](pymx/fakecode/inst.py).  Most optimizations are carried out at this stage.\n\n#### ASM generation\n\nPymx generate the RISCV target code from TypeLess LL code, [live analysis](pymx/codegen/riscv/allocator.py) and [register allocation](pymx/codegen/riscv/allocator.py) will be performed at this stage, and will do some simple peephole optimization. \n\n### Optimize\n\n#### Mem2reg\n#### Peephole\n#### CFG simplify\n#### DCE (Dead Code Eliminate)\n#### GVN (Global Value numbering)\n\n## Reference\n\n- RISCV Specification - https://riscv.org/specifications/privileged-isa/\n- RV32 ABI - https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md\n- LLVM mem2reg - https://llvm.org/doxygen/PromoteMemoryToRegister_8cpp_source.html\n- LLVM Language - https://llvm.org/docs/LangRef.html\n- Visitor mode - https://abcdabcd987.com/notes-on-antlr4/\n- Compilers: Principles, Techniques, and Tools (dragon book)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcla7aye15i4nd%2Fpymx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcla7aye15i4nd%2Fpymx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcla7aye15i4nd%2Fpymx/lists"}