mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add macro method test update LLVM version for MSVC.
This commit is contained in:
@@ -55,11 +55,11 @@ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
|||||||
endif()
|
endif()
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
LLVM_Windows
|
LLVM_Windows
|
||||||
URL https://github.com/c3lang/win-llvm/releases/download/llvm-vs22/llvm-14.0.1-windows-amd64-msvc17-libcmt.7z
|
URL https://github.com/c3lang/win-llvm/releases/download/llvm1406/llvm-14.0.6-windows-amd64-msvc17-libcmt.7z
|
||||||
)
|
)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
LLVM_Windows_debug
|
LLVM_Windows_debug
|
||||||
URL https://github.com/c3lang/win-llvm/releases/download/llvm-vs22/llvm-14.0.1-windows-amd64-msvc17-libcmt-dbg.7z
|
URL https://github.com/c3lang/win-llvm/releases/download/llvm1406/llvm-14.0.6-windows-amd64-msvc17-libcmt-dbg.7z
|
||||||
)
|
)
|
||||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
message("Loading Windows LLVM debug libraries, this may take a while...")
|
message("Loading Windows LLVM debug libraries, this may take a while...")
|
||||||
|
|||||||
@@ -254,6 +254,8 @@ You should now have a `c3c` executable.
|
|||||||
|
|
||||||
You can try it out by running some sample code: `c3c.exe compile ../resources/examples/hash.c3`
|
You can try it out by running some sample code: `c3c.exe compile ../resources/examples/hash.c3`
|
||||||
|
|
||||||
|
*Note that if you run into linking issues when building, make sure that you are using the latest version of VS17.*
|
||||||
|
|
||||||
|
|
||||||
#### Compiling on Ubuntu 20.10
|
#### Compiling on Ubuntu 20.10
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
// #target: macos-x64
|
||||||
|
module foo;
|
||||||
|
|
||||||
|
extern fn void printf(char* fmt, ...);
|
||||||
|
struct Foo
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
}
|
||||||
|
|
||||||
|
macro void Foo.@hello(Foo &this) { this.x = 3; printf("-%d\n", this.x); }
|
||||||
|
macro void Foo.hello(Foo* this) { this.x = 4; printf("-%d\n", this.x); }
|
||||||
|
macro void Foo.hello2(Foo this) { this.x = 5; printf("-%d\n", this.x); }
|
||||||
|
|
||||||
|
fn void main()
|
||||||
|
{
|
||||||
|
Foo a;
|
||||||
|
a.@hello();
|
||||||
|
printf("%d\n", a.x);
|
||||||
|
a.hello();
|
||||||
|
printf("%d\n", a.x);
|
||||||
|
a.hello2();
|
||||||
|
printf("%d\n", a.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #expect: foo.ll
|
||||||
|
|
||||||
|
define void @foo_main() #0 {
|
||||||
|
entry:
|
||||||
|
%a = alloca %Foo, align 4
|
||||||
|
%this = alloca %Foo*, align 8
|
||||||
|
%this1 = alloca %Foo, align 4
|
||||||
|
%0 = bitcast %Foo* %a to i32*
|
||||||
|
store i32 0, i32* %0, align 4
|
||||||
|
%1 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
||||||
|
store i32 3, i32* %1, align 4
|
||||||
|
%2 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
||||||
|
%3 = load i32, i32* %2, align 4
|
||||||
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 %3)
|
||||||
|
%4 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
||||||
|
%5 = load i32, i32* %4, align 4
|
||||||
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %5)
|
||||||
|
store %Foo* %a, %Foo** %this, align 8
|
||||||
|
%6 = load %Foo*, %Foo** %this, align 8
|
||||||
|
%7 = getelementptr inbounds %Foo, %Foo* %6, i32 0, i32 0
|
||||||
|
store i32 4, i32* %7, align 8
|
||||||
|
%8 = load %Foo*, %Foo** %this, align 8
|
||||||
|
%9 = getelementptr inbounds %Foo, %Foo* %8, i32 0, i32 0
|
||||||
|
%10 = load i32, i32* %9, align 8
|
||||||
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 %10)
|
||||||
|
%11 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
||||||
|
%12 = load i32, i32* %11, align 4
|
||||||
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %12)
|
||||||
|
%13 = bitcast %Foo* %this1 to i8*
|
||||||
|
%14 = bitcast %Foo* %a to i8*
|
||||||
|
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %13, i8* align 4 %14, i32 4, i1 false)
|
||||||
|
%15 = getelementptr inbounds %Foo, %Foo* %this1, i32 0, i32 0
|
||||||
|
store i32 5, i32* %15, align 4
|
||||||
|
%16 = getelementptr inbounds %Foo, %Foo* %this1, i32 0, i32 0
|
||||||
|
%17 = load i32, i32* %16, align 4
|
||||||
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i32 %17)
|
||||||
|
%18 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
|
||||||
|
%19 = load i32, i32* %18, align 4
|
||||||
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i32 %19)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// #target: macos-x64
|
||||||
|
module foo;
|
||||||
|
|
||||||
|
extern fn void printf(char* fmt, ...);
|
||||||
|
struct Foo
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
}
|
||||||
|
|
||||||
|
macro void Foo.@hello(Foo &this) { this.x = 3; printf("-%d\n", this.x); }
|
||||||
|
macro void Foo.hello(Foo* this) { this.x = 4; printf("-%d\n", this.x); }
|
||||||
|
macro void Foo.hello2(Foo this) { this.x = 5; printf("-%d\n", this.x); }
|
||||||
|
|
||||||
|
fn void main()
|
||||||
|
{
|
||||||
|
Foo a;
|
||||||
|
a.@hello();
|
||||||
|
printf("%d\n", a.x);
|
||||||
|
a.hello();
|
||||||
|
printf("%d\n", a.x);
|
||||||
|
a.hello2();
|
||||||
|
printf("%d\n", a.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #expect: foo.ll
|
||||||
|
|
||||||
|
define void @foo_main() #0 {
|
||||||
|
entry:
|
||||||
|
%a = alloca %Foo, align 4
|
||||||
|
%this = alloca ptr, align 8
|
||||||
|
%this1 = alloca %Foo, align 4
|
||||||
|
store i32 0, ptr %a, align 4
|
||||||
|
%0 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
|
||||||
|
store i32 3, ptr %0, align 4
|
||||||
|
%1 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
|
||||||
|
%2 = load i32, ptr %1, align 4
|
||||||
|
call void (ptr, ...) @printf(ptr @.str, i32 %2)
|
||||||
|
%3 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
|
||||||
|
%4 = load i32, ptr %3, align 4
|
||||||
|
call void (ptr, ...) @printf(ptr @.str.1, i32 %4)
|
||||||
|
store ptr %a, ptr %this, align 8
|
||||||
|
%5 = load ptr, ptr %this, align 8
|
||||||
|
%6 = getelementptr inbounds %Foo, ptr %5, i32 0, i32 0
|
||||||
|
store i32 4, ptr %6, align 8
|
||||||
|
%7 = load ptr, ptr %this, align 8
|
||||||
|
%8 = getelementptr inbounds %Foo, ptr %7, i32 0, i32 0
|
||||||
|
%9 = load i32, ptr %8, align 8
|
||||||
|
call void (ptr, ...) @printf(ptr @.str.2, i32 %9)
|
||||||
|
%10 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
|
||||||
|
%11 = load i32, ptr %10, align 4
|
||||||
|
call void (ptr, ...) @printf(ptr @.str.3, i32 %11)
|
||||||
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %this1, ptr align 4 %a, i32 4, i1 false)
|
||||||
|
%12 = getelementptr inbounds %Foo, ptr %this1, i32 0, i32 0
|
||||||
|
store i32 5, ptr %12, align 4
|
||||||
|
%13 = getelementptr inbounds %Foo, ptr %this1, i32 0, i32 0
|
||||||
|
%14 = load i32, ptr %13, align 4
|
||||||
|
call void (ptr, ...) @printf(ptr @.str.4, i32 %14)
|
||||||
|
%15 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
|
||||||
|
%16 = load i32, ptr %15, align 4
|
||||||
|
call void (ptr, ...) @printf(ptr @.str.5, i32 %16)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user