{"id":27344796,"url":"https://github.com/azarattum/carmustcompiler","last_synced_at":"2025-07-23T19:05:21.055Z","repository":{"id":287144768,"uuid":"815218337","full_name":"Azarattum/CarmustCompiler","owner":"Azarattum","description":"C to ARM64 compiler written in Rust","archived":false,"fork":false,"pushed_at":"2025-04-25T12:13:21.000Z","size":75,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-25T13:26:55.062Z","etag":null,"topics":["arm64","c-compiler","compilers","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/Azarattum.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":"2024-06-14T15:57:58.000Z","updated_at":"2025-04-25T12:13:25.000Z","dependencies_parsed_at":"2025-04-10T07:41:02.205Z","dependency_job_id":"0e00e3f9-85be-493c-8210-f3f2daf55e78","html_url":"https://github.com/Azarattum/CarmustCompiler","commit_stats":null,"previous_names":["azarattum/carmustcompiler"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Azarattum/CarmustCompiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azarattum%2FCarmustCompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azarattum%2FCarmustCompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azarattum%2FCarmustCompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azarattum%2FCarmustCompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azarattum","download_url":"https://codeload.github.com/Azarattum/CarmustCompiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azarattum%2FCarmustCompiler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266737717,"owners_count":23976392,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["arm64","c-compiler","compilers","rust"],"created_at":"2025-04-12T17:34:03.316Z","updated_at":"2025-07-23T19:05:21.042Z","avatar_url":"https://github.com/Azarattum.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Carmust Compiler\n\nCarmust is a C to ARM64 compiler written in Rust. This project is a prototype the primary goal of which was learning Rust. As it stands, the compiler currently supports a subset of C and lacks any real optimizations.\n\n## Showcase\n\nAn example program that it can compile:\n```c\ntypedef int point[2];\n\ntypedef int i32;\ntypedef float f32;\n\ni32 globalData = 42;\nf32 floatEncoding = 32.0;\npoint globalPoint = {4, 2};\n\nint main() {\n  // Expressions\n  i32 unaryOperators = 43 + -globalData - 11;\n  i32 wildExpressions = 1 \u003c\u003c !!!!!!-2 \u003e (6 \u0026 1 ^ (3 % 4)) \u0026 255 == 1;\n  i32 booleanAndBinaryOps = 7 || (1 + !5 == 2 - 3) \u0026\u0026 1;\n  f32 floatingPointMath = (2.5 * 2 + floatEncoding) / globalPoint[1];\n\n  // Arrays with initializers\n  int numbers[3] = {1, 2, 3};\n  point point = {1, 2};\n\n  short shortsAreAlsoAllowed = 1;\n  long longsAreSupportedAsWell = 123456;\n\n  // Assignments\n  unaryOperators = unaryOperators + wildExpressions + ' ';\n  point[1] = point[1] + numbers[2];\n  globalPoint[0] = 0;\n\n  // Empty statements\n  ;\n  ;\n\n  // For loops\n  for (int i = 0 + 0; i \u003c 5 + 1; i = i + 1) {\n    unaryOperators = unaryOperators + 1 + globalPoint[0];\n  }\n\n  // Expressions in the return statement\n  return unaryOperators + floatingPointMath + booleanAndBinaryOps - point[1];\n}\n```\n\nLet's look closely at the compilation process with a more simple program:\n```c\nfloat global = 42;\n\nint main() {\n  int local = 1337;\n  return local % 255 + global;\n}\n```\n\nAt first the following tokens are extracted from the source code: \n\u003cpre\u003e\n\u003cspan style=\"color:cyan\"\u003eTokens\u003c/span\u003e: [Keyword(\"float\"), Identifier(\"global\"), Symbol(\"=\"), Data(Integer(42), \"42\"), Symbol(\";\"), Keyword(\"int\"), Identifier(\"main\"), Symbol(\"(\"), Symbol(\")\"), Symbol(\"{\"), Keyword(\"int\"), Identifier(\"local\"), Symbol(\"=\"), Data(Integer(1337), \"1337\"), Symbol(\";\"), Keyword(\"return\"), Identifier(\"local\"), Symbol(\"%\"), Data(Integer(255), \"255\"), Symbol(\"+\"), Identifier(\"global\"), Symbol(\";\"), Symbol(\"}\")]\n\u003c/pre\u003e\n\nThen an abstract syntax tree is generated:\n\u003cpre\u003e\n\u003cspan style=\"color:magenta\"\u003eAST\u003c/span\u003e: [Variable(Variable { datatype: Type(Compound(Float, 1)), name: \"global\", assignment: Some(Assignment { identifier: (\"global\", 0), value: Expression(Value(Data(Integer(42)))) }) }), Function(Function { datatype: Type(Compound(Int, 1)), name: \"main\", body: [Variable(Variable { datatype: Type(Compound(Int, 1)), name: \"local\", assignment: Some(Assignment { identifier: (\"local\", 0), value: Expression(Value(Data(Integer(1337)))) }) }), Return(Binary { op: Addition, lhs: Binary { op: Remainder, lhs: Value(Pointer(\"local\", 0)), rhs: Value(Data(Integer(255))) }, rhs: Value(Pointer(\"global\", 0)) })] })]\n\u003c/pre\u003e\n\nWhich can be compiled into an intermediate representation:\n\u003cpre\u003e\n\u003cspan style=\"color:lime\"\u003eIR\u003c/span\u003e:\nglobals:\n  global_0 = 42\n\nmain:\n  0) Mov @ 1337\n  1) Str 'local_1' @0\n  2) Ldr @ 'local_1'\n  3) Mov @ 255\n  4) Div @2 @3\n  5) Mul @3 @4\n  6) Sub @2 @5\n  7) Ldg @ 'global_0'\n  8) SCvtF @6 \n  9) Add @8 @7\n 10) FCvtZS @9 \n 11) Ret @10\n\u003c/pre\u003e\n\nAnd finally compiled to ARM64 assembly:\n\u003cpre\u003e\n\u003cspan style=\"color:yellow\"\u003eASM\u003c/span\u003e:\n.section __DATA,__data\nglobal_0:\n  .word 1109917696\n\n.section __TEXT,__text\n.global main\nmain:\n  sub sp, sp, 16\n  mov w0, 1337\n  str w0, [sp, 12]\n  ldr w0, [sp, 12]\n  mov w1, 255\n  sdiv w2, w0, w1\n  mul w1, w1, w2\n  sub w0, w0, w1\n  adrp x3, global_0@GOTPAGE\n  ldr x3, [x3, global_0@GOTPAGEOFF]\n  ldr s1, [x3, 0]\n  scvtf s0, w0\n  fadd s0, s0, s1\n  fcvtzs w0, s0\n  add sp, sp, 16\n  ret\n\u003c/pre\u003e\n\nAs you can see, it supports type inference, global/local variables, simple `for` loops, arbitrary expressions (with bitwise and boolean operators) and `return` statement which allows us to observe the result of the program:\n\u003cpre\u003e\n\u003cspan style=\"color:dodgerblue\"\u003eExecution Result\u003c/span\u003e: 104\n\u003c/pre\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazarattum%2Fcarmustcompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazarattum%2Fcarmustcompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazarattum%2Fcarmustcompiler/lists"}