Compare commits
132 Commits
emit-llvm-
...
main
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4bfbd5ded5 | ||
![]() |
3d9d26ea82 | ||
![]() |
fee5ed17e5 | ||
![]() |
53894589ff | ||
![]() |
11f70a1d9e | ||
![]() |
610faec907 | ||
![]() |
200cc7b76e | ||
![]() |
06f9fe3597 | ||
![]() |
9000a9abd7 | ||
![]() |
4b80adf2fa | ||
![]() |
e2268ca74a | ||
![]() |
adebadc573 | ||
![]() |
27a620fb57 | ||
![]() |
8e7e28c096 | ||
![]() |
edab2ed2ac | ||
![]() |
87b7dc9af8 | ||
![]() |
ba1b4669f0 | ||
![]() |
21af15ac3a | ||
![]() |
5c6b050a94 | ||
![]() |
4c6bc6cf8a | ||
![]() |
ea29b5b300 | ||
![]() |
8f0c533b98 | ||
![]() |
59ac6702d9 | ||
![]() |
291735086b | ||
![]() |
5347b1f0e9 | ||
![]() |
a4c60754cd | ||
![]() |
0d87c928e8 | ||
![]() |
f7a37f7346 | ||
![]() |
92443cca38 | ||
![]() |
4fbdaeaab8 | ||
![]() |
58fb05ef17 | ||
![]() |
6033fdc9b9 | ||
![]() |
90f3a01c22 | ||
![]() |
6d43d39597 | ||
![]() |
b4145308a3 | ||
![]() |
fff62dd396 | ||
![]() |
2826a7d59a | ||
![]() |
455ec8cf50 | ||
![]() |
bfe8ee5198 | ||
![]() |
a0e489b2dc | ||
![]() |
1470ca0b18 | ||
![]() |
7a18413c29 | ||
![]() |
d01384928f | ||
![]() |
faf8ad9212 | ||
![]() |
64481926f4 | ||
![]() |
a5c49e6f4c | ||
![]() |
fb3494255b | ||
![]() |
2c1ed2efd8 | ||
![]() |
19b3cb3103 | ||
![]() |
0ee4e907b6 | ||
![]() |
6cd7c28efb | ||
![]() |
4a8b224c19 | ||
![]() |
3381aa0625 | ||
![]() |
088c8d8d5d | ||
![]() |
cbf6829cd4 | ||
![]() |
c9d7dd6aa8 | ||
![]() |
6709fac566 | ||
![]() |
65ed3502c8 | ||
![]() |
3ad8cbe3ec | ||
![]() |
a86f990a5f | ||
![]() |
110b1496ef | ||
![]() |
663e4e8a1d | ||
![]() |
01f3e5beae | ||
![]() |
b549b6ed49 | ||
![]() |
42659314ea | ||
![]() |
f6bb34a354 | ||
![]() |
ef662415d9 | ||
![]() |
02de0f1eb3 | ||
![]() |
30ed5a235a | ||
![]() |
9712d54290 | ||
![]() |
c504cbdc73 | ||
![]() |
62cf76b1d7 | ||
![]() |
3a19ee4151 | ||
![]() |
d998376bc0 | ||
![]() |
56b6443c1f | ||
![]() |
f2b1066cc6 | ||
![]() |
ae7d7f6e3b | ||
![]() |
940213c420 | ||
![]() |
0292799d71 | ||
![]() |
d1e450233d | ||
![]() |
da2414b698 | ||
![]() |
1e5020fed1 | ||
![]() |
381ea47e39 | ||
![]() |
69e01a1a7f | ||
![]() |
9731d8c893 | ||
![]() |
45306355e9 | ||
![]() |
bdbc33d685 | ||
![]() |
1a49c86154 | ||
![]() |
4d29a31a4a | ||
![]() |
9485bed0a7 | ||
![]() |
7f56a0fe3d | ||
![]() |
4a91fa7e95 | ||
![]() |
3d1cea128a | ||
![]() |
bcb49f3adf | ||
![]() |
c868aa05ae | ||
![]() |
bcd5e52bf3 | ||
![]() |
b0111b2a79 | ||
![]() |
6106f090aa | ||
![]() |
5cbbebe29a | ||
![]() |
536a810b98 | ||
![]() |
0c750963f6 | ||
![]() |
61f91d12d2 | ||
![]() |
19e6246b9a | ||
![]() |
7902aeca97 | ||
![]() |
ffb0110ea7 | ||
![]() |
48db2c9265 | ||
![]() |
e66fa4f70d | ||
![]() |
2f8c86a750 | ||
![]() |
09b6869ed0 | ||
![]() |
f5291dfb9b | ||
![]() |
36d59bc372 | ||
![]() |
074465a7e5 | ||
![]() |
812e436bb7 | ||
![]() |
ed38358ad8 | ||
![]() |
43ff44f44d | ||
![]() |
69e6fba3fe | ||
![]() |
1d52b9abdc | ||
![]() |
e4dd1bb7b9 | ||
![]() |
8713de03d3 | ||
![]() |
a4c6f37d63 | ||
![]() |
d021521963 | ||
![]() |
bd22f8eb80 | ||
![]() |
9baae7fb24 | ||
![]() |
7a69bb0686 | ||
![]() |
eda0ae3448 | ||
![]() |
3df904b3d3 | ||
![]() |
1152d7fb6b | ||
![]() |
b28aab2dae | ||
![]() |
ac95126fce | ||
![]() |
d0039ec494 | ||
![]() |
d9799035ef | ||
![]() |
cd2316f7ee |
55
.github/workflows/ci.yml
vendored
55
.github/workflows/ci.yml
vendored
@ -8,6 +8,11 @@ on:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
env:
|
||||
NAT_LLVM_VERSION: 18
|
||||
NAT_ZIG_GENERIC_COMMAND: zig build -Dthird_party_ci=true
|
||||
NAT_ZIG_TEST_GENERIC_COMMAND: zig build test -Dthird_party_ci=true
|
||||
TIMEOUT_MINUTES: 15
|
||||
jobs:
|
||||
linux-gnu:
|
||||
runs-on: ubuntu-latest
|
||||
@ -15,13 +20,55 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build and test
|
||||
run: ./ci/linux_gnu_runner.sh
|
||||
- name: Set Zig up mlugg/setup-zig@v1
|
||||
uses: mlugg/setup-zig@v1
|
||||
with:
|
||||
version: master
|
||||
- name: Set up LLVM
|
||||
run: |
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x llvm.sh
|
||||
sudo ./llvm.sh $NAT_LLVM_VERSION all
|
||||
sudo apt install liblld-$NAT_LLVM_VERSION-dev libclang-$NAT_LLVM_VERSION-dev liblld-$NAT_LLVM_VERSION ninja-build cmake -y
|
||||
- name: Build
|
||||
run: |
|
||||
set -ex
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=Debug
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=ReleaseSafe
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=ReleaseSmall
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=ReleaseFast
|
||||
- name: Test
|
||||
run: |
|
||||
set -ex
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=Debug
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=ReleaseSafe
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=ReleaseSmall
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=ReleaseFast
|
||||
macos:
|
||||
runs-on: macos-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Build and test
|
||||
run: ./ci/macos_runner.sh
|
||||
- name: Set Zig up mlugg/setup-zig@v1
|
||||
uses: mlugg/setup-zig@v1
|
||||
with:
|
||||
version: master
|
||||
- name: Set up LLVM
|
||||
run: |
|
||||
brew update
|
||||
brew install llvm@$NAT_LLVM_VERSION ninja
|
||||
- name: Build
|
||||
run: |
|
||||
set -ex
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=Debug
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=ReleaseSafe
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=ReleaseSmall
|
||||
$NAT_ZIG_GENERIC_COMMAND -Doptimize=ReleaseFast
|
||||
- name: Test
|
||||
run: |
|
||||
set -ex
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=Debug
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=ReleaseSafe
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=ReleaseSmall
|
||||
$NAT_ZIG_TEST_GENERIC_COMMAND -Doptimize=ReleaseFast
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.zig-cache/
|
||||
zig-cache/
|
||||
zig-out/
|
||||
nat/
|
||||
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -12,7 +12,7 @@
|
||||
"args": [
|
||||
"exe",
|
||||
"-main_source_file",
|
||||
"test/build/c-abi/main.nat",
|
||||
"retest/standalone/first/main.nat"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
|
@ -18,6 +18,8 @@ const starts_with_slice = library.starts_with_slice;
|
||||
const PinnedArray = library.PinnedArray;
|
||||
const PinnedArrayAdvanced = library.PinnedArrayAdvanced;
|
||||
const PinnedHashMap = library.PinnedHashMap;
|
||||
const realpath = library.realpath;
|
||||
const self_exe_path = library.self_exe_path;
|
||||
const span = library.span;
|
||||
const format_int = library.format_int;
|
||||
const my_hash = library.my_hash;
|
||||
@ -2750,19 +2752,6 @@ pub fn argsCopyZ(arena: *Arena, args: []const []const u8) ![:null]?[*:0]u8 {
|
||||
return result[0..args.len :null];
|
||||
}
|
||||
|
||||
extern "c" fn NativityLLVMArchiverMain(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
|
||||
fn arMain(arena: *Arena, arguments: []const []const u8) !u8 {
|
||||
const argv = try argsCopyZ(arena, arguments);
|
||||
const exit_code = NativityLLVMArchiverMain(@as(c_int, @intCast(arguments.len)), argv.ptr);
|
||||
return @as(u8, @bitCast(@as(i8, @truncate(exit_code))));
|
||||
}
|
||||
|
||||
extern "c" fn NativityClangMain(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
|
||||
pub fn clangMain(arena: *Arena, arguments: []const []const u8) !u8 {
|
||||
const argv = try argsCopyZ(arena, arguments);
|
||||
const exit_code = NativityClangMain(@as(c_int, @intCast(arguments.len)), argv.ptr);
|
||||
return @as(u8, @bitCast(@as(i8, @truncate(exit_code))));
|
||||
}
|
||||
|
||||
const ExecutableOptions = struct {
|
||||
is_test: bool,
|
||||
@ -2836,46 +2825,6 @@ pub fn buildExecutable(context: *const Context, arguments: []const []const u8, o
|
||||
} else {
|
||||
reportUnterminatedArgumentError(current_argument);
|
||||
}
|
||||
} else if (byte_equal(current_argument, "-log")) {
|
||||
if (i + 1 != arguments.len) {
|
||||
i += 1;
|
||||
|
||||
// var log_argument_iterator = std.mem.splitScalar(u8, span(arguments[i]), ',');
|
||||
//
|
||||
// while (log_argument_iterator.next()) |log_argument| {
|
||||
// var log_argument_splitter = std.mem.splitScalar(u8, log_argument, '.');
|
||||
// const log_scope_candidate = log_argument_splitter.next() orelse unreachable;
|
||||
// var recognized_scope = false;
|
||||
//
|
||||
// inline for (@typeInfo(LoggerScope).Enum.fields) |logger_scope_enum_field| {
|
||||
// const log_scope = @field(LoggerScope, logger_scope_enum_field.name);
|
||||
//
|
||||
// if (byte_equal(@tagName(log_scope), log_scope_candidate)) {
|
||||
// const LogScope = getLoggerScopeType(log_scope);
|
||||
//
|
||||
// if (log_argument_splitter.next()) |particular_log_candidate| {
|
||||
// var recognized_particular = false;
|
||||
// inline for (@typeInfo(LogScope.Logger).Enum.fields) |particular_log_field| {
|
||||
// const particular_log = @field(LogScope.Logger, particular_log_field.name);
|
||||
//
|
||||
// if (byte_equal(particular_log_candidate, @tagName(particular_log))) {
|
||||
// LogScope.Logger.bitset.setPresent(particular_log, true);
|
||||
// recognized_particular = true;
|
||||
// }
|
||||
// } else if (!recognized_particular) @panic("Unrecognized particular log"); //std.debug.panic("Unrecognized particular log \"{s}\" in scope {s}", .{ particular_log_candidate, @tagName(log_scope) });
|
||||
// } else {
|
||||
// // LogScope.Logger.bitset = @TypeOf(LogScope.Logger.bitset).initFull();
|
||||
// }
|
||||
//
|
||||
// logger_bitset.setPresent(log_scope, true);
|
||||
//
|
||||
// recognized_scope = true;
|
||||
// }
|
||||
// } else if (!recognized_scope) @panic("Unrecognized particular log"); //std.debug.panic("Unrecognized log scope: {s}", .{log_scope_candidate});
|
||||
// }
|
||||
} else {
|
||||
reportUnterminatedArgumentError(current_argument);
|
||||
}
|
||||
} else if (byte_equal(current_argument, "-parse")) {
|
||||
if (i + 1 != arguments.len) {
|
||||
i += 1;
|
||||
@ -3087,19 +3036,6 @@ fn createUnit(context: *const Context, arguments: struct {
|
||||
return unit;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
pub fn realpath(arena: *Arena, dir: std.fs.Dir, relative_path: []const u8) ![]const u8 {
|
||||
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||
const stack_realpath = try dir.realpath(relative_path, &buffer);
|
||||
const heap_realpath = try arena.new_array(u8, stack_realpath.len);
|
||||
@memcpy(heap_realpath, stack_realpath);
|
||||
return heap_realpath;
|
||||
}
|
||||
|
||||
pub const ContainerType = enum {
|
||||
@"struct",
|
||||
@"enum",
|
||||
@ -17680,7 +17616,9 @@ pub const Unit = struct {
|
||||
return unit.importPackage(context, package);
|
||||
}
|
||||
|
||||
const ends_with_nat = import_name.len >= 4 and @as(u32, @bitCast(import_name[import_name.len - 4 ..][0..4].*)) == @as(u32, @bitCast(@as([*]const u8, ".nat")[0..4].*));
|
||||
const nat_ending = ".nat";
|
||||
const nat_ending_len = nat_ending.len;
|
||||
const ends_with_nat = import_name.len >= 4 and @as(u32, @bitCast(import_name[import_name.len - nat_ending_len ..][0..nat_ending_len].*)) == @as(u32, @bitCast(@as([*]const u8, ".nat")[0..nat_ending_len].*));
|
||||
if (!ends_with_nat) {
|
||||
unreachable;
|
||||
}
|
||||
|
@ -76,6 +76,8 @@ pub const LLVM = struct {
|
||||
nounwind: *Attribute,
|
||||
inreg: *Attribute,
|
||||
@"noalias": *Attribute,
|
||||
zero_extend: *Attribute,
|
||||
sign_extend: *Attribute,
|
||||
};
|
||||
|
||||
pub const Linkage = enum(c_uint) {
|
||||
@ -141,7 +143,6 @@ pub const LLVM = struct {
|
||||
const createConditionalBranch = bindings.NativityLLVMBuilderCreateConditionalBranch;
|
||||
const createSwitch = bindings.NativityLLVMBuilderCreateSwitch;
|
||||
const createGEP = bindings.NativityLLVMBuilderCreateGEP;
|
||||
const createStructGEP = bindings.NativityLLVMBuilderCreateStructGEP;
|
||||
const createICmp = bindings.NativityLLVMBuilderCreateICmp;
|
||||
const createLoad = bindings.NativityLLVMBuilderCreateLoad;
|
||||
const createMultiply = bindings.NativityLLVMBuilderCreateMultiply;
|
||||
@ -167,6 +168,7 @@ pub const LLVM = struct {
|
||||
const getInsertBlock = bindings.NativityLLVMBuilderGetInsertBlock;
|
||||
const isCurrentBlockTerminated = bindings.NativityLLVMBuilderIsCurrentBlockTerminated;
|
||||
const setCurrentDebugLocation = bindings.NativityLLVMBuilderSetCurrentDebugLocation;
|
||||
const setInstructionDebugLocation = bindings.NativityLLVMBuilderSetInstructionDebugLocation;
|
||||
};
|
||||
|
||||
pub const DebugInfo = struct {
|
||||
@ -2417,6 +2419,8 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
|
||||
.nounwind = llvm_context.getAttributeFromEnum(.NoUnwind, 0),
|
||||
.inreg = llvm_context.getAttributeFromEnum(.InReg, 0),
|
||||
.@"noalias" = llvm_context.getAttributeFromEnum(.NoAlias, 0),
|
||||
.sign_extend = llvm_context.getAttributeFromEnum(.SExt, 0),
|
||||
.zero_extend = llvm_context.getAttributeFromEnum(.ZExt, 0),
|
||||
},
|
||||
.debug_info_file_map = try PinnedHashMap(Compilation.Debug.File.Index, *LLVM.DebugInfo.File).init(std.mem.page_size),
|
||||
.debug_type_map = try PinnedHashMap(Compilation.Type.Index, *LLVM.DebugInfo.Type).init(std.mem.page_size),
|
||||
@ -3424,17 +3428,6 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
|
||||
const target_machine = target.createTargetMachine(target_triple.ptr, target_triple.len, cpu, cpu.len, features.pointer, features.length, LLVM.RelocationModel.static, code_model, is_code_model_present, codegen_optimization_level, jit) orelse unreachable;
|
||||
llvm.module.setTargetMachineDataLayout(target_machine);
|
||||
llvm.module.setTargetTriple(target_triple.ptr, target_triple.len);
|
||||
const file_path = unit.descriptor.executable_path;
|
||||
const object_file_path = blk: {
|
||||
const slice = try context.arena.new_array(u8, file_path.len + 3);
|
||||
@memcpy(slice[0..file_path.len], file_path);
|
||||
slice[file_path.len] = '.';
|
||||
slice[file_path.len + 1] = 'o';
|
||||
slice[file_path.len + 2] = 0;
|
||||
const object_file_path = slice[0 .. slice.len - 1 :0];
|
||||
break :blk object_file_path;
|
||||
};
|
||||
|
||||
if (unit.descriptor.optimization != .none) {
|
||||
const optimization_level: LLVM.OptimizationLevel = switch (unit.descriptor.optimization) {
|
||||
.none => unreachable,
|
||||
@ -3448,6 +3441,17 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo
|
||||
|
||||
llvm.module.runOptimizationPipeline(target_machine, optimization_level);
|
||||
}
|
||||
const file_path = unit.descriptor.executable_path;
|
||||
const object_file_path = blk: {
|
||||
const slice = try context.arena.new_array(u8, file_path.len + 3);
|
||||
@memcpy(slice[0..file_path.len], file_path);
|
||||
slice[file_path.len] = '.';
|
||||
slice[file_path.len + 1] = 'o';
|
||||
slice[file_path.len + 2] = 0;
|
||||
const object_file_path = slice[0 .. slice.len - 1 :0];
|
||||
break :blk object_file_path;
|
||||
};
|
||||
|
||||
|
||||
const disable_verify = false;
|
||||
const result = llvm.module.addPassesToEmitFile(target_machine, object_file_path.ptr, object_file_path.len, LLVM.CodeGenFileType.object, disable_verify);
|
||||
|
@ -1,125 +1,137 @@
|
||||
const llvm = @import("llvm.zig");
|
||||
const LLVM = llvm.LLVM;
|
||||
pub extern fn NativityLLVMCreateContext() ?*LLVM.Context;
|
||||
pub extern fn NativityLLVMCreateModule(module_name_ptr: [*:0]const u8, module_name_len: usize, context: *LLVM.Context) ?*LLVM.Module;
|
||||
pub extern fn NativityLLVMCreateBuilder(context: *LLVM.Context) ?*LLVM.Builder;
|
||||
pub extern fn NativityLLVMGetFunctionType(return_type: *LLVM.Type, argument_type_ptr: [*]const *LLVM.Type, argument_type_len: usize, is_var_args: bool) ?*LLVM.Type.Function;
|
||||
const compiler = @import("../compiler.zig");
|
||||
const LLVM = compiler.LLVM;
|
||||
|
||||
pub extern fn NativityLLVMInitializeAll() void;
|
||||
pub extern fn NativityLLVMCreateContext() *LLVM.Context;
|
||||
pub extern fn NativityLLVMCreateModule(module_name_ptr: [*]const u8, module_name_len: usize, context: *LLVM.Context) *LLVM.Module;
|
||||
pub extern fn NativityLLVMCreateBuilder(context: *LLVM.Context) *LLVM.Builder;
|
||||
pub extern fn NativityLLVMGetFunctionType(return_type: *LLVM.Type, argument_type_ptr: [*]const *LLVM.Type, argument_type_len: usize, is_var_args: bool) *LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMFunctionTypeGetArgumentType(function_type: *LLVM.Type.Function, argument_index: c_uint) *LLVM.Type;
|
||||
pub extern fn NativityLLVMGetIntegerType(context: *LLVM.Context, bit_count: u32) ?*LLVM.Type.Integer;
|
||||
pub extern fn NativityLLVMGetPointerType(context: *LLVM.Context, address_space: u32) ?*LLVM.Type.Pointer;
|
||||
pub extern fn NativityLLVMGetIntegerType(context: *LLVM.Context, bit_count: u32) *LLVM.Type.Integer;
|
||||
pub extern fn NativityLLVMGetPointerType(context: *LLVM.Context, address_space: u32) *LLVM.Type.Pointer;
|
||||
pub extern fn NativityLLVMPointerTypeGetNull(pointer_type: *LLVM.Type.Pointer) *LLVM.Value.Constant.PointerNull;
|
||||
pub extern fn NativityLLVMGetArrayType(element_type: *LLVM.Type, element_count: u64) ?*LLVM.Type.Array;
|
||||
pub extern fn NativityLLVMGetStructType(context: *LLVM.Context, type_ptr: [*]const *LLVM.Type, type_count: usize, is_packed: bool) ?*LLVM.Type.Struct;
|
||||
pub extern fn NativityLLVMConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_count: usize) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMGetArrayType(element_type: *LLVM.Type, element_count: u64) *LLVM.Type.Array;
|
||||
pub extern fn NativityLLVMGetStructType(context: *LLVM.Context, type_ptr: [*]const *LLVM.Type, type_count: usize, is_packed: bool) *LLVM.Type.Struct;
|
||||
pub extern fn NativityLLVMCreateStructType(context: *LLVM.Context, type_pointer: [*]const *LLVM.Type, type_count: usize, name_pointer: [*]const u8, name_length: usize, is_packed: bool) *LLVM.Type.Struct;
|
||||
pub extern fn NativityLLVMConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_count: usize) *LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMModuleGetFunction(module: *LLVM.Module, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVModuleCreateFunction(module: *LLVM.Module, function_type: *LLVM.Type.Function, linkage: LLVM.Linkage, address_space: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMModuleCreateDebugInfoBuilder(module: *LLVM.Module) ?*LLVM.DebugInfo.Builder;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFile(builder: *LLVM.DebugInfo.Builder, filename_ptr: [*]const u8, filename_len: usize, directory_ptr: [*]const u8, directory_len: usize) ?*LLVM.DebugInfo.File;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateCompileUnit(builder: *LLVM.DebugInfo.Builder, language: LLVM.DebugInfo.Language, file: *LLVM.DebugInfo.File, producer_ptr: [*]const u8, producer_len: usize, is_optimized: bool, flags_ptr: [*]const u8, flags_len: usize, runtime_version: c_uint, split_name_ptr: [*]const u8, split_name_len: usize, debug_info_emission_kind: LLVM.DebugInfo.CompileUnit.EmissionKind, DWOId: u64, split_debug_inlining: bool, debug_info_for_profiling: bool, debug_info_name_table_kind: LLVM.DebugInfo.CompileUnit.NameTableKind, ranges_base_address: bool, sysroot_ptr: [*]const u8, sysroot_len: usize, sdk_ptr: [*]const u8, sdk_len: usize) ?*LLVM.DebugInfo.CompileUnit;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFunction(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type.Subroutine, scope_line: c_uint, flags: LLVM.DebugInfo.Node.Flags, subprogram_flags: LLVM.DebugInfo.Subprogram.Flags, declaration: ?*LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateSubroutineType(builder: *LLVM.DebugInfo.Builder, parameter_types_ptr: [*]const *LLVM.DebugInfo.Type, parameter_type_count: usize, flags: LLVM.DebugInfo.Node.Flags, calling_convention: LLVM.DebugInfo.CallingConvention) ?*LLVM.DebugInfo.Type.Subroutine;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateLexicalBlock(builder: *LLVM.DebugInfo.Builder, parent_scope: *LLVM.DebugInfo.Scope, parent_file: *LLVM.DebugInfo.File, line: c_uint, column: c_uint) ?*LLVM.DebugInfo.LexicalBlock;
|
||||
pub extern fn NativityLLVModuleCreateFunction(module: *LLVM.Module, function_type: *LLVM.Type.Function, linkage: LLVM.Linkage, address_space: c_uint, name_ptr: [*]const u8, name_len: usize) *LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMModuleCreateDebugInfoBuilder(module: *LLVM.Module) *LLVM.DebugInfo.Builder;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFile(builder: *LLVM.DebugInfo.Builder, filename_ptr: [*]const u8, filename_len: usize, directory_ptr: [*]const u8, directory_len: usize) *LLVM.DebugInfo.File;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateCompileUnit(builder: *LLVM.DebugInfo.Builder, language: LLVM.DebugInfo.Language, file: *LLVM.DebugInfo.File, producer_ptr: [*]const u8, producer_len: usize, is_optimized: bool, flags_ptr: [*]const u8, flags_len: usize, runtime_version: c_uint, split_name_ptr: [*]const u8, split_name_len: usize, debug_info_emission_kind: LLVM.DebugInfo.CompileUnit.EmissionKind, DWOId: u64, split_debug_inlining: bool, debug_info_for_profiling: bool, debug_info_name_table_kind: LLVM.DebugInfo.CompileUnit.NameTableKind, ranges_base_address: bool, sysroot_ptr: [*]const u8, sysroot_len: usize, sdk_ptr: [*]const u8, sdk_len: usize) *LLVM.DebugInfo.CompileUnit;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateFunction(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type.Subroutine, scope_line: c_uint, flags: LLVM.DebugInfo.Node.Flags, subprogram_flags: LLVM.DebugInfo.Subprogram.Flags, declaration: ?*LLVM.DebugInfo.Subprogram) *LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateSubroutineType(builder: *LLVM.DebugInfo.Builder, parameter_types_ptr: [*]const *LLVM.DebugInfo.Type, parameter_type_count: usize, flags: LLVM.DebugInfo.Node.Flags, calling_convention: LLVM.DebugInfo.CallingConvention) *LLVM.DebugInfo.Type.Subroutine;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateLexicalBlock(builder: *LLVM.DebugInfo.Builder, parent_scope: *LLVM.DebugInfo.Scope, parent_file: *LLVM.DebugInfo.File, line: c_uint, column: c_uint) *LLVM.DebugInfo.LexicalBlock;
|
||||
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateExpression(builder: *LLVM.DebugInfo.Builder, address: [*]const u64, length: usize) *LLVM.DebugInfo.Expression;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateGlobalVariableExpression(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, is_local_to_unit: bool, is_defined: bool, expression: ?*LLVM.DebugInfo.Expression, declaration: ?*LLVM.Metadata.Node, template_parameters: ?*LLVM.Metadata.Tuple, alignment: u32) ?*LLVM.DebugInfo.GlobalVariableExpression;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateParameterVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, argument_index: c_uint, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags) ?*LLVM.DebugInfo.LocalVariable;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateAutoVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags, alignment: u32) ?*LLVM.DebugInfo.LocalVariable; // 0 means 1 << 0 (alignment of 1)
|
||||
pub extern fn NativityLLVMDebugInfoBuilderInsertDeclare(builder: *LLVM.DebugInfo.Builder, pointer: *LLVM.Value, local_variable: *LLVM.DebugInfo.LocalVariable, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, basic_block: *LLVM.Value.BasicBlock) ?*LLVM.Value.Instruction;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateGlobalVariableExpression(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, is_local_to_unit: bool, is_defined: bool, expression: ?*LLVM.DebugInfo.Expression, declaration: ?*LLVM.Metadata.Node, template_parameters: ?*LLVM.Metadata.Tuple, alignment: u32) *LLVM.DebugInfo.GlobalVariableExpression;
|
||||
pub extern fn NativityLLVMDebugInfoGlobalVariableAddDebugInfo(global_variable: *LLVM.Value.Constant.GlobalVariable, global_variable_expression: *LLVM.DebugInfo.GlobalVariableExpression) void;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateParameterVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, argument_index: c_uint, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags) *LLVM.DebugInfo.LocalVariable;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateAutoVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags, alignment: u32) *LLVM.DebugInfo.LocalVariable; // 0 means 1 << 0 (alignment of 1)
|
||||
pub extern fn NativityLLVMDebugInfoBuilderInsertDeclare(builder: *LLVM.DebugInfo.Builder, pointer: *LLVM.Value, local_variable: *LLVM.DebugInfo.LocalVariable, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, basic_block: *LLVM.Value.BasicBlock) *LLVM.Value.Instruction;
|
||||
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateBasicType(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, bit_count: u64, dwarf_encoding: LLVM.DebugInfo.AttributeType, flags: LLVM.DebugInfo.Node.Flags) ?*LLVM.DebugInfo.Type;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreatePointerType(builder: *LLVM.DebugInfo.Builder, element_type: *LLVM.DebugInfo.Type, pointer_bit_count: u64, alignment: u32, name_ptr: [*]const u8, name_len: usize) ?*LLVM.DebugInfo.Type.Derived;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateStructType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_count: u64, alignment: u32, flags: LLVM.DebugInfo.Node.Flags, derived_from: ?*LLVM.DebugInfo.Type, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize, forward_declaration: ?*LLVM.DebugInfo.Type.Composite) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateArrayType(builder: *LLVM.DebugInfo.Builder, bit_size: u64, alignment: u32, type: *LLVM.DebugInfo.Type, element_count: usize) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line: c_uint, bit_size: u64, alignment: u32, enumerator_ptr: [*]const *LLVM.DebugInfo.Type.Enumerator, enumerator_count: usize, underlying_type: *LLVM.DebugInfo.Type) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerator(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, value: u64, is_unsigned: bool) ?*LLVM.DebugInfo.Type.Enumerator;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateReplaceableCompositeType(builder: *LLVM.DebugInfo.Builder, tag: c_uint, name_ptr: [*]const u8, name_len: usize, scope: ?*LLVM.DebugInfo.Scope, file: ?*LLVM.DebugInfo.File, line: c_uint) ?*LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateBasicType(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, bit_count: u64, dwarf_encoding: LLVM.DebugInfo.AttributeType, flags: LLVM.DebugInfo.Node.Flags) *LLVM.DebugInfo.Type;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreatePointerType(builder: *LLVM.DebugInfo.Builder, element_type: *LLVM.DebugInfo.Type, pointer_bit_count: u64, alignment: u32, name_ptr: [*]const u8, name_len: usize) *LLVM.DebugInfo.Type.Derived;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateStructType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_count: u64, alignment: u32, flags: LLVM.DebugInfo.Node.Flags, derived_from: ?*LLVM.DebugInfo.Type, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize, forward_declaration: ?*LLVM.DebugInfo.Type.Composite) *LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateArrayType(builder: *LLVM.DebugInfo.Builder, bit_size: u64, alignment: u32, type: *LLVM.DebugInfo.Type, element_count: usize) *LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line: c_uint, bit_size: u64, alignment: u32, enumerator_ptr: [*]const *LLVM.DebugInfo.Type.Enumerator, enumerator_count: usize, underlying_type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerator(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, value: u64, is_unsigned: bool) *LLVM.DebugInfo.Type.Enumerator;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateReplaceableCompositeType(builder: *LLVM.DebugInfo.Builder, tag: c_uint, name_ptr: [*]const u8, name_len: usize, scope: ?*LLVM.DebugInfo.Scope, file: ?*LLVM.DebugInfo.File, line: c_uint) *LLVM.DebugInfo.Type.Composite;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateMemberType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, alignment: u32, bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCreateBitfieldMemberType(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_pointer: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, bit_offset: u64, storage_bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderCompositeTypeReplaceTypes(builder: *LLVM.DebugInfo.Builder, type: *LLVM.DebugInfo.Type.Composite, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize) void;
|
||||
pub extern fn NativityLLLVMDITypeGetName(type: *LLVM.DebugInfo.Type, name_pointer: *[*]const u8, name_length: *usize) void;
|
||||
pub extern fn NativityLLLVMDITypeIsResolved(type: *LLVM.DebugInfo.Type) bool;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderFinalizeSubprogram(builder: *LLVM.DebugInfo.Builder, subprogram: *LLVM.DebugInfo.Subprogram, function: *LLVM.Value.Constant.Function) void;
|
||||
pub extern fn NativityLLVMDebugInfoBuilderFinalize(builder: *LLVM.DebugInfo.Builder) void;
|
||||
pub extern fn NativityLLVMDebugInfoSubprogramGetFile(subprogram: *LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.File;
|
||||
pub extern fn NativityLLVMDebugInfoSubprogramGetArgumentType(subprogram: *LLVM.DebugInfo.Subprogram, argument_index: usize) ?*LLVM.DebugInfo.Type;
|
||||
pub extern fn NativityLLVMDebugInfoSubprogramGetFile(subprogram: *LLVM.DebugInfo.Subprogram) *LLVM.DebugInfo.File;
|
||||
pub extern fn NativityLLVMDebugInfoSubprogramGetArgumentType(subprogram: *LLVM.DebugInfo.Subprogram, argument_index: usize) *LLVM.DebugInfo.Type;
|
||||
pub extern fn NativityLLVMDebugInfoScopeToSubprogram(scope: *LLVM.DebugInfo.Scope) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMCreateBasicBlock(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, parent_function: ?*LLVM.Value.Constant.Function, insert_before: ?*LLVM.Value.BasicBlock) ?*LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMCreateBasicBlock(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, parent_function: ?*LLVM.Value.Constant.Function, insert_before: ?*LLVM.Value.BasicBlock) *LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMBasicBlockRemoveFromParent(basic_block: *LLVM.Value.BasicBlock) void;
|
||||
pub extern fn NativityLLVMBuilderSetInsertPoint(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) void;
|
||||
pub extern fn NativityLLVMBuilderGetInsertBlock(builder: *LLVM.Builder) ?*LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMBuilderGetInsertBlock(builder: *LLVM.Builder) *LLVM.Value.BasicBlock;
|
||||
pub extern fn NativityLLVMBuilderSetCurrentDebugLocation(builder: *LLVM.Builder, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, function: *LLVM.Value.Constant.Function) void;
|
||||
pub extern fn NativityLLVMBuilderClearCurrentDebugLocation(builder: *LLVM.Builder) void;
|
||||
pub extern fn NativityLLVMBuilderSetInstructionDebugLocation(builder: *LLVM.Builder, instruction: *LLVM.Value.Instruction) void;
|
||||
pub extern fn NativityLLVMValueSetName(value: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) void;
|
||||
pub extern fn NativityLLVMValueGetType(value: *LLVM.Value) *LLVM.Type;
|
||||
pub extern fn NativityLLVMValueGetContext(value: *LLVM.Value) *LLVM.Context;
|
||||
pub extern fn NativityLLVMArgumentGetIndex(argument: *LLVM.Value.Argument) c_uint;
|
||||
pub extern fn NativityLLVMFunctionGetArguments(function: *LLVM.Value.Constant.Function, argument_ptr: [*]*LLVM.Value.Argument, argument_len: *usize) void;
|
||||
pub extern fn NativityLLVMFunctionGetArgument(function: *LLVM.Value.Constant.Function, index: c_uint) ?*LLVM.Value.Argument;
|
||||
pub extern fn NativityLLVMFunctionGetArgument(function: *LLVM.Value.Constant.Function, index: c_uint) *LLVM.Value.Argument;
|
||||
pub extern fn NativityLLVMFunctionGetType(function: *LLVM.Value.Constant.Function) *LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMFunctionTypeGetReturnType(function_type: *LLVM.Type.Function) *LLVM.Type;
|
||||
pub extern fn NativityLLVMTypeIsVoid(type: *LLVM.Type) bool;
|
||||
pub extern fn NativityLLVMBuilderCreateAlloca(builder: *LLVM.Builder, type: *LLVM.Type, address_space: c_uint, array_size: ?*LLVM.Value, name_ptr: [*]const u8, name_len: usize, alignment: u32) ?*LLVM.Value.Instruction.Alloca;
|
||||
pub extern fn NativityLLVMBuilderCreateStore(builder: *LLVM.Builder, value: *LLVM.Value, pointer: *LLVM.Value, is_volatile: bool, alignment: u32) ?*LLVM.Value.Instruction.Store;
|
||||
pub extern fn NativityLLVMBuilderCreateAlloca(builder: *LLVM.Builder, type: *LLVM.Type, address_space: c_uint, array_size: ?*LLVM.Value, name_ptr: [*]const u8, name_len: usize, alignment: u32) *LLVM.Value.Instruction.Alloca;
|
||||
pub extern fn NativityLLVMBuilderCreateStore(builder: *LLVM.Builder, value: *LLVM.Value, pointer: *LLVM.Value, is_volatile: bool, alignment: u32) *LLVM.Value.Instruction.Store;
|
||||
pub extern fn NativityLLVMBuilderCreateMemcpy(builder: *LLVM.Builder, destination: *LLVM.Value, destination_alignment: u32, source: *LLVM.Value, source_alignment: u32, size: u64, is_volatile: bool) *LLVM.Value.Instruction.Call;
|
||||
pub extern fn NativityLLVMContextGetConstantInt(context: *LLVM.Context, bit_count: c_uint, value: u64, is_signed: bool) ?*LLVM.Value.Constant.Int;
|
||||
pub extern fn NativityLLVMContextGetConstantString(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, null_terminate: bool) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMGetConstantArray(array_type: *LLVM.Type.Array, value_ptr: [*]const *LLVM.Value.Constant, value_count: usize) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMGetConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMContextGetConstantInt(context: *LLVM.Context, bit_count: c_uint, value: u64, is_signed: bool) *LLVM.Value.Constant.Int;
|
||||
pub extern fn NativityLLVMContextGetConstantString(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, null_terminate: bool) *LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMGetConstantArray(array_type: *LLVM.Type.Array, value_ptr: [*]const *LLVM.Value.Constant, value_count: usize) *LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMGetConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) *LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMConstantToInt(constant: *LLVM.Value.Constant) ?*LLVM.Value.Constant.Int;
|
||||
pub extern fn NativityLLVMBuilderCreateICmp(builder: *LLVM.Builder, integer_comparison: LLVM.Value.Instruction.ICmp.Kind, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateLoad(builder: *LLVM.Builder, type: *LLVM.Type, value: *LLVM.Value, is_volatile: bool, name_ptr: [*]const u8, name_len: usize, alignment: u32) ?*LLVM.Value.Instruction.Load;
|
||||
pub extern fn NativityLLVMBuilderCreateRet(builder: *LLVM.Builder, value: ?*LLVM.Value) ?*LLVM.Value.Instruction.Ret;
|
||||
pub extern fn NativityLLVMBuilderCreateCast(builder: *LLVM.Builder, cast_type: LLVM.Value.Instruction.Cast.Type, value: *LLVM.Value, type: *LLVM.Type, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateICmp(builder: *LLVM.Builder, integer_comparison: LLVM.Value.Instruction.ICmp.Kind, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateIsNotNull(builder: *LLVM.Builder, value: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateLoad(builder: *LLVM.Builder, type: *LLVM.Type, value: *LLVM.Value, is_volatile: bool, name_ptr: [*]const u8, name_len: usize, alignment: u32) *LLVM.Value.Instruction.Load;
|
||||
pub extern fn NativityLLVMBuilderCreateRet(builder: *LLVM.Builder, value: ?*LLVM.Value) *LLVM.Value.Instruction.Ret;
|
||||
pub extern fn NativityLLVMBuilderCreateCast(builder: *LLVM.Builder, cast_type: LLVM.Value.Instruction.Cast.Type, value: *LLVM.Value, type: *LLVM.Type, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMContextGetAttributeFromEnum(context: *LLVM.Context, attribute_key: LLVM.Attribute.Id, attribute_value: u64) *LLVM.Attribute;
|
||||
pub extern fn NativityLLVMContextGetAttributeFromString(context: *LLVM.Context, key_ptr: [*]const u8, key_len: usize, value_ptr: [*]const u8, value_len: usize) *LLVM.Attribute;
|
||||
pub extern fn NativityLLVMContextGetAttributeFromType(context: *LLVM.Context, attribute_key: LLVM.Attribute.Id, type: *LLVM.Type) *LLVM.Attribute;
|
||||
pub extern fn NativityLLVMContextGetAttributeSet(context: *LLVM.Context, attribute_ptr: ?[*]const *LLVM.Attribute, attribute_count: usize) *const LLVM.Attribute.Set;
|
||||
pub extern fn NativityLLVMFunctionSetAttributes(function: *LLVM.Value.Constant.Function, context: *LLVM.Context, function_attributes: *const LLVM.Attribute.Set, return_attributes: *const LLVM.Attribute.Set, parameter_attribute_set_ptr: [*]const *const LLVM.Attribute.Set, parameter_attribute_set_count: usize) void;
|
||||
pub extern fn NativityLLVMCallSetAttributes(call: *LLVM.Value.Instruction.Call, context: *LLVM.Context, function_attributes: *const LLVM.Attribute.Set, return_attributes: *const LLVM.Attribute.Set, parameter_attribute_set_ptr: [*]const *const LLVM.Attribute.Set, parameter_attribute_set_count: usize) void;
|
||||
pub extern fn NativityLLVMGlobalObjectSetAlignment(global_object: *LLVM.Value.Constant.GlobalObject, alignment: u32) void;
|
||||
// pub extern fn NativityLLVMFunctionAddAttributeKey(builder: *LLVM.Value.Constant.Function, attribute_key: LLVM.Attribute) void;
|
||||
pub extern fn NativityLLVMGetVoidType(context: *LLVM.Context) ?*LLVM.Type;
|
||||
pub extern fn NativityLLVMGetInlineAssembly(function_type: *LLVM.Type.Function, assembly_ptr: [*]const u8, assembly_len: usize, constraints_ptr: [*]const u8, constrains_len: usize, has_side_effects: bool, is_align_stack: bool, dialect: LLVM.Value.InlineAssembly.Dialect, can_throw: bool) ?*LLVM.Value.InlineAssembly;
|
||||
pub extern fn NativityLLVMBuilderCreateCall(builder: *LLVM.Builder, function_type: *LLVM.Type.Function, callee: *LLVM.Value, argument_ptr: [*]const *LLVM.Value, argument_count: usize, name_ptr: [*]const u8, name_len: usize, fp_math_tag: ?*LLVM.Metadata.Node) ?*LLVM.Value.Instruction.Call;
|
||||
pub extern fn NativityLLVMBuilderCreateUnreachable(builder: *LLVM.Builder) ?*LLVM.Value.Instruction.Unreachable;
|
||||
pub extern fn NativityLLVMModuleAddGlobalVariable(module: *LLVM.Module, type: *LLVM.Type, is_constant: bool, linkage: LLVM.Linkage, initializer: ?*LLVM.Value.Constant, name_ptr: [*]const u8, name_len: usize, insert_before: ?*LLVM.Value.Constant.GlobalVariable, thread_local_mode: LLVM.ThreadLocalMode, address_space: c_uint, externally_initialized: bool) ?*LLVM.Value.Constant.GlobalVariable;
|
||||
pub extern fn NativityLLVMGetVoidType(context: *LLVM.Context) *LLVM.Type;
|
||||
pub extern fn NativityLLVMGetInlineAssembly(function_type: *LLVM.Type.Function, assembly_ptr: [*]const u8, assembly_len: usize, constraints_ptr: [*]const u8, constrains_len: usize, has_side_effects: bool, is_align_stack: bool, dialect: LLVM.Value.InlineAssembly.Dialect, can_throw: bool) *LLVM.Value.InlineAssembly;
|
||||
pub extern fn NativityLLVMBuilderCreateCall(builder: *LLVM.Builder, function_type: *LLVM.Type.Function, callee: *LLVM.Value, argument_ptr: [*]const *LLVM.Value, argument_count: usize, name_ptr: [*]const u8, name_len: usize, fp_math_tag: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Call;
|
||||
pub extern fn NativityLLVMBuilderCreateUnreachable(builder: *LLVM.Builder) *LLVM.Value.Instruction.Unreachable;
|
||||
pub extern fn NativityLLVMModuleAddGlobalVariable(module: *LLVM.Module, type: *LLVM.Type, is_constant: bool, linkage: LLVM.Linkage, initializer: ?*LLVM.Value.Constant, name_ptr: [*]const u8, name_len: usize, insert_before: ?*LLVM.Value.Constant.GlobalVariable, thread_local_mode: LLVM.ThreadLocalMode, address_space: c_uint, externally_initialized: bool) *LLVM.Value.Constant.GlobalVariable;
|
||||
|
||||
pub extern fn NativityLLVMBuilderCreateAdd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateSub(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateMultiply(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateShiftLeft(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateAdd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateSub(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateMultiply(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateShiftLeft(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
|
||||
|
||||
pub extern fn NativityLLVMBuilderCreateUDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateSDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateURem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateSRem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateLogicalShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateArithmeticShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateUDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateSDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateURem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateSRem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateLogicalShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateArithmeticShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
|
||||
|
||||
pub extern fn NativityLLVMBuilderCreateXor(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateAnd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateOr(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index_ptr: [*]const *LLVM.Value, index_count: usize, name_ptr: [*]const u8, name_len: usize, in_bounds: bool) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateStructGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateBranch(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) ?*LLVM.Value.Instruction.Branch;
|
||||
pub extern fn NativityLLVMBuilderCreateConditionalBranch(builder: *LLVM.Builder, condition: *LLVM.Value, true_block: *LLVM.Value.BasicBlock, false_block: *LLVM.Value.BasicBlock, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) ?*LLVM.Value.Instruction.Branch;
|
||||
pub extern fn NativityLLVMBuilderCreateXor(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateAnd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateOr(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index_ptr: [*]const *LLVM.Value, index_count: usize, name_ptr: [*]const u8, name_len: usize, in_bounds: bool) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateBranch(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) *LLVM.Value.Instruction.Branch;
|
||||
pub extern fn NativityLLVMBuilderCreateConditionalBranch(builder: *LLVM.Builder, condition: *LLVM.Value, true_block: *LLVM.Value.BasicBlock, false_block: *LLVM.Value.BasicBlock, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Branch;
|
||||
pub extern fn NativityLLVMBuilderCreateSwitch(builder: *LLVM.Builder, condition: *LLVM.Value, default_block: ?*LLVM.Value.BasicBlock, case_ptr: [*]const *LLVM.Value.Constant.Int, case_block_ptr: [*]const *LLVM.Value.BasicBlock, case_count: c_uint, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Switch;
|
||||
|
||||
pub extern fn NativityLLVMVerifyFunction(function: *LLVM.Value.Constant.Function, message_ptr: *[*]const u8, message_len: *usize) bool;
|
||||
pub extern fn NativityLLVMVerifyModule(module: *LLVM.Module, message_ptr: *[*]const u8, message_len: *usize) bool;
|
||||
|
||||
pub extern fn NativityLLVMModuleToString(module: *LLVM.Module, message_len: *usize) [*]const u8;
|
||||
pub extern fn NativityLLVMFunctionToString(function: *LLVM.Value.Constant.Function, message_len: *usize) [*]const u8;
|
||||
pub extern fn NativityLLVMValueToString(value: *LLVM.Value, message_len: *usize) [*]const u8;
|
||||
pub extern fn NativityLLVMModuleToString(module: *LLVM.Module, message_pointer: *[*]const u8, message_len: *usize) void;
|
||||
pub extern fn NativityLLVMFunctionToString(function: *LLVM.Value.Constant.Function, message_pointer: *[*]const u8, message_len: *usize) void;
|
||||
pub extern fn NativityLLVMValueToString(value: *LLVM.Value, message_pointer: *[*]const u8, message_len: *usize) void;
|
||||
|
||||
pub extern fn NativityLLVMBuilderIsCurrentBlockTerminated(builder: *LLVM.Builder) bool;
|
||||
pub extern fn NativityLLVMGetUndefined(type: *LLVM.Type) ?*LLVM.Value.Constant.Undefined;
|
||||
pub extern fn NativityLLVMGetPoisonValue(type: *LLVM.Type) ?*LLVM.Value.Constant.Poison;
|
||||
pub extern fn NativityLLVMGetUndefined(type: *LLVM.Type) *LLVM.Value.Constant.Undefined;
|
||||
pub extern fn NativityLLVMGetPoisonValue(type: *LLVM.Type) *LLVM.Value.Constant.Poison;
|
||||
pub extern fn NativityLLVMTypeGetContext(type: *LLVM.Type) *LLVM.Context;
|
||||
pub extern fn NativityLLVMFunctionSetCallingConvention(function: *LLVM.Value.Constant.Function, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void;
|
||||
pub extern fn NativityLLVMFunctionGetCallingConvention(function: *LLVM.Value.Constant.Function) LLVM.Value.Constant.Function.CallingConvention;
|
||||
pub extern fn NativityLLVMFunctionSetSubprogram(function: *LLVM.Value.Constant.Function, subprogram: *LLVM.DebugInfo.Subprogram) void;
|
||||
pub extern fn NativityLLVMFunctionGetSubprogram(function: *LLVM.Value.Constant.Function) ?*LLVM.DebugInfo.Subprogram;
|
||||
pub extern fn NativityLLVMFunctionGetSubprogram(function: *LLVM.Value.Constant.Function) *LLVM.DebugInfo.Subprogram;
|
||||
|
||||
pub extern fn NativityLLVMCallSetCallingConvention(instruction: *LLVM.Value.Instruction.Call, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void;
|
||||
pub extern fn NativityLLVMGetStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMGetStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) *LLVM.Value.Constant;
|
||||
|
||||
pub extern fn NativityLLVMValueToConstant(value: *LLVM.Value) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMValueToFunction(value: *LLVM.Value) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMValueToBasicBlock(value: *LLVM.Value) ?*LLVM.Value.BasicBlock;
|
||||
|
||||
pub extern fn NativityLLVMTypeIsPointer(type: *LLVM.Type) bool;
|
||||
pub extern fn NativityLLVMTypeIsInteger(type: *LLVM.Type) bool;
|
||||
@ -129,29 +141,30 @@ pub extern fn NativityLLVMTypeToFunction(type: *LLVM.Type) ?*LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMTypeToArray(type: *LLVM.Type) ?*LLVM.Type.Array;
|
||||
pub extern fn NativityLLVMTypeToPointer(Type: *LLVM.Type) ?*LLVM.Type.Pointer;
|
||||
|
||||
pub extern fn NativityLLVMArrayTypeGetElementType(array_type: *LLVM.Type.Array) ?*LLVM.Type;
|
||||
pub extern fn NativityLLVMArrayTypeGetElementType(array_type: *LLVM.Type.Array) *LLVM.Type;
|
||||
pub extern fn NativityLLVMLookupIntrinsic(name_ptr: [*]const u8, name_len: usize) LLVM.Value.IntrinsicID;
|
||||
pub extern fn NativityLLVMModuleGetIntrinsicDeclaration(module: *LLVM.Module, intrinsic_id: LLVM.Value.IntrinsicID, parameter_types_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMContextGetIntrinsicType(context: *LLVM.Context, intrinsic_id: LLVM.Value.IntrinsicID, parameter_type_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMBuilderCreateExtractValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateInsertValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, value: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateGlobalString(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) ?*LLVM.Value.Constant.GlobalVariable;
|
||||
pub extern fn NativityLLVMBuilderCreateGlobalStringPointer(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) ?*LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMModuleGetIntrinsicDeclaration(module: *LLVM.Module, intrinsic_id: LLVM.Value.IntrinsicID, parameter_types_ptr: [*]const *LLVM.Type, parameter_type_count: usize) *LLVM.Value.Constant.Function;
|
||||
pub extern fn NativityLLVMContextGetIntrinsicType(context: *LLVM.Context, intrinsic_id: LLVM.Value.IntrinsicID, parameter_type_ptr: [*]const *LLVM.Type, parameter_type_count: usize) *LLVM.Type.Function;
|
||||
pub extern fn NativityLLVMBuilderCreateExtractValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateInsertValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, value: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
|
||||
pub extern fn NativityLLVMBuilderCreateGlobalString(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) *LLVM.Value.Constant.GlobalVariable;
|
||||
pub extern fn NativityLLVMBuilderCreateGlobalStringPointer(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) *LLVM.Value.Constant;
|
||||
pub extern fn NativityLLVMCompareTypes(a: *LLVM.Type, b: *LLVM.Type) bool;
|
||||
pub extern fn NativityLLVMBuilderCreatePhi(builder: *LLVM.Builder, type: *LLVM.Type, reserved_value_count: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Instruction.PhiNode;
|
||||
pub extern fn NativityLLVMBuilderCreatePhi(builder: *LLVM.Builder, type: *LLVM.Type, reserved_value_count: c_uint, name_ptr: [*]const u8, name_len: usize) *LLVM.Value.Instruction.PhiNode;
|
||||
pub extern fn NativityLLVMPhiAddIncoming(phi: *LLVM.Value.Instruction.PhiNode, value: *LLVM.Value, basic_block: *LLVM.Value.BasicBlock) void;
|
||||
|
||||
pub extern fn NativityLLVMAllocatGetAllocatedType(alloca: *LLVM.Value.Instruction.Alloca) *LLVM.Type;
|
||||
pub extern fn NativityLLVMValueToAlloca(value: *LLVM.Value) ?*LLVM.Value.Instruction.Alloca;
|
||||
pub extern fn NativityLLVMGlobalVariableSetInitializer(global_variable: *LLVM.Value.Constant.GlobalVariable, constant_initializer: *LLVM.Value.Constant) void;
|
||||
|
||||
pub extern fn NativityLLVMInitializeCodeGeneration() void;
|
||||
pub extern fn NativityLLVMLinkModules(destination: *LLVM.Module, source: *LLVM.Module, flags: LLVM.LinkFlags) bool;
|
||||
|
||||
pub extern fn NativityLLVMGetTarget(target_triple_ptr: [*]const u8, target_triple_len: usize, message_ptr: *[*]const u8, message_len: *usize) ?*LLVM.Target;
|
||||
pub extern fn NativityLLVMTargetCreateTargetMachine(target: *LLVM.Target, target_triple_ptr: [*]const u8, target_triple_len: usize, cpu_ptr: [*]const u8, cpu_len: usize, features_ptr: [*]const u8, features_len: usize, relocation_model: LLVM.RelocationModel, maybe_code_model: LLVM.CodeModel, is_code_model_present: bool, optimization_level: LLVM.CodegenOptimizationLevel, jit: bool) ?*LLVM.Target.Machine;
|
||||
pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module, target_machine: *LLVM.Target.Machine) void;
|
||||
pub extern fn NativityLLVMModuleSetTargetTriple(module: *LLVM.Module, target_triple_ptr: [*]const u8, target_triple_len: usize) void;
|
||||
pub extern fn NativityLLVMTargetCreateTargetMachine(target: *LLVM.Target, target_triple_ptr: [*]const u8, target_triple_len: usize, cpu_ptr: [*]const u8, cpu_len: usize, features_ptr: [*]const u8, features_len: usize, relocation_model: LLVM.RelocationModel, maybe_code_model: LLVM.CodeModel, is_code_model_present: bool, optimization_level: LLVM.CodegenOptimizationLevel, jit: bool) *LLVM.Target.Machine;
|
||||
pub extern fn NativityLLVMRunOptimizationPipeline(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, optimization_level: LLVM.OptimizationLevel) void;
|
||||
pub extern fn NativityLLVMModuleAddPassesToEmitFile(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, object_file_path_ptr: [*]const u8, object_file_path_len: usize, codegen_file_type: LLVM.CodeGenFileType, disable_verify: bool) bool;
|
||||
pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module, target_machine: *LLVM.Target.Machine) void;
|
||||
pub extern fn NativityLLVMModuleSetTargetTriple(module: *LLVM.Module, target_triple_ptr: [*]const u8, target_triple_len: usize) void;
|
||||
pub extern fn NativityLLVMTypeAssertEqual(a: *LLVM.Type, b: *LLVM.Type) void;
|
||||
|
||||
pub extern fn LLVMInitializeAArch64TargetInfo() void;
|
||||
|
11727
bootstrap/compiler.zig
Normal file
11727
bootstrap/compiler.zig
Normal file
File diff suppressed because it is too large
Load Diff
@ -70,12 +70,16 @@ pub const Arena = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub inline fn new(arena: *Arena, comptime T: type) !*T {
|
||||
pub fn align_forward(arena: *Arena, alignment: u64) void {
|
||||
arena.position = std.mem.alignForward(u64, arena.position, alignment);
|
||||
}
|
||||
|
||||
pub fn new(arena: *Arena, comptime T: type) !*T {
|
||||
const result: *T = @ptrCast(@alignCast(try arena.allocate(@sizeOf(T))));
|
||||
return result;
|
||||
}
|
||||
|
||||
pub inline fn new_array(arena: *Arena, comptime T: type, count: usize) ![]T {
|
||||
pub fn new_array(arena: *Arena, comptime T: type, count: usize) ![]T {
|
||||
const result: [*]T = @ptrCast(@alignCast(try arena.allocate(@sizeOf(T) * count)));
|
||||
return result[0..count];
|
||||
}
|
||||
@ -155,17 +159,19 @@ const pinned_array_page_size = 2 * 1024 * 1024;
|
||||
const pinned_array_max_size = std.math.maxInt(u32) - pinned_array_page_size;
|
||||
const pinned_array_default_granularity = pinned_array_page_size;
|
||||
|
||||
const small_granularity = std.mem.page_size;
|
||||
const large_granularity = 2 * 1024 * 1024;
|
||||
// This must be used with big arrays, which are not resizeable (can't be cleared)
|
||||
pub fn PinnedArray(comptime T: type) type {
|
||||
return PinnedArrayAdvanced(T, null);
|
||||
return PinnedArrayAdvanced(T, null, small_granularity);
|
||||
}
|
||||
|
||||
// This must be used with big arrays, which are not resizeable (can't be cleared)
|
||||
pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
|
||||
pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptime granularity: comptime_int) type {
|
||||
return struct {
|
||||
pointer: [*]T = @constCast((&[_]T{}).ptr),
|
||||
pointer: [*]T = undefined,
|
||||
length: u32 = 0,
|
||||
granularity: u32 = 0,
|
||||
committed: u32 = 0,
|
||||
|
||||
pub const Index = if (MaybeIndex) |I| getIndexForType(T, I) else enum(u32) {
|
||||
null = 0xffff_ffff,
|
||||
@ -193,38 +199,36 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
|
||||
return array.get_unchecked(i);
|
||||
}
|
||||
|
||||
pub fn get_index(array: *Array, item: *T) Index {
|
||||
pub fn get_index(array: *Array, item: *T) u32 {
|
||||
const many_item: [*]T = @ptrCast(item);
|
||||
const result = @intFromPtr(many_item) - @intFromPtr(array.pointer);
|
||||
const result: u32 = @intCast(@intFromPtr(many_item) - @intFromPtr(array.pointer));
|
||||
assert(result < pinned_array_max_size);
|
||||
return @enumFromInt(@divExact(result, @sizeOf(T)));
|
||||
return @divExact(result, @sizeOf(T));
|
||||
}
|
||||
|
||||
pub fn init(granularity: u32) !Array {
|
||||
assert(granularity & 0xfff == 0);
|
||||
const raw_ptr = try reserve(pinned_array_max_size);
|
||||
try commit(raw_ptr, granularity);
|
||||
return Array{
|
||||
.pointer = @alignCast(@ptrCast(raw_ptr)),
|
||||
.length = 0,
|
||||
.granularity = granularity,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_with_default_granularity() !Array {
|
||||
return try Array.init(pinned_array_default_granularity);
|
||||
pub fn get_typed_index(array: *Array, item: *T) Index {
|
||||
return @enumFromInt(array.get_index(item));
|
||||
}
|
||||
|
||||
pub fn ensure_capacity(array: *Array, additional: u32) void {
|
||||
if (array.committed == 0) {
|
||||
assert(array.length == 0);
|
||||
array.pointer = @alignCast(@ptrCast(reserve(pinned_array_max_size) catch unreachable));
|
||||
}
|
||||
|
||||
const length = array.length;
|
||||
const size = length * @sizeOf(T);
|
||||
const granularity_aligned_size = align_forward(size, array.granularity);
|
||||
const granularity_aligned_size = align_forward(size, granularity);
|
||||
const new_size = size + additional * @sizeOf(T);
|
||||
|
||||
if (granularity_aligned_size < new_size) {
|
||||
assert((length + additional) * @sizeOf(T) <= pinned_array_max_size);
|
||||
const new_granularity_aligned_size = align_forward(new_size, array.granularity);
|
||||
const ptr: [*]u8 = @ptrCast(array.pointer);
|
||||
commit(ptr + granularity_aligned_size, new_granularity_aligned_size - granularity_aligned_size) catch unreachable;
|
||||
const new_granularity_aligned_size = align_forward(new_size, granularity);
|
||||
const pointer: [*]u8 = @ptrCast(array.pointer);
|
||||
const commit_pointer = pointer + granularity_aligned_size;
|
||||
const commit_size = new_granularity_aligned_size - granularity_aligned_size;
|
||||
commit(commit_pointer, commit_size) catch unreachable;
|
||||
array.committed += @intCast(@divExact(commit_size, granularity));
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,31 +237,60 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
|
||||
return array.append_with_capacity(item);
|
||||
}
|
||||
|
||||
pub fn append_index(array: *Array, item: T) Index {
|
||||
pub fn append_index(array: *Array, item: T) u32 {
|
||||
return array.get_index(array.append(item));
|
||||
}
|
||||
|
||||
pub fn append_typed_index(array: *Array, item: T) Index {
|
||||
return array.get_typed_index(array.append(item));
|
||||
}
|
||||
|
||||
pub fn append_slice(array: *Array, items: []const T) void {
|
||||
array.ensure_capacity(@intCast(items.len));
|
||||
array.append_slice_with_capacity(items);
|
||||
}
|
||||
|
||||
pub fn append_with_capacity(array: *Array, item: T) *T {
|
||||
pub fn add_one_with_capacity(array: *Array) *T {
|
||||
const index = array.length;
|
||||
assert(index * @sizeOf(T) < pinned_array_max_size);
|
||||
array.length += 1;
|
||||
const ptr = &array.pointer[index];
|
||||
return ptr;
|
||||
}
|
||||
|
||||
pub fn add_many_with_capacity(array: *Array, count: u32) []T {
|
||||
const index = array.length;
|
||||
assert((index + count) * @sizeOf(T) < pinned_array_max_size);
|
||||
array.length += count;
|
||||
const ptr = array.pointer[index..][0..count];
|
||||
return ptr;
|
||||
}
|
||||
|
||||
pub fn add_one(array: *Array) *T{
|
||||
array.ensure_capacity(1);
|
||||
return array.add_one_with_capacity();
|
||||
}
|
||||
|
||||
pub fn add_slice(array: *Array, count: u32) []T {
|
||||
array.ensure_capacity(count);
|
||||
return array.add_many_with_capacity(count);
|
||||
}
|
||||
|
||||
pub fn append_with_capacity(array: *Array, item: T) *T {
|
||||
const ptr = array.add_one_with_capacity();
|
||||
ptr.* = item;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
pub fn append_slice_with_capacity(array: *Array, items: []const T) void {
|
||||
if (items.len > 0) {
|
||||
const index = array.length;
|
||||
const count: u32 = @intCast(items.len);
|
||||
assert((index + count - 1) * @sizeOf(T) < pinned_array_max_size);
|
||||
array.length += count;
|
||||
@memcpy(array.pointer[index..][0..count], items);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn insert(array: *@This(), index: u32, item: T) void {
|
||||
assert(index < array.length);
|
||||
@ -268,6 +301,18 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
|
||||
copy_backwards(T, dst, src);
|
||||
array.slice()[index] = item;
|
||||
}
|
||||
|
||||
pub fn in_range(array: *@This(), item: *T) bool {
|
||||
if (array.committed == 0) return false;
|
||||
if (@intFromPtr(item) < @intFromPtr(array.pointer)) return false;
|
||||
const top = @intFromPtr(array.pointer) + array.committed * granularity;
|
||||
if (@intFromPtr(item) >= top) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn clear(array: *@This()) void {
|
||||
array.length = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -318,9 +363,18 @@ pub fn getIndexForType(comptime T: type, comptime E: type) type {
|
||||
return Result;
|
||||
}
|
||||
|
||||
fn JointEnum(comptime enums: []const type, comptime backing_type: ?type) type {
|
||||
_ = backing_type; // autofix
|
||||
_ = enums; // autofix
|
||||
return @Type(.{
|
||||
.Enum = .{
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
pub const fnv_offset = 14695981039346656037;
|
||||
pub const fnv_prime = 1099511628211;
|
||||
pub fn my_hash(bytes: []const u8) u32 {
|
||||
const fnv_offset = 14695981039346656037;
|
||||
const fnv_prime = 1099511628211;
|
||||
var result: u64 = fnv_offset;
|
||||
|
||||
for (bytes) |byte| {
|
||||
@ -385,31 +439,19 @@ const pinned_hash_map_max_size = std.math.maxInt(u32) - pinned_hash_map_page_siz
|
||||
const pinned_hash_map_default_granularity = pinned_hash_map_page_size;
|
||||
|
||||
pub fn PinnedHashMap(comptime K: type, comptime V: type) type {
|
||||
return PinnedHashMapAdvanced(K, V, small_granularity);
|
||||
}
|
||||
|
||||
pub fn PinnedHashMapAdvanced(comptime K: type, comptime V: type, comptime granularity: comptime_int) type {
|
||||
return struct {
|
||||
key_pointer: [*]K,
|
||||
value_pointer: [*]V,
|
||||
length: u32,
|
||||
granularity: u32,
|
||||
committed: u32,
|
||||
key_pointer: [*]K = undefined,
|
||||
value_pointer: [*]V = undefined,
|
||||
length: u64 = 0,
|
||||
committed_key: u32 = 0,
|
||||
committed_value: u32 = 0,
|
||||
|
||||
const Map = @This();
|
||||
|
||||
pub fn init(granularity: u32) !Map {
|
||||
assert(granularity & 0xfff == 0);
|
||||
const key_raw_pointer = try reserve(pinned_hash_map_max_size);
|
||||
try commit(key_raw_pointer, granularity);
|
||||
const value_raw_pointer = try reserve(pinned_hash_map_max_size);
|
||||
try commit(value_raw_pointer, granularity);
|
||||
|
||||
return Map{
|
||||
.key_pointer = @alignCast(@ptrCast(key_raw_pointer)),
|
||||
.value_pointer = @alignCast(@ptrCast(value_raw_pointer)),
|
||||
.length = 0,
|
||||
.granularity = granularity,
|
||||
.committed = 1,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn get_pointer(map: *Map, key: K) ?*V {
|
||||
for (map.keys(), 0..) |k, i| {
|
||||
const is_equal = switch (@typeInfo(K)) {
|
||||
@ -437,55 +479,69 @@ pub fn PinnedHashMap(comptime K: type, comptime V: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put(map: *@This(), key: K, value: V) !void {
|
||||
pub fn put(map: *@This(), key: K, value: V) *V {
|
||||
if (map.get_pointer(key)) |value_pointer| {
|
||||
value_pointer.* = value;
|
||||
return value_pointer;
|
||||
} else {
|
||||
const len = map.length;
|
||||
map.ensure_capacity(len + 1);
|
||||
map.put_at_with_capacity(len, key, value);
|
||||
return map.put_at_with_capacity(len, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_no_clobber(map: *@This(), key: K, value: V) !void {
|
||||
pub fn put_no_clobber(map: *@This(), key: K, value: V) *V {
|
||||
assert(map.get_pointer(key) == null);
|
||||
const len = map.length;
|
||||
map.ensure_capacity(len + 1);
|
||||
map.put_at_with_capacity(len, key, value);
|
||||
return map.put_at_with_capacity(len, key, value);
|
||||
}
|
||||
|
||||
fn put_at_with_capacity(map: *@This(), index: u32, key: K, value: V) void {
|
||||
fn put_at_with_capacity(map: *@This(), index: u64, key: K, value: V) *V {
|
||||
map.length += 1;
|
||||
assert(index < map.length);
|
||||
map.key_pointer[index] = key;
|
||||
map.value_pointer[index] = value;
|
||||
return &map.value_pointer[index];
|
||||
}
|
||||
|
||||
fn ensure_capacity(map: *Map, additional: u64) void {
|
||||
if (map.committed_key == 0) {
|
||||
map.key_pointer = @alignCast(@ptrCast(reserve(pinned_hash_map_max_size) catch unreachable));
|
||||
map.value_pointer = @alignCast(@ptrCast(reserve(pinned_hash_map_max_size) catch unreachable));
|
||||
}
|
||||
|
||||
fn ensure_capacity(map: *Map, additional: u32) void {
|
||||
const length = map.length;
|
||||
assert((length + additional) * @sizeOf(K) <= pinned_array_max_size);
|
||||
|
||||
{
|
||||
const key_size = length * @sizeOf(K);
|
||||
const key_granularity_aligned_size = align_forward(key_size, map.granularity);
|
||||
const key_granularity_aligned_size = align_forward(key_size, granularity);
|
||||
const key_new_size = key_size + additional * @sizeOf(K);
|
||||
|
||||
if (key_granularity_aligned_size < key_new_size) {
|
||||
const new_key_granularity_aligned_size = align_forward(key_new_size, map.granularity);
|
||||
const new_key_granularity_aligned_size = align_forward(key_new_size, granularity);
|
||||
const key_pointer: [*]u8 = @ptrCast(map.key_pointer);
|
||||
commit(key_pointer + key_granularity_aligned_size, new_key_granularity_aligned_size - key_granularity_aligned_size) catch unreachable;
|
||||
const commit_pointer = key_pointer + key_granularity_aligned_size;
|
||||
const commit_size = new_key_granularity_aligned_size - key_granularity_aligned_size;
|
||||
commit(commit_pointer, commit_size) catch unreachable;
|
||||
map.committed_key += @intCast(@divExact(commit_size, granularity));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const value_size = length * @sizeOf(V);
|
||||
const value_granularity_aligned_size = align_forward(value_size, map.granularity);
|
||||
const value_granularity_aligned_size = align_forward(value_size, granularity);
|
||||
const value_new_size = value_size + additional * @sizeOf(K);
|
||||
|
||||
if (value_granularity_aligned_size < value_new_size) {
|
||||
const new_value_granularity_aligned_size = align_forward(value_new_size, map.granularity);
|
||||
const new_value_granularity_aligned_size = align_forward(value_new_size, granularity);
|
||||
const value_pointer: [*]u8 = @ptrCast(map.value_pointer);
|
||||
commit(value_pointer + value_granularity_aligned_size, new_value_granularity_aligned_size - value_granularity_aligned_size) catch unreachable;
|
||||
const commit_pointer = value_pointer + value_granularity_aligned_size;
|
||||
const commit_size = new_value_granularity_aligned_size - value_granularity_aligned_size;
|
||||
commit(commit_pointer, commit_size) catch unreachable;
|
||||
map.committed_value += @intCast(@divExact(commit_size, granularity));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -737,3 +793,51 @@ pub fn exit_with_error() noreturn {
|
||||
@breakpoint();
|
||||
std.posix.exit(1);
|
||||
}
|
||||
|
||||
pub fn read_file(arena: *Arena, directory: std.fs.Dir, file_relative_path: []const u8) []const u8 {
|
||||
const source_file = directory.openFile(file_relative_path, .{}) catch |err| {
|
||||
const stdout = std.io.getStdOut();
|
||||
stdout.writeAll("Can't find file '") catch {};
|
||||
stdout.writeAll(file_relative_path) catch {};
|
||||
// stdout.writeAll(" in directory ") catch {};
|
||||
// stdout.writeAll(file.package.directory.path) catch {};
|
||||
stdout.writeAll("' for error ") catch {};
|
||||
stdout.writeAll(@errorName(err)) catch {};
|
||||
@panic("Unrecoverable error");
|
||||
};
|
||||
|
||||
const file_size = source_file.getEndPos() catch unreachable;
|
||||
var file_buffer = arena.new_array(u8, file_size) catch unreachable;
|
||||
|
||||
const read_byte_count = source_file.readAll(file_buffer) catch unreachable;
|
||||
assert(read_byte_count == file_size);
|
||||
source_file.close();
|
||||
|
||||
//TODO: adjust file maximum size
|
||||
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));
|
||||
}
|
||||
|
||||
pub fn realpath(arena: *Arena, dir: std.fs.Dir, relative_path: []const u8) ![]const u8 {
|
||||
var buffer: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const stack_realpath = try dir.realpath(relative_path, &buffer);
|
||||
const heap_realpath = try arena.new_array(u8, stack_realpath.len);
|
||||
@memcpy(heap_realpath, stack_realpath);
|
||||
return heap_realpath;
|
||||
}
|
||||
|
||||
pub fn argument_copy_zero_terminated(arena: *Arena, args: []const []const u8) ![:null]?[*:0]u8 {
|
||||
var result = try arena.new_array(?[*:0]u8, args.len + 1);
|
||||
result[args.len] = null;
|
||||
|
||||
for (args, 0..) |argument, i| {
|
||||
result[i] = try arena.duplicate_bytes_zero_terminated(argument);
|
||||
}
|
||||
|
||||
return result[0..args.len :null];
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const linker = @import("linker.zig");
|
||||
|
||||
const library = @import("../library.zig");
|
||||
@ -11,7 +13,7 @@ const write = Compilation.write;
|
||||
pub fn link(context: *const Compilation.Context, options: linker.Options) !void {
|
||||
assert(options.backend == .lld);
|
||||
var argv = try PinnedArray([]const u8).init_with_default_granularity();
|
||||
const driver_program = switch (@import("builtin").os.tag) {
|
||||
const driver_program = switch (builtin.os.tag) {
|
||||
.windows => "lld-link",
|
||||
.linux => "ld.lld",
|
||||
.macos => "ld64.lld",
|
||||
@ -20,8 +22,8 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
_ = argv.append(driver_program);
|
||||
_ = argv.append("--error-limit=0");
|
||||
|
||||
switch (@import("builtin").cpu.arch) {
|
||||
.aarch64 => switch (@import("builtin").os.tag) {
|
||||
switch (builtin.cpu.arch) {
|
||||
.aarch64 => switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
_ = argv.append("-znow");
|
||||
_ = argv.append_slice(&.{ "-m", "aarch64linux" });
|
||||
@ -42,12 +44,12 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
}
|
||||
|
||||
const ci = @import("configuration").ci;
|
||||
switch (@import("builtin").os.tag) {
|
||||
switch (builtin.os.tag) {
|
||||
.macos => {
|
||||
_ = argv.append("-dynamic");
|
||||
argv.append_slice(&.{ "-platform_version", "macos", "13.4.1", "13.3" });
|
||||
_ = argv.append("-arch");
|
||||
_ = argv.append(switch (@import("builtin").cpu.arch) {
|
||||
_ = argv.append(switch (builtin.cpu.arch) {
|
||||
.aarch64 => "arm64",
|
||||
else => |t| @panic(@tagName(t)),
|
||||
});
|
||||
@ -98,7 +100,7 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
argv.append_slice(&.{ "-L", "/usr/lib64" });
|
||||
|
||||
_ = argv.append("-dynamic-linker");
|
||||
switch (@import("builtin").cpu.arch) {
|
||||
switch (builtin.cpu.arch) {
|
||||
.x86_64 => _ = argv.append("/lib64/ld-linux-x86-64.so.2"),
|
||||
.aarch64 => _ = argv.append("/lib/ld-linux-aarch64.so.1"),
|
||||
else => unreachable,
|
||||
@ -130,7 +132,7 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
var stdout_len: usize = 0;
|
||||
var stderr_ptr: [*]const u8 = undefined;
|
||||
var stderr_len: usize = 0;
|
||||
const result = switch (@import("builtin").os.tag) {
|
||||
const result = switch (builtin.os.tag) {
|
||||
.linux => NativityLLDLinkELF(argv_zero_terminated.ptr, argv_zero_terminated.len, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len),
|
||||
.macos => NativityLLDLinkMachO(argv_zero_terminated.ptr, argv_zero_terminated.len, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len),
|
||||
.windows => NativityLLDLinkCOFF(argv_zero_terminated.ptr, argv_zero_terminated.len, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len),
|
||||
|
@ -1,14 +1,15 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const Compilation = @import("Compilation.zig");
|
||||
pub const panic = Compilation.panic;
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const library = @import("library.zig");
|
||||
const byte_equal = library.byte_equal;
|
||||
|
||||
const configuration = @import("configuration");
|
||||
const editor = @import("editor.zig");
|
||||
const compiler = @import("compiler.zig");
|
||||
pub const panic = compiler.panic;
|
||||
|
||||
const env_detecting_libc_paths = "NATIVITY_IS_DETECTING_LIBC_PATHS";
|
||||
|
||||
@ -16,58 +17,11 @@ test {
|
||||
_ = library;
|
||||
}
|
||||
|
||||
fn todo() noreturn {
|
||||
@setCold(true);
|
||||
@panic("TODO");
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
if (configuration.editor) {
|
||||
editor.main();
|
||||
} else {
|
||||
var arg_iterator = std.process.ArgIterator.init();
|
||||
var buffer = library.BoundedArray([]const u8, 512){};
|
||||
while (arg_iterator.next()) |argument| {
|
||||
buffer.appendAssumeCapacity(argument);
|
||||
}
|
||||
const arguments = buffer.slice();
|
||||
const context = try Compilation.createContext();
|
||||
|
||||
if (arguments.len <= 1) {
|
||||
return error.InvalidInput;
|
||||
}
|
||||
|
||||
if (std.process.can_execv and std.posix.getenvZ(env_detecting_libc_paths) != null) {
|
||||
todo();
|
||||
}
|
||||
|
||||
const command = arguments[1];
|
||||
const command_arguments = arguments[2..];
|
||||
|
||||
if (byte_equal(command, "build")) {
|
||||
try Compilation.compileBuildExecutable(context, command_arguments);
|
||||
} else if (byte_equal(command, "clang") or byte_equal(command, "-cc1") or byte_equal(command, "-cc1as")) {
|
||||
const exit_code = try Compilation.clangMain(context.arena, arguments);
|
||||
std.process.exit(exit_code);
|
||||
} else if (byte_equal(command, "cc")) {
|
||||
try Compilation.compileCSourceFile(context, command_arguments, .c);
|
||||
} else if (byte_equal(command, "c++")) {
|
||||
try Compilation.compileCSourceFile(context, command_arguments, .cpp);
|
||||
} else if (byte_equal(command, "exe")) {
|
||||
try Compilation.buildExecutable(context, command_arguments, .{
|
||||
.is_test = false,
|
||||
});
|
||||
} else if (byte_equal(command, "lib")) {
|
||||
todo();
|
||||
} else if (byte_equal(command, "obj")) {
|
||||
todo();
|
||||
} else if (byte_equal(command, "test")) {
|
||||
try Compilation.buildExecutable(context, command_arguments, .{
|
||||
.is_test = true,
|
||||
});
|
||||
} else {
|
||||
todo();
|
||||
}
|
||||
compiler.main();
|
||||
}
|
||||
}
|
||||
|
||||
|
126
build.zig
126
build.zig
@ -6,7 +6,7 @@ const os = builtin.os.tag;
|
||||
|
||||
fn discover_brew_prefix(b: *std.Build, library_name: []const u8) ![]const u8 {
|
||||
assert(os == .macos);
|
||||
const result = try std.ChildProcess.run(.{
|
||||
const result = try std.process.Child.run(.{
|
||||
.allocator = b.allocator,
|
||||
.argv = &.{ "brew", "--prefix", library_name },
|
||||
});
|
||||
@ -26,24 +26,26 @@ pub fn build(b: *std.Build) !void {
|
||||
const print_stack_trace = b.option(bool, "print_stack_trace", "This option enables printing stack traces inside the compiler") orelse is_ci;
|
||||
const native_target = b.resolveTargetQuery(.{});
|
||||
const optimization = b.standardOptimizeOption(.{});
|
||||
const use_editor = b.option(bool, "editor", "Use the GUI editor to play around the programming language") orelse !is_ci;
|
||||
const enable_editor = false;
|
||||
const use_editor = b.option(bool, "editor", "Use the GUI editor to play around the programming language") orelse (!is_ci and enable_editor);
|
||||
const use_debug = b.option(bool, "use_debug", "This option enables the LLVM debug build in the development PC") orelse false;
|
||||
const sanitize = b.option(bool, "sanitize", "This option enables sanitizers for the compiler") orelse false;
|
||||
const sleep_on_thread_hot_loops = b.option(bool, "sleep", "This option enables sleep calls on hot threaded loops") orelse false;
|
||||
const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) {
|
||||
else => use_debug,
|
||||
.windows => true,
|
||||
// .macos => true,
|
||||
};
|
||||
const compiler_options = b.addOptions();
|
||||
compiler_options.addOption(bool, "print_stack_trace", print_stack_trace);
|
||||
compiler_options.addOption(bool, "ci", is_ci);
|
||||
compiler_options.addOption(bool, "editor", use_editor);
|
||||
const timers = b.option(bool, "timers", "This option enables to make and print timers") orelse !is_ci and switch (optimization) {
|
||||
.Debug => false,
|
||||
else => true,
|
||||
};
|
||||
|
||||
const fetcher = b.addExecutable(.{
|
||||
.name = "llvm_fetcher",
|
||||
.root_source_file = .{ .path = "build/fetcher.zig" },
|
||||
.root_source_file = b.path("build/fetcher.zig"),
|
||||
.target = native_target,
|
||||
.optimize = .Debug,
|
||||
.single_threaded = true,
|
||||
});
|
||||
|
||||
var target_query = b.standardTargetOptionsQueryOnly(switch (@import("builtin").os.tag) {
|
||||
@ -82,7 +84,7 @@ pub fn build(b: *std.Build) !void {
|
||||
|
||||
const compiler = b.addExecutable(.{
|
||||
.name = "nat",
|
||||
.root_source_file = .{ .path = "bootstrap/main.zig" },
|
||||
.root_source_file = b.path("bootstrap/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimization,
|
||||
});
|
||||
@ -93,7 +95,7 @@ pub fn build(b: *std.Build) !void {
|
||||
"src/llvm/clang_main.cpp",
|
||||
"src/llvm/clang_cc1.cpp",
|
||||
"src/llvm/clang_cc1as.cpp",
|
||||
"src/llvm/ar.cpp",
|
||||
// "src/llvm/ar.cpp",
|
||||
};
|
||||
|
||||
compiler.addCSourceFiles(.{
|
||||
@ -105,21 +107,24 @@ pub fn build(b: *std.Build) !void {
|
||||
"-D__STDC_FORMAT_MACROS",
|
||||
"-D__STDC_LIMIT_MACROS",
|
||||
"-D_GNU_SOURCE",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-fno-exceptions",
|
||||
"-fno-rtti",
|
||||
"-Werror=type-limits",
|
||||
"-fno-stack-protector",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-Wno-type-limits",
|
||||
"-Wno-missing-braces",
|
||||
"-Wno-comment",
|
||||
},
|
||||
});
|
||||
|
||||
compiler.root_module.addOptions("configuration", compiler_options);
|
||||
compiler.formatted_panics = print_stack_trace;
|
||||
compiler.root_module.unwind_tables = print_stack_trace or target.result.os.tag == .windows;
|
||||
compiler.root_module.omit_frame_pointer = false;
|
||||
compiler.root_module.error_tracing = print_stack_trace;
|
||||
compiler.want_lto = false;
|
||||
if (sanitize) {
|
||||
compiler.root_module.sanitize_thread = true;
|
||||
}
|
||||
|
||||
compiler.linkLibC();
|
||||
|
||||
@ -364,6 +369,8 @@ pub fn build(b: *std.Build) !void {
|
||||
"libclangTransformer.a",
|
||||
};
|
||||
|
||||
var include_paths = std.ArrayList([]const u8).init(b.allocator);
|
||||
|
||||
if (static or target.result.os.tag == .windows) {
|
||||
if (target.result.os.tag == .linux) compiler.linkage = .static;
|
||||
compiler.linkLibCpp();
|
||||
@ -408,8 +415,8 @@ pub fn build(b: *std.Build) !void {
|
||||
break :blk llvm_directory.items;
|
||||
} else {
|
||||
break :blk switch (use_debug) {
|
||||
true => "../llvm-17-static-debug",
|
||||
false => "../llvm-17-static-release",
|
||||
true => "../zig-bootstrap/out/x86_64-linux-musl-native",
|
||||
false => "../zig-bootstrap/out/x86_64-linux-musl-native",
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -422,30 +429,33 @@ pub fn build(b: *std.Build) !void {
|
||||
compiler.addObjectFile(std.Build.path(b, try std.mem.concat(b.allocator, u8, &.{ llvm_lib_dir, "/", llvm_library })));
|
||||
}
|
||||
} else {
|
||||
compiler.linkSystemLibrary("LLVM-17");
|
||||
compiler.linkSystemLibrary("LLVM");
|
||||
compiler.linkSystemLibrary("clang-cpp");
|
||||
compiler.linkSystemLibrary("lldCommon");
|
||||
compiler.linkSystemLibrary("lldCOFF");
|
||||
compiler.linkSystemLibrary("lldELF");
|
||||
compiler.linkSystemLibrary("lldMachO");
|
||||
compiler.linkSystemLibrary("lldWasm");
|
||||
compiler.linkSystemLibrary("unwind");
|
||||
compiler.linkSystemLibrary(if (is_ci) "z" else "zlib");
|
||||
// compiler.linkSystemLibrary("unwind");
|
||||
compiler.linkSystemLibrary(if (is_ci or builtin.os.tag == .macos) "z" else "zlib");
|
||||
compiler.linkSystemLibrary("zstd");
|
||||
|
||||
var llvm_prefix: []const u8 = "";
|
||||
switch (target.result.os.tag) {
|
||||
.linux => {
|
||||
if (third_party_ci) {
|
||||
compiler.addObjectFile(.{ .cwd_relative = "/lib/x86_64-linux-gnu/libstdc++.so.6" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/include" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/include/c++/11" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/include/x86_64-linux-gnu/c++/11" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/lib/llvm-17/include" });
|
||||
try include_paths.append("/usr/include");
|
||||
try include_paths.append("/usr/include" );
|
||||
try include_paths.append("/usr/include/x86_64-linux-gnu" );
|
||||
try include_paths.append("/usr/include/c++/11" );
|
||||
try include_paths.append("/usr/include/x86_64-linux-gnu/c++/11" );
|
||||
try include_paths.append("/usr/lib/llvm-18/include" );
|
||||
llvm_prefix = "/usr/lib/llvm-18";
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/lib/x86_64-linux-gnu" });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib/llvm-17/lib" });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib/llvm-18/lib" });
|
||||
} else {
|
||||
const result = try std.ChildProcess.run(.{
|
||||
const result = try std.process.Child.run(.{
|
||||
.allocator = b.allocator,
|
||||
.argv = &.{
|
||||
"c++", "--version",
|
||||
@ -461,11 +471,15 @@ pub fn build(b: *std.Build) !void {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
var tokenizer = std.mem.tokenize(u8, result.stdout, " ");
|
||||
var tokenizer = std.mem.tokenizeScalar(u8, result.stdout, ' ');
|
||||
const cxx_version = while (tokenizer.next()) |chunk| {
|
||||
if (std.ascii.isDigit(chunk[0])) {
|
||||
if (std.SemanticVersion.parse(chunk)) |sema_version| {
|
||||
break try std.fmt.allocPrint(b.allocator, "{}.{}.{}", .{sema_version.major, sema_version.minor, sema_version.patch});
|
||||
break switch (builtin.cpu.arch) {
|
||||
.x86_64 => try std.fmt.allocPrint(b.allocator, "{}.{}.{}", .{sema_version.major, sema_version.minor, sema_version.patch}),
|
||||
.aarch64 => try std.fmt.allocPrint(b.allocator, "{}", .{sema_version.major}),
|
||||
else => @compileError("Architecture not supported"),
|
||||
};
|
||||
} else |err| err catch {};
|
||||
}
|
||||
} else {
|
||||
@ -473,23 +487,30 @@ pub fn build(b: *std.Build) !void {
|
||||
};
|
||||
|
||||
const cxx_include_base = try std.mem.concat(b.allocator, u8, &.{ "/usr/include/c++/", cxx_version });
|
||||
const cxx_include_arch = try std.mem.concat(b.allocator, u8, &.{ cxx_include_base, "/" ++ @tagName(@import("builtin").cpu.arch) ++ "-pc-linux-gnu" });
|
||||
const cxx_include_arch = try std.mem.concat(b.allocator, u8, &.{ cxx_include_base, "/" ++ @tagName(builtin.cpu.arch) ++ switch (builtin.cpu.arch) {
|
||||
.x86_64 => "-pc-linux-gnu",
|
||||
.aarch64 => "-redhat-linux",
|
||||
else => @compileError("Architecture not supported"),
|
||||
}
|
||||
});
|
||||
compiler.addObjectFile(.{ .cwd_relative = "/usr/lib64/libstdc++.so.6" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/lib64/llvm17/include/" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/include" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = cxx_include_base });
|
||||
compiler.addIncludePath(.{ .cwd_relative = cxx_include_arch });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64/llvm17/lib" });
|
||||
llvm_prefix = if (use_debug) "../../local/llvm18-debug/" else "../../local/llvm18-release";
|
||||
try include_paths.append(try std.mem.concat(b.allocator, u8, &.{llvm_prefix, "/include"}));
|
||||
try include_paths.append("/usr/include");
|
||||
try include_paths.append(cxx_include_base);
|
||||
try include_paths.append(cxx_include_arch);
|
||||
compiler.addLibraryPath(.{ .cwd_relative = if (use_debug) "../../local/llvm18-debug/lib" else "../../local/llvm18-release/lib" });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64" });
|
||||
}
|
||||
},
|
||||
.macos => {
|
||||
compiler.linkLibCpp();
|
||||
|
||||
if (discover_brew_prefix(b, "llvm@17")) |llvm_prefix| {
|
||||
if (discover_brew_prefix(b, "llvm@18")) |prefix| {
|
||||
llvm_prefix = prefix;
|
||||
const llvm_include_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/include" });
|
||||
const llvm_lib_path = try std.mem.concat(b.allocator, u8, &.{ llvm_prefix, "/lib" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = llvm_include_path });
|
||||
try include_paths.append(llvm_include_path);
|
||||
compiler.addLibraryPath(.{ .cwd_relative = llvm_lib_path });
|
||||
} else |err| {
|
||||
return err;
|
||||
@ -513,6 +534,12 @@ pub fn build(b: *std.Build) !void {
|
||||
else => |tag| @panic(@tagName(tag)),
|
||||
}
|
||||
|
||||
for (include_paths.items) |include_path| {
|
||||
compiler.addIncludePath(.{ .cwd_relative = include_path });
|
||||
}
|
||||
|
||||
try include_paths.append(try std.mem.concat(b.allocator, u8, &.{llvm_prefix, "/lib/clang/18/include"}));
|
||||
|
||||
if (use_editor) {
|
||||
compiler.linkSystemLibrary("glfw");
|
||||
compiler.linkSystemLibrary("GL");
|
||||
@ -536,6 +563,15 @@ pub fn build(b: *std.Build) !void {
|
||||
}
|
||||
}
|
||||
|
||||
const compiler_options = b.addOptions();
|
||||
compiler_options.addOption(bool, "print_stack_trace", print_stack_trace);
|
||||
compiler_options.addOption(bool, "ci", is_ci);
|
||||
compiler_options.addOption(bool, "editor", use_editor);
|
||||
compiler_options.addOption(bool, "sleep_on_thread_hot_loops", sleep_on_thread_hot_loops);
|
||||
compiler_options.addOption([]const []const u8, "include_paths", include_paths.items);
|
||||
compiler_options.addOption(bool, "timers", timers);
|
||||
compiler.root_module.addOptions("configuration", compiler_options);
|
||||
|
||||
if (target.result.os.tag == .windows) {
|
||||
compiler.linkSystemLibrary("ole32");
|
||||
compiler.linkSystemLibrary("version");
|
||||
@ -557,6 +593,7 @@ pub fn build(b: *std.Build) !void {
|
||||
const debug_command = switch (os) {
|
||||
.linux => blk: {
|
||||
const result = b.addSystemCommand(&.{"gf2"});
|
||||
result.addArgs(&.{ "-ex", "set debuginfod enabled off" });
|
||||
result.addArgs(&.{ "-ex", "set disassembly-flavor intel" });
|
||||
result.addArg("-ex=r");
|
||||
result.addArgs(&.{ "-ex", "up" });
|
||||
@ -581,10 +618,9 @@ pub fn build(b: *std.Build) !void {
|
||||
|
||||
const test_runner = b.addExecutable(.{
|
||||
.name = "test_runner",
|
||||
.root_source_file = .{ .path = "build/test_runner.zig" },
|
||||
.root_source_file = b.path("build/test_runner.zig"),
|
||||
.target = native_target,
|
||||
.optimize = optimization,
|
||||
.single_threaded = true,
|
||||
});
|
||||
b.default_step.dependOn(&test_runner.step);
|
||||
|
||||
@ -593,10 +629,22 @@ pub fn build(b: *std.Build) !void {
|
||||
b.installArtifact(test_runner);
|
||||
test_command.step.dependOn(b.getInstallStep());
|
||||
|
||||
const new_test = b.addExecutable(.{
|
||||
.name = "new_test",
|
||||
.target = native_target,
|
||||
.root_source_file = b.path("build/new_test.zig"),
|
||||
.optimize = .ReleaseSmall,
|
||||
});
|
||||
b.default_step.dependOn(&new_test.step);
|
||||
|
||||
const new_test_command = b.addRunArtifact(new_test);
|
||||
new_test_command.step.dependOn(b.getInstallStep());
|
||||
|
||||
if (b.args) |args| {
|
||||
run_command.addArgs(args);
|
||||
debug_command.addArgs(args);
|
||||
test_command.addArgs(args);
|
||||
new_test_command.addArgs(args);
|
||||
}
|
||||
|
||||
const run_step = b.step("run", "Test the Nativity compiler");
|
||||
@ -605,7 +653,11 @@ pub fn build(b: *std.Build) !void {
|
||||
debug_step.dependOn(&debug_command.step);
|
||||
const test_step = b.step("test", "Test the Nativity compiler");
|
||||
test_step.dependOn(&test_command.step);
|
||||
const new_test_step = b.step("new_test", "Script to make a new test");
|
||||
new_test_step.dependOn(&new_test_command.step);
|
||||
|
||||
const test_all = b.step("test_all", "Test all");
|
||||
test_all.dependOn(&test_command.step);
|
||||
}
|
||||
|
||||
|
||||
|
17
build/new_test.zig
Normal file
17
build/new_test.zig
Normal file
@ -0,0 +1,17 @@
|
||||
const std = @import("std");
|
||||
pub fn main () !void {
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
const allocator = arena.allocator();
|
||||
const args = try std.process.argsAlloc(allocator);
|
||||
if (args.len < 2) return;
|
||||
|
||||
const test_name = args[1];
|
||||
try std.fs.cwd().makeDir(try std.mem.concat(allocator, u8, &.{"retest/standalone/", test_name}));
|
||||
try std.fs.cwd().writeFile(.{
|
||||
.sub_path = try std.mem.concat(allocator, u8, &.{"retest/standalone/", test_name, "/main.nat"}),
|
||||
.data =
|
||||
\\fn[cc(.c)] main[export]() s32 {
|
||||
\\ return 0;
|
||||
\\}
|
||||
});
|
||||
}
|
@ -31,37 +31,43 @@ fn collectDirectoryDirEntries(allocator: Allocator, path: []const u8) ![]const [
|
||||
|
||||
const bootstrap_relative_path = "zig-out/bin/nat";
|
||||
|
||||
fn runStandalone(allocator: Allocator, args: struct {
|
||||
directory_path: []const u8,
|
||||
group_name: []const u8,
|
||||
self_hosted: bool,
|
||||
is_test: bool,
|
||||
const Run = struct{
|
||||
compilation_run: usize = 0,
|
||||
compilation_failure: usize = 0,
|
||||
test_run: usize = 0,
|
||||
test_failure: usize = 0,
|
||||
|
||||
fn add(run: *Run, other: Run) void {
|
||||
run.compilation_run += other.compilation_run;
|
||||
run.compilation_failure += other.compilation_failure;
|
||||
run.test_run += other.test_run;
|
||||
run.test_failure += other.test_failure;
|
||||
}
|
||||
};
|
||||
|
||||
fn compiler_run(allocator: Allocator, args: struct{
|
||||
test_name: []const u8,
|
||||
repetitions: usize,
|
||||
extra_arguments: []const []const u8,
|
||||
source_file_path: []const u8,
|
||||
compiler_path: []const u8,
|
||||
}) !void {
|
||||
const test_names = try collectDirectoryDirEntries(allocator, args.directory_path);
|
||||
is_test: bool,
|
||||
self_hosted: bool,
|
||||
}) !Run {
|
||||
std.debug.print("{s} [repetitions={}] {s}", .{args.test_name, args.repetitions, if (args.repetitions > 1) "\n\n" else ""});
|
||||
var run = Run{};
|
||||
|
||||
const total_compilation_count = test_names.len;
|
||||
var ran_compilation_count: usize = 0;
|
||||
var failed_compilation_count: usize = 0;
|
||||
|
||||
var ran_test_count: usize = 0;
|
||||
var failed_test_count: usize = 0;
|
||||
const total_test_count = test_names.len;
|
||||
|
||||
std.debug.print("\n[{s} START]\n\n", .{args.group_name});
|
||||
|
||||
for (test_names) |test_name| {
|
||||
std.debug.print("{s}... ", .{test_name});
|
||||
const source_file_path = try std.mem.concat(allocator, u8, &.{ args.directory_path, "/", test_name, "/main.nat" });
|
||||
const argv: []const []const u8 = &.{ args.compiler_path, if (args.is_test) "test" else "exe", "-main_source_file", source_file_path };
|
||||
for (0..args.repetitions) |_| {
|
||||
const base_argv: []const []const u8 = &.{ args.compiler_path, if (args.is_test) "test" else "exe", "-main_source_file", args.source_file_path };
|
||||
const argv = try std.mem.concat(allocator, []const u8, &.{base_argv, args.extra_arguments});
|
||||
// if (std.mem.eql(u8, args.compiler_path, "nat/compiler_lightly_optimize_for_speed")) @breakpoint();
|
||||
const compile_run = try std.ChildProcess.run(.{
|
||||
const compile_run = try std.process.Child.run(.{
|
||||
.allocator = allocator,
|
||||
// TODO: delete -main_source_file?
|
||||
.argv = argv,
|
||||
.max_output_bytes = std.math.maxInt(u64),
|
||||
});
|
||||
ran_compilation_count += 1;
|
||||
run.compilation_run += 1;
|
||||
|
||||
const compilation_result: TestError!bool = switch (compile_run.term) {
|
||||
.Exited => |exit_code| if (exit_code == 0) true else error.abnormal_exit_code,
|
||||
@ -71,7 +77,7 @@ fn runStandalone(allocator: Allocator, args: struct {
|
||||
};
|
||||
|
||||
const compilation_success = compilation_result catch b: {
|
||||
failed_compilation_count += 1;
|
||||
run.compilation_failure += 1;
|
||||
break :b false;
|
||||
};
|
||||
|
||||
@ -84,13 +90,13 @@ fn runStandalone(allocator: Allocator, args: struct {
|
||||
}
|
||||
|
||||
if (compilation_success and !args.self_hosted) {
|
||||
const test_path = try std.mem.concat(allocator, u8, &.{ "nat/", test_name });
|
||||
const test_run = try std.ChildProcess.run(.{
|
||||
const test_path = try std.mem.concat(allocator, u8, &.{ "nat/", args.test_name });
|
||||
const test_run = try std.process.Child.run(.{
|
||||
.allocator = allocator,
|
||||
.argv = &.{test_path},
|
||||
.max_output_bytes = std.math.maxInt(u64),
|
||||
});
|
||||
ran_test_count += 1;
|
||||
run.test_run += 1;
|
||||
const test_result: TestError!bool = switch (test_run.term) {
|
||||
.Exited => |exit_code| if (exit_code == 0) true else error.abnormal_exit_code,
|
||||
.Signal => error.signaled,
|
||||
@ -99,9 +105,10 @@ fn runStandalone(allocator: Allocator, args: struct {
|
||||
};
|
||||
|
||||
const test_success = test_result catch b: {
|
||||
failed_test_count += 1;
|
||||
break :b false;
|
||||
};
|
||||
run.test_failure += @intFromBool(!test_success);
|
||||
|
||||
std.debug.print("[TEST {s}]\n", .{if (test_success) "\x1b[32mOK\x1b[0m" else "\x1b[31mFAILED\x1b[0m"});
|
||||
if (test_run.stdout.len > 0) {
|
||||
std.debug.print("STDOUT:\n\n{s}\n\n", .{test_run.stdout});
|
||||
@ -114,14 +121,55 @@ fn runStandalone(allocator: Allocator, args: struct {
|
||||
}
|
||||
}
|
||||
|
||||
std.debug.print("\n{s} COMPILATIONS: {}. FAILED: {}\n", .{ args.group_name, total_compilation_count, failed_compilation_count });
|
||||
std.debug.print("{s} TESTS: {}. RAN: {}. FAILED: {}\n", .{ args.group_name, total_test_count, ran_test_count, failed_test_count });
|
||||
return run;
|
||||
}
|
||||
|
||||
if (failed_compilation_count > 0 or failed_test_count > 0) {
|
||||
fn group_start(group: []const u8, test_count: usize) void {
|
||||
std.debug.print("\n[{s} START ({} tests queued)]\n\n", .{group, test_count});
|
||||
}
|
||||
|
||||
fn group_end(group: []const u8, test_count: usize, run: Run) !void {
|
||||
std.debug.print("\n{s} COMPILATIONS: {}. FAILED: {}\n", .{ group, test_count, run.compilation_failure });
|
||||
std.debug.print("{s} TESTS: {}. RAN: {}. FAILED: {}\n", .{ group, test_count, run.test_run, run.test_failure });
|
||||
std.debug.print("\n[{s} END]\n\n", .{group});
|
||||
|
||||
if (run.compilation_failure > 0 or run.test_failure > 0) {
|
||||
return error.fail;
|
||||
}
|
||||
}
|
||||
|
||||
fn runStandalone(allocator: Allocator, args: struct {
|
||||
directory_path: []const u8,
|
||||
group_name: []const u8,
|
||||
self_hosted: bool,
|
||||
is_test: bool,
|
||||
compiler_path: []const u8,
|
||||
repetitions: usize,
|
||||
}) !void {
|
||||
const test_names = try collectDirectoryDirEntries(allocator, args.directory_path);
|
||||
std.debug.assert(args.repetitions > 0);
|
||||
|
||||
var total_run = Run{};
|
||||
|
||||
group_start(args.group_name, test_names.len * args.repetitions);
|
||||
|
||||
for (test_names) |test_name| {
|
||||
const source_file_path = try std.mem.concat(allocator, u8, &.{ args.directory_path, "/", test_name, "/main.nat" });
|
||||
const run = try compiler_run(allocator, .{
|
||||
.compiler_path = args.compiler_path,
|
||||
.source_file_path = source_file_path,
|
||||
.test_name = test_name,
|
||||
.repetitions = args.repetitions,
|
||||
.extra_arguments = &.{},
|
||||
.is_test = args.is_test,
|
||||
.self_hosted = args.self_hosted,
|
||||
});
|
||||
total_run.add(run);
|
||||
}
|
||||
|
||||
try group_end(args.group_name, test_names.len * args.repetitions, total_run);
|
||||
}
|
||||
|
||||
fn runBuildTests(allocator: Allocator, args: struct {
|
||||
self_hosted: bool,
|
||||
compiler_path: []const u8,
|
||||
@ -579,34 +627,67 @@ fn run_test_suite(allocator: Allocator, args: struct {
|
||||
return errors;
|
||||
}
|
||||
|
||||
fn c_abi_tests(allocator: Allocator) !void {
|
||||
const test_count = 1;
|
||||
const group = "C ABI";
|
||||
group_start(group, test_count);
|
||||
const run = try compiler_run(allocator, .{
|
||||
.test_name = "c_abi",
|
||||
.repetitions = 1,
|
||||
.extra_arguments = &.{
|
||||
"-c_source_files_start",
|
||||
"test/build/c-abi/c.c",
|
||||
"-c_source_files_end",
|
||||
},
|
||||
.source_file_path = "retest/c_abi/main.nat",
|
||||
.compiler_path = bootstrap_relative_path,
|
||||
.is_test = false,
|
||||
.self_hosted = false,
|
||||
});
|
||||
try group_end(group, test_count, run);
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||
const allocator = arena.allocator();
|
||||
|
||||
var errors = run_test_suite(allocator, .{
|
||||
.self_hosted = false,
|
||||
.compiler_path = bootstrap_relative_path,
|
||||
});
|
||||
|
||||
if (!errors) {
|
||||
inline for (@typeInfo(Optimization).Enum.fields) |opt| {
|
||||
const optimization = @field(Optimization, opt.name);
|
||||
if (compile_self_hosted(allocator, .{
|
||||
try runStandalone(allocator, .{
|
||||
.is_test = false,
|
||||
.optimization = optimization,
|
||||
})) |compiler_path| {
|
||||
errors = errors or run_test_suite(allocator, .{
|
||||
.self_hosted = true,
|
||||
.compiler_path = compiler_path,
|
||||
.compiler_path = bootstrap_relative_path,
|
||||
.self_hosted = false,
|
||||
.group_name = "STANDALONE",
|
||||
.directory_path = "retest/standalone",
|
||||
.repetitions = 1,
|
||||
});
|
||||
} else |err| {
|
||||
err catch {};
|
||||
errors = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors) {
|
||||
return error.fail;
|
||||
}
|
||||
try c_abi_tests(allocator);
|
||||
|
||||
// var errors = run_test_suite(allocator, .{
|
||||
// .self_hosted = false,
|
||||
// .compiler_path = bootstrap_relative_path,
|
||||
// });
|
||||
//
|
||||
// if (!errors) {
|
||||
// inline for (@typeInfo(Optimization).Enum.fields) |opt| {
|
||||
// const optimization = @field(Optimization, opt.name);
|
||||
// if (compile_self_hosted(allocator, .{
|
||||
// .is_test = false,
|
||||
// .optimization = optimization,
|
||||
// })) |compiler_path| {
|
||||
// errors = errors or run_test_suite(allocator, .{
|
||||
// .self_hosted = true,
|
||||
// .compiler_path = compiler_path,
|
||||
// });
|
||||
// } else |err| {
|
||||
// err catch {};
|
||||
// errors = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (errors) {
|
||||
// return error.fail;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,12 +4,17 @@ set -ex
|
||||
# Install LLVM and system dependencies
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x llvm.sh
|
||||
sudo ./llvm.sh 17 all
|
||||
sudo apt install liblld-17-dev libclang-17-dev liblld-17 ninja-build cmake -y
|
||||
MY_LLVM_VERSION=18
|
||||
sudo ./llvm.sh $MY_LLVM_VERSION all
|
||||
sudo apt install liblld-$MY_LLVM_VERSION-dev libclang-$MY_LLVM_VERSION-dev liblld-$MY_LLVM_VERSION ninja-build cmake -y
|
||||
|
||||
# Install Zig
|
||||
source ci/download_zig.sh
|
||||
download_zig master x86_64-linux
|
||||
|
||||
# Build and test
|
||||
zig build test -Dthird_party_ci=true
|
||||
|
||||
zig build test -Dthird_party_ci=true -Doptimize=Debug
|
||||
zig build test -Dthird_party_ci=true -Doptimize=ReleaseSafe
|
||||
zig build test -Dthird_party_ci=true -Doptimize=ReleaseSmall
|
||||
zig build test -Dthird_party_ci=true -Doptimize=ReleaseFast
|
||||
|
@ -3,11 +3,14 @@ set -ex
|
||||
|
||||
# Install LLVM and system dependencies
|
||||
brew update
|
||||
brew install llvm@17 ninja
|
||||
brew install llvm@18 ninja
|
||||
|
||||
# Install Zig
|
||||
source ci/download_zig.sh
|
||||
download_zig master aarch64-macos
|
||||
|
||||
# Build and test
|
||||
zig build test -Dthird_party_ci=true
|
||||
zig build test -Dthird_party_ci=true -Doptimize=Debug
|
||||
zig build test -Dthird_party_ci=true -Doptimize=ReleaseSafe
|
||||
zig build test -Dthird_party_ci=true -Doptimize=ReleaseSmall
|
||||
zig build test -Dthird_party_ci=true -Doptimize=ReleaseFast
|
||||
|
4
newlib/std/std.nat
Normal file
4
newlib/std/std.nat
Normal file
@ -0,0 +1,4 @@
|
||||
fn align_forward(n: u64, alignment: u64) u64 {
|
||||
const mask = alignment - 1;
|
||||
return (value + mask) & ~mask;
|
||||
}
|
481
retest/c_abi/main.nat
Normal file
481
retest/c_abi/main.nat
Normal file
@ -0,0 +1,481 @@
|
||||
struct Struct_u64_u64 {
|
||||
a: u64,
|
||||
b: u64,
|
||||
}
|
||||
|
||||
struct BigStruct {
|
||||
a: u64,
|
||||
b: u64,
|
||||
c: u64,
|
||||
d: u64,
|
||||
e: u8,
|
||||
}
|
||||
|
||||
bitfield(u8) SmallPackedStruct {
|
||||
a: u2,
|
||||
b: u2,
|
||||
c: u2,
|
||||
d: u2,
|
||||
}
|
||||
|
||||
struct SmallStructInts{
|
||||
a: u8,
|
||||
b: u8,
|
||||
c: u8,
|
||||
d: u8,
|
||||
}
|
||||
|
||||
struct SplitStructInt {
|
||||
a: u64,
|
||||
b: u8,
|
||||
c: u32,
|
||||
}
|
||||
|
||||
struct MedStructInts {
|
||||
x: s32,
|
||||
y: s32,
|
||||
z: s32,
|
||||
}
|
||||
|
||||
struct Rect {
|
||||
left: u32,
|
||||
right: u32,
|
||||
top: u32,
|
||||
bottom: u32,
|
||||
}
|
||||
|
||||
struct StructWithArray {
|
||||
a: s32,
|
||||
padding: [4]u8,
|
||||
b: s64,
|
||||
}
|
||||
|
||||
struct ByRef {
|
||||
val: s32,
|
||||
arr: [15]s32,
|
||||
}
|
||||
|
||||
struct ByValOrigin {
|
||||
x: u64,
|
||||
y: u64,
|
||||
z: u64,
|
||||
}
|
||||
|
||||
struct ByValSize{
|
||||
width: u64,
|
||||
height: u64,
|
||||
depth: u64,
|
||||
}
|
||||
|
||||
struct ByVal {
|
||||
origin: ByValOrigin,
|
||||
size: ByValSize,
|
||||
}
|
||||
|
||||
fn[cc(.c)] run_c_tests[extern]() void;
|
||||
|
||||
fn[cc(.c)] c_u8[extern](x: u8) void;
|
||||
fn[cc(.c)] c_u16[extern](x: u16) void;
|
||||
fn[cc(.c)] c_u32[extern](x: u32) void;
|
||||
fn[cc(.c)] c_u64[extern](x: u64) void;
|
||||
|
||||
fn[cc(.c)] c_s8[extern](x: s8) void;
|
||||
fn[cc(.c)] c_s16[extern](x: s16) void;
|
||||
fn[cc(.c)] c_s32[extern](x: s32) void;
|
||||
fn[cc(.c)] c_s64[extern](x: s64) void;
|
||||
|
||||
fn[cc(.c)] c_bool[extern](x: u8) void;
|
||||
|
||||
fn[cc(.c)] c_five_integers[extern](a: s32, b: s32, c: s32, d: s32, e: s32) void;
|
||||
fn[cc(.c)] c_ret_struct_u64_u64[extern]() Struct_u64_u64;
|
||||
|
||||
fn[cc(.c)] c_struct_u64_u64_0 [extern] (a: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_1 [extern] (a: u64, b: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_2 [extern] (a: u64, b: u64, c: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_3 [extern] (a: u64, b: u64, c: u64, d: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_4 [extern] (a: u64, b: u64, c: u64, d: u64, e: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_5 [extern] (a: u64, b: u64, c: u64, d: u64, e: u64, f: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_6 [extern] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_7 [extern] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: Struct_u64_u64) void;
|
||||
fn[cc(.c)] c_struct_u64_u64_8 [extern] (a: u64, b: u64, c: u64, d: u64, e: u64, f: u64, g: u64, h: u64, i: Struct_u64_u64) void;
|
||||
|
||||
fn [cc(.c)] c_big_struct[extern](x: BigStruct) void;
|
||||
fn [cc(.c)] c_small_struct_ints[extern](x: SmallStructInts) void;
|
||||
fn [cc(.c)] c_ret_small_struct_ints[extern]() SmallStructInts;
|
||||
fn [cc(.c)] c_med_struct_ints[extern](x: MedStructInts) void;
|
||||
fn [cc(.c)] c_ret_med_struct_ints[extern]() MedStructInts;
|
||||
fn [cc(.c)] c_small_packed_struct[extern](x: SmallPackedStruct) void;
|
||||
fn [cc(.c)] c_ret_small_packed_struct[extern]() SmallPackedStruct;
|
||||
fn [cc(.c)] c_split_struct_ints[extern](x: SplitStructInt) void;
|
||||
fn [cc(.c)] c_big_struct_both[extern](x: BigStruct) BigStruct;
|
||||
fn [cc(.c)] c_multiple_struct_ints[extern](a: Rect, b: Rect) void;
|
||||
|
||||
fn [cc(.c)] c_ret_bool[extern]() u8;
|
||||
|
||||
fn [cc(.c)] c_ret_u8[extern]() u8;
|
||||
fn [cc(.c)] c_ret_u16[extern]() u16;
|
||||
fn [cc(.c)] c_ret_u32[extern]() u32;
|
||||
fn [cc(.c)] c_ret_u64[extern]() u64;
|
||||
|
||||
fn [cc(.c)] c_ret_s8[extern]() s8;
|
||||
fn [cc(.c)] c_ret_s16[extern]() s16;
|
||||
fn [cc(.c)] c_ret_s32[extern]() s32;
|
||||
fn [cc(.c)] c_ret_s64[extern]() s64;
|
||||
|
||||
fn [cc(.c)] c_struct_with_array[extern](x: StructWithArray) void;
|
||||
fn [cc(.c)] c_ret_struct_with_array[extern]() StructWithArray;
|
||||
|
||||
fn [cc(.c)] c_modify_by_ref_param[extern](x: ByRef) ByRef;
|
||||
fn [cc(.c)] c_func_ptr_byval[extern] (a: u64, b: u64, c: ByVal, d: u64, e: u64, f: u64) void;
|
||||
|
||||
fn[cc(.c)] main[export]() s32
|
||||
{
|
||||
run_c_tests();
|
||||
c_u8(0xff);
|
||||
c_u16(0xfffe);
|
||||
c_u32(0xfffffffd);
|
||||
c_u64(0xfffffffffffffffc);
|
||||
|
||||
//if (has_i128) {
|
||||
// c_struct_u128({ .value = 0xfffffffffffffffc, });
|
||||
//}
|
||||
|
||||
c_s8(-1);
|
||||
c_s16(-2);
|
||||
c_s32(-3);
|
||||
c_s64(-4);
|
||||
|
||||
//if (has_i128) {
|
||||
// c_struct_i128({ .value = -6, });
|
||||
//}
|
||||
|
||||
c_bool(1);
|
||||
|
||||
c_five_integers(12, 34, 56, 78, 90);
|
||||
|
||||
>s = c_ret_struct_u64_u64();
|
||||
#require(s.a == 21);
|
||||
#require(s.b == 22);
|
||||
c_struct_u64_u64_0({ .a = 23, .b = 24, });
|
||||
c_struct_u64_u64_1(0, { .a = 25, .b = 26, });
|
||||
c_struct_u64_u64_2(0, 1, { .a = 27, .b = 28, });
|
||||
c_struct_u64_u64_3(0, 1, 2, { .a = 29, .b = 30, });
|
||||
c_struct_u64_u64_4(0, 1, 2, 3, { .a = 31, .b = 32, });
|
||||
c_struct_u64_u64_5(0, 1, 2, 3, 4, { .a = 33, .b = 34, });
|
||||
c_struct_u64_u64_6(0, 1, 2, 3, 4, 5, { .a = 35, .b = 36, });
|
||||
c_struct_u64_u64_7(0, 1, 2, 3, 4, 5, 6, { .a = 37, .b = 38, });
|
||||
c_struct_u64_u64_8(0, 1, 2, 3, 4, 5, 6, 7, { .a = 39, .b = 40, });
|
||||
|
||||
>big_struct: BigStruct = {
|
||||
.a = 1,
|
||||
.b = 2,
|
||||
.c = 3,
|
||||
.d = 4,
|
||||
.e = 5,
|
||||
};
|
||||
c_big_struct(big_struct);
|
||||
|
||||
>small: SmallStructInts = {
|
||||
.a = 1,
|
||||
.b = 2,
|
||||
.c = 3,
|
||||
.d = 4,
|
||||
};
|
||||
c_small_struct_ints(small);
|
||||
>small2 = c_ret_small_struct_ints();
|
||||
#require(small2.a == 1);
|
||||
#require(small2.b == 2);
|
||||
#require(small2.c == 3);
|
||||
#require(small2.d == 4);
|
||||
|
||||
>med: MedStructInts = {
|
||||
.x = 1,
|
||||
.y = 2,
|
||||
.z = 3,
|
||||
};
|
||||
c_med_struct_ints(med);
|
||||
>med2 = c_ret_med_struct_ints();
|
||||
#require(med2.x == 1);
|
||||
#require(med2.y == 2);
|
||||
#require(med2.z == 3);
|
||||
|
||||
>p: SmallPackedStruct = { .a = 0, .b = 1, .c = 2, .d = 3, };
|
||||
c_small_packed_struct(p);
|
||||
>p2 = c_ret_small_packed_struct();
|
||||
#require(p2.a == 0);
|
||||
#require(p2.b == 1);
|
||||
#require(p2.c == 2);
|
||||
#require(p2.d == 3);
|
||||
|
||||
>split: SplitStructInt = {
|
||||
.a = 1234,
|
||||
.b = 100,
|
||||
.c = 1337,
|
||||
};
|
||||
c_split_struct_ints(split);
|
||||
|
||||
> big: BigStruct = {
|
||||
.a = 1,
|
||||
.b = 2,
|
||||
.c = 3,
|
||||
.d = 4,
|
||||
.e = 5,
|
||||
};
|
||||
>big2 = c_big_struct_both(big);
|
||||
#require(big2.a == 10);
|
||||
#require(big2.b == 11);
|
||||
#require(big2.c == 12);
|
||||
#require(big2.d == 13);
|
||||
#require(big2.e == 14);
|
||||
|
||||
>r1: Rect = {
|
||||
.left = 1,
|
||||
.right = 21,
|
||||
.top = 16,
|
||||
.bottom = 4,
|
||||
};
|
||||
>r2: Rect = {
|
||||
.left = 178,
|
||||
.right = 189,
|
||||
.top = 21,
|
||||
.bottom = 15,
|
||||
};
|
||||
c_multiple_struct_ints(r1, r2);
|
||||
|
||||
#require(c_ret_bool() == 1);
|
||||
|
||||
#require(c_ret_u8() == 0xff);
|
||||
#require(c_ret_u16() == 0xffff);
|
||||
#require(c_ret_u32() == 0xffffffff);
|
||||
#require(c_ret_u64() == 0xffffffffffffffff);
|
||||
|
||||
#require(c_ret_s8() == -1);
|
||||
#require(c_ret_s16() == -1);
|
||||
#require(c_ret_s32() == -1);
|
||||
#require(c_ret_s64() == -1);
|
||||
|
||||
c_struct_with_array({ .a = 1, .padding = undefined, .b = 2, });
|
||||
|
||||
>x = c_ret_struct_with_array();
|
||||
#require(x.a == 4);
|
||||
#require(x.b == 155);
|
||||
|
||||
>res = c_modify_by_ref_param({ .val = 1, .arr = undefined, });
|
||||
#require(res.val == 42);
|
||||
|
||||
>function_pointer = c_func_ptr_byval&;
|
||||
function_pointer(1, 2, { .origin = { .x = 9, .y = 10, .z = 11, }, .size = { .width = 12, .height = 13, .depth = 14, }, }, 3, 4, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_u8[export] (x: u8) void {
|
||||
#require(x == 0xff);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_u16 [export] (x: u16) void {
|
||||
#require(x == 0xfffe);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_u32 [export] (x: u32) void {
|
||||
#require(x == 0xfffffffd);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_u64 [export] (x: u64) void {
|
||||
#require(x == 0xfffffffffffffffc);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_s8 [export] (x: s8) void {
|
||||
#require(x == -1);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_s16 [export] (x: s16) void {
|
||||
#require(x == -2);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_s32 [export] (x: s32) void {
|
||||
#require(x == -3);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_s64 [export] (x: s64) void {
|
||||
#require(x == -4);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ptr [export] (x: *u8) void {
|
||||
#require(#int_from_pointer(x) == 0xdeadbeef);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_five_integers [export] (a: s32, b: s32, c: s32, d: s32, e: s32) void {
|
||||
#require(a == 12);
|
||||
#require(b == 34);
|
||||
#require(c == 56);
|
||||
#require(d == 78);
|
||||
#require(e == 90);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_bool [export] (x: u8) void {
|
||||
#require(x);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_struct_u64_u64 [export] () Struct_u64_u64 {
|
||||
return { .a = 1, .b = 2, };
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_0 [export] (s: Struct_u64_u64) void {
|
||||
#require(s.a == 3);
|
||||
#require(s.b == 4);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_1 [export] (_: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 5);
|
||||
#require(s.b == 6);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_2 [export] (_: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 7);
|
||||
#require(s.b == 8);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_3 [export] (_: u64, _: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 9);
|
||||
#require(s.b == 10);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_4 [export](_: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 11);
|
||||
#require(s.b == 12);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_5 [export](_: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 13);
|
||||
#require(s.b == 14);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_6 [export](_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 15);
|
||||
#require(s.b == 16);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_7 [export](_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 17);
|
||||
#require(s.b == 18);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_struct_u64_u64_8 [export](_: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, _: u64, s: Struct_u64_u64) void {
|
||||
#require(s.a == 19);
|
||||
#require(s.b == 20);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_big_struct [export] (x: BigStruct) void {
|
||||
#require(x.a == 1);
|
||||
#require(x.b == 2);
|
||||
#require(x.c == 3);
|
||||
#require(x.d == 4);
|
||||
#require(x.e == 5);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_small_packed_struct [export] (x: SmallPackedStruct) void {
|
||||
#require(x.a == 0);
|
||||
#require(x.b == 1);
|
||||
#require(x.c == 2);
|
||||
#require(x.d == 3);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_split_struct_ints [export] (x: SplitStructInt) void {
|
||||
#require(x.a == 1234);
|
||||
#require(x.b == 100);
|
||||
#require(x.c == 1337);
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_big_struct_both [export] (x: BigStruct) BigStruct {
|
||||
#require(x.a == 30);
|
||||
#require(x.b == 31);
|
||||
#require(x.c == 32);
|
||||
#require(x.d == 33);
|
||||
#require(x.e == 34);
|
||||
>s: BigStruct = {
|
||||
.a = 20,
|
||||
.b = 21,
|
||||
.c = 22,
|
||||
.d = 23,
|
||||
.e = 24,
|
||||
};
|
||||
return s;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_bool[export] () u8 {
|
||||
return 1;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_u8[export] () u8 {
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_u16[export] () u16 {
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_u32[export] () u32 {
|
||||
return 0xffffffff;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_u64[export] () u64 {
|
||||
return 0xffffffffffffffff;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_s8[export] () s8 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_s16[export] () s16 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_s32[export] () s32 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_s64[export] () s64 {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_small_struct_ints[export] () SmallStructInts {
|
||||
return {
|
||||
.a = 1,
|
||||
.b = 2,
|
||||
.c = 3,
|
||||
.d = 4,
|
||||
};
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_ret_med_struct_ints[export] () MedStructInts {
|
||||
return {
|
||||
.x = 1,
|
||||
.y = 2,
|
||||
.z = 3,
|
||||
};
|
||||
}
|
||||
|
||||
fn[cc(.c)] nat_multiple_struct_ints [export] (x: Rect, y: Rect) void {
|
||||
#require(x.left == 1);
|
||||
#require(x.right == 21);
|
||||
#require(x.top == 16);
|
||||
#require(x.bottom == 4);
|
||||
#require(y.left == 178);
|
||||
#require(y.right == 189);
|
||||
#require(y.top == 21);
|
||||
#require(y.bottom == 15);
|
||||
}
|
||||
|
||||
fn [cc(.c)] nat_small_struct_ints [export] (x: SmallStructInts) void {
|
||||
#require(x.a == 1);
|
||||
#require(x.b == 2);
|
||||
#require(x.c == 3);
|
||||
#require(x.d == 4);
|
||||
}
|
||||
|
||||
fn [cc(.c)] nat_med_struct_ints [export] (s: MedStructInts) void {
|
||||
#require(s.x == 1);
|
||||
#require(s.y == 2);
|
||||
#require(s.z == 3);
|
||||
}
|
||||
|
8
retest/standalone/add_sub/main.nat
Normal file
8
retest/standalone/add_sub/main.nat
Normal file
@ -0,0 +1,8 @@
|
||||
fn [cc(.c)] main [export]() s32 {
|
||||
>a: s32 = 1;
|
||||
>b: s32 = 2;
|
||||
>c = a + b;
|
||||
>d: s32 = 3;
|
||||
>e = d - c;
|
||||
return e;
|
||||
}
|
7
retest/standalone/and/main.nat
Normal file
7
retest/standalone/and/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
>a: s32 = 5;
|
||||
>b: s32 = 4;
|
||||
>result = a & b;
|
||||
return result - b;
|
||||
}
|
4
retest/standalone/arrays/main.nat
Normal file
4
retest/standalone/arrays/main.nat
Normal file
@ -0,0 +1,4 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>array: [1]s32 = [0];
|
||||
return array[0];
|
||||
}
|
5
retest/standalone/assert/main.nat
Normal file
5
retest/standalone/assert/main.nat
Normal file
@ -0,0 +1,5 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>n: s32 = 1;
|
||||
#assert(n);
|
||||
return n - n;
|
||||
}
|
25
retest/standalone/bitfield/main.nat
Normal file
25
retest/standalone/bitfield/main.nat
Normal file
@ -0,0 +1,25 @@
|
||||
bitfield(s32) Bitfield{
|
||||
a: u1,
|
||||
b: u1,
|
||||
c: u1,
|
||||
d: u29,
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>bf: Bitfield = {
|
||||
.a = 0,
|
||||
.b = 1,
|
||||
.c = 1,
|
||||
.d = 0,
|
||||
};
|
||||
>bf_int: s32 = #transmute(bf);
|
||||
|
||||
>bf_int2: s32 = 6;
|
||||
>bf2: Bitfield = #transmute(bf_int2);
|
||||
#assert(bf.a == bf2.a);
|
||||
#assert(bf.b == bf2.b);
|
||||
#assert(bf.c == bf2.c);
|
||||
#assert(bf.d == bf2.d);
|
||||
|
||||
return bf_int - bf_int2;
|
||||
}
|
4
retest/standalone/call_other_file/file.nat
Normal file
4
retest/standalone/call_other_file/file.nat
Normal file
@ -0,0 +1,4 @@
|
||||
fn foo() s32
|
||||
{
|
||||
return 0;
|
||||
}
|
7
retest/standalone/call_other_file/main.nat
Normal file
7
retest/standalone/call_other_file/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
import "file.nat";
|
||||
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
>result: s32 = file.foo();
|
||||
return result;
|
||||
}
|
9
retest/standalone/comments/main.nat
Normal file
9
retest/standalone/comments/main.nat
Normal file
@ -0,0 +1,9 @@
|
||||
// comment
|
||||
fn[cc(.c)]
|
||||
// comment
|
||||
main[export]()
|
||||
// comment
|
||||
s32 { // comment
|
||||
// comment
|
||||
return 0; // comment
|
||||
} // comment
|
16
retest/standalone/complicated_if/main.nat
Normal file
16
retest/standalone/complicated_if/main.nat
Normal file
@ -0,0 +1,16 @@
|
||||
fn foo() s32 {
|
||||
return 5;
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export] () s32 {
|
||||
>a = foo();
|
||||
|
||||
if (a > 4) {
|
||||
a += 2;
|
||||
} else {
|
||||
a += 1;
|
||||
}
|
||||
|
||||
a += 1;
|
||||
return a - 8;
|
||||
}
|
5
retest/standalone/const_local/main.nat
Normal file
5
retest/standalone/const_local/main.nat
Normal file
@ -0,0 +1,5 @@
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
>result: s32 = 0;
|
||||
return result;
|
||||
}
|
7
retest/standalone/div/main.nat
Normal file
7
retest/standalone/div/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>dividend: s32 = 30;
|
||||
>divisor: s32 = 6;
|
||||
>result = dividend / divisor;
|
||||
>n: s32 = 5;
|
||||
return n - result;
|
||||
}
|
10
retest/standalone/else_if/main.nat
Normal file
10
retest/standalone/else_if/main.nat
Normal file
@ -0,0 +1,10 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>result: s32 = 0;
|
||||
if (result > 0) {
|
||||
return 1;
|
||||
} else if (result == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
4
retest/standalone/first/main.nat
Normal file
4
retest/standalone/first/main.nat
Normal file
@ -0,0 +1,4 @@
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
return 0;
|
||||
}
|
3
retest/standalone/fn_args/main.nat
Normal file
3
retest/standalone/fn_args/main.nat
Normal file
@ -0,0 +1,3 @@
|
||||
fn [cc(.c)] main [export] (argc: s32) s32 {
|
||||
return argc - argc;
|
||||
}
|
10
retest/standalone/function_pointer/main.nat
Normal file
10
retest/standalone/function_pointer/main.nat
Normal file
@ -0,0 +1,10 @@
|
||||
>n: s32 = 5;
|
||||
fn foo() s32 {
|
||||
return n;
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>fn_pointer = foo&;
|
||||
>a = fn_pointer();
|
||||
return a - n;
|
||||
}
|
5
retest/standalone/global/main.nat
Normal file
5
retest/standalone/global/main.nat
Normal file
@ -0,0 +1,5 @@
|
||||
>n: s32 = 1;
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
n = 0;
|
||||
return n;
|
||||
}
|
6
retest/standalone/hello_world_array/main.nat
Normal file
6
retest/standalone/hello_world_array/main.nat
Normal file
@ -0,0 +1,6 @@
|
||||
fn [cc(.c)] write[extern](file_descriptor: s32, byte_pointer: *u8, byte_count: u64) s64;
|
||||
fn [cc(.c)] main[export]() s32 {
|
||||
>arr: [4]u8 = ['H', 'i', '!', '\n'];
|
||||
write(1, arr&, arr.length);
|
||||
return 0;
|
||||
}
|
9
retest/standalone/hello_world_string/main.nat
Normal file
9
retest/standalone/hello_world_string/main.nat
Normal file
@ -0,0 +1,9 @@
|
||||
fn [cc(.c)] write[extern](file_descriptor: s32, byte_pointer: *u8, byte_count: u64) s64;
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>local_string = "Hello world from local string!\n";
|
||||
write(1, local_string&, local_string.length);
|
||||
>global_string: []u8 = "Hello world from global string!\n";
|
||||
write(1, global_string.pointer, global_string.length);
|
||||
return 0;
|
||||
}
|
11
retest/standalone/if_else/main.nat
Normal file
11
retest/standalone/if_else/main.nat
Normal file
@ -0,0 +1,11 @@
|
||||
fn foo() s32 {
|
||||
return 1;
|
||||
}
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a = foo();
|
||||
if (a == 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
7
retest/standalone/leading_zeroes/main.nat
Normal file
7
retest/standalone/leading_zeroes/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 0xffffffff;
|
||||
#assert(#leading_zeroes(a) == 0);
|
||||
>b: s32 = 0x1fffffff;
|
||||
#assert(#leading_zeroes(b) == 3);
|
||||
return 0;
|
||||
}
|
9
retest/standalone/loop/main.nat
Normal file
9
retest/standalone/loop/main.nat
Normal file
@ -0,0 +1,9 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
>top: s32 = 10;
|
||||
loop (i < top) {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return i - top;
|
||||
}
|
12
retest/standalone/loop_break/main.nat
Normal file
12
retest/standalone/loop_break/main.nat
Normal file
@ -0,0 +1,12 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
>n: s32 = 5;
|
||||
loop (i < 10) {
|
||||
i += 1;
|
||||
if (i == n) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return i - n;
|
||||
}
|
13
retest/standalone/loop_continue/main.nat
Normal file
13
retest/standalone/loop_continue/main.nat
Normal file
@ -0,0 +1,13 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
>n: s32 = 0;
|
||||
loop (i < 10) {
|
||||
i += 1;
|
||||
if (n == 0) {
|
||||
continue;
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
18
retest/standalone/loop_no_condition/main.nat
Normal file
18
retest/standalone/loop_no_condition/main.nat
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
fn foo() s32 {
|
||||
>n: s32 = 6;
|
||||
>a: s32 = 0;
|
||||
loop {
|
||||
if (a == n) {
|
||||
return a;
|
||||
}
|
||||
|
||||
a += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>n: s32 = 6;
|
||||
>result = foo();
|
||||
return result - n;
|
||||
}
|
21
retest/standalone/loop_return_else/main.nat
Normal file
21
retest/standalone/loop_return_else/main.nat
Normal file
@ -0,0 +1,21 @@
|
||||
>n: s32 = 10;
|
||||
>m: s32 = 3;
|
||||
|
||||
fn foo(arg: s32) s32 {
|
||||
>i: s32 = 0;
|
||||
loop (i < arg) {
|
||||
if (i < m) {
|
||||
i += 1;
|
||||
} else {
|
||||
return i - 100;
|
||||
}
|
||||
}
|
||||
|
||||
return 321;
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a = foo(n);
|
||||
>b = foo(n);
|
||||
return (a - b) + (a + 97) + (b + 97);
|
||||
}
|
21
retest/standalone/loop_return_if/main.nat
Normal file
21
retest/standalone/loop_return_if/main.nat
Normal file
@ -0,0 +1,21 @@
|
||||
>m: s32 = 2;
|
||||
>n: s32 = 6;
|
||||
|
||||
fn foo(arg: s32) s32 {
|
||||
>i: s32 = 0;
|
||||
loop (i < arg) {
|
||||
if (i > 2) {
|
||||
return i;
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return 15;
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a = foo(n);
|
||||
>b = foo(n);
|
||||
return (a - b) + (a - (m + 1)) + (b - (m + 1));
|
||||
}
|
7
retest/standalone/loop_return_no_conditional/main.nat
Normal file
7
retest/standalone/loop_return_no_conditional/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
loop (i < 1) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
19
retest/standalone/more_if/main.nat
Normal file
19
retest/standalone/more_if/main.nat
Normal file
@ -0,0 +1,19 @@
|
||||
fn foo(arg: s32) s32 {
|
||||
if (arg > 1) {
|
||||
return 6;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a = foo(5);
|
||||
>b = foo(5);
|
||||
if (a - 6 != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (b - 6 != 0) {
|
||||
return 1;
|
||||
}
|
||||
return a - b;
|
||||
}
|
5
retest/standalone/mul/main.nat
Normal file
5
retest/standalone/mul/main.nat
Normal file
@ -0,0 +1,5 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 5;
|
||||
>b: s32 = 4;
|
||||
return (a * b) - (a * b);
|
||||
}
|
18
retest/standalone/nested_if/main.nat
Normal file
18
retest/standalone/nested_if/main.nat
Normal file
@ -0,0 +1,18 @@
|
||||
fn foo (arg: s32) s32 {
|
||||
if (arg > 1) {
|
||||
if (arg < 5) {
|
||||
return 6;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export] () s32 {
|
||||
>a = foo(5);
|
||||
>b = foo(5);
|
||||
return a - b;
|
||||
}
|
||||
|
14
retest/standalone/one_complement/main.nat
Normal file
14
retest/standalone/one_complement/main.nat
Normal file
@ -0,0 +1,14 @@
|
||||
fn align_forward(value: s32, alignment: s32) s32 {
|
||||
>mask = alignment - 1;
|
||||
return (value + mask) & ~mask;
|
||||
}
|
||||
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 1;
|
||||
>aligned_a = align_forward(a, 8);
|
||||
>b: s32 = 9;
|
||||
>aligned_b = align_forward(b, 8);
|
||||
>c: s32 = 512;
|
||||
>aligned_c = align_forward(c, 0x1000);
|
||||
return (aligned_a - 8) + (aligned_b - 16) + (aligned_c - 0x1000);
|
||||
}
|
7
retest/standalone/or/main.nat
Normal file
7
retest/standalone/or/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 0xffff;
|
||||
>b: s32 = 0xffff0000;
|
||||
>c: s32 = 0xffffffff;
|
||||
>result = c - (a | b);
|
||||
return result;
|
||||
}
|
9
retest/standalone/orelse/main.nat
Normal file
9
retest/standalone/orelse/main.nat
Normal file
@ -0,0 +1,9 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 5;
|
||||
>b: s32 = a orelse 4;
|
||||
#assert(b == a);
|
||||
>c: s32 = 0;
|
||||
>d: s32 = c orelse a;
|
||||
#assert(d == a);
|
||||
return 0;
|
||||
}
|
7
retest/standalone/out_of_order/main.nat
Normal file
7
retest/standalone/out_of_order/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
return foo();
|
||||
}
|
||||
|
||||
fn foo() s32 {
|
||||
return 0;
|
||||
}
|
10
retest/standalone/plain_polymorphic_type/main.nat
Normal file
10
retest/standalone/plain_polymorphic_type/main.nat
Normal file
@ -0,0 +1,10 @@
|
||||
struct SimplePolymorphic[$T] {
|
||||
member: T,
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>s: SimplePolymorphic[s32] = {
|
||||
.member = 0,
|
||||
};
|
||||
return s.member;
|
||||
}
|
6
retest/standalone/pointer/main.nat
Normal file
6
retest/standalone/pointer/main.nat
Normal file
@ -0,0 +1,6 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 0;
|
||||
>pointer = a&;
|
||||
pointer@ = 4;
|
||||
return pointer@ - a;
|
||||
}
|
6
retest/standalone/shifts/main.nat
Normal file
6
retest/standalone/shifts/main.nat
Normal file
@ -0,0 +1,6 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 1;
|
||||
>b: s32 = a << 5;
|
||||
>c: s32 = b >> 5;
|
||||
return c - a;
|
||||
}
|
12
retest/standalone/simple_if/main.nat
Normal file
12
retest/standalone/simple_if/main.nat
Normal file
@ -0,0 +1,12 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>constant: s32 = 4;
|
||||
>result: s32 = 0;
|
||||
|
||||
if (result > 0) {
|
||||
result = constant - 1;
|
||||
} else {
|
||||
result = constant;
|
||||
}
|
||||
|
||||
return result - constant;
|
||||
}
|
6
retest/standalone/size/main.nat
Normal file
6
retest/standalone/size/main.nat
Normal file
@ -0,0 +1,6 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>sizeofu32: s32 = #size(u32);
|
||||
>sizeofu16: s32 = #size(u16);
|
||||
|
||||
return sizeofu32 - (2 * sizeofu16);
|
||||
}
|
10
retest/standalone/struct/main.nat
Normal file
10
retest/standalone/struct/main.nat
Normal file
@ -0,0 +1,10 @@
|
||||
struct Struct {
|
||||
a: s32,
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>result: Struct = {
|
||||
.a = 0,
|
||||
};
|
||||
return result.a;
|
||||
}
|
7
retest/standalone/trailing_zeroes/main.nat
Normal file
7
retest/standalone/trailing_zeroes/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 7;
|
||||
#assert(#trailing_zeroes(a) == 0);
|
||||
>b: s32 = 8;
|
||||
#assert(#trailing_zeroes(b) == 3);
|
||||
return 0;
|
||||
}
|
7
retest/standalone/xor/main.nat
Normal file
7
retest/standalone/xor/main.nat
Normal file
@ -0,0 +1,7 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 561;
|
||||
>b: s32 = 124;
|
||||
>c = a ^ b;
|
||||
>d = a ^ b;
|
||||
return c ^ d;
|
||||
}
|
14
script.sh
Normal file
14
script.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
MY_SOURCE_FILE=retest/standalone/call_other_file/main.nat
|
||||
|
||||
i=$((0))
|
||||
while ((i < 1000)); do
|
||||
zig build run -Dprint_stack_trace=true -Doptimize=Debug -- exe -main_source_file $MY_SOURCE_FILE
|
||||
zig build run -Dprint_stack_trace=true -Doptimize=ReleaseSafe -- exe -main_source_file $MY_SOURCE_FILE
|
||||
zig build run -Dprint_stack_trace=true -Doptimize=ReleaseSmall -- exe -main_source_file $MY_SOURCE_FILE
|
||||
zig build run -Dprint_stack_trace=true -Doptimize=ReleaseFast -- exe -main_source_file $MY_SOURCE_FILE
|
||||
i=$((i + 1))
|
||||
done
|
@ -28,6 +28,7 @@
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
#include "llvm/LinkAllPasses.h"
|
||||
#include "llvm/MC/MCSubtargetInfo.h"
|
||||
#include "llvm/MC/TargetRegistry.h"
|
||||
#include "llvm/Option/Arg.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
@ -38,12 +39,15 @@
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/Support/RISCVISAInfo.h"
|
||||
#include "llvm/Support/Signals.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/TimeProfiler.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/TargetParser/AArch64TargetParser.h"
|
||||
#include "llvm/TargetParser/ARMTargetParser.h"
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef CLANG_HAVE_RLIMITS
|
||||
@ -182,6 +186,43 @@ static int PrintSupportedCPUs(std::string TargetStr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PrintSupportedExtensions(std::string TargetStr) {
|
||||
std::string Error;
|
||||
const llvm::Target *TheTarget =
|
||||
llvm::TargetRegistry::lookupTarget(TargetStr, Error);
|
||||
if (!TheTarget) {
|
||||
llvm::errs() << Error;
|
||||
return 1;
|
||||
}
|
||||
|
||||
llvm::TargetOptions Options;
|
||||
std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
|
||||
TheTarget->createTargetMachine(TargetStr, "", "", Options, std::nullopt));
|
||||
const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
|
||||
const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
|
||||
const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =
|
||||
MCInfo->getAllProcessorFeatures();
|
||||
|
||||
llvm::StringMap<llvm::StringRef> DescMap;
|
||||
for (const llvm::SubtargetFeatureKV &feature : Features)
|
||||
DescMap.insert({feature.Key, feature.Desc});
|
||||
|
||||
if (MachineTriple.isRISCV())
|
||||
llvm::riscvExtensionsHelp(DescMap);
|
||||
else if (MachineTriple.isAArch64())
|
||||
llvm::AArch64::PrintSupportedExtensions(DescMap);
|
||||
else if (MachineTriple.isARM())
|
||||
llvm::ARM::PrintSupportedExtensions(DescMap);
|
||||
else {
|
||||
// The option was already checked in Driver::HandleImmediateArgs,
|
||||
// so we do not expect to get here if we are not a supported architecture.
|
||||
assert(0 && "Unhandled triple for --print-supported-extensions option.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
||||
ensureSufficientStack();
|
||||
|
||||
@ -221,6 +262,10 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
||||
if (Clang->getFrontendOpts().PrintSupportedCPUs)
|
||||
return PrintSupportedCPUs(Clang->getTargetOpts().Triple);
|
||||
|
||||
// --print-supported-extensions takes priority over the actual compilation.
|
||||
if (Clang->getFrontendOpts().PrintSupportedExtensions)
|
||||
return PrintSupportedExtensions(Clang->getTargetOpts().Triple);
|
||||
|
||||
// Infer the builtin include path if unspecified.
|
||||
if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
|
||||
Clang->getHeaderSearchOpts().ResourceDir.empty())
|
||||
|
@ -204,10 +204,10 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
||||
// Parse the arguments.
|
||||
const OptTable &OptTbl = getDriverOptTable();
|
||||
|
||||
const unsigned IncludedFlagsBitmask = options::CC1AsOption;
|
||||
llvm::opt::Visibility VisibilityMask(options::CC1AsOption);
|
||||
unsigned MissingArgIndex, MissingArgCount;
|
||||
InputArgList Args = OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount,
|
||||
IncludedFlagsBitmask);
|
||||
InputArgList Args =
|
||||
OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount, VisibilityMask);
|
||||
|
||||
// Check for missing argument error.
|
||||
if (MissingArgCount) {
|
||||
@ -220,7 +220,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
|
||||
for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
|
||||
auto ArgString = A->getAsString(Args);
|
||||
std::string Nearest;
|
||||
if (OptTbl.findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
|
||||
if (OptTbl.findNearest(ArgString, Nearest, VisibilityMask) > 1)
|
||||
Diags.Report(diag::err_drv_unknown_argument) << ArgString;
|
||||
else
|
||||
Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
|
||||
@ -643,9 +643,10 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
|
||||
if (Asm.ShowHelp) {
|
||||
getDriverOptTable().printHelp(
|
||||
llvm::outs(), "clang -cc1as [options] file...",
|
||||
"Clang Integrated Assembler",
|
||||
/*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
|
||||
/*ShowAllAliases=*/false);
|
||||
"Clang Integrated Assembler", /*ShowHidden=*/false,
|
||||
/*ShowAllAliases=*/false,
|
||||
llvm::opt::Visibility(driver::options::CC1AsOption));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "llvm/Support/CrashRecoveryContext.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/LLVMDriver.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
@ -65,7 +64,7 @@ std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
|
||||
if (llvm::ErrorOr<std::string> P =
|
||||
llvm::sys::findProgramByName(ExecutablePath))
|
||||
ExecutablePath = *P;
|
||||
return std::string(ExecutablePath.str());
|
||||
return std::string(ExecutablePath);
|
||||
}
|
||||
|
||||
// This just needs to be some symbol in the binary; C++ doesn't
|
||||
@ -79,9 +78,9 @@ static const char *GetStableCStr(std::set<std::string> &SavedStrings,
|
||||
return SavedStrings.insert(std::string(S)).first->c_str();
|
||||
}
|
||||
|
||||
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
||||
/// ApplyOneQAOverride - Apply a list of edits to the input argument lists.
|
||||
///
|
||||
/// The input string is a space separate list of edits to perform,
|
||||
/// The input string is a space separated list of edits to perform,
|
||||
/// they are applied in order to the input argument lists. Edits
|
||||
/// should be one of the following forms:
|
||||
///
|
||||
@ -122,7 +121,7 @@ static void ApplyOneQAOverride(raw_ostream &OS,
|
||||
GetStableCStr(SavedStrings, Edit.substr(1));
|
||||
OS << "### Adding argument " << Str << " at end\n";
|
||||
Args.push_back(Str);
|
||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.ends_with("/") &&
|
||||
Edit.slice(2, Edit.size() - 1).contains('/')) {
|
||||
StringRef MatchPattern = Edit.substr(2).split('/').first;
|
||||
StringRef ReplPattern = Edit.substr(2).split('/').second;
|
||||
@ -177,7 +176,7 @@ static void ApplyOneQAOverride(raw_ostream &OS,
|
||||
}
|
||||
}
|
||||
|
||||
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
||||
/// ApplyQAOverride - Apply a space separated list of edits to the
|
||||
/// input argument lists. See ApplyOneQAOverride.
|
||||
static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
|
||||
const char *OverrideStr,
|
||||
@ -371,14 +370,6 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
|
||||
|
||||
static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
|
||||
noteBottomOfStack();
|
||||
// ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(),
|
||||
// and overwrites the args. We don't want it to do that,
|
||||
// and we also don't need the signal handlers it installs
|
||||
// (we have our own already), so we just use llvm_shutdown_obj
|
||||
// instead.
|
||||
// llvm::InitLLVM X(Argc, Argv);
|
||||
llvm::llvm_shutdown_obj X;
|
||||
|
||||
llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
|
||||
" and include the crash backtrace, preprocessed "
|
||||
"source, and associated run script.\n");
|
||||
@ -405,7 +396,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
|
||||
}
|
||||
|
||||
// Handle -cc1 integrated tools.
|
||||
if (Args.size() >= 2 && StringRef(Args[1]).startswith("-cc1"))
|
||||
if (Args.size() >= 2 && StringRef(Args[1]).starts_with("-cc1"))
|
||||
return ExecuteCC1Tool(Args, ToolContext);
|
||||
|
||||
// Handle options that need handling before the real command line parsing in
|
||||
@ -606,6 +597,6 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
|
||||
return Res;
|
||||
}
|
||||
|
||||
extern "C" int NativityClangMain(int argc, char **argv) {
|
||||
extern "C" int nat_clang_main(int argc, char ** argv) {
|
||||
return clang_main(argc, argv, {argv[0], nullptr, false});
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
#include "llvm/Passes/PassBuilder.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
|
||||
|
||||
#include "llvm/Linker/Linker.h"
|
||||
|
||||
#include "llvm/Passes/PassBuilder.h"
|
||||
|
||||
#include "llvm/MC/TargetRegistry.h"
|
||||
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
@ -17,6 +22,17 @@
|
||||
|
||||
|
||||
using namespace llvm;
|
||||
using llvm::orc::ThreadSafeContext;
|
||||
using llvm::orc::ThreadSafeModule;
|
||||
|
||||
extern "C" void NativityLLVMInitializeAll()
|
||||
{
|
||||
InitializeAllTargetInfos();
|
||||
InitializeAllTargets();
|
||||
InitializeAllTargetMCs();
|
||||
InitializeAllAsmParsers();
|
||||
InitializeAllAsmPrinters();
|
||||
}
|
||||
|
||||
extern "C" LLVMContext* NativityLLVMCreateContext()
|
||||
{
|
||||
@ -28,6 +44,10 @@ extern "C" Module* NativityLLVMCreateModule(const char* name_ptr, size_t name_le
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* module = new Module(name, context);
|
||||
// module->addModuleFlag(Module::Max, "Dwarf Version", 5);
|
||||
// module->addModuleFlag(Module::Warning, "Debug Info Version", 3);
|
||||
// module->addModuleFlag(Module::Max, "frame-pointer", 2);
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
@ -96,6 +116,16 @@ extern "C" void NativityLLVMBuilderSetCurrentDebugLocation(IRBuilder<>& builder,
|
||||
builder.SetCurrentDebugLocation(debug_location);
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMBuilderClearCurrentDebugLocation(IRBuilder<>&builder)
|
||||
{
|
||||
builder.SetCurrentDebugLocation(DebugLoc());
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMBuilderSetInstructionDebugLocation(IRBuilder<>& builder, Instruction* instruction)
|
||||
{
|
||||
builder.SetInstDebugLocation(instruction);
|
||||
}
|
||||
|
||||
extern "C" DIExpression* NativityLLVMDebugInfoBuilderCreateExpression(DIBuilder& builder, uint64_t* address, size_t length)
|
||||
{
|
||||
auto expr = ArrayRef<uint64_t>(address, length);
|
||||
@ -112,6 +142,11 @@ extern "C" DIGlobalVariableExpression* NativityLLVMDebugInfoBuilderCreateGlobalV
|
||||
return global_variable;
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMDebugInfoGlobalVariableAddDebugInfo(GlobalVariable& global_variable, DIGlobalVariableExpression* global_variable_expression)
|
||||
{
|
||||
global_variable.addDebugInfo(global_variable_expression);
|
||||
}
|
||||
|
||||
extern "C" DILocalVariable* NativityLLVMDebugInfoBuilderCreateParameterVariable(DIBuilder& builder, DIScope* scope, const char* name_ptr, size_t name_len, unsigned argument_index, DIFile* file, unsigned line_number, DIType* type, bool always_preserve, DINode::DIFlags flags)
|
||||
{
|
||||
assert(isa<DILocalScope>(scope));
|
||||
@ -139,6 +174,7 @@ extern "C" DIType* NativityLLVMDebugInfoBuilderCreateBasicType(DIBuilder& builde
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* type = builder.createBasicType(name, bit_count, dwarf_encoding, flags);
|
||||
type->getName();
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -208,11 +244,25 @@ extern "C" DIDerivedType* NativityLLVMDebugInfoBuilderCreateMemberType(DIBuilder
|
||||
return member_type;
|
||||
}
|
||||
|
||||
extern "C" DIDerivedType* NativityLLVMDebugInfoBuilderCreateBitfieldMemberType(DIBuilder& builder, DIScope *scope, const char* name_ptr, size_t name_len, DIFile* file, unsigned line_number, uint64_t bit_size, uint64_t bit_offset, uint64_t storage_bit_offset, DINode::DIFlags flags, DIType* type)
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* member_type = builder.createBitFieldMemberType(scope, name, file, line_number, bit_size, bit_offset, storage_bit_offset, flags, type);
|
||||
return member_type;
|
||||
}
|
||||
|
||||
extern "C" bool NativityLLLVMDITypeIsResolved(DIType* type)
|
||||
{
|
||||
return type->isResolved();
|
||||
}
|
||||
|
||||
extern "C" void NativityLLLVMDITypeGetName(DIType& type, const char** name_pointer, size_t* name_length)
|
||||
{
|
||||
auto name = type.getName();
|
||||
*name_pointer = name.data();
|
||||
*name_length = name.size();
|
||||
}
|
||||
|
||||
extern "C" DISubprogram* NativityLLVMDebugInfoScopeToSubprogram(DIScope* scope)
|
||||
{
|
||||
auto* subprogram = dyn_cast<DISubprogram>(scope);
|
||||
@ -280,6 +330,21 @@ extern "C" StructType* NativityLLVMGetStructType(LLVMContext& context, Type** ty
|
||||
auto* struct_type = StructType::get(context, types, is_packed);
|
||||
return struct_type;
|
||||
}
|
||||
|
||||
extern "C" StructType* NativityLLVMCreateStructType(LLVMContext& context, Type** type_ptr, size_t type_count, const char* name_pointer, size_t name_length, bool is_packed)
|
||||
{
|
||||
auto types = ArrayRef<Type*>(type_ptr, type_count);
|
||||
auto name = StringRef(name_pointer, name_length);
|
||||
auto* struct_type = StructType::create(context, types, name, is_packed);
|
||||
return struct_type;
|
||||
}
|
||||
|
||||
extern "C" LLVMContext* NativityLLVMTypeGetContext(Type& type)
|
||||
{
|
||||
auto& context = type.getContext();
|
||||
return &context;
|
||||
}
|
||||
|
||||
extern "C" Function* NativityLLVMModuleGetFunction(Module& module, const char* name_ptr, size_t name_len)
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
@ -341,6 +406,12 @@ extern "C" Type* NativityLLVMValueGetType(Value* value)
|
||||
return type;
|
||||
}
|
||||
|
||||
extern "C" LLVMContext* NativityLLVMValueGetContext(Value& value)
|
||||
{
|
||||
auto& context = value.getContext();
|
||||
return &context;
|
||||
}
|
||||
|
||||
extern "C" PoisonValue* NativityLLVMGetPoisonValue(Type* type)
|
||||
{
|
||||
auto* poison_value = PoisonValue::get(type);
|
||||
@ -425,6 +496,13 @@ extern "C" Value* NativityLLVMBuilderCreateICmp(IRBuilder<>& builder, CmpInst::P
|
||||
return icmp;
|
||||
}
|
||||
|
||||
extern "C" Value* NativityLLVMBuilderCreateIsNotNull(IRBuilder<>& builder, Value* value, const char* name_ptr, size_t name_len)
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* not_null = builder.CreateIsNotNull(value, name);
|
||||
return not_null;
|
||||
}
|
||||
|
||||
extern "C" LoadInst* NativityLLVMBuilderCreateLoad(IRBuilder<>& builder, Type* type, Value* pointer, bool is_volatile, const char* name_ptr, size_t name_len, uint32_t alignment)
|
||||
{
|
||||
auto align = Align{alignment};
|
||||
@ -576,13 +654,6 @@ extern "C" Value* NativityLLVMBuilderCreateGEP(IRBuilder<>& builder, Type* type,
|
||||
return GEP;
|
||||
}
|
||||
|
||||
extern "C" Value* NativityLLVMBuilderCreateStructGEP(IRBuilder<>& builder, Type* type, Value* pointer, unsigned index, const char* name_ptr, size_t name_len)
|
||||
{
|
||||
auto name = StringRef(name_ptr, name_len);
|
||||
auto* gep = builder.CreateStructGEP(type, pointer, index, name);
|
||||
return gep;
|
||||
}
|
||||
|
||||
extern "C" BranchInst* NativityLLVMBuilderCreateBranch(IRBuilder<>& builder, BasicBlock* basic_block)
|
||||
{
|
||||
auto* conditional_branch = builder.CreateBr(basic_block);
|
||||
@ -737,15 +808,14 @@ extern "C" bool NativityLLVMVerifyModule(const Module& module, const char** mess
|
||||
return !result;
|
||||
}
|
||||
|
||||
extern "C" const char* NativityLLVMFunctionToString(const Function& function, size_t* len)
|
||||
extern "C" void NativityLLVMFunctionToString(const Function& function, const char** ptr, size_t* len)
|
||||
{
|
||||
std::string buf;
|
||||
raw_string_ostream os(buf);
|
||||
function.print(os);
|
||||
os.flush();
|
||||
*len = buf.size();
|
||||
auto* result = strdup(buf.c_str());
|
||||
return result;
|
||||
*ptr = strdup(buf.c_str());
|
||||
}
|
||||
|
||||
extern "C" Type* NativityLLVMAllocatGetAllocatedType(AllocaInst& alloca)
|
||||
@ -775,6 +845,12 @@ extern "C" Function* NativityLLVMValueToFunction(Value* value)
|
||||
return function;
|
||||
}
|
||||
|
||||
extern "C" BasicBlock* NativityLLVMValueToBasicBlock(Value* value)
|
||||
{
|
||||
auto* basic_block = dyn_cast<BasicBlock>(value);
|
||||
return basic_block;
|
||||
}
|
||||
|
||||
extern "C" bool NativityLLVMTypeIsPointer(Type* type)
|
||||
{
|
||||
bool is_pointer = type->isPointerTy();
|
||||
@ -829,26 +905,24 @@ extern "C" Type* NativityLLVMArrayTypeGetElementType(ArrayType* array_type)
|
||||
return element_type;
|
||||
}
|
||||
|
||||
extern "C" const char* NativityLLVMModuleToString(const Module& module, size_t* len)
|
||||
extern "C" void NativityLLVMModuleToString(const Module& module, const char** ptr, size_t* len)
|
||||
{
|
||||
std::string buf;
|
||||
raw_string_ostream os(buf);
|
||||
module.print(os, nullptr);
|
||||
os.flush();
|
||||
*len = buf.size();
|
||||
auto* result = strdup(buf.c_str());
|
||||
return result;
|
||||
*ptr = strdup(buf.c_str());
|
||||
}
|
||||
|
||||
extern "C" const char* NativityLLVMValueToString(const Value& value, size_t* len)
|
||||
extern "C" void NativityLLVMValueToString(const Value& value, const char** ptr, size_t* len)
|
||||
{
|
||||
std::string buf;
|
||||
raw_string_ostream os(buf);
|
||||
value.print(os, true);
|
||||
os.flush();
|
||||
*len = buf.size();
|
||||
auto* result = strdup(buf.c_str());
|
||||
return result;
|
||||
*ptr = strdup(buf.c_str());
|
||||
}
|
||||
|
||||
extern "C" BasicBlock* NativityLLVMBuilderGetInsertBlock(IRBuilder<>& builder)
|
||||
@ -883,14 +957,6 @@ extern "C" void NativityLLVMCallSetCallingConvention(CallBase& call_instruction,
|
||||
call_instruction.setCallingConv(calling_convention);
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMInitializeCodeGeneration()
|
||||
{
|
||||
InitializeAllTargetInfos();
|
||||
InitializeAllTargets();
|
||||
InitializeAllTargetMCs();
|
||||
InitializeAllAsmParsers();
|
||||
InitializeAllAsmPrinters();
|
||||
}
|
||||
|
||||
extern "C" const Target* NativityLLVMGetTarget(const char* target_triple_ptr, size_t target_triple_len, const char** message_ptr, size_t* message_len)
|
||||
{
|
||||
@ -910,7 +976,7 @@ extern "C" const Target* NativityLLVMGetTarget(const char* target_triple_ptr, si
|
||||
return target;
|
||||
}
|
||||
|
||||
extern "C" TargetMachine* NativityLLVMTargetCreateTargetMachine(Target& target, const char* target_triple_ptr, size_t target_triple_len, const char* cpu_ptr, size_t cpu_len, const char* features_ptr, size_t features_len, Reloc::Model relocation_model, CodeModel::Model maybe_code_model, bool is_code_model_present, CodeGenOpt::Level optimization_level, bool jit)
|
||||
extern "C" TargetMachine* NativityLLVMTargetCreateTargetMachine(Target& target, const char* target_triple_ptr, size_t target_triple_len, const char* cpu_ptr, size_t cpu_len, const char* features_ptr, size_t features_len, Reloc::Model relocation_model, CodeModel::Model maybe_code_model, bool is_code_model_present, CodeGenOptLevel optimization_level, bool jit)
|
||||
{
|
||||
auto target_triple = StringRef(target_triple_ptr, target_triple_len);
|
||||
auto cpu = StringRef(cpu_ptr, cpu_len);
|
||||
@ -1042,18 +1108,26 @@ extern "C" AttributeSet NativityLLVMContextGetAttributeSet(LLVMContext& context,
|
||||
return attribute_set;
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMFunctionSetAttributes(Function& function, LLVMContext& context, AttributeSet function_attributes, AttributeSet return_attributes, const AttributeSet* parameter_attribute_set_ptr, size_t parameter_attribute_set_count)
|
||||
static AttributeList get_attribute_list(LLVMContext& context, AttributeSet function_attributes, AttributeSet return_attributes, const AttributeSet* parameter_attribute_set_ptr, size_t parameter_attribute_set_count)
|
||||
{
|
||||
auto parameter_attribute_sets = ArrayRef<AttributeSet>(parameter_attribute_set_ptr, parameter_attribute_set_count);
|
||||
auto attribute_list = AttributeList::get(context, function_attributes, return_attributes, parameter_attribute_sets);
|
||||
function.setAttributes(attribute_list);
|
||||
return attribute_list;
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMFunctionSetAttributes(Function& function, LLVMContext& context, AttributeSet function_attributes, AttributeSet return_attributes, const AttributeSet* parameter_attribute_set_ptr, size_t parameter_attribute_set_count)
|
||||
{
|
||||
function.setAttributes(get_attribute_list(context, function_attributes, return_attributes, parameter_attribute_set_ptr, parameter_attribute_set_count));
|
||||
}
|
||||
|
||||
extern "C" void NativityLLVMCallSetAttributes(CallInst& call, LLVMContext& context, AttributeSet function_attributes, AttributeSet return_attributes, const AttributeSet* parameter_attribute_set_ptr, size_t parameter_attribute_set_count)
|
||||
{
|
||||
auto parameter_attribute_sets = ArrayRef<AttributeSet>(parameter_attribute_set_ptr, parameter_attribute_set_count);
|
||||
auto attribute_list = AttributeList::get(context, function_attributes, return_attributes, parameter_attribute_sets);
|
||||
call.setAttributes(attribute_list);
|
||||
call.setAttributes(get_attribute_list(context, function_attributes, return_attributes, parameter_attribute_set_ptr, parameter_attribute_set_count));
|
||||
}
|
||||
extern "C" void NativityLLVMGlobalObjectSetAlignment(GlobalObject& global_object, uint32_t alignment)
|
||||
{
|
||||
Align align(alignment);
|
||||
global_object.setAlignment(align);
|
||||
}
|
||||
|
||||
extern "C" CallInst* NativityLLVMBuilderCreateMemcpy(IRBuilder<>& builder, Value* destination, uint32_t destination_alignment, Value* source, uint32_t source_alignment, uint64_t size, bool is_volatile)
|
||||
@ -1065,6 +1139,13 @@ extern "C" CallInst* NativityLLVMBuilderCreateMemcpy(IRBuilder<>& builder, Value
|
||||
return memcpy;
|
||||
}
|
||||
|
||||
extern "C" bool NativityLLVMLinkModules(Module& destination, Module* source)
|
||||
{
|
||||
auto src = std::unique_ptr<Module>(source);
|
||||
bool result = Linker::linkModules(destination, std::move(src));
|
||||
// Invert the condition because LLVM boolean concept is lame
|
||||
return !result;
|
||||
}
|
||||
extern "C" void NativityLLVMTypeAssertEqual(Type* a, Type* b)
|
||||
{
|
||||
assert(a == b);
|
||||
|
@ -2726,6 +2726,7 @@ void run_c_tests(void) {
|
||||
{
|
||||
assert_or_panic(nat_ret_bool() == 1);
|
||||
|
||||
|
||||
assert_or_panic(nat_ret_u8() == 0xff);
|
||||
assert_or_panic(nat_ret_u16() == 0xffff);
|
||||
assert_or_panic(nat_ret_u32() == 0xffffffff);
|
||||
@ -5423,35 +5424,35 @@ typedef struct {
|
||||
// }
|
||||
// #endif
|
||||
|
||||
void __attribute__((stdcall)) stdcall_scalars(char a, short b, int c, float d, double e) {
|
||||
assert_or_panic(a == 1);
|
||||
assert_or_panic(b == 2);
|
||||
assert_or_panic(c == 3);
|
||||
assert_or_panic(d == 4.0);
|
||||
assert_or_panic(e == 5.0);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
short x;
|
||||
short y;
|
||||
} Coord2;
|
||||
|
||||
Coord2 __attribute__((stdcall)) stdcall_coord2(Coord2 a, Coord2 b, Coord2 c) {
|
||||
assert_or_panic(a.x == 0x1111);
|
||||
assert_or_panic(a.y == 0x2222);
|
||||
assert_or_panic(b.x == 0x3333);
|
||||
assert_or_panic(b.y == 0x4444);
|
||||
assert_or_panic(c.x == 0x5555);
|
||||
assert_or_panic(c.y == 0x6666);
|
||||
return (Coord2){123, 456};
|
||||
}
|
||||
|
||||
void __attribute__((stdcall)) stdcall_big_union(union BigUnion x) {
|
||||
assert_or_panic(x.a.a == 1);
|
||||
assert_or_panic(x.a.b == 2);
|
||||
assert_or_panic(x.a.c == 3);
|
||||
assert_or_panic(x.a.d == 4);
|
||||
}
|
||||
// void __attribute__((stdcall)) stdcall_scalars(char a, short b, int c, float d, double e) {
|
||||
// assert_or_panic(a == 1);
|
||||
// assert_or_panic(b == 2);
|
||||
// assert_or_panic(c == 3);
|
||||
// assert_or_panic(d == 4.0);
|
||||
// assert_or_panic(e == 5.0);
|
||||
// }
|
||||
//
|
||||
// typedef struct {
|
||||
// short x;
|
||||
// short y;
|
||||
// } Coord2;
|
||||
//
|
||||
// Coord2 __attribute__((stdcall)) stdcall_coord2(Coord2 a, Coord2 b, Coord2 c) {
|
||||
// assert_or_panic(a.x == 0x1111);
|
||||
// assert_or_panic(a.y == 0x2222);
|
||||
// assert_or_panic(b.x == 0x3333);
|
||||
// assert_or_panic(b.y == 0x4444);
|
||||
// assert_or_panic(c.x == 0x5555);
|
||||
// assert_or_panic(c.y == 0x6666);
|
||||
// return (Coord2){123, 456};
|
||||
// }
|
||||
//
|
||||
// void __attribute__((stdcall)) stdcall_big_union(union BigUnion x) {
|
||||
// assert_or_panic(x.a.a == 1);
|
||||
// assert_or_panic(x.a.b == 2);
|
||||
// assert_or_panic(x.a.c == 3);
|
||||
// assert_or_panic(x.a.d == 4);
|
||||
// }
|
||||
|
||||
#ifdef __x86_64__
|
||||
struct ByRef __attribute__((ms_abi)) c_explict_win64(struct ByRef in) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user