Compare commits
18 Commits
main
...
emit-llvm-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3994767e8d | ||
![]() |
d3af927719 | ||
![]() |
ebac108da4 | ||
![]() |
b5e762c2b9 | ||
![]() |
586900dde5 | ||
![]() |
95c3570871 | ||
![]() |
d366a911a1 | ||
![]() |
871e8f13ef | ||
![]() |
2f6ba47ac5 | ||
![]() |
b9fdc72ed6 | ||
![]() |
b9df85f55a | ||
![]() |
3a7ee24509 | ||
![]() |
b9ba5eee11 | ||
![]() |
aade460a50 | ||
![]() |
1f945a8877 | ||
![]() |
7094d59372 | ||
![]() |
a379ba9cf1 | ||
![]() |
3ce2a607ad |
55
.github/workflows/ci.yml
vendored
55
.github/workflows/ci.yml
vendored
@ -8,11 +8,6 @@ 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
|
||||
@ -20,55 +15,13 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- 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
|
||||
- name: Build and test
|
||||
run: ./ci/linux_gnu_runner.sh
|
||||
macos:
|
||||
runs-on: macos-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- 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
|
||||
- name: Build and test
|
||||
run: ./ci/macos_runner.sh
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
.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",
|
||||
"retest/standalone/first/main.nat"
|
||||
"test/build/c-abi/main.nat",
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
|
@ -2752,6 +2752,19 @@ 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,
|
||||
@ -2825,6 +2838,46 @@ 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;
|
||||
@ -17616,9 +17669,7 @@ pub const Unit = struct {
|
||||
return unit.importPackage(context, package);
|
||||
}
|
||||
|
||||
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].*));
|
||||
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].*));
|
||||
if (!ends_with_nat) {
|
||||
unreachable;
|
||||
}
|
||||
|
@ -76,8 +76,6 @@ pub const LLVM = struct {
|
||||
nounwind: *Attribute,
|
||||
inreg: *Attribute,
|
||||
@"noalias": *Attribute,
|
||||
zero_extend: *Attribute,
|
||||
sign_extend: *Attribute,
|
||||
};
|
||||
|
||||
pub const Linkage = enum(c_uint) {
|
||||
@ -143,6 +141,7 @@ 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;
|
||||
@ -168,7 +167,6 @@ pub const LLVM = struct {
|
||||
const getInsertBlock = bindings.NativityLLVMBuilderGetInsertBlock;
|
||||
const isCurrentBlockTerminated = bindings.NativityLLVMBuilderIsCurrentBlockTerminated;
|
||||
const setCurrentDebugLocation = bindings.NativityLLVMBuilderSetCurrentDebugLocation;
|
||||
const setInstructionDebugLocation = bindings.NativityLLVMBuilderSetInstructionDebugLocation;
|
||||
};
|
||||
|
||||
pub const DebugInfo = struct {
|
||||
@ -2419,8 +2417,6 @@ 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),
|
||||
@ -3428,6 +3424,17 @@ 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,
|
||||
@ -3441,17 +3448,6 @@ 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,7 +1,6 @@
|
||||
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;
|
||||
@ -12,7 +11,6 @@ pub extern fn NativityLLVMGetPointerType(context: *LLVM.Context, address_space:
|
||||
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 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;
|
||||
@ -25,7 +23,6 @@ pub extern fn NativityLLVMDebugInfoBuilderCreateLexicalBlock(builder: *LLVM.Debu
|
||||
|
||||
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 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;
|
||||
@ -38,9 +35,7 @@ pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.D
|
||||
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;
|
||||
@ -52,11 +47,8 @@ pub extern fn NativityLLVMBasicBlockRemoveFromParent(basic_block: *LLVM.Value.Ba
|
||||
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 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;
|
||||
@ -72,7 +64,6 @@ pub extern fn NativityLLVMGetConstantArray(array_type: *LLVM.Type.Array, value_p
|
||||
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 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;
|
||||
@ -82,7 +73,6 @@ pub extern fn NativityLLVMContextGetAttributeFromType(context: *LLVM.Context, at
|
||||
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;
|
||||
@ -106,6 +96,7 @@ pub extern fn NativityLLVMBuilderCreateXor(builder: *LLVM.Builder, left: *LLVM.V
|
||||
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 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;
|
||||
@ -131,7 +122,6 @@ pub extern fn NativityLLVMGetStruct(struct_type: *LLVM.Type.Struct, constant_ptr
|
||||
|
||||
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;
|
||||
@ -167,6 +157,9 @@ pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module,
|
||||
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 LLVMCreateMemoryBufferWithMemoryRange(InputData: [*]const u8, InputDataLength: usize, BufferName: ?[*:0]const u8, RequiresNullTerminator: c_int) *LLVM.MemoryBuffer;
|
||||
pub extern fn LLVMParseBitcodeInContext2(context: *LLVM.Context, memory_buffer: *LLVM.MemoryBuffer, out_module: **LLVM.Module) c_int;
|
||||
|
||||
pub extern fn LLVMInitializeAArch64TargetInfo() void;
|
||||
pub extern fn LLVMInitializeAMDGPUTargetInfo() void;
|
||||
pub extern fn LLVMInitializeARMTargetInfo() void;
|
||||
|
15745
bootstrap/compiler.zig
15745
bootstrap/compiler.zig
File diff suppressed because it is too large
Load Diff
@ -70,16 +70,12 @@ pub const Arena = struct {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
pub inline fn new(arena: *Arena, comptime T: type) !*T {
|
||||
const result: *T = @ptrCast(@alignCast(try arena.allocate(@sizeOf(T))));
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn new_array(arena: *Arena, comptime T: type, count: usize) ![]T {
|
||||
pub inline 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];
|
||||
}
|
||||
@ -157,7 +153,6 @@ pub fn DynamicBoundedArray(comptime T: type) type {
|
||||
|
||||
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;
|
||||
@ -180,6 +175,10 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptim
|
||||
|
||||
const Array = @This();
|
||||
|
||||
pub fn clear(array: *Array) void {
|
||||
array.length = 0;
|
||||
}
|
||||
|
||||
pub fn const_slice(array: *const Array) []const T {
|
||||
return array.pointer[0..array.length];
|
||||
}
|
||||
@ -218,7 +217,7 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptim
|
||||
|
||||
const length = array.length;
|
||||
const size = length * @sizeOf(T);
|
||||
const granularity_aligned_size = align_forward(size, granularity);
|
||||
const granularity_aligned_size = array.committed * granularity;
|
||||
const new_size = size + additional * @sizeOf(T);
|
||||
|
||||
if (granularity_aligned_size < new_size) {
|
||||
@ -258,24 +257,11 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptim
|
||||
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{
|
||||
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;
|
||||
@ -309,10 +295,6 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptim
|
||||
if (@intFromPtr(item) >= top) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn clear(array: *@This()) void {
|
||||
array.length = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -363,18 +345,9 @@ 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| {
|
||||
@ -479,30 +452,28 @@ pub fn PinnedHashMapAdvanced(comptime K: type, comptime V: type, comptime granul
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put(map: *@This(), key: K, value: V) *V {
|
||||
pub fn put(map: *@This(), key: K, value: V) void {
|
||||
if (map.get_pointer(key)) |value_pointer| {
|
||||
value_pointer.* = value;
|
||||
return value_pointer;
|
||||
} else {
|
||||
const len = map.length;
|
||||
map.ensure_capacity(len + 1);
|
||||
return map.put_at_with_capacity(len, key, value);
|
||||
map.put_at_with_capacity(len, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_no_clobber(map: *@This(), key: K, value: V) *V {
|
||||
pub fn put_no_clobber(map: *@This(), key: K, value: V) void {
|
||||
assert(map.get_pointer(key) == null);
|
||||
const len = map.length;
|
||||
map.ensure_capacity(len + 1);
|
||||
return map.put_at_with_capacity(len, key, value);
|
||||
map.put_at_with_capacity(len, key, value);
|
||||
}
|
||||
|
||||
fn put_at_with_capacity(map: *@This(), index: u64, key: K, value: V) *V {
|
||||
fn put_at_with_capacity(map: *@This(), index: u64, key: K, value: V) void {
|
||||
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 {
|
||||
@ -516,7 +487,7 @@ pub fn PinnedHashMapAdvanced(comptime K: type, comptime V: type, comptime granul
|
||||
|
||||
{
|
||||
const key_size = length * @sizeOf(K);
|
||||
const key_granularity_aligned_size = align_forward(key_size, granularity);
|
||||
const key_granularity_aligned_size = map.committed_key * granularity;
|
||||
const key_new_size = key_size + additional * @sizeOf(K);
|
||||
|
||||
if (key_granularity_aligned_size < key_new_size) {
|
||||
@ -531,7 +502,7 @@ pub fn PinnedHashMapAdvanced(comptime K: type, comptime V: type, comptime granul
|
||||
|
||||
{
|
||||
const value_size = length * @sizeOf(V);
|
||||
const value_granularity_aligned_size = align_forward(value_size, granularity);
|
||||
const value_granularity_aligned_size = map.committed_value * granularity;
|
||||
const value_new_size = value_size + additional * @sizeOf(K);
|
||||
|
||||
if (value_granularity_aligned_size < value_new_size) {
|
||||
@ -797,11 +768,11 @@ pub fn exit_with_error() noreturn {
|
||||
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("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(" for error ") catch {};
|
||||
stdout.writeAll(@errorName(err)) catch {};
|
||||
@panic("Unrecoverable error");
|
||||
};
|
||||
@ -818,26 +789,14 @@ pub fn read_file(arena: *Arena, directory: std.fs.Dir, file_relative_path: []con
|
||||
}
|
||||
|
||||
pub fn self_exe_path(arena: *Arena) ![]const u8 {
|
||||
var buffer: [std.fs.max_path_bytes]u8 = undefined;
|
||||
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;
|
||||
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,7 +1,5 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const linker = @import("linker.zig");
|
||||
|
||||
const library = @import("../library.zig");
|
||||
@ -13,7 +11,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 (builtin.os.tag) {
|
||||
const driver_program = switch (@import("builtin").os.tag) {
|
||||
.windows => "lld-link",
|
||||
.linux => "ld.lld",
|
||||
.macos => "ld64.lld",
|
||||
@ -22,8 +20,8 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
_ = argv.append(driver_program);
|
||||
_ = argv.append("--error-limit=0");
|
||||
|
||||
switch (builtin.cpu.arch) {
|
||||
.aarch64 => switch (builtin.os.tag) {
|
||||
switch (@import("builtin").cpu.arch) {
|
||||
.aarch64 => switch (@import("builtin").os.tag) {
|
||||
.linux => {
|
||||
_ = argv.append("-znow");
|
||||
_ = argv.append_slice(&.{ "-m", "aarch64linux" });
|
||||
@ -44,12 +42,12 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
}
|
||||
|
||||
const ci = @import("configuration").ci;
|
||||
switch (builtin.os.tag) {
|
||||
switch (@import("builtin").os.tag) {
|
||||
.macos => {
|
||||
_ = argv.append("-dynamic");
|
||||
argv.append_slice(&.{ "-platform_version", "macos", "13.4.1", "13.3" });
|
||||
_ = argv.append("-arch");
|
||||
_ = argv.append(switch (builtin.cpu.arch) {
|
||||
_ = argv.append(switch (@import("builtin").cpu.arch) {
|
||||
.aarch64 => "arm64",
|
||||
else => |t| @panic(@tagName(t)),
|
||||
});
|
||||
@ -100,7 +98,7 @@ pub fn link(context: *const Compilation.Context, options: linker.Options) !void
|
||||
argv.append_slice(&.{ "-L", "/usr/lib64" });
|
||||
|
||||
_ = argv.append("-dynamic-linker");
|
||||
switch (builtin.cpu.arch) {
|
||||
switch (@import("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,
|
||||
@ -132,7 +130,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 (builtin.os.tag) {
|
||||
const result = switch (@import("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,7 +1,8 @@
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const builtin = @import("builtin");
|
||||
const Compilation = @import("Compilation.zig");
|
||||
pub const panic = Compilation.panic;
|
||||
|
||||
const library = @import("library.zig");
|
||||
const byte_equal = library.byte_equal;
|
||||
@ -9,7 +10,6 @@ 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";
|
||||
|
||||
@ -17,11 +17,59 @@ test {
|
||||
_ = library;
|
||||
}
|
||||
|
||||
fn todo() noreturn {
|
||||
@setCold(true);
|
||||
@panic("TODO");
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
if (configuration.editor) {
|
||||
editor.main();
|
||||
} else {
|
||||
compiler.main();
|
||||
compiler.make();
|
||||
// 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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
142
build.zig
142
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.process.Child.run(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = b.allocator,
|
||||
.argv = &.{ "brew", "--prefix", library_name },
|
||||
});
|
||||
@ -29,23 +29,22 @@ pub fn build(b: *std.Build) !void {
|
||||
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,
|
||||
else => false,
|
||||
.windows => true,
|
||||
// .macos => true,
|
||||
};
|
||||
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 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 fetcher = b.addExecutable(.{
|
||||
.name = "llvm_fetcher",
|
||||
.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) {
|
||||
@ -91,10 +90,10 @@ pub fn build(b: *std.Build) !void {
|
||||
|
||||
const cpp_files = .{
|
||||
"src/llvm/llvm.cpp",
|
||||
"src/llvm/lld.cpp",
|
||||
"src/llvm/clang_main.cpp",
|
||||
"src/llvm/clang_cc1.cpp",
|
||||
"src/llvm/clang_cc1as.cpp",
|
||||
// "src/llvm/lld.cpp",
|
||||
// "src/llvm/clang_main.cpp",
|
||||
// "src/llvm/clang_cc1.cpp",
|
||||
// "src/llvm/clang_cc1as.cpp",
|
||||
// "src/llvm/ar.cpp",
|
||||
};
|
||||
|
||||
@ -107,24 +106,21 @@ 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",
|
||||
"-fno-stack-protector",
|
||||
"-fvisibility-inlines-hidden",
|
||||
"-Wno-type-limits",
|
||||
"-Werror=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();
|
||||
|
||||
@ -369,8 +365,6 @@ 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();
|
||||
@ -415,8 +409,8 @@ pub fn build(b: *std.Build) !void {
|
||||
break :blk llvm_directory.items;
|
||||
} else {
|
||||
break :blk switch (use_debug) {
|
||||
true => "../zig-bootstrap/out/x86_64-linux-musl-native",
|
||||
false => "../zig-bootstrap/out/x86_64-linux-musl-native",
|
||||
true => "../zig-bootstrap/out/x86_64-linux-musl-native-debug-static",
|
||||
false => "../zig-bootstrap/out/x86_64-linux-musl-native-release-static",
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -430,32 +424,29 @@ pub fn build(b: *std.Build) !void {
|
||||
}
|
||||
} else {
|
||||
compiler.linkSystemLibrary("LLVM");
|
||||
compiler.linkSystemLibrary("clang-cpp");
|
||||
compiler.linkSystemLibrary("lldCommon");
|
||||
compiler.linkSystemLibrary("lldCOFF");
|
||||
compiler.linkSystemLibrary("lldELF");
|
||||
compiler.linkSystemLibrary("lldMachO");
|
||||
compiler.linkSystemLibrary("lldWasm");
|
||||
// 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 or builtin.os.tag == .macos) "z" else "zlib");
|
||||
compiler.linkSystemLibrary("zstd");
|
||||
// compiler.linkSystemLibrary(if (is_ci) "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" });
|
||||
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.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" });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/lib/x86_64-linux-gnu" });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib/llvm-18/lib" });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib/llvm-17/lib" });
|
||||
} else {
|
||||
const result = try std.process.Child.run(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = b.allocator,
|
||||
.argv = &.{
|
||||
"c++", "--version",
|
||||
@ -471,15 +462,11 @@ pub fn build(b: *std.Build) !void {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
var tokenizer = std.mem.tokenizeScalar(u8, result.stdout, ' ');
|
||||
var tokenizer = std.mem.tokenize(u8, result.stdout, " ");
|
||||
const cxx_version = while (tokenizer.next()) |chunk| {
|
||||
if (std.ascii.isDigit(chunk[0])) {
|
||||
if (std.SemanticVersion.parse(chunk)) |sema_version| {
|
||||
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"),
|
||||
};
|
||||
break try std.fmt.allocPrint(b.allocator, "{}.{}.{}", .{sema_version.major, sema_version.minor, sema_version.patch});
|
||||
} else |err| err catch {};
|
||||
}
|
||||
} else {
|
||||
@ -487,30 +474,31 @@ 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(builtin.cpu.arch) ++ switch (builtin.cpu.arch) {
|
||||
.x86_64 => "-pc-linux-gnu",
|
||||
.aarch64 => "-redhat-linux",
|
||||
else => @compileError("Architecture not supported"),
|
||||
}
|
||||
});
|
||||
const cxx_include_arch = try std.mem.concat(b.allocator, u8, &.{ cxx_include_base, "/" ++ @tagName(@import("builtin").cpu.arch) ++ "-pc-linux-gnu" });
|
||||
compiler.addObjectFile(.{ .cwd_relative = "/usr/lib64/libstdc++.so.6" });
|
||||
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" });
|
||||
if (use_debug) {
|
||||
compiler.addIncludePath(.{ .cwd_relative = "../../local/llvm18-debug/include" });
|
||||
} else {
|
||||
compiler.addIncludePath(.{ .cwd_relative = "../../local/llvm18-release/include" });
|
||||
}
|
||||
compiler.addIncludePath(.{ .cwd_relative = "/usr/include" });
|
||||
compiler.addIncludePath(.{ .cwd_relative = cxx_include_base });
|
||||
compiler.addIncludePath(.{ .cwd_relative = cxx_include_arch });
|
||||
if (use_debug) {
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "../../local/llvm18-debug/lib" });
|
||||
} else {
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "../../local/llvm18-release/lib" });
|
||||
}
|
||||
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64" });
|
||||
}
|
||||
},
|
||||
.macos => {
|
||||
compiler.linkLibCpp();
|
||||
|
||||
if (discover_brew_prefix(b, "llvm@18")) |prefix| {
|
||||
llvm_prefix = prefix;
|
||||
if (discover_brew_prefix(b, "llvm@17")) |llvm_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" });
|
||||
try include_paths.append(llvm_include_path);
|
||||
compiler.addIncludePath(.{ .cwd_relative = llvm_include_path });
|
||||
compiler.addLibraryPath(.{ .cwd_relative = llvm_lib_path });
|
||||
} else |err| {
|
||||
return err;
|
||||
@ -534,12 +522,6 @@ 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");
|
||||
@ -563,15 +545,6 @@ 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");
|
||||
@ -621,6 +594,7 @@ pub fn build(b: *std.Build) !void {
|
||||
.root_source_file = b.path("build/test_runner.zig"),
|
||||
.target = native_target,
|
||||
.optimize = optimization,
|
||||
.single_threaded = true,
|
||||
});
|
||||
b.default_step.dependOn(&test_runner.step);
|
||||
|
||||
@ -629,22 +603,10 @@ 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");
|
||||
@ -653,11 +615,7 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
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,43 +31,37 @@ fn collectDirectoryDirEntries(allocator: Allocator, path: []const u8) ![]const [
|
||||
|
||||
const bootstrap_relative_path = "zig-out/bin/nat";
|
||||
|
||||
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,
|
||||
is_test: bool,
|
||||
fn runStandalone(allocator: Allocator, args: struct {
|
||||
directory_path: []const u8,
|
||||
group_name: []const u8,
|
||||
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{};
|
||||
is_test: bool,
|
||||
compiler_path: []const u8,
|
||||
}) !void {
|
||||
const test_names = try collectDirectoryDirEntries(allocator, args.directory_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});
|
||||
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 };
|
||||
// if (std.mem.eql(u8, args.compiler_path, "nat/compiler_lightly_optimize_for_speed")) @breakpoint();
|
||||
const compile_run = try std.process.Child.run(.{
|
||||
const compile_run = try std.ChildProcess.run(.{
|
||||
.allocator = allocator,
|
||||
// TODO: delete -main_source_file?
|
||||
.argv = argv,
|
||||
.max_output_bytes = std.math.maxInt(u64),
|
||||
});
|
||||
run.compilation_run += 1;
|
||||
ran_compilation_count += 1;
|
||||
|
||||
const compilation_result: TestError!bool = switch (compile_run.term) {
|
||||
.Exited => |exit_code| if (exit_code == 0) true else error.abnormal_exit_code,
|
||||
@ -77,7 +71,7 @@ fn compiler_run(allocator: Allocator, args: struct{
|
||||
};
|
||||
|
||||
const compilation_success = compilation_result catch b: {
|
||||
run.compilation_failure += 1;
|
||||
failed_compilation_count += 1;
|
||||
break :b false;
|
||||
};
|
||||
|
||||
@ -90,13 +84,13 @@ fn compiler_run(allocator: Allocator, args: struct{
|
||||
}
|
||||
|
||||
if (compilation_success and !args.self_hosted) {
|
||||
const test_path = try std.mem.concat(allocator, u8, &.{ "nat/", args.test_name });
|
||||
const test_run = try std.process.Child.run(.{
|
||||
const test_path = try std.mem.concat(allocator, u8, &.{ "nat/", test_name });
|
||||
const test_run = try std.ChildProcess.run(.{
|
||||
.allocator = allocator,
|
||||
.argv = &.{test_path},
|
||||
.max_output_bytes = std.math.maxInt(u64),
|
||||
});
|
||||
run.test_run += 1;
|
||||
ran_test_count += 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,
|
||||
@ -105,10 +99,9 @@ fn compiler_run(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});
|
||||
@ -121,55 +114,14 @@ fn compiler_run(allocator: Allocator, args: struct{
|
||||
}
|
||||
}
|
||||
|
||||
return run;
|
||||
}
|
||||
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 });
|
||||
|
||||
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) {
|
||||
if (failed_compilation_count > 0 or failed_test_count > 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,
|
||||
@ -627,67 +579,34 @@ 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();
|
||||
|
||||
try runStandalone(allocator, .{
|
||||
.is_test = false,
|
||||
.compiler_path = bootstrap_relative_path,
|
||||
var errors = run_test_suite(allocator, .{
|
||||
.self_hosted = false,
|
||||
.group_name = "STANDALONE",
|
||||
.directory_path = "retest/standalone",
|
||||
.repetitions = 1,
|
||||
.compiler_path = bootstrap_relative_path,
|
||||
});
|
||||
|
||||
try c_abi_tests(allocator);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
// }
|
||||
if (errors) {
|
||||
return error.fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,17 +4,12 @@ set -ex
|
||||
# Install LLVM and system dependencies
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x llvm.sh
|
||||
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
|
||||
sudo ./llvm.sh 17 all
|
||||
sudo apt install liblld-17-dev libclang-17-dev liblld-17 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 -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
|
||||
zig build test -Dthird_party_ci=true
|
||||
|
@ -3,14 +3,11 @@ set -ex
|
||||
|
||||
# Install LLVM and system dependencies
|
||||
brew update
|
||||
brew install llvm@18 ninja
|
||||
brew install llvm@17 ninja
|
||||
|
||||
# Install Zig
|
||||
source ci/download_zig.sh
|
||||
download_zig master aarch64-macos
|
||||
|
||||
# Build and test
|
||||
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
|
||||
zig build test -Dthird_party_ci=true
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn align_forward(n: u64, alignment: u64) u64 {
|
||||
const mask = alignment - 1;
|
||||
return (value + mask) & ~mask;
|
||||
fn[extern] exit(exit_code: s32) noreturn;
|
||||
fn my_exit(exit_code: s32) noreturn {
|
||||
exit(exit_code);
|
||||
}
|
||||
|
@ -1,481 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
fn [cc(.c)] main [export]() s32 {
|
||||
>a: s32 = 1;
|
||||
>b: s32 = 2;
|
||||
>c = a + b;
|
||||
>d: s32 = 3;
|
||||
>e = d - c;
|
||||
return e;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
>a: s32 = 5;
|
||||
>b: s32 = 4;
|
||||
>result = a & b;
|
||||
return result - b;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>array: [1]s32 = [0];
|
||||
return array[0];
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>n: s32 = 1;
|
||||
#assert(n);
|
||||
return n - n;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
import "file.nat";
|
||||
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
>result: s32 = file.foo();
|
||||
return result;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
// comment
|
||||
fn[cc(.c)]
|
||||
// comment
|
||||
main[export]()
|
||||
// comment
|
||||
s32 { // comment
|
||||
// comment
|
||||
return 0; // comment
|
||||
} // comment
|
@ -1,16 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
fn [cc(.c)] main [export]() s32
|
||||
{
|
||||
>result: s32 = 0;
|
||||
return result;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>dividend: s32 = 30;
|
||||
>divisor: s32 = 6;
|
||||
>result = dividend / divisor;
|
||||
>n: s32 = 5;
|
||||
return n - result;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>result: s32 = 0;
|
||||
if (result > 0) {
|
||||
return 1;
|
||||
} else if (result == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fn [cc(.c)] main [export] (argc: s32) s32 {
|
||||
return argc - argc;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
>n: s32 = 5;
|
||||
fn foo() s32 {
|
||||
return n;
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>fn_pointer = foo&;
|
||||
>a = fn_pointer();
|
||||
return a - n;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
>n: s32 = 1;
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
n = 0;
|
||||
return n;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fn foo() s32 {
|
||||
return 1;
|
||||
}
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a = foo();
|
||||
if (a == 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 0xffffffff;
|
||||
#assert(#leading_zeroes(a) == 0);
|
||||
>b: s32 = 0x1fffffff;
|
||||
#assert(#leading_zeroes(b) == 3);
|
||||
return 0;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
>top: s32 = 10;
|
||||
loop (i < top) {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return i - top;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
>n: s32 = 5;
|
||||
loop (i < 10) {
|
||||
i += 1;
|
||||
if (i == n) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return i - n;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
|
||||
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;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
>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);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
>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));
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>i: s32 = 0;
|
||||
loop (i < 1) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 5;
|
||||
>b: s32 = 4;
|
||||
return (a * b) - (a * b);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
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);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 0xffff;
|
||||
>b: s32 = 0xffff0000;
|
||||
>c: s32 = 0xffffffff;
|
||||
>result = c - (a | b);
|
||||
return result;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
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;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
return foo();
|
||||
}
|
||||
|
||||
fn foo() s32 {
|
||||
return 0;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
struct SimplePolymorphic[$T] {
|
||||
member: T,
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>s: SimplePolymorphic[s32] = {
|
||||
.member = 0,
|
||||
};
|
||||
return s.member;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 0;
|
||||
>pointer = a&;
|
||||
pointer@ = 4;
|
||||
return pointer@ - a;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 1;
|
||||
>b: s32 = a << 5;
|
||||
>c: s32 = b >> 5;
|
||||
return c - a;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>constant: s32 = 4;
|
||||
>result: s32 = 0;
|
||||
|
||||
if (result > 0) {
|
||||
result = constant - 1;
|
||||
} else {
|
||||
result = constant;
|
||||
}
|
||||
|
||||
return result - constant;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>sizeofu32: s32 = #size(u32);
|
||||
>sizeofu16: s32 = #size(u16);
|
||||
|
||||
return sizeofu32 - (2 * sizeofu16);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
struct Struct {
|
||||
a: s32,
|
||||
}
|
||||
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>result: Struct = {
|
||||
.a = 0,
|
||||
};
|
||||
return result.a;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn[cc(.c)] main[export]() s32 {
|
||||
>a: s32 = 7;
|
||||
#assert(#trailing_zeroes(a) == 0);
|
||||
>b: s32 = 8;
|
||||
#assert(#trailing_zeroes(b) == 3);
|
||||
return 0;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
fn [cc(.c)] main [export] () s32 {
|
||||
>a: s32 = 561;
|
||||
>b: s32 = 124;
|
||||
>c = a ^ b;
|
||||
>d = a ^ b;
|
||||
return c ^ d;
|
||||
}
|
14
script.sh
14
script.sh
@ -1,14 +0,0 @@
|
||||
#!/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,7 +28,6 @@
|
||||
#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"
|
||||
@ -39,15 +38,12 @@
|
||||
#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
|
||||
@ -186,43 +182,6 @@ 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();
|
||||
|
||||
@ -262,10 +221,6 @@ 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();
|
||||
|
||||
llvm::opt::Visibility VisibilityMask(options::CC1AsOption);
|
||||
const unsigned IncludedFlagsBitmask = options::CC1AsOption;
|
||||
unsigned MissingArgIndex, MissingArgCount;
|
||||
InputArgList Args =
|
||||
OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount, VisibilityMask);
|
||||
InputArgList Args = OptTbl.ParseArgs(Argv, MissingArgIndex, MissingArgCount,
|
||||
IncludedFlagsBitmask);
|
||||
|
||||
// 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, VisibilityMask) > 1)
|
||||
if (OptTbl.findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
|
||||
Diags.Report(diag::err_drv_unknown_argument) << ArgString;
|
||||
else
|
||||
Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
|
||||
@ -643,10 +643,9 @@ 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", /*ShowHidden=*/false,
|
||||
/*ShowAllAliases=*/false,
|
||||
llvm::opt::Visibility(driver::options::CC1AsOption));
|
||||
|
||||
"Clang Integrated Assembler",
|
||||
/*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
|
||||
/*ShowAllAliases=*/false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#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"
|
||||
@ -64,7 +65,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);
|
||||
return std::string(ExecutablePath.str());
|
||||
}
|
||||
|
||||
// This just needs to be some symbol in the binary; C++ doesn't
|
||||
@ -78,9 +79,9 @@ static const char *GetStableCStr(std::set<std::string> &SavedStrings,
|
||||
return SavedStrings.insert(std::string(S)).first->c_str();
|
||||
}
|
||||
|
||||
/// ApplyOneQAOverride - Apply a list of edits to the input argument lists.
|
||||
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
||||
///
|
||||
/// The input string is a space separated list of edits to perform,
|
||||
/// The input string is a space separate list of edits to perform,
|
||||
/// they are applied in order to the input argument lists. Edits
|
||||
/// should be one of the following forms:
|
||||
///
|
||||
@ -121,7 +122,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.ends_with("/") &&
|
||||
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
||||
Edit.slice(2, Edit.size() - 1).contains('/')) {
|
||||
StringRef MatchPattern = Edit.substr(2).split('/').first;
|
||||
StringRef ReplPattern = Edit.substr(2).split('/').second;
|
||||
@ -176,7 +177,7 @@ static void ApplyOneQAOverride(raw_ostream &OS,
|
||||
}
|
||||
}
|
||||
|
||||
/// ApplyQAOverride - Apply a space separated list of edits to the
|
||||
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
||||
/// input argument lists. See ApplyOneQAOverride.
|
||||
static void ApplyQAOverride(SmallVectorImpl<const char*> &Args,
|
||||
const char *OverrideStr,
|
||||
@ -370,6 +371,14 @@ 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");
|
||||
@ -396,7 +405,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
|
||||
}
|
||||
|
||||
// Handle -cc1 integrated tools.
|
||||
if (Args.size() >= 2 && StringRef(Args[1]).starts_with("-cc1"))
|
||||
if (Args.size() >= 2 && StringRef(Args[1]).startswith("-cc1"))
|
||||
return ExecuteCC1Tool(Args, ToolContext);
|
||||
|
||||
// Handle options that need handling before the real command line parsing in
|
||||
@ -597,6 +606,6 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
|
||||
return Res;
|
||||
}
|
||||
|
||||
extern "C" int nat_clang_main(int argc, char ** argv) {
|
||||
extern "C" int NativityClangMain(int argc, char **argv) {
|
||||
return clang_main(argc, argv, {argv[0], nullptr, false});
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
#include "llvm/Bitcode/BitcodeReader.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
|
||||
|
||||
@ -22,17 +23,6 @@
|
||||
|
||||
|
||||
using namespace llvm;
|
||||
using llvm::orc::ThreadSafeContext;
|
||||
using llvm::orc::ThreadSafeModule;
|
||||
|
||||
extern "C" void NativityLLVMInitializeAll()
|
||||
{
|
||||
InitializeAllTargetInfos();
|
||||
InitializeAllTargets();
|
||||
InitializeAllTargetMCs();
|
||||
InitializeAllAsmParsers();
|
||||
InitializeAllAsmPrinters();
|
||||
}
|
||||
|
||||
extern "C" LLVMContext* NativityLLVMCreateContext()
|
||||
{
|
||||
@ -44,10 +34,6 @@ 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;
|
||||
}
|
||||
|
||||
@ -116,16 +102,6 @@ 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);
|
||||
@ -142,11 +118,6 @@ 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));
|
||||
@ -174,7 +145,6 @@ 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;
|
||||
}
|
||||
|
||||
@ -244,25 +214,11 @@ 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);
|
||||
@ -331,14 +287,6 @@ extern "C" StructType* NativityLLVMGetStructType(LLVMContext& context, Type** ty
|
||||
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();
|
||||
@ -406,12 +354,6 @@ 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);
|
||||
@ -496,13 +438,6 @@ 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};
|
||||
@ -654,6 +589,13 @@ 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);
|
||||
@ -845,12 +787,6 @@ 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();
|
||||
@ -957,6 +893,14 @@ 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)
|
||||
{
|
||||
@ -976,19 +920,20 @@ 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, CodeGenOptLevel optimization_level, bool jit)
|
||||
{
|
||||
auto target_triple = StringRef(target_triple_ptr, target_triple_len);
|
||||
auto cpu = StringRef(cpu_ptr, cpu_len);
|
||||
auto features = StringRef(features_ptr, features_len);
|
||||
TargetOptions target_options;
|
||||
std::optional<CodeModel::Model> code_model = std::nullopt;
|
||||
if (is_code_model_present) {
|
||||
code_model = maybe_code_model;
|
||||
}
|
||||
TargetMachine* target_machine = target.createTargetMachine(target_triple, cpu, features, target_options, relocation_model, code_model, optimization_level, jit);
|
||||
return target_machine;
|
||||
}
|
||||
// TODO:
|
||||
// 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)
|
||||
// {
|
||||
// auto target_triple = StringRef(target_triple_ptr, target_triple_len);
|
||||
// auto cpu = StringRef(cpu_ptr, cpu_len);
|
||||
// auto features = StringRef(features_ptr, features_len);
|
||||
// TargetOptions target_options;
|
||||
// std::optional<CodeModel::Model> code_model = std::nullopt;
|
||||
// if (is_code_model_present) {
|
||||
// code_model = maybe_code_model;
|
||||
// }
|
||||
// TargetMachine* target_machine = target.createTargetMachine(target_triple, cpu, features, target_options, relocation_model, code_model, optimization_level, jit);
|
||||
// return target_machine;
|
||||
// }
|
||||
|
||||
extern "C" void NativityLLVMModuleSetTargetMachineDataLayout(Module& module, TargetMachine& target_machine)
|
||||
{
|
||||
@ -1108,26 +1053,18 @@ extern "C" AttributeSet NativityLLVMContextGetAttributeSet(LLVMContext& context,
|
||||
return attribute_set;
|
||||
}
|
||||
|
||||
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)
|
||||
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)
|
||||
{
|
||||
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);
|
||||
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));
|
||||
function.setAttributes(attribute_list);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
extern "C" CallInst* NativityLLVMBuilderCreateMemcpy(IRBuilder<>& builder, Value* destination, uint32_t destination_alignment, Value* source, uint32_t source_alignment, uint64_t size, bool is_volatile)
|
||||
@ -1139,13 +1076,6 @@ 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,7 +2726,6 @@ 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);
|
||||
@ -5424,35 +5423,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