translator: add assert to stdlib
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
external fun assert_c(value: Boolean)
|
||||
|
||||
fun assert(value: Boolean) {
|
||||
println(value)
|
||||
assert_c(value)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
; ModuleID = 'assert_arm.c'
|
||||
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
|
||||
target triple = "thumbv7m-none--eabi"
|
||||
|
||||
; Function Attrs: nounwind
|
||||
define weak void @assert_c(i32 %value) #0 {
|
||||
%1 = alloca i32, align 4
|
||||
store i32 %value, i32* %1, align 4
|
||||
ret void
|
||||
}
|
||||
|
||||
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
@@ -0,0 +1,36 @@
|
||||
; ModuleID = 'assert_x86.c'
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-pc-linux-gnu"
|
||||
|
||||
@.str = private unnamed_addr constant [71 x i8] c"Exception in thread \22main\22 java.lang.AssertionError: Assertion failed\0A\00", align 1
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define void @assert_c(i32 %value) #0 {
|
||||
%1 = alloca i32, align 4
|
||||
store i32 %value, i32* %1, align 4
|
||||
%2 = load i32* %1, align 4
|
||||
%3 = icmp ne i32 %2, 0
|
||||
br i1 %3, label %6, label %4
|
||||
|
||||
; <label>:4 ; preds = %0
|
||||
%5 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([71 x i8]* @.str, i32 0, i32 0))
|
||||
call void @abort() #3
|
||||
unreachable
|
||||
|
||||
; <label>:6 ; preds = %0
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(i8*, ...) #1
|
||||
|
||||
; Function Attrs: noreturn nounwind
|
||||
declare void @abort() #2
|
||||
|
||||
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #2 = { noreturn nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #3 = { noreturn nounwind }
|
||||
|
||||
!llvm.ident = !{!0}
|
||||
|
||||
!0 = !{!"Ubuntu clang version 3.6.2-3ubuntu2 (tags/RELEASE_362/final) (based on LLVM 3.6.2)"}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void assert_c(int value) {
|
||||
if (!value) {
|
||||
printf("Exception in thread \"main\" java.lang.AssertionError: Assertion failed\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user