add lib and module stuff
This commit is contained in:
parent
7d3604957e
commit
ae9b3e5eb1
3 changed files with 34 additions and 7 deletions
|
@ -24,6 +24,8 @@ pub fn build(b: *std.Build) void {
|
|||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
|
||||
addModule(b);
|
||||
|
||||
// Testing
|
||||
const elf_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/elf.zig"),
|
||||
|
@ -36,3 +38,10 @@ pub fn build(b: *std.Build) void {
|
|||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_elf_unit_tests.step);
|
||||
}
|
||||
|
||||
/// Module function for depending on the elphin module
|
||||
pub fn addModule(b: *std.Build) void {
|
||||
_ = b.addModule("elphin", .{
|
||||
.root_source_file = .{ .path = "src/lib.zig" },
|
||||
});
|
||||
}
|
||||
|
|
22
src/lib.zig
Normal file
22
src/lib.zig
Normal file
|
@ -0,0 +1,22 @@
|
|||
const elf = @import("elf.zig");
|
||||
const dol = @import("dol.zig");
|
||||
|
||||
pub const ELFError = elf.ELFError;
|
||||
pub const ELFSegments = elf.ELFSegments;
|
||||
|
||||
pub const readELF = elf.readELF;
|
||||
pub const createDOLMapping = dol.createDOLMapping;
|
||||
pub const writeDOL = dol.writeDOL;
|
||||
|
||||
/// Converts an ELF file to a DOL file.
|
||||
/// `input` and `output` must be open files.
|
||||
pub fn convert(input: anytype, output: anytype) !void {
|
||||
// Read input
|
||||
const map = try elf.readELF(input);
|
||||
|
||||
// Align segments to 64 byte boundaries
|
||||
const dolMap = dol.createDOLMapping(map);
|
||||
|
||||
// Write header and copy over segments from input
|
||||
try dol.writeDOL(dolMap, input, output);
|
||||
}
|
10
src/main.zig
10
src/main.zig
|
@ -1,6 +1,5 @@
|
|||
const std = @import("std");
|
||||
const elf = @import("elf.zig");
|
||||
const dol = @import("dol.zig");
|
||||
const lib = @import("lib.zig");
|
||||
|
||||
pub fn main() !void {
|
||||
// Get allocator
|
||||
|
@ -23,13 +22,10 @@ pub fn main() !void {
|
|||
// Read input
|
||||
const input = try std.fs.cwd().openFile(inputPath, .{});
|
||||
defer input.close();
|
||||
const map = try elf.readELF(input);
|
||||
|
||||
// Align segments to 64 byte boundaries
|
||||
const dolMap = dol.createDOLMapping(map);
|
||||
|
||||
// Write header and copy over segments from input
|
||||
const output = try std.fs.cwd().createFile(outputPath, .{});
|
||||
defer output.close();
|
||||
try dol.writeDOL(dolMap, input, output);
|
||||
|
||||
try lib.convert(input, output);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue