wy2249 / Digo

Distributed Go-like Language
http://www.cs.columbia.edu/~sedwards/classes/2021/4115-spring/reports/Digo.pdf
3 stars 0 forks source link

Digo library API #18

Open sdh21 opened 3 years ago

sdh21 commented 3 years ago

Updated 2021/4/11

Async library 的导出函数:

  1. String 相关

    
    (1)  declare dso_local i8* @CreateString(i8*)   ; Accepts a C-layout string and returns a wrapped Digo String object
      Example: 
      Defined at the beginning of the LLVM IR:
      @.str.test.number2000 = private unnamed_addr constant [6 x i8] c"2000\0A\00", align 1
    
      define i8* @ConstStringToDigoString(i8* %c_layout_string) {
             %r1 = call i8* @CreateString(i8* %c_layout_string)
             ret i8* %r1
      }

(2) declare dso_local i8 @CreateEmptyString() ; Returns an empty Digo String object (3) declare dso_local i8 @AddString(i8, i8) ; concat(Digo String A + Digo String B) declare dso_local i8 @AddCString(i8, i8) ; the second parameter is a C-style string (4) declare dso_local i8 @CloneString(i8) ; Get a copy of Digo String (5) declare dso_local i8 @CompareString(i8 %strA, i8 %strB) ; Returns strcmp(strA, strB) (6) declare dso_local i64 @GetStringSize(i8) ; Returns strlen (7) declare dso_local i8 @GetCStr(i8*) ; Get C-style string

2. Slice 

(1) declare dso_local i8* @CreateSlice(i64 %type) Returns an empty Digo Slice object with element type=%type

 Type 定义如下:
            TYPE_UNDEFINED = 0,
            TYPE_STR = 1,
            TYPE_INT64 = 3,
            TYPE_DOUBLE = 4, 
            TYPE_FUTURE_OBJ = 6,

(2) declare dso_local i8 @SliceSlice(i8 %obj, i64 %begin, i64 %end) Returns a new Digo Slice object = obj[begin:end]

(3) declare dso_local i8 @SliceAppend(i8 %obj, ...)

Usage:

call i8 (i8, ...) @SliceAppend(obj, i8 %DigoString) 返回一个新的 Digo Slice Object,参数%DigoString必须是由CreateString或CreateEmptyString创建的Wrapped String i8 call i8 (i8, ...) @SliceAppend(obj, i64 %number) call i8 (i8, ...) @SliceAppend(obj, double %number) call i8 (i8, ...) @SliceAppend(obj, i8* %FutureObject)

(4) declare dso_local i8 @CloneSlice(i8)

(5) declare dso_local i64 @GetSliceSize(i8*)

------

Linker 的导出函数
#8 
参考
[test-async-1.ll](../blob/main/digo-linker/test/test-async-1.ll)
[test-async-2.ll](../blob/main/digo-linker/test/test-async-2.ll)

Print:
有两个,和printf用法差不多,第一个无最后换行符,第二个最后会换行
    void print(const char * format, ...);
    void println(const char * format, ...);
类型如下:

%d => int, %s => string(obj), %x => future(obj), %f => double, %l => slice(obj)

使用方法参考
[test-async-1.ll](../blob/main/digo-linker/test/test-async-1.ll)
[test-async-2.ll](../blob/main/digo-linker/test/test-async-2.ll)

------

List of Exported LLVM IR functions

declare dso_local i8 @CreateString(i8) declare dso_local i8 @CreateEmptyString() declare dso_local i8 @AddString(i8, i8) declare dso_local i8 @AddCString(i8, i8) declare dso_local i8 @CloneString(i8) declare dso_local i64 @CompareString(i8, i8) declare dso_local i64 @GetStringSize(i8) declare dso_local i8 @GetCStr(i8)

declare dso_local void @print(i8, ...) declare dso_local void @println(i8, ...)

declare dso_local i8 @CreateSlice(i64) declare dso_local i8 @SliceSlice(i8, i64, i64) declare dso_local i8 @SliceAppend(i8, ...) declare dso_local i8 @CloneSlice(i8) declare dso_local i64 @GetSliceSize(i8)

define double @SetSliceIndexDouble(i8 nocapture readonly, i64, double returned) define i8 @SetSliceIndexFuture(i8 nocapture readonly, i64, i8 returned) define i8 @SetSliceIndexString(i8 nocapture readonly, i64, i8 returned) define i64 @SetSliceIndexInt(i8 nocapture readonly, i64, i64 returned) define i64 @GetSliceSize(i8 nocapture readonly) define i8 @GetSliceIndexString(i8 nocapture readonly, i64) define i64 @GetSliceIndexInt(i8 nocapture readonly, i64) define double @GetSliceIndexDouble(i8* nocapture readonly, i64)

declare dso_local void @AwaitJob(i8*, i8*, i32) declare dso_local void @JobDecRef(i8) declare dso_local i8 @CreateAsyncJob(i32, i8, i32) declare dso_local i8 @CreateRemoteJob(i32, i8*, i32)

declare dso_local i8 @SW_CreateWrapper() declare dso_local void @SW_AddString(i8, i8) declare dso_local void @SW_AddInt32(i8, i32) declare dso_local void @SW_AddInt64(i8, i64) declare dso_local void @SW_AddDouble(i8, double) declare dso_local void @SW_AddSlice(i8, i8) declare dso_local void @SW_GetAndDestroy(i8*, i8*, i32)

declare dso_local i8 @SW_CreateExtractor(i8, i32) declare dso_local i32 @SW_ExtractInt32(i8) declare dso_local i64 @SW_ExtractInt64(i8) declare dso_local double @SW_ExtractDouble(i8) declare dso_local i8 @SW_ExtractString(i8) declare dso_local i8 @SW_ExtractSlice(i8) declare dso_local void @SW_DestroyExtractor(i8)

declare dso_local void @NoMatchExceptionHandler(i32 %func_id) declare dso_local void @ASYNC_AddFunction(i32, i8*)

declare dso_local i32 @entry(i32, i8**)

declare dso_local void @Debug_Real_LinkerCallFunction(i32, i32)

wy2249 commented 3 years ago

test-async-1.ll里面createString是这样用的:

%msg1_str_ptr = getelementptr inbounds [14 x i8], [14 x i8]* @.str.msg.1, i64 0, i64 0

%arg5_inner_str = call i8* @CreateString(i8* %msg1_str_ptr)


下面这样可以接受吗

%arg5_inner_str = call i8* @CreateString(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.msg.1, i64 0, i64 0))
sdh21 commented 3 years ago

test-async-1.ll里面createString是这样用的:

%msg1_str_ptr = getelementptr inbounds [14 x i8], [14 x i8]* @.str.msg.1, i64 0, i64 0

%arg5_inner_str = call i8* @CreateString(i8* %msg1_str_ptr)

下面这样可以接受吗

%arg5_inner_str = call i8* @CreateString(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.msg.1, i64 0, i64 0))

可以,两者应该是等价的 一般来说能通过llvm编译,就没问题