- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
function main() {
print("Hello", 1, false, true, parseInt("01"), parseFloat("00.1"));
}
// ASM
; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
@__true__ = internal constant [5 x i8] c"true\00"
@__false__ = internal constant [6 x i8] c"false\00"
@frmt_9481649210695450612 = internal constant [19 x i8] c"%s %d %s %s %d %f\0A\00"
@s_3144841719139014728 = internal constant [5 x i8] c"00.1\00"
@s_12300967985959445949 = internal constant [3 x i8] c"01\00"
@s_1772061916968062023 = internal constant [6 x i8] c"Hello\00"
declare i8* @malloc(i64)
declare void @free(i8*)
declare i32 @printf(i8*, ...)
declare float @atof(i8*)
declare i32 @atoi(i8*)
define void @main() !dbg !3 {
%1 = call i32 @atoi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @s_12300967985959445949, i64 0, i64 0)), !dbg !7
%2 = call float @atof(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @s_3144841719139014728, i64 0, i64 0)), !dbg !9
%3 = fpext float %2 to double, !dbg !10
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @frmt_9481649210695450612, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @s_1772061916968062023, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__false__, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__true__, i64 0, i64 0), i32 %1, double %3), !dbg !10
br label %5, !dbg !11
5: ; preds = %0
ret void, !dbg !11
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2}
Продолжение писания уе..(зачеркнуто) супер компилятора с TypeScript (JavaScript) в нативный код.
как обычно компилим просто
set LIBPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc 15\VC\lib
set SDKPATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\SDK\ScopeCppSDK\vc 15\SDK\lib
tsc.exe --emit=llvm C:\temp\1.ts 2>1.ll
llc.exe --filetype=obj -o=out.o 1.ll
lld.exe -flavor link out.o "%LIBPATH%\libcmt.lib" "%LIBPATH%\libvcruntime.lib" "%SDKPATH%\kernel32.lib" "%SDKPATH%\libucrt.lib" "%SDKPATH%\uuid.lib"
получаетм Ехе и грузим его. и результат
=====================================
и выполнение
C:\>out.exe
Hello 1 false true 1 0.100000