asmdot
所属分类:嵌入式/单片机/硬件编程
开发工具:Rust
文件大小:0KB
下载次数:0
上传日期:2020-02-25 14:32:52
上 传 者:
sh-1993
说明: [不稳定](C|C++|C#|Go|Haskell|Javascript|Nim|OCaml|Pyth...,)中的快速、零拷贝和轻量级(Arm|Mips|x86)汇编程序...,
([Unstable] Fast, zero-copy and lightweight (Arm | Mips | x86) assembler in (C | C++ | C# | Go | Haskell | Javascript | Nim | OCaml | Python | Rust).)
文件列表:
.vscode/ (0, 2020-02-25)
.vscode/launch.json (249, 2020-02-25)
.vscode/settings.json (166, 2020-02-25)
.vscode/tasks.json (332, 2020-02-25)
HACKING.md (4156, 2020-02-25)
LICENSE.md (1071, 2020-02-25)
Makefile (3146, 2020-02-25)
asmdot/ (0, 2020-02-25)
asmdot/__init__.py (4669, 2020-02-25)
asmdot/arch/ (0, 2020-02-25)
asmdot/arch/__init__.py (1470, 2020-02-25)
asmdot/arch/arm/ (0, 2020-02-25)
asmdot/arch/arm/__init__.py (20, 2020-02-25)
asmdot/arch/arm/arch.py (19715, 2020-02-25)
asmdot/arch/arm/data.txt (8702, 2020-02-25)
asmdot/arch/arm/tests.py (358, 2020-02-25)
asmdot/arch/mips/ (0, 2020-02-25)
asmdot/arch/mips/__init__.py (20, 2020-02-25)
asmdot/arch/mips/arch.py (6122, 2020-02-25)
asmdot/arch/mips/data.txt (1733, 2020-02-25)
asmdot/arch/mips/tests.py (385, 2020-02-25)
asmdot/arch/testsource.py (3142, 2020-02-25)
asmdot/arch/x86/ (0, 2020-02-25)
asmdot/arch/x86/__init__.py (20, 2020-02-25)
asmdot/arch/x86/arch.py (8339, 2020-02-25)
asmdot/arch/x86/data.txt (1820, 2020-02-25)
asmdot/arch/x86/tests.py (335, 2020-02-25)
asmdot/ast.py (10973, 2020-02-25)
asmdot/emit.py (8649, 2020-02-25)
asmdot/helpers.py (5675, 2020-02-25)
asmdot/metadata.ini (343, 2020-02-25)
asmdot/options.py (285, 2020-02-25)
asmdot/requirements.txt (38, 2020-02-25)
asmdot/setup.py (978, 2020-02-25)
languages/ (0, 2020-02-25)
languages/c/ (0, 2020-02-25)
... ...
ASM.
====
Providing an extensible Python framework for building a **fast, zero-copy** assembler.
## History and goals
This project originally aimed to create a fast, minimalist and unopinionated assembler in C
that could live in a single file, and support multiple architectures.
Thus, a Python library was built to transform various instructions from different architectures
into a simple, common AST that supports bitwise and logical expressions, basic flow control
and variables into C code.
Since code would be generated automatically, other options such as naming conventions and parameter
types could be easily modified when generating it.
However, I soon realized that, since a complete AST was built, it could be easily to extend this
process to not only support C, but also other programming languages.
At first, the goal was thus to produce bindings to the C API, which is *very* efficient; but since a
complete AST was built anyway, and that a mechanism already existed to distinguish source files and
include files, I decided to make the whole process available in different languages.
As such, ASM. was born. **Parsers** transform data files that define instructions in various architectures
to an AST, which is then transformed by **emitters** into source code in various programming languages.
### Goals and non-goals
- **ASM. is a lightweight assembler library. It is designed to be as simple as possible.**
- **ASM. has no support for labels or macros**: developers are expected to build their own
interface on top of the provided functions.
- **ASM. is not a binary, it's a library**. You cannot use it directly.
- **ASM. has no built-in parser**: if you want an assembler that works with arbitrary strings, use
[Keystone](https://www.keystone-engine.org).
- **ASM. has different instructions for different architectures**: if you want a common
interface for all architectures, use [GNU Lightning](https://www.gnu.org/software/lightning)
or [libjit](https://www.gnu.org/software/libjit).
## Usage
### Using `make`
A [Makefile](./Makefile) is provided to automate most tasks, including generating sources,
as well as building and testing every generated library.
The `emit`, `build` and `test` recipes are made available, and invoke all language-specific
recipes that are defined. To execute tasks in a language-specific manner, the recipes
`emit-lang`, `build-lang`, and `test-lang` are also available, where `lang` is either one
of these values:
- `c` (uses any C compiler).
- `cpp` (uses any C++ compiler).
- `csharp` (uses `dotnet`).
- `go` (uses `go`).
- `haskell` (uses `cabal`, **doesn't compile; help needed**).
- `javascript` (uses `npm`).
- `nim` (uses `nimble`).
- `ocaml` (uses `dune`, **doesn't compile; help needed**).
- `python` (uses `pytest`).
- `rust` (uses `cargo`).
### Generating the sources
Each language directory contains a `generate.py` file, which can be directly invoked
from the command line.
Here is an example output of the C generation script:
```
usage: generate.py [-h] [-ns] [-nt] [-o output-dir/] [-v] [-np] [-ah]
[-cc CALLING-CONVENTION]
Generate ASM. sources.
optional arguments:
-h, --help Show the help message.
-ns, --no-sources Do not generate sources.
-nt, --no-tests Do not generate tests.
-be, --big-endian Use big-endian instead of little-endian.
-o output-dir/, --output output-dir/
Change the output directory (default: directory of
calling emitter).
-v, --verbose Increase verbosity (can be given multiple times to
increase it further).
C:
-np, --no-prefix Do not prefix function names by their architecture.
-ah, --as-header Generate headers instead of regular files.
-cc CALLING-CONVENTION, --calling-convention CALLING-CONVENTION
Specify the calling convention of generated functions.
```
### Using the C API
```c
#include "./x86.h"
void* buffer = malloc(0xff);
void* origin = buffer;
inc_r32(&buffer, eax);
ret(&buffer);
free(origin);
```
### Using the Nim API
```nim
# The Nim language goes very well with ASM., thanks to its UFCS support.
import asmdot/x86
var
bytes = newSeqOfCap[byte](10)
buf = addr bytes[0]
buf.inc(eax)
buf.ret()
```
### Using the Python API
```python
from asm.x86 import Reg32, X86Assembler
asm = X86Assembler(10)
asm.inc_r32(Reg32.eax)
asm.ret()
```
### Using the Rust API
```rust
use asm::x86::{Register32, X86Assembler};
let mut buf = vec!();
buf.inc_r32(Register32::EAX)?;
buf.ret()?;
```
## Installing
We're not there yet, but if you want to experiment with the project or contribute,
you're welcome to clone it and play around.
```bash
# Clone project
git clone https://github.com/71/asmdot.git
# Get dependencies
python -m pip install -r asmdot/requirements.txt
# Play around
PYTHONPATH=. && python languages/c/generate.py --help
```
## Status
### Architectures
* [ARM](./asmdot/arch/arm): **WIP**.
* [MIPS](./asmdot/arch/mips): **WIP**.
* [X86](./asmdot/arch/x86): **WIP**.
### Sources
* [C](./languages/c)
* [C++](./languages/cpp)
* [C#](./languages/csharp)
* [Go](./languages/go)
* [Haskell](./languages/haskell)
* [JavaScript](./languages/javascript)
* [Nim](./languages/nim)
* [OCaml](./languages/ocaml)
* [Python](./languages/python)
* [Rust](./languages/rust)
## Docs
The directory of each language (list available above) contains the documentation for
said language. Furthermore, a [hacking](./HACKING.md) guide is available for those who want
to extend or improve ASM.
## License
All the content of the repository is [MIT-licensed](./LICENSE.md), except the [data](./src/data)
directory which is [Unlicensed](http://unlicense.org).
近期下载者:
相关文件:
收藏者: