{"id":18619866,"url":"https://github.com/thamugadi/dynastone","last_synced_at":"2025-04-11T02:30:52.595Z","repository":{"id":261398369,"uuid":"882838007","full_name":"thamugadi/dynastone","owner":"thamugadi","description":"Keystone-based dynamic assembler. Allows to easily write a JIT compiler in C/C++. ","archived":false,"fork":false,"pushed_at":"2024-11-20T10:36:38.000Z","size":66,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T08:11:15.692Z","etag":null,"topics":["assembler","dynamic-assembly","dynasm","jit","jit-compiler","keystone"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thamugadi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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-11-03T22:05:29.000Z","updated_at":"2025-03-13T21:10:02.000Z","dependencies_parsed_at":"2024-11-06T11:35:25.886Z","dependency_job_id":null,"html_url":"https://github.com/thamugadi/dynastone","commit_stats":null,"previous_names":["thamugadi/dynastone"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamugadi%2Fdynastone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamugadi%2Fdynastone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamugadi%2Fdynastone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamugadi%2Fdynastone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thamugadi","download_url":"https://codeload.github.com/thamugadi/dynastone/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248329523,"owners_count":21085549,"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":["assembler","dynamic-assembly","dynasm","jit","jit-compiler","keystone"],"created_at":"2024-11-07T04:03:37.941Z","updated_at":"2025-04-11T02:30:52.583Z","avatar_url":"https://github.com/thamugadi.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dynastone\nThis project uses Keystone Assembler to assemble instructions by leaving \"holes\" in certain operands, which are to be replaced by a variable specified along with its size using a special syntax. At the end, a C code is generated, intended to contain calls to an emitter, such as those commonly used in JIT compilers.\nIt works in a similar way to a dynamic assembler like LuaJIT's dynasm.\n\nUsage:\n``dynastone \u003carch\u003e \u003ccode\u003e \u003cemit_function_8\u003e \u003cemit_function_16\u003e \u003cemit_function_32\u003e \u003cemit_function_64\u003e``\n\nExample:\n\n```\n$ ./dynastone \"x64\" \"mov rdi, |var1,64|\" \"emit_8\"\n\nemit_8(0x48);\nemit_8(0xbf);\nemit_64(var1);\n```\n\n```\n$ ./dynastone \"ppc64be\" \"addi |var1,5|,|var2,5|,|var3, 16|\" \"emit_8\" \"emit_16\"\n\nemit_8(0x38 | (var1 \u0026 0x03));\nemit_8(0x00 | (((var1 \u003e\u003e 2) \u0026 0x07) \u003c\u003c 5) | (var2 \u0026 0x1f));\nemit_16(var3);\n```\n\nThe user must specify the maximum operand size, in bits. If there is a minimum size below which the instruction structure changes, it is the user's responsibility to ensure the specified variable does not fall below this size.\n\n**An instruction with multiple immediate operands where the order of their occurrence in the generated machine code is different from the order of their occurrence in the mnemonic instruction, unless its architecture has a big-endian equivalent supported by keystone where the order matches, will not be supported.**\n\n**In its current state, it will not work for instructions where the mnemonic syntax presents the instruction as having one operand, but where it is discontinuous in the assembled code, such as ``mov reg, #imm`` with ``imm`` \u003e 255 in ARMv6T2 and later.** (unless it is treated as 2 successive operands in the dynastone syntax)\n\n# Integration with text editors\nAn interesting application of this project could be integration with text editors to directly generate calls to emitters, based on instructions written with placeholders in the syntax of the tool, which would be written in comments.\n\nAn integration with emacs could take this form:\n\n```elisp\n(defvar *dynastone-bin* \"{path to dynastone binary file}\")\n(defvar *emit-8* \"emit_8\") (defvar *emit-16* \"emit_16\") (defvar *emit-32* \"emit_32\") (defvar *emit-64* \"emit_64\") \n(defvar *arch* \"x64\")\n\n(defun append-f-comment-to-lines (f)\n  (when (use-region-p)\n    (save-excursion\n      (save-restriction\n        (narrow-to-region (region-beginning) (region-end))\n        (goto-char (point-min))\n        (while (re-search-forward \"^\\\\([ \\t]*\\\\)//[ \\t]*\\\\(.*\\\\)$\" nil t)\n          (let* ((indent (match-string 1))\n                 (comment (match-string 2))\n                 (result-lines (split-string (funcall f comment) \"\\n\" t))\n                 (last-index (1- (length result-lines))))\n            (end-of-line)\n            (newline)\n            (dolist (line result-lines)\n              (insert indent line)\n              (unless (eq (cl-position line result-lines) last-index)\n                (newline)))))))))\n\n(defun send-to-dynastone (comment-text)\n  (let* ((args (list *arch* comment-text *emit-8* *emit-16* *emit-32* *emit-64*))\n         (output-buffer (generate-new-buffer \"*dynastone-output*\")))\n    (unwind-protect\n        (progn\n          (apply 'call-process *dynastone-bin* nil output-buffer nil args)\n          (with-current-buffer output-buffer\n            (string-trim (buffer-string))))\n      (kill-buffer output-buffer))))\n\n(defun run-dynastone ()\n  (interactive)\n  (append-f-comment-to-lines 'send-to-dynastone))\n(global-set-key (kbd \"C-c f\") 'run-dynastone)\n```\nA demonstration:\n![](https://i.imgur.com/uBcNsQO.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthamugadi%2Fdynastone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthamugadi%2Fdynastone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthamugadi%2Fdynastone/lists"}