Compare commits

..

No commits in common. "86e899e771e91edc3625fa07061175b16e5c14d1" and "6c3d20bbbbe775b81e247c4a617afe3237596e74" have entirely different histories.

4 changed files with 4 additions and 17 deletions

2
.gitignore vendored
View file

@ -1,3 +1 @@
zig-cache/ zig-cache/
*.bc
*.ll

View file

@ -6,9 +6,7 @@ pub fn build(b: *Builder) void {
exe.setBuildMode(mode); exe.setBuildMode(mode);
exe.install(); exe.install();
exe.linkSystemLibrary("c");
exe.linkSystemLibrary("LLVM-8"); exe.linkSystemLibrary("LLVM-8");
exe.linkSystemLibrary("stdc++");
const run_cmd = exe.run(); const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());

View file

@ -62,18 +62,18 @@ pub const Codegen = struct {
} }
pub fn gen(self: *Codegen, root: *ast.Node) !void { pub fn gen(self: *Codegen, root: *ast.Node) !void {
//std.debug.warn("cgen: init native target\n");
//_ = llvm.LLVMInitializeNativeTarget();
std.debug.warn("cgen: start gen\n"); std.debug.warn("cgen: start gen\n");
var mod = llvm.LLVMModuleCreateWithName(c"awoo");
var mod = llvm.LLVMModuleCreateWithName(c"awoo").?;
defer llvm.LLVMDisposeModule(mod); defer llvm.LLVMDisposeModule(mod);
std.debug.warn("cgen: got mod\n");
for (root.Root.toSlice()) |child| { for (root.Root.toSlice()) |child| {
std.debug.warn("cgen: gen child {}\n", child); std.debug.warn("cgen: gen child {}\n", child);
try self.genNode(mod, &child); try self.genNode(mod, &child);
} }
std.debug.warn("cgen: done\n");
var err: ?[*]u8 = null; var err: ?[*]u8 = null;
_ = llvm.LLVMVerifyModule( _ = llvm.LLVMVerifyModule(
mod, mod,
@ -81,9 +81,5 @@ pub const Codegen = struct {
&err, &err,
); );
llvm.LLVMDisposeMessage(err); llvm.LLVMDisposeMessage(err);
if (llvm.LLVMWriteBitcodeToFile(mod, c"awoo.bc") != 0) {
std.debug.warn("error writing bitcode to file\n");
}
} }
}; };

View file

@ -6,11 +6,6 @@ pub const llvm = @cImport({
@cInclude("llvm-c/Target.h"); @cInclude("llvm-c/Target.h");
@cInclude("llvm-c/Analysis.h"); @cInclude("llvm-c/Analysis.h");
@cInclude("llvm-c/BitWriter.h"); @cInclude("llvm-c/BitWriter.h");
@cDefine("_GNU_SOURCE", {});
@cDefine("__STDC_CONSTANT_MACROS", {});
@cDefine("__STDC_FORMAT_MACROS", {});
@cDefine("__STDC_LIMIT_MACROS", {});
}); });
usingnamespace llvm; usingnamespace llvm;