Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "spec"
require "llvm"
require "compiler/crystal/codegen/abi/aarch64"

{% if LibLLVM::BUILT_TARGETS.includes?(:aarch64) %}
LLVM.init_aarch64
Expand All @@ -10,18 +11,18 @@ private def abi
target = LLVM::Target.from_triple(triple)
machine = target.create_target_machine(triple)
machine.enable_global_isel = false
LLVM::ABI::AArch64.new(machine)
Crystal::ABI::AArch64.new(machine)
end

private def test(msg, &block : LLVM::ABI, LLVM::Context ->)
private def test(msg, &block : Crystal::ABI, LLVM::Context ->)
it msg do
abi = abi()
ctx = LLVM::Context.new
block.call(abi, ctx)
end
end

class LLVM::ABI
class Crystal::ABI
describe AArch64 do
{% if LibLLVM::BUILT_TARGETS.includes?(:aarch64) %}
describe "align" do
Expand Down Expand Up @@ -142,7 +143,7 @@ class LLVM::ABI
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.indirect(str, nil))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end

test "does with homogeneous structs" do |abi, ctx|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "spec"
require "llvm"
require "compiler/crystal/codegen/abi/arm"

{% if LibLLVM::BUILT_TARGETS.includes?(:arm) %}
LLVM.init_arm
Expand All @@ -10,18 +11,18 @@ private def abi
target = LLVM::Target.from_triple(triple)
machine = target.create_target_machine(triple)
machine.enable_global_isel = false
LLVM::ABI::ARM.new(machine)
Crystal::ABI::ARM.new(machine)
end

private def test(msg, &block : LLVM::ABI, LLVM::Context ->)
private def test(msg, &block : Crystal::ABI, LLVM::Context ->)
it msg do
abi = abi()
ctx = LLVM::Context.new
block.call(abi, ctx)
end
end

class LLVM::ABI
class Crystal::ABI
describe ARM do
{% if LibLLVM::BUILT_TARGETS.includes?(:arm) %}
describe "align" do
Expand Down Expand Up @@ -130,7 +131,7 @@ class LLVM::ABI
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.direct(str, cast: ctx.int64.array(2)))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end

test "does with structs between 64 and 128 bits" do |abi, ctx|
Expand All @@ -142,7 +143,7 @@ class LLVM::ABI
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.direct(str, cast: ctx.int64.array(3)))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end
end
{% end %}
Expand Down
51 changes: 26 additions & 25 deletions spec/std/llvm/avr_spec.cr → spec/compiler/codegen/abi/avr_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "spec"
require "llvm"
require "compiler/crystal/codegen/abi/avr"

{% if LibLLVM::BUILT_TARGETS.includes?(:avr) %}
LLVM.init_avr
Expand All @@ -10,18 +11,18 @@ private def abi
target = LLVM::Target.from_triple(triple)
machine = target.create_target_machine(triple)
machine.enable_global_isel = false
LLVM::ABI::AVR.new(machine)
Crystal::ABI::AVR.new(machine)
end

private def test(msg, &block : LLVM::ABI, LLVM::Context ->)
private def test(msg, &block : Crystal::ABI, LLVM::Context ->)
it msg do
abi = abi()
ctx = LLVM::Context.new
block.call(abi, ctx)
end
end

class LLVM::ABI
class Crystal::ABI
describe AVR do
{% if LibLLVM::BUILT_TARGETS.includes?(:avr) %}
describe "align" do
Expand Down Expand Up @@ -104,9 +105,9 @@ class LLVM::ABI
info = abi.abi_info([ctx.int{{bits}}], ctx.int{{bits}}, true, ctx)
info.arg_types.size.should eq(1)
info.arg_types[0].should eq(arg_type)
info.arg_types[0].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[0].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.return_type.should eq(arg_type)
info.return_type.kind.should eq(LLVM::ABI::ArgKind::Direct)
info.return_type.kind.should eq(Crystal::ABI::ArgKind::Direct)
end
{% end %}

Expand All @@ -115,37 +116,37 @@ class LLVM::ABI
info = abi.abi_info([ctx.float], ctx.float, true, ctx)
info.arg_types.size.should eq(1)
info.arg_types[0].should eq(arg_type)
info.arg_types[0].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[0].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.return_type.should eq(arg_type)
info.return_type.kind.should eq(LLVM::ABI::ArgKind::Direct)
info.return_type.kind.should eq(Crystal::ABI::ArgKind::Direct)
end

test "double" do |abi, ctx|
arg_type = ArgType.direct(ctx.double)
info = abi.abi_info([ctx.double], ctx.double, true, ctx)
info.arg_types.size.should eq(1)
info.arg_types[0].should eq(arg_type)
info.arg_types[0].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[0].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.return_type.should eq(arg_type)
info.return_type.kind.should eq(LLVM::ABI::ArgKind::Direct)
info.return_type.kind.should eq(Crystal::ABI::ArgKind::Direct)
end

test "multiple arguments" do |abi, ctx|
args = 9.times.map { ctx.int16 }.to_a
info = abi.abi_info(args, ctx.int8, false, ctx)
info.arg_types.size.should eq(9)
info.arg_types.each(&.kind.should eq(LLVM::ABI::ArgKind::Direct))
info.arg_types.each(&.kind.should eq(Crystal::ABI::ArgKind::Direct))
end

test "multiple arguments above registers" do |abi, ctx|
args = 5.times.map { ctx.int32 }.to_a
info = abi.abi_info(args, ctx.int8, false, ctx)
info.arg_types.size.should eq(5)
info.arg_types[0].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[1].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[2].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[3].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[4].kind.should eq(LLVM::ABI::ArgKind::Indirect)
info.arg_types[0].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[1].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[2].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[3].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[4].kind.should eq(Crystal::ABI::ArgKind::Indirect)
end

