restructure project layout
This commit is contained in:
parent
cef071d28f
commit
adcb0891fb
44
build.zig
44
build.zig
@ -14,11 +14,13 @@ fn addLinuxAssembly(b: *Builder, filename: []const u8) !std.Build.LazyPath {
|
|||||||
return output_obj;
|
return output_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn addAllLinuxAssmeblies(b: *Builder) !std.ArrayList(std.Build.LazyPath) {
|
fn addAllLinuxAssmeblies(b: *Builder, path: []const u8) !std.ArrayList(std.Build.LazyPath) {
|
||||||
var linux_assemblies = std.ArrayList(std.Build.LazyPath).init(b.allocator);
|
const allocator = b.allocator;
|
||||||
|
|
||||||
|
var linux_assemblies = std.ArrayList(std.Build.LazyPath).init(allocator);
|
||||||
errdefer linux_assemblies.deinit();
|
errdefer linux_assemblies.deinit();
|
||||||
|
|
||||||
var dir = try std.fs.cwd().openIterableDir("src", .{ });
|
var dir = try std.fs.cwd().openIterableDir(path, .{ });
|
||||||
var it = dir.iterate();
|
var it = dir.iterate();
|
||||||
while (try it.next()) |file| {
|
while (try it.next()) |file| {
|
||||||
if (file.kind != .file) continue;
|
if (file.kind != .file) continue;
|
||||||
@ -26,8 +28,8 @@ fn addAllLinuxAssmeblies(b: *Builder) !std.ArrayList(std.Build.LazyPath) {
|
|||||||
const ext = std.fs.path.extension(file.name);
|
const ext = std.fs.path.extension(file.name);
|
||||||
if (!std.mem.eql(u8, ext, ".asm")) continue;
|
if (!std.mem.eql(u8, ext, ".asm")) continue;
|
||||||
|
|
||||||
const assembly_path = try std.mem.concat(b.allocator, u8, &.{ "src/", file.name });
|
const assembly_path = try std.fs.path.join(allocator, &.{ path, file.name });
|
||||||
defer b.allocator.free(assembly_path);
|
defer allocator.free(assembly_path);
|
||||||
|
|
||||||
try linux_assemblies.append(try addLinuxAssembly(b, assembly_path));
|
try linux_assemblies.append(try addLinuxAssembly(b, assembly_path));
|
||||||
}
|
}
|
||||||
@ -39,32 +41,32 @@ pub fn build(b: *Builder) !void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
var linux_assemblies = try addAllLinuxAssmeblies(b);
|
const allocator = b.allocator;
|
||||||
defer linux_assemblies.deinit();
|
|
||||||
|
|
||||||
var dir = try std.fs.cwd().openIterableDir("src/tests", .{ });
|
var dir = try std.fs.cwd().openIterableDir("src", .{ });
|
||||||
var it = dir.iterate();
|
var it = dir.iterate();
|
||||||
while (try it.next()) |file| {
|
while (try it.next()) |entry| {
|
||||||
if (file.kind != .file) continue;
|
if (entry.kind != .directory) continue;
|
||||||
|
|
||||||
const ext = std.fs.path.extension(file.name);
|
const program_dir = try std.fs.path.join(allocator, &.{ "src", entry.name });
|
||||||
if (!std.mem.eql(u8, ext, ".c")) continue;
|
defer allocator.free(program_dir);
|
||||||
|
|
||||||
const source_file_path = try std.mem.concat(b.allocator, u8, &.{ "src/tests/", file.name });
|
const main_c = try std.fs.path.join(allocator, &.{ program_dir, "main.c" });
|
||||||
defer b.allocator.free(source_file_path);
|
defer allocator.free(main_c);
|
||||||
|
|
||||||
const executable_name = std.fs.path.stem(file.name);
|
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = executable_name,
|
.name = entry.name,
|
||||||
.root_source_file = .{ .path = source_file_path },
|
.root_source_file = .{ .path = main_c },
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.target = target
|
.target = target
|
||||||
});
|
});
|
||||||
|
exe.addIncludePath(.{ .path = program_dir });
|
||||||
exe.addIncludePath(.{ .path = "src" });
|
exe.addIncludePath(.{ .path = "src" });
|
||||||
exe.linkLibC();
|
exe.linkLibC();
|
||||||
|
|
||||||
for (linux_assemblies.items) |obj| {
|
var assemblies = try addAllLinuxAssmeblies(b, program_dir);
|
||||||
|
defer assemblies.deinit();
|
||||||
|
for (assemblies.items) |obj| {
|
||||||
exe.addObjectFile(obj);
|
exe.addObjectFile(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,9 +77,9 @@ pub fn build(b: *Builder) !void {
|
|||||||
run_exe.addArgs(args);
|
run_exe.addArgs(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
const step_description = try std.fmt.allocPrint(b.allocator, "Run '{s}' test", .{source_file_path});
|
const step_description = try std.fmt.allocPrint(b.allocator, "Run '{s}' test", .{ entry.name });
|
||||||
defer b.allocator.free(step_description);
|
defer b.allocator.free(step_description);
|
||||||
const run_step = b.step(executable_name, step_description);
|
const run_step = b.step(entry.name, step_description);
|
||||||
run_step.dependOn(&run_exe.step);
|
run_step.dependOn(&run_exe.step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,3 +119,4 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -54,3 +54,4 @@ int main() {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -38,3 +38,4 @@ int main() {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -38,3 +38,4 @@ int main() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,3 +37,4 @@ int main() {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
64
src/main.c
64
src/main.c
@ -1,64 +0,0 @@
|
|||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#include "repetition_tester.c"
|
|
||||||
|
|
||||||
#define RPROF_IMPLEMENTATION
|
|
||||||
#include "rprof.h"
|
|
||||||
|
|
||||||
#include "main_read_file.c"
|
|
||||||
#include "main_write_bytes_asm.c"
|
|
||||||
#include "main_write_all_bytes.c"
|
|
||||||
#include "main_malloc_read.c"
|
|
||||||
#include "main_write_backward.c"
|
|
||||||
#include "main_write_loop.c"
|
|
||||||
#include "main_load_uop.c"
|
|
||||||
#include "main_store_uop.c"
|
|
||||||
#include "main_short_load_uop.c"
|
|
||||||
#include "main_read_widths.c"
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
if (argc < 2) {
|
|
||||||
printf("Usage: %s <test-name>\n", argv[0]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *test_name = argv[1];
|
|
||||||
|
|
||||||
if (!strncmp(test_name, "write_bytes_asm", sizeof("write_bytes_asm"))) {
|
|
||||||
return main_test_write_bytes_asm();
|
|
||||||
} else if (!strncmp(test_name, "read_widths", sizeof("read_widths"))) {
|
|
||||||
return main_test_read_widths();
|
|
||||||
} else if (!strncmp(test_name, "write_all_bytes", sizeof("write_bytes"))) {
|
|
||||||
return main_test_write_all_bytes();
|
|
||||||
} else if (!strncmp(test_name, "load_uop", sizeof("load_uop"))) {
|
|
||||||
return main_test_load_uop();
|
|
||||||
} else if (!strncmp(test_name, "store_uop", sizeof("store_uop"))) {
|
|
||||||
return main_test_store_uop();
|
|
||||||
} else if (!strncmp(test_name, "short_load_uop", sizeof("short_load_uop"))) {
|
|
||||||
return main_test_short_load_uop();
|
|
||||||
} else if (!strncmp(test_name, "write_loop", sizeof("write_loop"))) {
|
|
||||||
return main_test_write_loop();
|
|
||||||
} else if (!strncmp(test_name, "write_backward", sizeof("write_backward"))) {
|
|
||||||
return main_test_write_backward();
|
|
||||||
} else if (!strncmp(test_name, "read_file", sizeof("read_file"))) {
|
|
||||||
if (argc < 3) {
|
|
||||||
printf("Usage: %s read_file <filename>\n", argv[0]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return main_test_read_file(argv[2]);
|
|
||||||
} else if (!strncmp(test_name, "malloc_read", sizeof("malloc_read"))) {
|
|
||||||
if (argc < 3) {
|
|
||||||
printf("Usage: %s malloc_read <filename>\n", argv[0]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return main_test_malloc_read(argv[2]);
|
|
||||||
} else {
|
|
||||||
printf("ERROR: Unknown test case '%s'\n", test_name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user