diff --git a/bootstrap/compiler.zig b/bootstrap/compiler.zig index 080db13..eebf53b 100644 --- a/bootstrap/compiler.zig +++ b/bootstrap/compiler.zig @@ -49,8 +49,8 @@ fn is_decimal_digit(ch: u8) bool { } fn is_alphabetic(ch: u8) bool { - const lower = is_lower(ch); - const upper = is_upper(ch); + const lower = is_lower(ch); + const upper = is_upper(ch); return lower or upper; } @@ -66,14 +66,14 @@ fn is_identifier_char(ch: u8) bool { return is_identifier_start_ch or is_digit; } -const GlobalSymbol = struct{ +const GlobalSymbol = struct { attributes: Attributes = .{}, name: u32, - const Attributes = struct{ + const Attributes = struct { @"export": bool = false, @"extern": bool = false, }; - const Attribute = enum{ + const Attribute = enum { @"export", @"extern", @@ -81,7 +81,7 @@ const GlobalSymbol = struct{ }; }; -const Parser = struct{ +const Parser = struct { i: u64 = 0, current_line: u32 = 0, line_offset: u32 = 0, @@ -172,7 +172,7 @@ const Parser = struct{ fn parse_non_escaped_string_literal_content(parser: *Parser, src: []const u8) []const u8 { const string_literal = parser.parse_non_escaped_string_literal(src); - return string_literal[1..][0..string_literal.len - 2]; + return string_literal[1..][0 .. string_literal.len - 2]; } fn expect_character(parser: *Parser, file: []const u8, expected: u8) void { @@ -263,7 +263,7 @@ const Parser = struct{ const follow_up_alpha = is_alphabetic(follow_up_character); const follow_up_digit = is_decimal_digit(follow_up_character); const is_valid_after_zero = is_space(follow_up_character) or (!follow_up_digit and !follow_up_alpha); - // + // if (is_prefixed_start) { exit(1); } else if (is_valid_after_zero) { @@ -302,7 +302,7 @@ const Parser = struct{ .unresolved_import => { resolved = false; lazy_expression.* = LazyExpression.init(declaration); - + while (true) { switch (src[parser.i]) { '.' => { @@ -366,7 +366,7 @@ const Parser = struct{ }; const LazyExpression = union(enum) { - dynamic: struct{ + dynamic: struct { names: PinnedArray(u32) = .{}, outsider: *GlobalSymbolReference, }, @@ -395,7 +395,7 @@ const LazyExpression = union(enum) { fn names(lazy_expression: *LazyExpression) []const u32 { return switch (lazy_expression.*) { .dynamic => |*d| d.names.slice(), - .static => |*s| s.names[0.. for (s.names, 0..) |n, i| { + .static => |*s| s.names[0..for (s.names, 0..) |n, i| { if (n == 0) break @intCast(i); } else s.names.len], }; @@ -425,7 +425,7 @@ fn Descriptor(comptime Id: type, comptime Integer: type) type { }; } -const Expression = struct{ +const Expression = struct { type: *Type, value: *Value, }; @@ -439,7 +439,7 @@ const Value = struct { reserved: u7 = 0, id: Id, }, - const Id = enum(u8){ + const Id = enum(u8) { constant_int, lazy_expression, instruction, @@ -454,7 +454,7 @@ const Type = struct { id: Id, }, - const Id = enum(u8){ + const Id = enum(u8) { unresolved, void, integer, @@ -466,14 +466,13 @@ const Type = struct { reserved: u7 = 0, id: Id = .integer, - const Signedness = enum(u1){ + const Signedness = enum(u1) { unsigned, signed, }; }; }; - fn integer_bit_count(t: *Type) u16 { const integer: Type.Integer = @bitCast(t.sema); return integer.bit_count; @@ -484,10 +483,9 @@ fn integer_signedness(t: *Type) Type.Integer.Signedness { return integer.signedness; } -const IntegerType = struct{ -}; +const IntegerType = struct {}; -const Keyword = enum{ +const Keyword = enum { @"for", }; @@ -506,12 +504,12 @@ const Scope = Descriptor(enum(u3) { function, local, }, u32); -const Range = struct{ +const Range = struct { start: u32, end: u32, }; -const FileScope = struct{ +const FileScope = struct { declarations: PinnedHashMap(u32, GlobalSymbolReference) = .{}, }; @@ -522,7 +520,7 @@ const GlobalSymbolReference = Descriptor(enum(u3) { unresolved_import, }, u32); -const BasicBlock = struct{ +const BasicBlock = struct { instructions: PinnedArray(*Instruction) = .{}, predecessors: PinnedArray(u32) = .{}, is_terminated: bool = false, @@ -530,15 +528,15 @@ const BasicBlock = struct{ const Index = PinnedArray(BasicBlock).Index; }; -const Function = struct{ +const Function = struct { declaration: Function.Declaration, entry_block: BasicBlock.Index, - const Attributes = struct{ + const Attributes = struct { calling_convention: CallingConvention = .custom, }; - const Attribute = enum{ + const Attribute = enum { cc, pub const Mask = std.EnumSet(Function.Attribute); @@ -553,36 +551,34 @@ const Function = struct{ }; }; - -const Instruction = struct{ +const Instruction = struct { index: u24, id: Id, llvm: ?*LLVM.Value = null, - const Id = enum{ + const Id = enum { call, ret, ret_void, }; }; -const ConstantInt = struct{ +const ConstantInt = struct { value: u64, type: *Type, }; - -const Call = struct{ +const Call = struct { value: *Value, const Index = PinnedArray(Call).Index; }; -const Return = struct{ +const Return = struct { value: *Value, const Index = PinnedArray(Call).Index; }; -const Thread = struct{ +const Thread = struct { arena: *Arena = undefined, functions: PinnedArray(Function) = .{}, external_functions: PinnedArray(Function.Declaration) = .{}, @@ -610,7 +606,6 @@ const Thread = struct{ attributes: LLVM.Attributes, } = undefined, - fn add_thread_work(thread: *Thread, job: Job) void { thread.task_system.job.queue_job(job); } @@ -638,7 +633,7 @@ const Job = packed struct(u64) { count: u24 = 0, id: Id, - const Id = enum(u8){ + const Id = enum(u8) { analyze_file, llvm_setup, notify_file_resolved, @@ -647,12 +642,12 @@ const Job = packed struct(u64) { }; }; -const TaskSystem = struct{ +const TaskSystem = struct { job: JobQueue = .{}, ask: JobQueue = .{}, }; -const JobQueue = struct{ +const JobQueue = struct { entries: [64]Job = [1]Job{@bitCast(@as(u64, 0))} ** 64, to_do: u64 = 0, completed: u64 = 0, @@ -666,13 +661,13 @@ const JobQueue = struct{ var threads: []Thread = undefined; -const Instance = struct{ +const Instance = struct { files: PinnedArray(File) = .{}, file_paths: PinnedArray(u32) = .{}, arena: *Arena = undefined, }; -const File = struct{ +const File = struct { scope: Scope, source_code: []const u8, path: []const u8, @@ -688,7 +683,7 @@ const File = struct{ return std.fs.path.dirname(file.path) orelse unreachable; } - const State = enum{ + const State = enum { queued, analyzing, }; @@ -700,7 +695,7 @@ var instance = Instance{}; const do_codegen = true; const codegen_backend = CodegenBackend.llvm; -const CodegenBackend = enum{ +const CodegenBackend = enum { llvm, }; @@ -830,7 +825,7 @@ pub fn make() void { for (threads, 0..) |*thread, i| { const control_pending = thread.task_system.ask.to_do - thread.task_system.ask.completed; if (control_pending != 0) { - const jobs_to_do = thread.task_system.ask.entries[thread.task_system.ask.completed .. thread.task_system.ask.to_do]; + const jobs_to_do = thread.task_system.ask.entries[thread.task_system.ask.completed..thread.task_system.ask.to_do]; for (jobs_to_do) |job| { switch (job.id) { @@ -971,7 +966,7 @@ fn intern_identifier(pool: *PinnedHashMap(u32, []const u8), identifier: []const // switch (function_expression.kind) { // .resolved => |resolved| switch (resolved) { // .declaration => |declaration| switch (declaration.id) { -// .function_definition => |fn_def| { +// .function_definition => |fn_def| { // _ = fn_def; // autofix // _ = expression.instruction; // const basic_block = thread.basic_blocks.get(expression.basic_block); @@ -1046,340 +1041,686 @@ fn resolve_value(thread: *Thread, file_index: u32, value: *Value) void { // } } -const Bitcode = struct { -}; +const Bitcode = struct {}; fn write_bitcode() void { var buffer = PinnedArray(u8){}; // Magic - buffer.append_slice(&.{0x42, 0x43, 0xc0, 0xde}); - buffer.append_slice(&.{0x35, 0x14, 0x00, 0x00}); - buffer.append_slice(sample_bitcode[buffer.length..]); + const magic = [_]u8{ 0x42, 0x43, 0xc0, 0xde }; + buffer.append_slice(&magic); + const identification_block = [_]u8{ + 0x35, 0x14, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, + 0x62, 0x0c, 0x30, 0x24, + 0x4a, 0x59, 0xbe, 0x66, + 0xbd, 0xfb, 0xb4, 0xaf, + 0x0b, 0x51, 0x80, 0x4c, + 0x01, 0x00, 0x00, 0x00, + }; + buffer.append_slice(&identification_block); + // ================== + // MODULE BLOCK START + // ================== + const module_block_start = [_]u8{ + 0x21, 0x0c, 0x00, 0x00, + 0x1f, 0x01, 0x00, 0x00, + 0x0b, 0x02, 0x21, 0x00, + }; + buffer.append_slice(&module_block_start); + const blockinfo_block = [_]u8{ + 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, + 0x07, 0x81, 0x23, 0x91, + 0x41, 0xc8, 0x04, 0x49, + 0x06, 0x10, 0x32, 0x39, + 0x92, 0x01, 0x84, 0x0c, + 0x25, 0x05, 0x08, 0x19, + 0x1e, 0x04, 0x8b, 0x62, + 0x80, 0x04, 0x45, 0x02, + 0x42, 0x92, 0x0b, 0x42, + 0x24, 0x10, 0x32, 0x14, + 0x38, 0x08, 0x18, 0x4b, + 0x0a, 0x32, 0x12, 0x88, + 0x48, 0x70, 0xc4, 0x21, + 0x23, 0x44, 0x12, 0x87, + 0x8c, 0x10, 0x41, 0x92, + 0x02, 0x64, 0xc8, 0x08, + 0xb1, 0x14, 0x20, 0x43, + 0x46, 0x88, 0x20, 0xc9, + 0x01, 0x32, 0x12, 0x84, + 0x18, 0x2a, 0x28, 0x2a, + 0x90, 0x31, 0x7c, 0xb0, + 0x5c, 0x91, 0x20, 0xc1, + 0xc8, 0x00, 0x00, 0x00, + }; + buffer.append_slice(&blockinfo_block); + const typeinfo_block = [_]u8{ + 0x89, 0x20, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, + 0x22, 0x66, 0x04, 0x10, + 0xb2, 0x42, 0x82, 0x49, + 0x10, 0x52, 0x42, 0x82, + 0x49, 0x90, 0x71, 0xc2, + 0x50, 0x48, 0x0a, 0x09, + 0x26, 0x41, 0xc6, 0x05, + 0x42, 0x12, 0x26, 0x08, + 0x82, 0x81, 0x00, 0x00, + 0x1a, 0x21, 0x4c, 0x0e, + 0x13, 0x36, 0xdb, 0xde, + 0x6e, 0xb1, 0xd3, 0xee, + 0xb5, 0xc4, 0x06, 0x81, + 0xa2, 0x24, 0x01, 0x00, + }; + buffer.append_slice(&typeinfo_block); + + const metadata_kind_block = [_]u8{ + 0x00, 0xb1, 0x18, 0x00, + 0xb9, 0x00, 0x00, 0x00, + 0x33, 0x08, 0x80, 0x1c, + 0xc4, 0xe1, 0x1c, 0x66, + 0x14, 0x01, 0x3d, 0x88, + 0x43, 0x38, 0x84, 0xc3, + 0x8c, 0x42, 0x80, 0x07, + 0x79, 0x78, 0x07, 0x73, + 0x98, 0x71, 0x0c, 0xe6, + 0x00, 0x0f, 0xed, 0x10, + 0x0e, 0xf4, 0x80, 0x0e, + 0x33, 0x0c, 0x42, 0x1e, + 0xc2, 0xc1, 0x1d, 0xce, + 0xa1, 0x1c, 0x66, 0x30, + 0x05, 0x3d, 0x88, 0x43, + 0x38, 0x84, 0x83, 0x1b, + 0xcc, 0x03, 0x3d, 0xc8, + 0x43, 0x3d, 0x8c, 0x03, + 0x3d, 0xcc, 0x78, 0x8c, + 0x74, 0x70, 0x07, 0x7b, + 0x08, 0x07, 0x79, 0x48, + 0x87, 0x70, 0x70, 0x07, + 0x7a, 0x70, 0x03, 0x76, + 0x78, 0x87, 0x70, 0x20, + 0x87, 0x19, 0xcc, 0x11, + 0x0e, 0xec, 0x90, 0x0e, + 0xe1, 0x30, 0x0f, 0x6e, + 0x30, 0x0f, 0xe3, 0xf0, + 0x0e, 0xf0, 0x50, 0x0e, + 0x33, 0x10, 0xc4, 0x1d, + 0xde, 0x21, 0x1c, 0xd8, + 0x21, 0x1d, 0xc2, 0x61, + 0x1e, 0x66, 0x30, 0x89, + 0x3b, 0xbc, 0x83, 0x3b, + 0xd0, 0x43, 0x39, 0xb4, + 0x03, 0x3c, 0xbc, 0x83, + 0x3c, 0x84, 0x03, 0x3b, + 0xcc, 0xf0, 0x14, 0x76, + 0x60, 0x07, 0x7b, 0x68, + 0x07, 0x37, 0x68, 0x87, + 0x72, 0x68, 0x07, 0x37, + 0x80, 0x87, 0x70, 0x90, + 0x87, 0x70, 0x60, 0x07, + 0x76, 0x28, 0x07, 0x76, + 0xf8, 0x05, 0x76, 0x78, + 0x87, 0x77, 0x80, 0x87, + 0x5f, 0x08, 0x87, 0x71, + 0x18, 0x87, 0x72, 0x98, + 0x87, 0x79, 0x98, 0x81, + 0x2c, 0xee, 0xf0, 0x0e, + 0xee, 0xe0, 0x0e, 0xf5, + 0xc0, 0x0e, 0xec, 0x30, + 0x03, 0x62, 0xc8, 0xa1, + 0x1c, 0xe4, 0xa1, 0x1c, + 0xcc, 0xa1, 0x1c, 0xe4, + 0xa1, 0x1c, 0xdc, 0x61, + 0x1c, 0xca, 0x21, 0x1c, + 0xc4, 0x81, 0x1d, 0xca, + 0x61, 0x06, 0xd6, 0x90, + 0x43, 0x39, 0xc8, 0x43, + 0x39, 0x98, 0x43, 0x39, + 0xc8, 0x43, 0x39, 0xb8, + 0xc3, 0x38, 0x94, 0x43, + 0x38, 0x88, 0x03, 0x3b, + 0x94, 0xc3, 0x2f, 0xbc, + 0x83, 0x3c, 0xfc, 0x82, + 0x3b, 0xd4, 0x03, 0x3b, + 0xb0, 0xc3, 0x0c, 0xc7, + 0x69, 0x87, 0x70, 0x58, + 0x87, 0x72, 0x70, 0x83, + 0x74, 0x68, 0x07, 0x78, + 0x60, 0x87, 0x74, 0x18, + 0x87, 0x74, 0xa0, 0x87, + 0x19, 0xce, 0x53, 0x0f, + 0xee, 0x00, 0x0f, 0xf2, + 0x50, 0x0e, 0xe4, 0x90, + 0x0e, 0xe3, 0x40, 0x0f, + 0xe1, 0x20, 0x0e, 0xec, + 0x50, 0x0e, 0x33, 0x20, + 0x28, 0x1d, 0xdc, 0xc1, + 0x1e, 0xc2, 0x41, 0x1e, + 0xd2, 0x21, 0x1c, 0xdc, + 0x81, 0x1e, 0xdc, 0xe0, + 0x1c, 0xe4, 0xe1, 0x1d, + 0xea, 0x01, 0x1e, 0x66, + 0x18, 0x51, 0x38, 0xb0, + 0x43, 0x3a, 0x9c, 0x83, + 0x3b, 0xcc, 0x50, 0x24, + 0x76, 0x60, 0x07, 0x7b, + 0x68, 0x07, 0x37, 0x60, + 0x87, 0x77, 0x78, 0x07, + 0x78, 0x98, 0x51, 0x4c, + 0xf4, 0x90, 0x0f, 0xf0, + 0x50, 0x0e, 0x33, 0x1e, + 0x6a, 0x1e, 0xca, 0x61, + 0x1c, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x7e, + 0x01, 0x1e, 0xe4, 0xa1, + 0x1c, 0xcc, 0x21, 0x1d, + 0xf0, 0x61, 0x06, 0x54, + 0x85, 0x83, 0x38, 0xcc, + 0xc3, 0x3b, 0xb0, 0x43, + 0x3d, 0xd0, 0x43, 0x39, + 0xfc, 0xc2, 0x3c, 0xe4, + 0x43, 0x3b, 0x88, 0xc3, + 0x3b, 0xb0, 0xc3, 0x8c, + 0xc5, 0x0a, 0x87, 0x79, + 0x98, 0x87, 0x77, 0x18, + 0x87, 0x74, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, + 0x98, 0x81, 0x5c, 0xe3, + 0x10, 0x0e, 0xec, 0xc0, + 0x0e, 0xe5, 0x50, 0x0e, + 0xf3, 0x30, 0x23, 0xc1, + 0xd2, 0x41, 0x1e, 0xe4, + 0xe1, 0x17, 0xd8, 0xe1, + 0x1d, 0xde, 0x01, 0x1e, + 0x66, 0x48, 0x19, 0x3b, + 0xb0, 0x83, 0x3d, 0xb4, + 0x83, 0x1b, 0x84, 0xc3, + 0x38, 0x8c, 0x43, 0x39, + 0xcc, 0xc3, 0x3c, 0xb8, + 0xc1, 0x39, 0xc8, 0xc3, + 0x3b, 0xd4, 0x03, 0x3c, + 0xcc, 0x48, 0xb4, 0x71, + 0x08, 0x07, 0x76, 0x60, + 0x07, 0x71, 0x08, 0x87, + 0x71, 0x58, 0x87, 0x19, + 0xdb, 0xc6, 0x0e, 0xec, + 0x60, 0x0f, 0xed, 0xe0, + 0x06, 0xf0, 0x20, 0x0f, + 0xe5, 0x30, 0x0f, 0xe5, + 0x20, 0x0f, 0xf6, 0x50, + 0x0e, 0x6e, 0x10, 0x0e, + 0xe3, 0x30, 0x0e, 0xe5, + 0x30, 0x0f, 0xf3, 0xe0, + 0x06, 0xe9, 0xe0, 0x0e, + 0xe4, 0x50, 0x0e, 0xf8, + 0x30, 0x23, 0xe2, 0xec, + 0x61, 0x1c, 0xc2, 0x81, + 0x1d, 0xd8, 0xe1, 0x17, + 0xec, 0x21, 0x1d, 0xe6, + 0x21, 0x1d, 0xc4, 0x21, + 0x1d, 0xd8, 0x21, 0x1d, + 0xe8, 0x21, 0x1f, 0x66, + 0x20, 0x9d, 0x3b, 0xbc, + 0x43, 0x3d, 0xb8, 0x03, + 0x39, 0x94, 0x83, 0x39, + 0xcc, 0x58, 0xbc, 0x70, + 0x70, 0x07, 0x77, 0x78, + 0x07, 0x7a, 0x08, 0x07, + 0x7a, 0x48, 0x87, 0x77, + 0x70, 0x87, 0x19, 0xcb, + 0xe7, 0x0e, 0xef, 0x30, + 0x0f, 0xe1, 0xe0, 0x0e, + 0xe9, 0x40, 0x0f, 0xe9, + 0xa0, 0x0f, 0xe5, 0x30, + 0xc3, 0x01, 0x03, 0x73, + 0xa8, 0x07, 0x77, 0x18, + 0x87, 0x5f, 0x98, 0x87, + 0x70, 0x70, 0x87, 0x74, + 0xa0, 0x87, 0x74, 0xd0, + 0x87, 0x72, 0x98, 0x81, + 0x84, 0x41, 0x39, 0xe0, + 0xc3, 0x38, 0xb0, 0x43, + 0x3d, 0x90, 0x43, 0x39, + 0xcc, 0x40, 0xc4, 0xa0, + 0x1d, 0xca, 0xa1, 0x1d, + 0xe0, 0x41, 0x1e, 0xde, + 0xc1, 0x1c, 0x66, 0x24, + 0x63, 0x30, 0x0e, 0xe1, + 0xc0, 0x0e, 0xec, 0x30, + 0x0f, 0xe9, 0x40, 0x0f, + 0xe5, 0x30, 0x43, 0x21, + 0x83, 0x75, 0x18, 0x07, + 0x73, 0x48, 0x87, 0x5f, + 0xa0, 0x87, 0x7c, 0x80, + 0x87, 0x72, 0x98, 0xb1, + 0x94, 0x01, 0x3c, 0x8c, + 0xc3, 0x3c, 0x94, 0xc3, + 0x38, 0xd0, 0x43, 0x3a, + 0xbc, 0x83, 0x3b, 0xcc, + 0xc3, 0x8c, 0xc5, 0x0c, + 0x48, 0x21, 0x15, 0x42, + 0x61, 0x1e, 0xe6, 0x21, + 0x1d, 0xce, 0xc1, 0x1d, + 0x52, 0x81, 0x14, 0x00, + }; + buffer.append_slice(&metadata_kind_block); + + const operand_bundle_tag = [_]u8{ + 0xa9, 0x18, 0x00, 0x00, + 0x2d, 0x00, 0x00, 0x00, + 0x0b, 0x0a, 0x72, 0x28, + 0x87, 0x77, 0x80, 0x07, + 0x7a, 0x58, 0x70, 0x98, + 0x43, 0x3d, 0xb8, 0xc3, + 0x38, 0xb0, 0x43, 0x39, + 0xd0, 0xc3, 0x82, 0xe6, + 0x1c, 0xc6, 0xa1, 0x0d, + 0xe8, 0x41, 0x1e, 0xc2, + 0xc1, 0x1d, 0xe6, 0x21, + 0x1d, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x16, + 0x34, 0xe3, 0x60, 0x0e, + 0xe7, 0x50, 0x0f, 0xe1, + 0x20, 0x0f, 0xe4, 0x40, + 0x0f, 0xe1, 0x20, 0x0f, + 0xe7, 0x50, 0x0e, 0xf4, + 0xb0, 0x80, 0x81, 0x07, + 0x79, 0x28, 0x87, 0x70, + 0x60, 0x07, 0x76, 0x78, + 0x87, 0x71, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, + 0x58, 0x70, 0x9c, 0xc3, + 0x38, 0xb4, 0x01, 0x3b, + 0xa4, 0x83, 0x3d, 0x94, + 0xc3, 0x02, 0x6b, 0x1c, + 0xd8, 0x21, 0x1c, 0xdc, + 0xe1, 0x1c, 0xdc, 0x20, + 0x1c, 0xe4, 0x61, 0x1c, + 0xdc, 0x20, 0x1c, 0xe8, + 0x81, 0x1e, 0xc2, 0x61, + 0x1c, 0xd0, 0xa1, 0x1c, + 0xc8, 0x61, 0x1c, 0xc2, + 0x81, 0x1d, 0xd8, 0x61, + 0xc1, 0x01, 0x0f, 0xf4, + 0x20, 0x0f, 0xe1, 0x50, + 0x0f, 0xf4, 0x80, 0x0e, + 0x0b, 0x88, 0x75, 0x18, + 0x07, 0x73, 0x48, 0x87, + 0x05, 0xcf, 0x38, 0xbc, + 0x83, 0x3b, 0xd8, 0x43, + 0x39, 0xc8, 0xc3, 0x39, + 0x94, 0x83, 0x3b, 0x8c, + 0x43, 0x39, 0x8c, 0x03, + 0x3d, 0xc8, 0x03, 0x3b, + 0x00, 0x00, 0x00, 0x00, + }; + buffer.append_slice(&operand_bundle_tag); + + const value26 = [_]u8{ + 0xd1, 0x10, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x07, 0xcc, 0x3c, 0xa4, + 0x83, 0x3b, 0x9c, 0x03, + 0x3b, 0x94, 0x03, 0x3d, + 0xa0, 0x83, 0x3c, 0x94, + 0x43, 0x38, 0x90, 0xc3, + 0x01, 0x00, 0x00, 0x00, + }; + buffer.append_slice(&value26); + const value_symtab = [_]u8{ + 0x71, 0x20, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, + 0x32, 0x0e, 0x10, 0x22, + 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + buffer.append_slice(&value_symtab); + + const strtab = [_]u8{ + 0x5d, 0x0c, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x12, 0x03, 0x94, 0x0f, + 0x31, 0x37, 0x2e, 0x30, + 0x2e, 0x36, 0x6c, 0x6c, + 0x76, 0x6d, 0x2d, 0x6c, + 0x69, 0x6e, 0x6b, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + + buffer.append_slice(&strtab); + + assert(buffer.length == sample_bitcode.len); + const context = LLVM.Context.create(); const module = context.parse_bitcode(buffer.slice()) orelse exit(1); _ = module; // autofix - // + // exit(0); } const sample_bitcode = [_]u8{ - 0x42, 0x43, 0xc0, 0xde, - 0x35, 0x14, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x62, 0x0c, 0x30, 0x24, - 0x4a, 0x59, 0xbe, 0x66, - 0xbd, 0xfb, 0xb4, 0xaf, - 0x0b, 0x51, 0x80, 0x4c, - 0x01, 0x00, 0x00, 0x00, - 0x21, 0x0c, 0x00, 0x00, - 0x1f, 0x01, 0x00, 0x00, - 0x0b, 0x02, 0x21, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x16, 0x00, 0x00, 0x00, - 0x07, 0x81, 0x23, 0x91, - 0x41, 0xc8, 0x04, 0x49, - 0x06, 0x10, 0x32, 0x39, - 0x92, 0x01, 0x84, 0x0c, - 0x25, 0x05, 0x08, 0x19, - 0x1e, 0x04, 0x8b, 0x62, - 0x80, 0x04, 0x45, 0x02, - 0x42, 0x92, 0x0b, 0x42, - 0x24, 0x10, 0x32, 0x14, - 0x38, 0x08, 0x18, 0x4b, - 0x0a, 0x32, 0x12, 0x88, - 0x48, 0x70, 0xc4, 0x21, - 0x23, 0x44, 0x12, 0x87, - 0x8c, 0x10, 0x41, 0x92, - 0x02, 0x64, 0xc8, 0x08, - 0xb1, 0x14, 0x20, 0x43, - 0x46, 0x88, 0x20, 0xc9, - 0x01, 0x32, 0x12, 0x84, - 0x18, 0x2a, 0x28, 0x2a, - 0x90, 0x31, 0x7c, 0xb0, - 0x5c, 0x91, 0x20, 0xc1, - 0xc8, 0x00, 0x00, 0x00, - 0x89, 0x20, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x22, 0x66, 0x04, 0x10, - 0xb2, 0x42, 0x82, 0x49, - 0x10, 0x52, 0x42, 0x82, - 0x49, 0x90, 0x71, 0xc2, - 0x50, 0x48, 0x0a, 0x09, - 0x26, 0x41, 0xc6, 0x05, - 0x42, 0x12, 0x26, 0x08, - 0x82, 0x81, 0x00, 0x00, - 0x1a, 0x21, 0x4c, 0x0e, - 0x13, 0x36, 0xdb, 0xde, - 0x6e, 0xb1, 0xd3, 0xee, - 0xb5, 0xc4, 0x06, 0x81, - 0xa2, 0x24, 0x01, 0x00, - 0x00, 0xb1, 0x18, 0x00, - 0xb9, 0x00, 0x00, 0x00, - 0x33, 0x08, 0x80, 0x1c, - 0xc4, 0xe1, 0x1c, 0x66, - 0x14, 0x01, 0x3d, 0x88, - 0x43, 0x38, 0x84, 0xc3, - 0x8c, 0x42, 0x80, 0x07, - 0x79, 0x78, 0x07, 0x73, - 0x98, 0x71, 0x0c, 0xe6, - 0x00, 0x0f, 0xed, 0x10, - 0x0e, 0xf4, 0x80, 0x0e, - 0x33, 0x0c, 0x42, 0x1e, - 0xc2, 0xc1, 0x1d, 0xce, - 0xa1, 0x1c, 0x66, 0x30, - 0x05, 0x3d, 0x88, 0x43, - 0x38, 0x84, 0x83, 0x1b, - 0xcc, 0x03, 0x3d, 0xc8, - 0x43, 0x3d, 0x8c, 0x03, - 0x3d, 0xcc, 0x78, 0x8c, - 0x74, 0x70, 0x07, 0x7b, - 0x08, 0x07, 0x79, 0x48, - 0x87, 0x70, 0x70, 0x07, - 0x7a, 0x70, 0x03, 0x76, - 0x78, 0x87, 0x70, 0x20, - 0x87, 0x19, 0xcc, 0x11, - 0x0e, 0xec, 0x90, 0x0e, - 0xe1, 0x30, 0x0f, 0x6e, - 0x30, 0x0f, 0xe3, 0xf0, - 0x0e, 0xf0, 0x50, 0x0e, - 0x33, 0x10, 0xc4, 0x1d, - 0xde, 0x21, 0x1c, 0xd8, - 0x21, 0x1d, 0xc2, 0x61, - 0x1e, 0x66, 0x30, 0x89, - 0x3b, 0xbc, 0x83, 0x3b, - 0xd0, 0x43, 0x39, 0xb4, - 0x03, 0x3c, 0xbc, 0x83, - 0x3c, 0x84, 0x03, 0x3b, - 0xcc, 0xf0, 0x14, 0x76, - 0x60, 0x07, 0x7b, 0x68, - 0x07, 0x37, 0x68, 0x87, - 0x72, 0x68, 0x07, 0x37, - 0x80, 0x87, 0x70, 0x90, - 0x87, 0x70, 0x60, 0x07, - 0x76, 0x28, 0x07, 0x76, - 0xf8, 0x05, 0x76, 0x78, - 0x87, 0x77, 0x80, 0x87, - 0x5f, 0x08, 0x87, 0x71, - 0x18, 0x87, 0x72, 0x98, - 0x87, 0x79, 0x98, 0x81, - 0x2c, 0xee, 0xf0, 0x0e, - 0xee, 0xe0, 0x0e, 0xf5, - 0xc0, 0x0e, 0xec, 0x30, - 0x03, 0x62, 0xc8, 0xa1, - 0x1c, 0xe4, 0xa1, 0x1c, - 0xcc, 0xa1, 0x1c, 0xe4, - 0xa1, 0x1c, 0xdc, 0x61, - 0x1c, 0xca, 0x21, 0x1c, - 0xc4, 0x81, 0x1d, 0xca, - 0x61, 0x06, 0xd6, 0x90, - 0x43, 0x39, 0xc8, 0x43, - 0x39, 0x98, 0x43, 0x39, - 0xc8, 0x43, 0x39, 0xb8, - 0xc3, 0x38, 0x94, 0x43, - 0x38, 0x88, 0x03, 0x3b, - 0x94, 0xc3, 0x2f, 0xbc, - 0x83, 0x3c, 0xfc, 0x82, - 0x3b, 0xd4, 0x03, 0x3b, - 0xb0, 0xc3, 0x0c, 0xc7, - 0x69, 0x87, 0x70, 0x58, - 0x87, 0x72, 0x70, 0x83, - 0x74, 0x68, 0x07, 0x78, - 0x60, 0x87, 0x74, 0x18, - 0x87, 0x74, 0xa0, 0x87, - 0x19, 0xce, 0x53, 0x0f, - 0xee, 0x00, 0x0f, 0xf2, - 0x50, 0x0e, 0xe4, 0x90, - 0x0e, 0xe3, 0x40, 0x0f, - 0xe1, 0x20, 0x0e, 0xec, - 0x50, 0x0e, 0x33, 0x20, - 0x28, 0x1d, 0xdc, 0xc1, - 0x1e, 0xc2, 0x41, 0x1e, - 0xd2, 0x21, 0x1c, 0xdc, - 0x81, 0x1e, 0xdc, 0xe0, - 0x1c, 0xe4, 0xe1, 0x1d, - 0xea, 0x01, 0x1e, 0x66, - 0x18, 0x51, 0x38, 0xb0, - 0x43, 0x3a, 0x9c, 0x83, - 0x3b, 0xcc, 0x50, 0x24, - 0x76, 0x60, 0x07, 0x7b, - 0x68, 0x07, 0x37, 0x60, - 0x87, 0x77, 0x78, 0x07, - 0x78, 0x98, 0x51, 0x4c, - 0xf4, 0x90, 0x0f, 0xf0, - 0x50, 0x0e, 0x33, 0x1e, - 0x6a, 0x1e, 0xca, 0x61, - 0x1c, 0xe8, 0x21, 0x1d, - 0xde, 0xc1, 0x1d, 0x7e, - 0x01, 0x1e, 0xe4, 0xa1, - 0x1c, 0xcc, 0x21, 0x1d, - 0xf0, 0x61, 0x06, 0x54, - 0x85, 0x83, 0x38, 0xcc, - 0xc3, 0x3b, 0xb0, 0x43, - 0x3d, 0xd0, 0x43, 0x39, - 0xfc, 0xc2, 0x3c, 0xe4, - 0x43, 0x3b, 0x88, 0xc3, - 0x3b, 0xb0, 0xc3, 0x8c, - 0xc5, 0x0a, 0x87, 0x79, - 0x98, 0x87, 0x77, 0x18, - 0x87, 0x74, 0x08, 0x07, - 0x7a, 0x28, 0x07, 0x72, - 0x98, 0x81, 0x5c, 0xe3, - 0x10, 0x0e, 0xec, 0xc0, - 0x0e, 0xe5, 0x50, 0x0e, - 0xf3, 0x30, 0x23, 0xc1, - 0xd2, 0x41, 0x1e, 0xe4, - 0xe1, 0x17, 0xd8, 0xe1, - 0x1d, 0xde, 0x01, 0x1e, - 0x66, 0x48, 0x19, 0x3b, - 0xb0, 0x83, 0x3d, 0xb4, - 0x83, 0x1b, 0x84, 0xc3, - 0x38, 0x8c, 0x43, 0x39, - 0xcc, 0xc3, 0x3c, 0xb8, - 0xc1, 0x39, 0xc8, 0xc3, - 0x3b, 0xd4, 0x03, 0x3c, - 0xcc, 0x48, 0xb4, 0x71, - 0x08, 0x07, 0x76, 0x60, - 0x07, 0x71, 0x08, 0x87, - 0x71, 0x58, 0x87, 0x19, - 0xdb, 0xc6, 0x0e, 0xec, - 0x60, 0x0f, 0xed, 0xe0, - 0x06, 0xf0, 0x20, 0x0f, - 0xe5, 0x30, 0x0f, 0xe5, - 0x20, 0x0f, 0xf6, 0x50, - 0x0e, 0x6e, 0x10, 0x0e, - 0xe3, 0x30, 0x0e, 0xe5, - 0x30, 0x0f, 0xf3, 0xe0, - 0x06, 0xe9, 0xe0, 0x0e, - 0xe4, 0x50, 0x0e, 0xf8, - 0x30, 0x23, 0xe2, 0xec, - 0x61, 0x1c, 0xc2, 0x81, - 0x1d, 0xd8, 0xe1, 0x17, - 0xec, 0x21, 0x1d, 0xe6, - 0x21, 0x1d, 0xc4, 0x21, - 0x1d, 0xd8, 0x21, 0x1d, - 0xe8, 0x21, 0x1f, 0x66, - 0x20, 0x9d, 0x3b, 0xbc, - 0x43, 0x3d, 0xb8, 0x03, - 0x39, 0x94, 0x83, 0x39, - 0xcc, 0x58, 0xbc, 0x70, - 0x70, 0x07, 0x77, 0x78, - 0x07, 0x7a, 0x08, 0x07, - 0x7a, 0x48, 0x87, 0x77, - 0x70, 0x87, 0x19, 0xcb, - 0xe7, 0x0e, 0xef, 0x30, - 0x0f, 0xe1, 0xe0, 0x0e, - 0xe9, 0x40, 0x0f, 0xe9, - 0xa0, 0x0f, 0xe5, 0x30, - 0xc3, 0x01, 0x03, 0x73, - 0xa8, 0x07, 0x77, 0x18, - 0x87, 0x5f, 0x98, 0x87, - 0x70, 0x70, 0x87, 0x74, - 0xa0, 0x87, 0x74, 0xd0, - 0x87, 0x72, 0x98, 0x81, - 0x84, 0x41, 0x39, 0xe0, - 0xc3, 0x38, 0xb0, 0x43, - 0x3d, 0x90, 0x43, 0x39, - 0xcc, 0x40, 0xc4, 0xa0, - 0x1d, 0xca, 0xa1, 0x1d, - 0xe0, 0x41, 0x1e, 0xde, - 0xc1, 0x1c, 0x66, 0x24, - 0x63, 0x30, 0x0e, 0xe1, - 0xc0, 0x0e, 0xec, 0x30, - 0x0f, 0xe9, 0x40, 0x0f, - 0xe5, 0x30, 0x43, 0x21, - 0x83, 0x75, 0x18, 0x07, - 0x73, 0x48, 0x87, 0x5f, - 0xa0, 0x87, 0x7c, 0x80, - 0x87, 0x72, 0x98, 0xb1, - 0x94, 0x01, 0x3c, 0x8c, - 0xc3, 0x3c, 0x94, 0xc3, - 0x38, 0xd0, 0x43, 0x3a, - 0xbc, 0x83, 0x3b, 0xcc, - 0xc3, 0x8c, 0xc5, 0x0c, - 0x48, 0x21, 0x15, 0x42, - 0x61, 0x1e, 0xe6, 0x21, - 0x1d, 0xce, 0xc1, 0x1d, - 0x52, 0x81, 0x14, 0x00, - 0xa9, 0x18, 0x00, 0x00, - 0x2d, 0x00, 0x00, 0x00, - 0x0b, 0x0a, 0x72, 0x28, - 0x87, 0x77, 0x80, 0x07, - 0x7a, 0x58, 0x70, 0x98, - 0x43, 0x3d, 0xb8, 0xc3, - 0x38, 0xb0, 0x43, 0x39, - 0xd0, 0xc3, 0x82, 0xe6, - 0x1c, 0xc6, 0xa1, 0x0d, - 0xe8, 0x41, 0x1e, 0xc2, - 0xc1, 0x1d, 0xe6, 0x21, - 0x1d, 0xe8, 0x21, 0x1d, - 0xde, 0xc1, 0x1d, 0x16, - 0x34, 0xe3, 0x60, 0x0e, - 0xe7, 0x50, 0x0f, 0xe1, - 0x20, 0x0f, 0xe4, 0x40, - 0x0f, 0xe1, 0x20, 0x0f, - 0xe7, 0x50, 0x0e, 0xf4, - 0xb0, 0x80, 0x81, 0x07, - 0x79, 0x28, 0x87, 0x70, - 0x60, 0x07, 0x76, 0x78, - 0x87, 0x71, 0x08, 0x07, - 0x7a, 0x28, 0x07, 0x72, - 0x58, 0x70, 0x9c, 0xc3, - 0x38, 0xb4, 0x01, 0x3b, - 0xa4, 0x83, 0x3d, 0x94, - 0xc3, 0x02, 0x6b, 0x1c, - 0xd8, 0x21, 0x1c, 0xdc, - 0xe1, 0x1c, 0xdc, 0x20, - 0x1c, 0xe4, 0x61, 0x1c, - 0xdc, 0x20, 0x1c, 0xe8, - 0x81, 0x1e, 0xc2, 0x61, - 0x1c, 0xd0, 0xa1, 0x1c, - 0xc8, 0x61, 0x1c, 0xc2, - 0x81, 0x1d, 0xd8, 0x61, - 0xc1, 0x01, 0x0f, 0xf4, - 0x20, 0x0f, 0xe1, 0x50, - 0x0f, 0xf4, 0x80, 0x0e, - 0x0b, 0x88, 0x75, 0x18, - 0x07, 0x73, 0x48, 0x87, - 0x05, 0xcf, 0x38, 0xbc, - 0x83, 0x3b, 0xd8, 0x43, - 0x39, 0xc8, 0xc3, 0x39, - 0x94, 0x83, 0x3b, 0x8c, - 0x43, 0x39, 0x8c, 0x03, - 0x3d, 0xc8, 0x03, 0x3b, - 0x00, 0x00, 0x00, 0x00, - 0xd1, 0x10, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x07, 0xcc, 0x3c, 0xa4, - 0x83, 0x3b, 0x9c, 0x03, - 0x3b, 0x94, 0x03, 0x3d, - 0xa0, 0x83, 0x3c, 0x94, - 0x43, 0x38, 0x90, 0xc3, - 0x01, 0x00, 0x00, 0x00, - 0x71, 0x20, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x32, 0x0e, 0x10, 0x22, - 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x5d, 0x0c, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x12, 0x03, 0x94, 0x0f, - 0x31, 0x37, 0x2e, 0x30, - 0x2e, 0x36, 0x6c, 0x6c, - 0x76, 0x6d, 0x2d, 0x6c, - 0x69, 0x6e, 0x6b, 0x00, + // Magic + 0x42, 0x43, 0xc0, 0xde, + // Start of the identification block + 0x35, 0x14, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, + 0x62, 0x0c, 0x30, 0x24, + 0x4a, 0x59, 0xbe, 0x66, + 0xbd, 0xfb, 0xb4, 0xaf, + 0x0b, 0x51, 0x80, 0x4c, + 0x01, 0x00, 0x00, 0x00, + // It looks like this is the start of the module block + 0x21, 0x0c, 0x00, 0x00, + 0x1f, 0x01, 0x00, 0x00, + 0x0b, 0x02, 0x21, 0x00, + // start of the blockinfo block? + 0x02, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, + 0x07, 0x81, 0x23, 0x91, + 0x41, 0xc8, 0x04, 0x49, + 0x06, 0x10, 0x32, 0x39, + 0x92, 0x01, 0x84, 0x0c, + 0x25, 0x05, 0x08, 0x19, + 0x1e, 0x04, 0x8b, 0x62, + 0x80, 0x04, 0x45, 0x02, + 0x42, 0x92, 0x0b, 0x42, + 0x24, 0x10, 0x32, 0x14, + 0x38, 0x08, 0x18, 0x4b, + 0x0a, 0x32, 0x12, 0x88, + 0x48, 0x70, 0xc4, 0x21, + 0x23, 0x44, 0x12, 0x87, + 0x8c, 0x10, 0x41, 0x92, + 0x02, 0x64, 0xc8, 0x08, + 0xb1, 0x14, 0x20, 0x43, + 0x46, 0x88, 0x20, 0xc9, + 0x01, 0x32, 0x12, 0x84, + 0x18, 0x2a, 0x28, 0x2a, + 0x90, 0x31, 0x7c, 0xb0, + 0x5c, 0x91, 0x20, 0xc1, + 0xc8, 0x00, 0x00, 0x00, + // type block? + 0x89, 0x20, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, + 0x22, 0x66, 0x04, 0x10, + 0xb2, 0x42, 0x82, 0x49, + 0x10, 0x52, 0x42, 0x82, + 0x49, 0x90, 0x71, 0xc2, + 0x50, 0x48, 0x0a, 0x09, + 0x26, 0x41, 0xc6, 0x05, + 0x42, 0x12, 0x26, 0x08, + 0x82, 0x81, 0x00, 0x00, + 0x1a, 0x21, 0x4c, 0x0e, + 0x13, 0x36, 0xdb, 0xde, + 0x6e, 0xb1, 0xd3, 0xee, + 0xb5, 0xc4, 0x06, 0x81, + 0xa2, 0x24, 0x01, 0x00, + // metadata kind block? + 0x00, 0xb1, 0x18, 0x00, + 0xb9, 0x00, 0x00, 0x00, + 0x33, 0x08, 0x80, 0x1c, + 0xc4, 0xe1, 0x1c, 0x66, + 0x14, 0x01, 0x3d, 0x88, + 0x43, 0x38, 0x84, 0xc3, + 0x8c, 0x42, 0x80, 0x07, + 0x79, 0x78, 0x07, 0x73, + 0x98, 0x71, 0x0c, 0xe6, + 0x00, 0x0f, 0xed, 0x10, + 0x0e, 0xf4, 0x80, 0x0e, + 0x33, 0x0c, 0x42, 0x1e, + 0xc2, 0xc1, 0x1d, 0xce, + 0xa1, 0x1c, 0x66, 0x30, + 0x05, 0x3d, 0x88, 0x43, + 0x38, 0x84, 0x83, 0x1b, + 0xcc, 0x03, 0x3d, 0xc8, + 0x43, 0x3d, 0x8c, 0x03, + 0x3d, 0xcc, 0x78, 0x8c, + 0x74, 0x70, 0x07, 0x7b, + 0x08, 0x07, 0x79, 0x48, + 0x87, 0x70, 0x70, 0x07, + 0x7a, 0x70, 0x03, 0x76, + 0x78, 0x87, 0x70, 0x20, + 0x87, 0x19, 0xcc, 0x11, + 0x0e, 0xec, 0x90, 0x0e, + 0xe1, 0x30, 0x0f, 0x6e, + 0x30, 0x0f, 0xe3, 0xf0, + 0x0e, 0xf0, 0x50, 0x0e, + 0x33, 0x10, 0xc4, 0x1d, + 0xde, 0x21, 0x1c, 0xd8, + 0x21, 0x1d, 0xc2, 0x61, + 0x1e, 0x66, 0x30, 0x89, + 0x3b, 0xbc, 0x83, 0x3b, + 0xd0, 0x43, 0x39, 0xb4, + 0x03, 0x3c, 0xbc, 0x83, + 0x3c, 0x84, 0x03, 0x3b, + 0xcc, 0xf0, 0x14, 0x76, + 0x60, 0x07, 0x7b, 0x68, + 0x07, 0x37, 0x68, 0x87, + 0x72, 0x68, 0x07, 0x37, + 0x80, 0x87, 0x70, 0x90, + 0x87, 0x70, 0x60, 0x07, + 0x76, 0x28, 0x07, 0x76, + 0xf8, 0x05, 0x76, 0x78, + 0x87, 0x77, 0x80, 0x87, + 0x5f, 0x08, 0x87, 0x71, + 0x18, 0x87, 0x72, 0x98, + 0x87, 0x79, 0x98, 0x81, + 0x2c, 0xee, 0xf0, 0x0e, + 0xee, 0xe0, 0x0e, 0xf5, + 0xc0, 0x0e, 0xec, 0x30, + 0x03, 0x62, 0xc8, 0xa1, + 0x1c, 0xe4, 0xa1, 0x1c, + 0xcc, 0xa1, 0x1c, 0xe4, + 0xa1, 0x1c, 0xdc, 0x61, + 0x1c, 0xca, 0x21, 0x1c, + 0xc4, 0x81, 0x1d, 0xca, + 0x61, 0x06, 0xd6, 0x90, + 0x43, 0x39, 0xc8, 0x43, + 0x39, 0x98, 0x43, 0x39, + 0xc8, 0x43, 0x39, 0xb8, + 0xc3, 0x38, 0x94, 0x43, + 0x38, 0x88, 0x03, 0x3b, + 0x94, 0xc3, 0x2f, 0xbc, + 0x83, 0x3c, 0xfc, 0x82, + 0x3b, 0xd4, 0x03, 0x3b, + 0xb0, 0xc3, 0x0c, 0xc7, + 0x69, 0x87, 0x70, 0x58, + 0x87, 0x72, 0x70, 0x83, + 0x74, 0x68, 0x07, 0x78, + 0x60, 0x87, 0x74, 0x18, + 0x87, 0x74, 0xa0, 0x87, + 0x19, 0xce, 0x53, 0x0f, + 0xee, 0x00, 0x0f, 0xf2, + 0x50, 0x0e, 0xe4, 0x90, + 0x0e, 0xe3, 0x40, 0x0f, + 0xe1, 0x20, 0x0e, 0xec, + 0x50, 0x0e, 0x33, 0x20, + 0x28, 0x1d, 0xdc, 0xc1, + 0x1e, 0xc2, 0x41, 0x1e, + 0xd2, 0x21, 0x1c, 0xdc, + 0x81, 0x1e, 0xdc, 0xe0, + 0x1c, 0xe4, 0xe1, 0x1d, + 0xea, 0x01, 0x1e, 0x66, + 0x18, 0x51, 0x38, 0xb0, + 0x43, 0x3a, 0x9c, 0x83, + 0x3b, 0xcc, 0x50, 0x24, + 0x76, 0x60, 0x07, 0x7b, + 0x68, 0x07, 0x37, 0x60, + 0x87, 0x77, 0x78, 0x07, + 0x78, 0x98, 0x51, 0x4c, + 0xf4, 0x90, 0x0f, 0xf0, + 0x50, 0x0e, 0x33, 0x1e, + 0x6a, 0x1e, 0xca, 0x61, + 0x1c, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x7e, + 0x01, 0x1e, 0xe4, 0xa1, + 0x1c, 0xcc, 0x21, 0x1d, + 0xf0, 0x61, 0x06, 0x54, + 0x85, 0x83, 0x38, 0xcc, + 0xc3, 0x3b, 0xb0, 0x43, + 0x3d, 0xd0, 0x43, 0x39, + 0xfc, 0xc2, 0x3c, 0xe4, + 0x43, 0x3b, 0x88, 0xc3, + 0x3b, 0xb0, 0xc3, 0x8c, + 0xc5, 0x0a, 0x87, 0x79, + 0x98, 0x87, 0x77, 0x18, + 0x87, 0x74, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, + 0x98, 0x81, 0x5c, 0xe3, + 0x10, 0x0e, 0xec, 0xc0, + 0x0e, 0xe5, 0x50, 0x0e, + 0xf3, 0x30, 0x23, 0xc1, + 0xd2, 0x41, 0x1e, 0xe4, + 0xe1, 0x17, 0xd8, 0xe1, + 0x1d, 0xde, 0x01, 0x1e, + 0x66, 0x48, 0x19, 0x3b, + 0xb0, 0x83, 0x3d, 0xb4, + 0x83, 0x1b, 0x84, 0xc3, + 0x38, 0x8c, 0x43, 0x39, + 0xcc, 0xc3, 0x3c, 0xb8, + 0xc1, 0x39, 0xc8, 0xc3, + 0x3b, 0xd4, 0x03, 0x3c, + 0xcc, 0x48, 0xb4, 0x71, + 0x08, 0x07, 0x76, 0x60, + 0x07, 0x71, 0x08, 0x87, + 0x71, 0x58, 0x87, 0x19, + 0xdb, 0xc6, 0x0e, 0xec, + 0x60, 0x0f, 0xed, 0xe0, + 0x06, 0xf0, 0x20, 0x0f, + 0xe5, 0x30, 0x0f, 0xe5, + 0x20, 0x0f, 0xf6, 0x50, + 0x0e, 0x6e, 0x10, 0x0e, + 0xe3, 0x30, 0x0e, 0xe5, + 0x30, 0x0f, 0xf3, 0xe0, + 0x06, 0xe9, 0xe0, 0x0e, + 0xe4, 0x50, 0x0e, 0xf8, + 0x30, 0x23, 0xe2, 0xec, + 0x61, 0x1c, 0xc2, 0x81, + 0x1d, 0xd8, 0xe1, 0x17, + 0xec, 0x21, 0x1d, 0xe6, + 0x21, 0x1d, 0xc4, 0x21, + 0x1d, 0xd8, 0x21, 0x1d, + 0xe8, 0x21, 0x1f, 0x66, + 0x20, 0x9d, 0x3b, 0xbc, + 0x43, 0x3d, 0xb8, 0x03, + 0x39, 0x94, 0x83, 0x39, + 0xcc, 0x58, 0xbc, 0x70, + 0x70, 0x07, 0x77, 0x78, + 0x07, 0x7a, 0x08, 0x07, + 0x7a, 0x48, 0x87, 0x77, + 0x70, 0x87, 0x19, 0xcb, + 0xe7, 0x0e, 0xef, 0x30, + 0x0f, 0xe1, 0xe0, 0x0e, + 0xe9, 0x40, 0x0f, 0xe9, + 0xa0, 0x0f, 0xe5, 0x30, + 0xc3, 0x01, 0x03, 0x73, + 0xa8, 0x07, 0x77, 0x18, + 0x87, 0x5f, 0x98, 0x87, + 0x70, 0x70, 0x87, 0x74, + 0xa0, 0x87, 0x74, 0xd0, + 0x87, 0x72, 0x98, 0x81, + 0x84, 0x41, 0x39, 0xe0, + 0xc3, 0x38, 0xb0, 0x43, + 0x3d, 0x90, 0x43, 0x39, + 0xcc, 0x40, 0xc4, 0xa0, + 0x1d, 0xca, 0xa1, 0x1d, + 0xe0, 0x41, 0x1e, 0xde, + 0xc1, 0x1c, 0x66, 0x24, + 0x63, 0x30, 0x0e, 0xe1, + 0xc0, 0x0e, 0xec, 0x30, + 0x0f, 0xe9, 0x40, 0x0f, + 0xe5, 0x30, 0x43, 0x21, + 0x83, 0x75, 0x18, 0x07, + 0x73, 0x48, 0x87, 0x5f, + 0xa0, 0x87, 0x7c, 0x80, + 0x87, 0x72, 0x98, 0xb1, + 0x94, 0x01, 0x3c, 0x8c, + 0xc3, 0x3c, 0x94, 0xc3, + 0x38, 0xd0, 0x43, 0x3a, + 0xbc, 0x83, 0x3b, 0xcc, + 0xc3, 0x8c, 0xc5, 0x0c, + 0x48, 0x21, 0x15, 0x42, + 0x61, 0x1e, 0xe6, 0x21, + 0x1d, 0xce, 0xc1, 0x1d, + 0x52, 0x81, 0x14, 0x00, + // operand bundle tags block? + 0xa9, 0x18, 0x00, 0x00, + 0x2d, 0x00, 0x00, 0x00, + 0x0b, 0x0a, 0x72, 0x28, + 0x87, 0x77, 0x80, 0x07, + 0x7a, 0x58, 0x70, 0x98, + 0x43, 0x3d, 0xb8, 0xc3, + 0x38, 0xb0, 0x43, 0x39, + 0xd0, 0xc3, 0x82, 0xe6, + 0x1c, 0xc6, 0xa1, 0x0d, + 0xe8, 0x41, 0x1e, 0xc2, + 0xc1, 0x1d, 0xe6, 0x21, + 0x1d, 0xe8, 0x21, 0x1d, + 0xde, 0xc1, 0x1d, 0x16, + 0x34, 0xe3, 0x60, 0x0e, + 0xe7, 0x50, 0x0f, 0xe1, + 0x20, 0x0f, 0xe4, 0x40, + 0x0f, 0xe1, 0x20, 0x0f, + 0xe7, 0x50, 0x0e, 0xf4, + 0xb0, 0x80, 0x81, 0x07, + 0x79, 0x28, 0x87, 0x70, + 0x60, 0x07, 0x76, 0x78, + 0x87, 0x71, 0x08, 0x07, + 0x7a, 0x28, 0x07, 0x72, + 0x58, 0x70, 0x9c, 0xc3, + 0x38, 0xb4, 0x01, 0x3b, + 0xa4, 0x83, 0x3d, 0x94, + 0xc3, 0x02, 0x6b, 0x1c, + 0xd8, 0x21, 0x1c, 0xdc, + 0xe1, 0x1c, 0xdc, 0x20, + 0x1c, 0xe4, 0x61, 0x1c, + 0xdc, 0x20, 0x1c, 0xe8, + 0x81, 0x1e, 0xc2, 0x61, + 0x1c, 0xd0, 0xa1, 0x1c, + 0xc8, 0x61, 0x1c, 0xc2, + 0x81, 0x1d, 0xd8, 0x61, + 0xc1, 0x01, 0x0f, 0xf4, + 0x20, 0x0f, 0xe1, 0x50, + 0x0f, 0xf4, 0x80, 0x0e, + 0x0b, 0x88, 0x75, 0x18, + 0x07, 0x73, 0x48, 0x87, + 0x05, 0xcf, 0x38, 0xbc, + 0x83, 0x3b, 0xd8, 0x43, + 0x39, 0xc8, 0xc3, 0x39, + 0x94, 0x83, 0x3b, 0x8c, + 0x43, 0x39, 0x8c, 0x03, + 0x3d, 0xc8, 0x03, 0x3b, + 0x00, 0x00, 0x00, 0x00, + // Unknown block 26? + 0xd1, 0x10, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x07, 0xcc, 0x3c, 0xa4, + 0x83, 0x3b, 0x9c, 0x03, + 0x3b, 0x94, 0x03, 0x3d, + 0xa0, 0x83, 0x3c, 0x94, + 0x43, 0x38, 0x90, 0xc3, + 0x01, 0x00, 0x00, 0x00, + // Value symtab block? + 0x71, 0x20, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, + 0x32, 0x0e, 0x10, 0x22, + 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Start of the strtab block + 0x5d, 0x0c, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x12, 0x03, 0x94, 0x0f, + 0x31, 0x37, 0x2e, 0x30, + 0x2e, 0x36, 0x6c, 0x6c, + 0x76, 0x6d, 0x2d, 0x6c, + 0x69, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, }; -fn get_integer_type(thread: *Thread) void { - _ = thread; // autofix -} - -const CallingConvention = enum{ +const CallingConvention = enum { c, custom, }; -const Analyzer = struct{ +const Analyzer = struct { current_basic_block: *BasicBlock = undefined, current_function: *Function = undefined, }; @@ -1409,7 +1750,7 @@ fn thread_callback(thread_index: u32) void { const thread = &threads[thread_index]; thread.arena = Arena.init(4 * 1024 * 1024) catch unreachable; - + while (true) { const to_do = thread.task_system.job.to_do; const completed = thread.task_system.job.completed; @@ -1419,8 +1760,8 @@ fn thread_callback(thread_index: u32) void { for (jobs) |job| { switch (job.id) { .llvm_setup => { - for ([_]Type.Integer.Signedness{.unsigned, .signed}) |signedness| { - for (0..64+1) |bit_count| { + for ([_]Type.Integer.Signedness{ .unsigned, .signed }) |signedness| { + for (0..64 + 1) |bit_count| { const integer_type = Type.Integer{ .bit_count = @intCast(bit_count), .signedness = signedness, @@ -1551,7 +1892,7 @@ fn thread_callback(thread_index: u32) void { .lazy_expression => { const lazy_expression = thread.lazy_expressions.get(@enumFromInt(value.sema.index)); assert(lazy_expression.* == .static); - for ( lazy_expression.static.names) |n| { + for (lazy_expression.static.names) |n| { assert(n == 0); } const declaration = lazy_expression.static.outsider; @@ -1777,7 +2118,7 @@ fn llvm_get_file(thread: *Thread, file_index: u32) *LLVMFile { const builder = thread.llvm.module.createDebugInfoBuilder(); const file = &instance.files.slice()[file_index]; const filename = std.fs.path.basename(file.path); - const directory = file.path[0..file.path.len - filename.len]; + const directory = file.path[0 .. file.path.len - filename.len]; const llvm_file = builder.createFile(filename.ptr, filename.len, directory.ptr, directory.len); const producer = "nativity"; const is_optimized = false; @@ -1818,7 +2159,7 @@ fn llvm_get_function(thread: *Thread, nat_function: *Function.Declaration, overr const is_var_args = false; const function_type = LLVM.getFunctionType(return_type, argument_types.pointer, argument_types.length, is_var_args); const is_extern_function = nat_function.global.attributes.@"extern"; - const export_or_extern = nat_function.global.attributes.@"export" or is_extern_function; + const export_or_extern = nat_function.global.attributes.@"export" or is_extern_function; const linkage: LLVM.Linkage = switch (export_or_extern) { true => .@"extern", false => .internal, @@ -1902,7 +2243,7 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { } file.functions.start = @intCast(thread.functions.length); - + var parser = Parser{}; var analyzer = Analyzer{}; @@ -1923,7 +2264,6 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { const identifier = parser.parse_identifier(thread, src); _ = identifier; // autofix - exit(1); }, 'f' => { @@ -1941,12 +2281,12 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { function.* = .{ .declaration = .{ - .return_type = undefined, - .global = .{ - .name = undefined, + .return_type = undefined, + .global = .{ + .name = undefined, + }, + .file = file_index, }, - .file = file_index, - }, .entry_block = entry_block_index, }; @@ -2047,7 +2387,7 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { .@"extern" => {}, } - const after_ch =src[parser.i]; + const after_ch = src[parser.i]; switch (after_ch) { ']' => {}, else => unreachable, @@ -2101,7 +2441,7 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { _ = block_line; // autofix const block_column = block_start - parser.line_offset + 1; _ = block_column; // autofix - // + // parser.expect_character(src, bracket_open); const file_scope = thread.file_scopes.get(@enumFromInt(file.scope.index)); file_scope.declarations.put_no_clobber(function.declaration.global.name, .{ @@ -2126,7 +2466,6 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { const return_value = parser.parse_typed_expression(&analyzer, thread, file, function.declaration.return_type); parser.expect_character(src, ';'); - const return_expression = thread.returns.append_index(.{ .value = return_value, }); @@ -2138,7 +2477,7 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { _ = analyzer.current_basic_block.instructions.append(return_instruction); analyzer.current_basic_block.is_terminated = true; - } else { + } else { exit(1); } } else { @@ -2167,11 +2506,11 @@ pub fn analyze_file(thread: *Thread, file_index: u32) void { parser.expect_character(src, ';'); const filename = std.fs.path.basename(string_literal); - const has_right_extension = filename.len > ".nat".len and byte_equal(filename[filename.len - ".nat".len..], ".nat"); + const has_right_extension = filename.len > ".nat".len and byte_equal(filename[filename.len - ".nat".len ..], ".nat"); if (!has_right_extension) { exit(1); } - const filename_without_extension = filename[0..filename.len - ".nat".len]; + const filename_without_extension = filename[0 .. filename.len - ".nat".len]; const filename_without_extension_hash = hash_bytes(filename_without_extension); const directory_path = file.get_directory_path(); @@ -2282,7 +2621,6 @@ pub const LLVM = struct { const getAttributeFromType = bindings.NativityLLVMContextGetAttributeFromType; const getAttributeSet = bindings.NativityLLVMContextGetAttributeSet; - pub fn parse_bitcode(context: *LLVM.Context, bytes: []const u8) ?*LLVM.Module { const memory_buffer = bindings.LLVMCreateMemoryBufferWithMemoryRange(bytes.ptr, bytes.len, null, 0); var out_module: *LLVM.Module = undefined; @@ -2930,10 +3268,9 @@ pub const LLVM = struct { intrinsic, array, }; - }; - pub const MemoryBuffer = opaque{}; + pub const MemoryBuffer = opaque {}; pub const Value = opaque { const setName = bindings.NativityLLVMValueSetName; diff --git a/bootstrap/library.zig b/bootstrap/library.zig index fcd5d87..2e32e55 100644 --- a/bootstrap/library.zig +++ b/bootstrap/library.zig @@ -253,7 +253,7 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptim return ptr; } - pub fn add_one(array: *Array) *T{ + pub fn add_one(array: *Array) *T { array.ensure_capacity(1); return array.add_one_with_capacity(); } @@ -784,7 +784,6 @@ pub fn read_file(arena: *Arena, directory: std.fs.Dir, file_relative_path: []con return file_buffer[0..read_byte_count]; } - pub fn self_exe_path(arena: *Arena) ![]const u8 { var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; return try arena.duplicate_bytes(try std.fs.selfExePath(&buffer)); diff --git a/bootstrap/main.zig b/bootstrap/main.zig index 92603ed..b389ede 100644 --- a/bootstrap/main.zig +++ b/bootstrap/main.zig @@ -76,5 +76,3 @@ pub fn main() !void { pub const std_options = std.Options{ .enable_segfault_handler = false, }; - -