test "struct args within 18 bytes" do |abi, ctx|
Expand All @@ -156,9 +157,9 @@ class LLVM::ABI
]
info = abi.abi_info(args, ctx.void, false, ctx)
info.arg_types.size.should eq(3)
info.arg_types[0].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[1].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[2].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[0].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[1].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[2].kind.should eq(Crystal::ABI::ArgKind::Direct)
end

test "struct args over 18 bytes" do |abi, ctx|
Expand All @@ -169,21 +170,21 @@ class LLVM::ABI
]
info = abi.abi_info(args, ctx.void, false, ctx)
info.arg_types.size.should eq(3)
info.arg_types[0].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[1].kind.should eq(LLVM::ABI::ArgKind::Direct)
info.arg_types[2].kind.should eq(LLVM::ABI::ArgKind::Indirect)
info.arg_types[0].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[1].kind.should eq(Crystal::ABI::ArgKind::Direct)
info.arg_types[2].kind.should eq(Crystal::ABI::ArgKind::Indirect)
end

test "returns struct within 8 bytes" do |abi, ctx|
rty = ctx.struct([ctx.int32, ctx.int32])
info = abi.abi_info([] of Type, rty, true, ctx)
info.return_type.kind.should eq(LLVM::ABI::ArgKind::Direct)
info = abi.abi_info([] of LLVM::Type, rty, true, ctx)
info.return_type.kind.should eq(Crystal::ABI::ArgKind::Direct)
end

test "returns struct over 8 bytes" do |abi, ctx|
rty = ctx.struct([ctx.int32, ctx.int32, ctx.int8])
info = abi.abi_info([] of Type, rty, true, ctx)
info.return_type.kind.should eq(LLVM::ABI::ArgKind::Indirect)
info = abi.abi_info([] of LLVM::Type, rty, true, ctx)
info.return_type.kind.should eq(Crystal::ABI::ArgKind::Indirect)
end
end
{% end %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "spec"
require "llvm"
require "compiler/crystal/codegen/abi/x86_64"
require "compiler/crystal/codegen/abi/x86_win64"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
LLVM.init_x86
Expand All @@ -10,18 +12,18 @@ private def abi(win64 = false)
target = LLVM::Target.from_triple(triple)
machine = target.create_target_machine(triple)
machine.enable_global_isel = false
win64 ? LLVM::ABI::X86_Win64.new(machine) : LLVM::ABI::X86_64.new(machine)
win64 ? Crystal::ABI::X86_Win64.new(machine) : Crystal::ABI::X86_64.new(machine)
end

private def test(msg, *, win64 = false, file = __FILE__, line = __LINE__, &block : LLVM::ABI, LLVM::Context ->)
private def test(msg, *, win64 = false, file = __FILE__, line = __LINE__, &block : Crystal::ABI, LLVM::Context ->)
it msg, file: file, line: line do
abi = abi(win64)
ctx = LLVM::Context.new
block.call(abi, ctx)
end
end

class LLVM::ABI
class Crystal::ABI
describe X86_64 do
{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
describe "align" do
Expand Down Expand Up @@ -141,8 +143,8 @@ class LLVM::ABI
info = abi.abi_info(arg_types, return_type, true, ctx)
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.indirect(str, Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.arg_types[0].should eq(ArgType.indirect(str, LLVM::Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end
end
{% end %}
Expand All @@ -159,8 +161,8 @@ class LLVM::ABI
info = abi.abi_info(arg_types, return_type, true, ctx)
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.indirect(str, Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.arg_types[0].should eq(ArgType.indirect(str, LLVM::Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end

test "does with structs larger than 128 bits", win64: true do |abi, ctx|
Expand All @@ -171,8 +173,8 @@ class LLVM::ABI
info = abi.abi_info(arg_types, return_type, true, ctx)
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.indirect(str, Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.arg_types[0].should eq(ArgType.indirect(str, LLVM::Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end

test "does with packed struct containing unaligned fields (#9873)" do |abi, ctx|
Expand All @@ -183,8 +185,8 @@ class LLVM::ABI
info = abi.abi_info(arg_types, return_type, true, ctx)
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.indirect(str, Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.arg_types[0].should eq(ArgType.indirect(str, LLVM::Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end

test "does with packed struct not containing unaligned fields" do |abi, ctx|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "spec"
require "llvm"
require "compiler/crystal/codegen/abi/x86"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
LLVM.init_x86
Expand All @@ -16,18 +17,18 @@ private def abi
target = LLVM::Target.from_triple(triple)
machine = target.create_target_machine(triple)
machine.enable_global_isel = false
LLVM::ABI::X86.new(machine)
Crystal::ABI::X86.new(machine)
end

private def test(msg, &block : LLVM::ABI, LLVM::Context ->)
private def test(msg, &block : Crystal::ABI, LLVM::Context ->)
it msg do
abi = abi()
ctx = LLVM::Context.new
block.call(abi, ctx)
end
end

class LLVM::ABI
class Crystal::ABI
describe X86 do
{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
describe "align" do
Expand Down Expand Up @@ -147,8 +148,8 @@ class LLVM::ABI
info = abi.abi_info(arg_types, return_type, true, ctx)
info.arg_types.size.should eq(1)

info.arg_types[0].should eq(ArgType.indirect(str, Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, Attribute::StructRet))
info.arg_types[0].should eq(ArgType.indirect(str, LLVM::Attribute::ByVal))
info.return_type.should eq(ArgType.indirect(str, LLVM::Attribute::StructRet))
end
end
{% end %}
Expand Down
Loading
Loading