{"id":19574526,"url":"https://github.com/dmaivel/vscc","last_synced_at":"2025-04-27T05:34:08.743Z","repository":{"id":172298732,"uuid":"649108458","full_name":"dmaivel/vscc","owner":"dmaivel","description":"Experimental x86-64 JIT compiler","archived":false,"fork":false,"pushed_at":"2024-10-21T04:27:22.000Z","size":46,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-21T07:19:03.749Z","etag":null,"topics":["assembly","compiler","compiler-backend","intermediate-code-generation","intermediate-language","intermediate-representation","jit","jit-compiler","just-in-time","x86","x86-64"],"latest_commit_sha":null,"homepage":"","language":"C","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/dmaivel.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":"2023-06-03T20:03:05.000Z","updated_at":"2024-10-21T04:27:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"9905016a-8fc3-4264-b348-fcda140b8dc6","html_url":"https://github.com/dmaivel/vscc","commit_stats":null,"previous_names":["dmaivel/vscc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmaivel%2Fvscc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmaivel%2Fvscc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmaivel%2Fvscc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmaivel%2Fvscc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmaivel","download_url":"https://codeload.github.com/dmaivel/vscc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224062782,"owners_count":17249289,"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":["assembly","compiler","compiler-backend","intermediate-code-generation","intermediate-language","intermediate-representation","jit","jit-compiler","just-in-time","x86","x86-64"],"created_at":"2024-11-11T06:42:26.001Z","updated_at":"2024-11-11T06:42:27.704Z","avatar_url":"https://github.com/dmaivel.png","language":"C","readme":"\u003cimg align=\"right\" width=\"18%\" src=\"https://cdn-icons-png.flaticon.com/512/547/547433.png\"\u003e\n\n# vscc ![license](https://img.shields.io/badge/license-MIT-blue)\n\nA lightweight, fast x86-64 compiler backend library.\n  - No third-party dependencies\n  - JIT compilation\n  - SYS-V ABI compliant\n\n## build (cmake)\n```bash\ngit clone https://github.com/dmaivel/vscc.git\ncd vscc\nmkdir build\ncd build\ncmake ..\ncmake --build . --config Release\n```\nTo build one of the examples, uncomment the `frontend` lines from the cmake file.\n\n## examples\nThe primary example is [pyvscc](https://github.com/dmaivel/pyvscc), which is an experimental python compiler. However, this repository contains additional, smaller examples.\nThe `examples` directory contains the following subprojects:\n- `basic_ir`: tests the intermediate language\n- `codecheck`: tests the ir, optimization, symbol generation and code generation\n- `mm_test`: test the memory manager (lists)\n- `strlen_jit`: generate a `strlen` implementation at runtime\n\n## to-do\nThis project is currently unfinished with a vast majority of the feature set either needing to be finished, polished, rewritten, or awaiting implementation. This is a list of priorities for future development:\n- [x] Internal memory manager\n- [ ] User memory manager (free code, symbols, ir, memory limits)\n- [x] Refactor `codegen` implementation\n    - create a codegen interface structure, contains function pointers\n    - base for adding support for new ABIs/architectures\n- [x] Save/load IR to and from storage\n- [ ] Full Sys-V support\n- [x] Basic support for all IR opcodes in `codegen`\n- [ ] Finish implementing all IR opcodes in `codegen`\n- [ ] Add/finish 8-bit \u0026 16-bit support\n- [ ] Add floating point support\n- [ ] Add more optimization routines\n\nLower priority features:\n- [ ] Support IR as source instead of just binary\n- [ ] MS-ABI support\n- [ ] x86 (32-bit) support\n- [ ] AVX2 support\n\n# features\n\n## intermediate language\n### opcodes\n| Opcode | Description | Destination Operand | Source Operand | Support |\n| --- | ----------- | --- | --- | --- |\n| O_ADD | Addition | Register | Register/Immediate | :warning: |\n| O_LOAD | Load value from memory into register | Register | Register/Immediate | :warning: |\n| O_STORE | Store value into register | Register | Register/Immediate | :heavy_check_mark: |\n| O_SUB | Subtraction | Register | Register/Immediate | :warning: |\n| O_MUL | Multiplication | Register | Register/Immediate | :warning: |\n| O_DIV | Division | Register | Register/Immediate | :warning: |\n| O_XOR | Exclusive Or | Register | Register/Immediate | :warning: |\n| O_AND | And | Register | Register/Immediate | :warning: |\n| O_OR | Or | Register | Register/Immediate | :warning: |\n| O_SHL | Left Shift | Register | Register/Immediate | :warning: |\n| O_SHR | Right Shift | Register | Register/Immediate | :warning: |\n| O_CMP | Compare register to value | Register | Register/Immediate | :warning: |\n| O_JMP | Jump | Immediate |  | :heavy_check_mark: |\n| O_JE | Jump if equal | Immediate |  | :heavy_check_mark: |\n| O_JNE | Jump if not equal | Immediate |  | :heavy_check_mark: |\n| O_JBE | Jump if below/equal | Immediate |  | :heavy_check_mark: |\n| O_JA | Jump if above | Immediate |  | :heavy_check_mark: |\n| O_JS | Jump if sign | Immediate |  | :heavy_check_mark: |\n| O_JNS | Jump if not sign | Immediate |  | :heavy_check_mark: |\n| O_JP | Jump if parity | Immediate |  | :heavy_check_mark: |\n| O_JNP | Jump if not parity | Immediate |  | :heavy_check_mark: |\n| O_JL | Jump if less | Immediate |  | :heavy_check_mark: |\n| O_JGE | Jump if greater/equal | Immediate |  | :heavy_check_mark: |\n| O_JLE | Jump if less/equal | Immediate |  | :heavy_check_mark: |\n| O_JG | Jump if greater | Immediate |  | :heavy_check_mark: |\n| O_RET | Return | Register/Immediate | | :heavy_check_mark: |\n| O_DECLABEL | Declare a label within a function for jumps | Immediate | | :heavy_check_mark: |\n| O_PSHARG | Push an argument | Register/Immediate | | :warning: |\n| O_SYSCALL | Perform syscall (use vscc_pushs) | | | :heavy_check_mark: |\n| O_SYSCALL_PSHARG | Push an argument for syscall (don't use unless not using vscc_pushs) | Register/Immediate | | :warning: |\n| O_CALL | Call a function | Register (return value storage) | Immediate (pointer to function) | :heavy_check_mark: |\n| O_CALLADDR | Call a function (not IR) by its address | Register (return value storage) | Immediate (pointer to function) | :heavy_check_mark: |\n| O_LEA | Load effective address of register | Register | Register/Immediate | :warning: |\n\n:x: no support\n:warning: partial support\n:heavy_check_mark: full support\n\n### planned\n| Opcode | Description | Destination Operand | Source Operand |\n| --- | ----------- | --- | --- |\n| O_FSTORE | Store floating point value into register | Register | Register/Immediate |\n| O_FLOAD | Load floating point value from memory into register | Register | Register/Immediate |\n| O_FADD | Addition | Register | Register/Immediate |\n| O_FSUB | Subtraction | Register | Register/Immediate |\n| O_FMUL | Multiplication | Register | Register/Immediate |\n| O_FDIV | Division | Register | Register/Immediate |\n\n### context initialization\n```c\nstruct vscc_context ctx = { 0 };\n```\n### function initialization\n```c\nstruct vscc_function *function = vscc_init_function(\u0026ctx, \"function_name\", SIZEOF_I32); // NO_RETURN, SIZEOF_I8, SIZEOF_I16, SIZEOF_I32, SIZEOF_I64, SIZEOF_PTR\n```\n### register allocation\n```c\nstruct vscc_register *variable = vscc_alloc(function, \"variable_name\", SIZEOF_I32, NOT_PARAMETER, NOT_VOLATILE); // [NOT_PARAMETER/IS_PARAMETER], [NOT_VOLATILE/IS_VOLATILE]\n```\n### global register allocation\n```c\nstruct vscc_register *global_variable = vscc_alloc_global(\u0026ctx, \"my_global_name\", SIZEOF_I32, NOT_VOLATILE);\n```\n### push instructions\n```c\n/* standard push instructions */ \nvscc_push0(function, O_..., reg, imm);\nvscc_push1(function, O_..., reg, reg);\nvscc_push2(function, O_..., imm);\nvscc_push3(function, O_..., reg);\n\n/* syscall */\nvscc_pushs(function, \u0026syscall_desc);\n\n/* call */\nvscc_push0(function, O_CALL, variable_return_storage, (uintptr_t)callee_function);\n_vscc_call(function, callee_function, variable_return_storage); // alternative to above\n```\n### syscall descriptor example (write(...))\n```c\nstruct vscc_syscall_args syscall_write = {\n    .syscall_id = 1,\n    .count = 3,\n\n    .values = { 1, (uintptr_t)string, (size_t)len },\n    .type = { M_IMM, M_REG, M_REG }\n};\n```\n### saving/loading context\n```c\nbool status;\n\nstatus = vscc_ir_save(\u0026ctx, \"/path/to/save.vscc\");\nstatus = vscc_ir_load(\u0026ctx, \"/path/to/save.vscc\");\n```\n\n## code generation\n### context initialization\n```c\nstruct vscc_codegen_data compiled = { 0 }; \nstruct vscc_codegen_interface interface = { 0 };\n```\n### enable alignment\n```c\ncompiled.align = true; /* compiled is of type 'struct vscc_codegen_data' */\n```\n### compile context\n```c\nvscc_codegen_implement_x64(\u0026interface, ABI_SYSV);\nvscc_codegen(\u0026ctx, \u0026interface, \u0026compiled, true); // true: generate symbols\n```\n\n## optimization\noptimizing routines must be called before `codegen`\n### eliminate dead store\n```c\nvscc_optfn_elim_dead_store(function);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmaivel%2Fvscc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmaivel%2Fvscc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmaivel%2Fvscc/lists"}