Implement static finalize / initialize. Version bump.

This commit is contained in:
Christoffer Lerno
2022-09-28 17:03:30 +02:00
committed by Christoffer Lerno
parent 58647043f4
commit e1b5b0b60c
33 changed files with 478 additions and 44 deletions

View File

@@ -0,0 +1,16 @@
static initialize @priority("hello") // #error: Expected an argument to '@priority'
{
}
static initialize @priority(1, 2) // #error: Too many arguments for
{
}
static initialize @priority(0) // #error: Expected an argument to '@priority'
{
}
static initialize @priority(65536) // #error: Expected an argument to '@priority'
{
}

View File

@@ -0,0 +1,62 @@
// #target: linux-x64
module test;
import std::io;
fn void main()
{
io::println("Hello, world!");
}
extern fn void puts(char*);
static initialize @priority(300)
{
puts("Hello startup2");
}
static initialize
{
puts("Let's start main...");
}
static initialize @priority(200)
{
puts("Hello startup");
}
static initialize
{}
static finalize
{
puts("Bye bye");
}
/* #expect: test.ll
@llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 300, void ()* @.static_initialize.0, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @.static_initialize.1, i8* null }, { i32, void ()*, i8* } { i32 200, void ()* @.static_initialize.2, i8* null }]
@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @.static_finalize.0, i8* null }]
define void @.static_initialize.0() {
entry:
call void @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0))
ret void
}
; Function Attrs: nounwind
declare void @puts(i8*) #0
define void @.static_initialize.1() {
entry:
call void @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i32 0, i32 0))
ret void
}
define void @.static_initialize.2() {
entry:
call void @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i32 0, i32 0))
ret void
}
define void @.static_finalize.0() {
entry:
call void @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0))
ret void
}

View File

@@ -0,0 +1,9 @@
static initialize
{
return; // This is fine
}
static initialize
{
return 123; // #error: You cannot cast 'int' into 'void' even with an explicit cast, so this looks like an error.
}

View File

@@ -0,0 +1 @@
static foo {} ; // #error: Expected 'static initialize'

View File

@@ -0,0 +1,3 @@
static initialize @priority() // #error: An expression was expected.
{
}