@@ -924,6 +924,9 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
924924        self . block_table . borrow ( ) . get ( & handle) . copied ( ) 
925925    } 
926926
927+     /// # get_pri_basic_type 
928+ /// 
929+ /// get_pri_basic_type converts a pivot-lang primitive type into a llvm primitive type 
927930fn  get_pri_basic_type ( & self ,  tp :  & PriType )  -> BasicTypeEnum < ' ctx >  { 
928931        match  tp { 
929932            PriType :: I8  => self . context . i8_type ( ) . into ( ) , 
@@ -1686,6 +1689,10 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
16861689        * self . optimized . borrow_mut ( )  = true ; 
16871690    } 
16881691
1692+     /// # try_load2var_inner 
1693+ /// 
1694+ /// it returns the element of a pointer, 
1695+ /// or array, int, float, struct, vector, and function value rirectly 
16891696fn  try_load2var_inner ( & self ,  v :  usize ,  tp :  & PLType ,  ctx :  & mut  Ctx < ' a > )  -> Result < usize ,  ( ) >  { 
16901697        let  handle = v; 
16911698        let  v = self . get_llvm_value ( handle) . unwrap ( ) ; 
@@ -1694,7 +1701,6 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
16941701                AnyValueEnum :: ArrayValue ( _) 
16951702                | AnyValueEnum :: IntValue ( _) 
16961703                | AnyValueEnum :: FloatValue ( _) 
1697-                 | AnyValueEnum :: PointerValue ( _) 
16981704                | AnyValueEnum :: StructValue ( _) 
16991705                | AnyValueEnum :: VectorValue ( _)  => handle, 
17001706                AnyValueEnum :: FunctionValue ( f)  => { 
@@ -1810,6 +1816,11 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
18101816                . as_debug_info_scope ( ) , 
18111817        ) ; 
18121818    } 
1819+ 
1820+     /// # position_at_end_block 
1821+ /// 
1822+ /// Set the position of the builder to the end of a basic block refered 
1823+ /// by the block handle. 
18131824fn  position_at_end_block ( & self ,  block :  BlockHandle )  { 
18141825        self . builder 
18151826            . position_at_end ( self . block_table . borrow ( ) [ & block] ) ; 
@@ -1829,7 +1840,6 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
18291840            self . get_llvm_value_handle ( & f. as_any_value_enum ( ) ) 
18301841        } 
18311842    } 
1832- 
18331843    fn  get_or_add_global ( 
18341844        & self , 
18351845        name :  & str , 
@@ -2032,6 +2042,10 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
20322042    )  -> ValueHandle  { 
20332043        self . alloc_with_f ( name,  pltype,  ctx,  declare,  "DioGC__malloc_no_collect" ) 
20342044    } 
2045+ 
2046+     /// # build_struct_gep 
2047+ /// 
2048+ /// it builds a GEP(GetElementPtr) instructions and returns the value handle of the instruction. 
20352049fn  build_struct_gep ( 
20362050        & self , 
20372051        structv :  ValueHandle , 
@@ -2041,9 +2055,11 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
20412055        ctx :  & mut  Ctx < ' a > , 
20422056    )  -> Result < ValueHandle ,  String >  { 
20432057        let  structv = self . get_llvm_value ( structv) . unwrap ( ) ; 
2044-         let  structv  = structv. into_pointer_value ( ) ; 
2058+         let  struct_val_ptr  = structv. into_pointer_value ( ) ; 
20452059        let  sttp = self . get_basic_type_op ( tp,  ctx) . unwrap ( ) ; 
2046-         let  gep = self . builder . build_struct_gep ( sttp,  structv,  index,  name) ; 
2060+         let  gep = self 
2061+             . builder 
2062+             . build_struct_gep ( sttp,  struct_val_ptr,  index,  name) ; 
20472063        if  let  Ok ( gep)  = gep { 
20482064            return  Ok ( self . get_llvm_value_handle ( & gep. as_any_value_enum ( ) ) ) ; 
20492065        }  else  { 
@@ -2204,6 +2220,16 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
22042220        // dbg.map(|d| self.builder.set_current_debug_location(d)); 
22052221    } 
22062222
2223+     /// # build_phi 
2224+ /// 
2225+ /// it emits the phi node of LLVM and sets up the phi node. 
2226+ /// it returns the value handle of emitted phi node 
2227+ /// 
2228+ /// the pltype specifies the type of variable charged by the phi node. 
2229+ /// for example, if a F64 is manupulated in different branches, 
2230+ /// 
2231+ /// the pltype will be F64. 
2232+ /// the vbs holds a list of tuple which maps the block and value. 
22072233fn  build_phi ( 
22082234        & self , 
22092235        pltype :  & PLType , 
@@ -2222,6 +2248,11 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
22222248        self . get_llvm_value_handle ( & phi. as_any_value_enum ( ) ) 
22232249    } 
22242250
2251+     /// # build_unconditional_branch 
2252+ /// 
2253+ /// builds a unconditional branch by the value refered by the block handle to 
2254+ /// terminates the current block of the builder, which adds a new block in the 
2255+ /// builder as well. 
22252256fn  build_unconditional_branch ( & self ,  bb :  BlockHandle )  { 
22262257        let  bb = self . get_llvm_block ( bb) . unwrap ( ) ; 
22272258        self . builder . build_unconditional_branch ( bb) . unwrap ( ) ; 
@@ -2266,6 +2297,7 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
22662297        // run_immix_pass(self.module); 
22672298        self . module . write_bitcode_to_path ( path) 
22682299    } 
2300+ 
22692301    fn  int_value ( & self ,  ty :  & PriType ,  v :  u64 ,  sign_ext :  bool )  -> ValueHandle  { 
22702302        let  ty = self . get_pri_basic_type ( ty) . into_int_type ( ) ; 
22712303        let  v = ty. const_int ( v,  sign_ext) ; 
@@ -2431,6 +2463,11 @@ impl<'a, 'ctx> IRBuilder<'a, 'ctx> for LLVMBuilder<'a, 'ctx> {
24312463        let  v = self . builder . build_int_truncate ( v,  dest_ty,  name) . unwrap ( ) ; 
24322464        self . get_llvm_value_handle ( & v. as_any_value_enum ( ) ) 
24332465    } 
2466+ 
2467+     /// # build_conditional_branch 
2468+ /// 
2469+ /// it helps to build a conditional branch by the condition, then bacis block and else block 
2470+ /// refered by the value handle and block handles. 
24342471fn  build_conditional_branch ( 
24352472        & self , 
24362473        cond :  ValueHandle , 
0 commit comments