making parser

This commit is contained in:
2024-12-20 00:00:51 +02:00
parent 69e90b6b9f
commit 228b215259
7 changed files with 405 additions and 196 deletions

View File

@@ -1,6 +1,11 @@
const std = @import("std");
const c_lib_files = &[_][]const u8{ "tokenizer.c", "ast.c", "zig1.c" };
const c_lib_files = &[_][]const u8{
"tokenizer.c",
"ast.c",
"zig1.c",
"parser.c",
};
const all_c_files = c_lib_files ++ &[_][]const u8{"main.c"};
const cflags = &[_][]const u8{
"-std=c11",
@@ -19,6 +24,7 @@ const cflags = &[_][]const u8{
"-Wdouble-promotion",
"-fstack-protector-all",
"-Wimplicit-fallthrough",
"-Wno-unused-function", // TODO remove once refactoring is done
//"-D_FORTIFY_SOURCE=2", // consider when optimization flags are enabled
};
@@ -37,24 +43,21 @@ pub fn build(b: *std.Build) !void {
if (std.mem.eql(u8, cc, "zig"))
lib.addCSourceFiles(.{ .files = c_lib_files, .flags = cflags })
else for (c_lib_files) |cfile| {
const objfile = try std.fmt.allocPrint(
b.allocator,
"{s}.o",
.{cfile[0 .. cfile.len - 2]},
);
const cc1 = b.addSystemCommand(&.{cc});
cc1.addArgs(cflags);
cc1.addArg("-g");
cc1.addArgs(switch (optimize) {
.Debug => &.{"-O0"},
.ReleaseFast, .ReleaseSafe => &.{"-O3"}, // TODO ubsan?
.ReleaseSmall => &.{"-Os"},
cc1.addArgs(cflags ++ .{"-g"});
cc1.addArg(switch (optimize) {
.Debug => "-O0",
.ReleaseFast, .ReleaseSafe => "-O3", // ubsan?
.ReleaseSmall => "-Os",
});
cc1.addArg("-c");
cc1.addFileArg(b.path(cfile));
cc1.addArg("-o");
const obj = cc1.addOutputFileArg(objfile);
lib.addObjectFile(obj);
lib.addObjectFile(cc1.addOutputFileArg(try std.fmt.allocPrint(
b.allocator,
"{s}.o",
.{cfile[0 .. cfile.len - 2]},
)));
}
lib.linkLibC();
@@ -91,11 +94,13 @@ pub fn build(b: *std.Build) !void {
const cppcheck = b.addSystemCommand(&.{"cppcheck"});
cppcheck.addArgs(&.{
"--quiet",
"--error-exitcode=1",
"--enable=all",
"--suppress=missingIncludeSystem",
"--suppress=checkersReport",
"--quiet",
"--suppress=unusedFunction", // TODO remove after plumbing is done
"--suppress=unusedStructMember", // TODO remove after plumbing is done
});
for (all_c_files) |cfile| cppcheck.addFileArg(b.path(cfile));
lint_step.dependOn(&cppcheck.step);