Skip to content

Commit

Permalink
[OBJ] starting object builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Jul 12, 2024
1 parent ddd7120 commit aefc9ea
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 0 deletions.
199 changes: 199 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
object = { version = "0.36.1", features = ["write"] }
27 changes: 27 additions & 0 deletions examples/obj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::{error::Error, fs::OpenOptions};

use Ygen::{Obj::*, Target::Triple};

fn main() -> Result<(), Box<dyn Error>> {
let mut obj = ObjectBuilder::new(
Triple::parse("x86_64-pc-windows")?
);

obj.decls(vec![
("test", Decl::Function, Linkage::External),
("test_data", Decl::Constant, Linkage::Extern),
]);

obj.define("test", vec![
0xB8, 0x00, 0x00, 0x00, 0x00, // mov eax, 5
0xC3,
]);

obj.link(Link { from: "test".into(), to: "test_data".into(), at: 1 });

obj.emit(
OpenOptions::new().create(true).write(true).open("output.o")?
)?;

Ok(())
}
Binary file added output.o
Binary file not shown.
6 changes: 6 additions & 0 deletions src/Obj/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod wrapper;

pub use wrapper::{
ObjectBuilder,
Decl, Link, Linkage,
};
Loading

0 comments on commit aefc9ea

Please sign in to comment.