<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Plume</title>
    <description>The latest articles on DEV Community by Plume (@chenganxu2014).</description>
    <link>https://dev.to/chenganxu2014</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F740629%2F6c321983-d43b-4a67-be2c-659cc6070ef8.jpeg</url>
      <title>DEV Community: Plume</title>
      <link>https://dev.to/chenganxu2014</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chenganxu2014"/>
    <language>en</language>
    <item>
      <title>DPIR: Data Propagating Intermediate Representation</title>
      <dc:creator>Plume</dc:creator>
      <pubDate>Thu, 06 Jan 2022 09:28:56 +0000</pubDate>
      <link>https://dev.to/chenganxu2014/dpir-data-propagation-intermediate-representation-1ddn</link>
      <guid>https://dev.to/chenganxu2014/dpir-data-propagation-intermediate-representation-1ddn</guid>
      <description>&lt;h1&gt;
  
  
  DPIR：Data Propagation Intermediate Representation
&lt;/h1&gt;

&lt;p&gt;Traditional data propagation generally use &lt;strong&gt;DXL&lt;/strong&gt;(Data eXchange Language e.g. &lt;strong&gt;XML&lt;/strong&gt;, &lt;strong&gt;YAML&lt;/strong&gt;, &lt;strong&gt;JSON&lt;/strong&gt;) as the data carrier.&lt;/p&gt;

&lt;p&gt;This approach have two penalties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;DXL&lt;/strong&gt;s are very high-level, convenient for user to edit but Inconvenient for program to parse.&lt;/li&gt;
&lt;li&gt;There are too many &lt;strong&gt;DXL&lt;/strong&gt;s exist, programs use different &lt;strong&gt;DXL&lt;/strong&gt;s can't exchange data directly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here I introduce a better way for data propagation: design a intermediate representation for data propagation.&lt;br&gt;
I name it &lt;strong&gt;DPIR&lt;/strong&gt;(Data Propagating Intermediate Representation).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DPIR&lt;/strong&gt; should be low-level enough for programs to access efficiently and expressive enough for transforming to and from &lt;strong&gt;DXL&lt;/strong&gt;s with no information lose.&lt;/p&gt;

&lt;h1&gt;
  
  
  Preliminary Design of DPIR
&lt;/h1&gt;

&lt;p&gt;String encoding is another problem for data propagation, to avoid this problem &lt;strong&gt;DPIR&lt;/strong&gt; save strings in a individual file: &lt;em&gt;StrFile&lt;/em&gt;.&lt;br&gt;
Non-string data is saved in &lt;em&gt;DataFile&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  StrFile
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;StrFile&lt;/em&gt;'s name form is: &lt;code&gt;name.dpir-str-encode&lt;/code&gt;.&lt;br&gt;
Where &lt;code&gt;name&lt;/code&gt; is the source file's name and &lt;code&gt;encode&lt;/code&gt; is the string encoding used.&lt;/p&gt;

&lt;p&gt;For example: &lt;strong&gt;DPIR&lt;/strong&gt; from &lt;code&gt;config.json&lt;/code&gt;, it's &lt;em&gt;StrFile&lt;/em&gt;'s name should be &lt;code&gt;config.dpir-str-encode&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the &lt;em&gt;StrFile&lt;/em&gt; saved with &lt;strong&gt;UTF-8&lt;/strong&gt; it's name should be &lt;code&gt;config.dpir-str-utf8&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;For the &lt;em&gt;StrFile&lt;/em&gt; saved with &lt;strong&gt;UTF-16 LE&lt;/strong&gt; it's name should be &lt;code&gt;config.dpir-str-utf16le&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;For the &lt;em&gt;StrFile&lt;/em&gt; saved with &lt;strong&gt;UTF-16 BE&lt;/strong&gt; it's name should be &lt;code&gt;config.dpir-str-utf16be&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There can be multiple &lt;em&gt;StrFiles&lt;/em&gt;'s saved with different encodings in a single &lt;strong&gt;DPIR&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The strings in &lt;em&gt;StrFile&lt;/em&gt; are terminated with &lt;code&gt;\n&lt;/code&gt; and accessed with index started from 1, the index 0 is used to represent empty string("").&lt;br&gt;
Therefore the line number of a line is also the index of the string saved in this line.&lt;/p&gt;

&lt;h3&gt;
  
  
  DataFile
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;DataFile&lt;/em&gt;'s name form is: &lt;code&gt;name.dpir-data&lt;/code&gt; where &lt;code&gt;name&lt;/code&gt; is source file's name.&lt;/p&gt;

&lt;h5&gt;
  
  
  There's a format description in GO-like syntax for &lt;em&gt;DataFile&lt;/em&gt;:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// structure of whole file, fields aligned to block size。&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;full_file&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;fileHead&lt;/span&gt;    &lt;span class="n"&gt;file_head&lt;/span&gt;      &lt;span class="c"&gt;// fileHead holds some global metadata.&lt;/span&gt;
  &lt;span class="n"&gt;root&lt;/span&gt;        &lt;span class="n"&gt;array_table&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;map_tabl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;list_table&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;struct_table&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;integer&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;float&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nb"&gt;complex&lt;/span&gt;
  &lt;span class="c"&gt;// field root is root of the whole data structure, it can be a array table, a map table, a list table, a struct table, a string, a integer, a float-point number, or a complex number.&lt;/span&gt;

  &lt;span class="c"&gt;// followed by subsequent tables(if root is a table).&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;//--------------------------------------------------&lt;/span&gt;









&lt;span class="c"&gt;//*******************************************************************&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;file_head&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;blockSizeLog&lt;/span&gt;        &lt;span class="kt"&gt;uint8&lt;/span&gt;    &lt;span class="c"&gt;// specified blockSize：blockSize=1 &amp;lt;&amp;lt; blockSizeLog&lt;/span&gt;
  &lt;span class="n"&gt;fileHeadSize&lt;/span&gt;        &lt;span class="kt"&gt;uint8&lt;/span&gt;    &lt;span class="c"&gt;// size of file_head, block unit.&lt;/span&gt;
  &lt;span class="n"&gt;majorVersion&lt;/span&gt;        &lt;span class="kt"&gt;uint8&lt;/span&gt;    &lt;span class="c"&gt;// major version.&lt;/span&gt;
  &lt;span class="n"&gt;minorVersion&lt;/span&gt;        &lt;span class="kt"&gt;uint8&lt;/span&gt;    &lt;span class="c"&gt;// minor version.&lt;/span&gt;
  &lt;span class="n"&gt;generalEncodeFlag&lt;/span&gt;   &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// specified UTF and ASCII encoding, can be combined with '|'.&lt;/span&gt;
  &lt;span class="n"&gt;charSetFlag&lt;/span&gt;         &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// specified char set.&lt;/span&gt;
  &lt;span class="n"&gt;encodeFormatFlag&lt;/span&gt;    &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// specified encodings of char set specified by charSetFlag, can be combined with '|'.&lt;/span&gt;
  &lt;span class="n"&gt;rootTypeFlag&lt;/span&gt;        &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// specified type of root&lt;/span&gt;
  &lt;span class="n"&gt;sonKeyTypeFlag&lt;/span&gt;      &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// (when rootTypeFlag is TYPE_MAP)specified keyType of all entrys in root table.&lt;/span&gt;
  &lt;span class="n"&gt;sonValueTypeFlag&lt;/span&gt;    &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// (when rootTypeFlag is TYPE_ARRAY or TYPE_MAP)specified valueType of all entrys in root table.&lt;/span&gt;
  &lt;span class="n"&gt;reserveFileHead&lt;/span&gt;     &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;  &lt;span class="c"&gt;// reserve space, used to align file_head to block size.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;// generalEncodeFlag:&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;ASCII&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;iota&lt;/span&gt;
  &lt;span class="n"&gt;UTF8&lt;/span&gt;
  &lt;span class="n"&gt;UTF16LE&lt;/span&gt;
  &lt;span class="n"&gt;UTF16BE&lt;/span&gt;
  &lt;span class="n"&gt;UTF32LE&lt;/span&gt;
  &lt;span class="n"&gt;UTF32BE&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c"&gt;// charSetFlag:&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;CHINESE&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="no"&gt;iota&lt;/span&gt;        &lt;span class="c"&gt;// Chinese char set.&lt;/span&gt;
  &lt;span class="n"&gt;JAPANESE&lt;/span&gt;                    &lt;span class="c"&gt;//  Japanese char set。&lt;/span&gt;
  &lt;span class="c"&gt;// and so on&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c"&gt;// encodeFormatFlag:&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;FLAG1&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;iota&lt;/span&gt;  
  &lt;span class="n"&gt;FLAG2&lt;/span&gt;
  &lt;span class="n"&gt;FLAG3&lt;/span&gt;
  &lt;span class="n"&gt;FLAG4&lt;/span&gt;
  &lt;span class="n"&gt;FLAG5&lt;/span&gt;
  &lt;span class="n"&gt;FLAG6&lt;/span&gt;
  &lt;span class="n"&gt;FLAG7&lt;/span&gt;
  &lt;span class="n"&gt;FLAG8&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;// For example:&lt;/span&gt;
&lt;span class="c"&gt;// When charSetFlag is CHINESE, FLAG1 represent GBK, FLAG2 represent GB2312, FLAG3 represent GB18030 ...&lt;/span&gt;
&lt;span class="c"&gt;// When charSetFlag is JAPANESE, FLAG1 represent Shift_JIS, FLAG2 represent EUC_JP, FLAG3 represent ISO-2022-JP ...&lt;/span&gt;





&lt;span class="c"&gt;// typeFlag: for rootTypeFlag，keyTypeFlag，valueTypeFlag，sonKeyTypeFlag and sonValueTypeFlag.&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_ARRAY&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="no"&gt;iota&lt;/span&gt;     &lt;span class="c"&gt;// array type&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_MAP&lt;/span&gt;                    &lt;span class="c"&gt;// map type&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_LIST&lt;/span&gt;                   &lt;span class="c"&gt;// list type&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_STRUCT&lt;/span&gt;                 &lt;span class="c"&gt;// struct type&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_STRING&lt;/span&gt;                 &lt;span class="c"&gt;// string type&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_INT8&lt;/span&gt;                   &lt;span class="c"&gt;// and so on...&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_INT16&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_INT32&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_INT64&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_INT128&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_INT256&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_UINT8&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_UINT16&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_UINT32&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_UINT64&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_UINT128&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_UINT256&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_FLOAT16&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_FLOAT32&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_FLOAT64&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_FLOAT128&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_FLOAT256&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_FLOAT512&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_COMPLEX32&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_COMPLEX64&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_COMPLEX128&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_COMPLEX256&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_COMPLEX512&lt;/span&gt;
  &lt;span class="n"&gt;TYPE_COMPLEX1024&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c"&gt;//----------------------------------------------------------------------&lt;/span&gt;










&lt;span class="c"&gt;//*******************************************************************&lt;/span&gt;
&lt;span class="c"&gt;// array table：&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;array_table&lt;/span&gt;  &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;entryNum&lt;/span&gt;            &lt;span class="kt"&gt;uint16&lt;/span&gt;   &lt;span class="c"&gt;// number of entrys in current table.&lt;/span&gt;
  &lt;span class="n"&gt;sonKeyTypeFlag&lt;/span&gt;      &lt;span class="kt"&gt;byte&lt;/span&gt;     &lt;span class="c"&gt;// this field only exist when value of all entrys in current table is map_table(specified by father entry's sonValueType), this field specified keyType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;sonValueTypeFlag&lt;/span&gt;    &lt;span class="kt"&gt;byte&lt;/span&gt;     &lt;span class="c"&gt;// this field only exist when value of all entrys in current table is map_table or array_table, this field specified valueType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;entrys&lt;/span&gt;              &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entryNum&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;array_entry&lt;/span&gt;    &lt;span class="c"&gt;// entrys of current table.&lt;/span&gt;
  &lt;span class="n"&gt;reserveTable&lt;/span&gt;        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;  &lt;span class="c"&gt;// reserved space, used to align current table to block size.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c"&gt;// array entry:&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt;  &lt;span class="n"&gt;array_entry&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;valueSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;
  &lt;span class="c"&gt;// according to father entry's sonValueTypeFlag：&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_ARRAY, TYPE_MAP, TYPE_LIST or TYPE_STRUCT，then value is uint16 type，specified son table's offset, relative to current table's end, block unit.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_STRING, then value is uint16 type, specified the index of string in *StrFile*.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's other type(e.g. int64, complex128), then value is the real value of this entry.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;//---------------------------------------------------------------------------------------&lt;/span&gt;









&lt;span class="c"&gt;//*******************************************************************************************&lt;/span&gt;
&lt;span class="c"&gt;// map table:&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt;  &lt;span class="n"&gt;map_table&lt;/span&gt;  &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;entryNum&lt;/span&gt;           &lt;span class="kt"&gt;uint16&lt;/span&gt;            &lt;span class="c"&gt;// specified nuber of entrys in current table.&lt;/span&gt;
  &lt;span class="n"&gt;sonKeyTypeFlag&lt;/span&gt;     &lt;span class="kt"&gt;byte&lt;/span&gt;              &lt;span class="c"&gt;// this field only exist when value of all entrys in current table is map_table(specified by father entry's sonValueType), this field specified keyType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;sonValueTypeFlag&lt;/span&gt;   &lt;span class="kt"&gt;byte&lt;/span&gt;              &lt;span class="c"&gt;// this field only exist when value of all entrys in current table is map_table or array_table, this field specified valueType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;entrys&lt;/span&gt;             &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entryNum&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;map_entry&lt;/span&gt;      &lt;span class="c"&gt;// entrys of current table.&lt;/span&gt;
  &lt;span class="n"&gt;reserveTable&lt;/span&gt;       &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;            &lt;span class="c"&gt;// reserved space, used to align current table to block size.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c"&gt;// map entry&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt;  &lt;span class="n"&gt;map_entry&lt;/span&gt;  &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;key&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;keySize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;          &lt;span class="c"&gt;// current entry's key, type and size is specified by father entry's sonKeyTypeFlag; &lt;/span&gt;
  &lt;span class="c"&gt;// if father entry's sonKeyTypeFlag is TYPE_STRING, then key is uint16 type, specified the index of string in *StrFile*.&lt;/span&gt;

  &lt;span class="n"&gt;value&lt;/span&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;valueSize&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;        &lt;span class="c"&gt;// current entry's value, according to father entry's sonValueTypeFlag:&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_ARRAY, TYPE_MAP, TYPE_LIST or TYPE_STRUCT，then value is uint16 type，specified son table's offset, relative to current table's end, block unit.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_STRING, then value is uint16 type, specified the index of string in *StrFile*.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's other type(e.g. int64, complex128), then value is the real value of this entry.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;//-------------------------------------------------------------------------------------&lt;/span&gt;









&lt;span class="c"&gt;//*************************************************************************************&lt;/span&gt;
&lt;span class="c"&gt;// list table:&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;list_table&lt;/span&gt;  &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;entryNum&lt;/span&gt;      &lt;span class="kt"&gt;uint16&lt;/span&gt;      &lt;span class="c"&gt;// specified nuber of entrys in current table.&lt;/span&gt;
  &lt;span class="n"&gt;entrys&lt;/span&gt;        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entryNum&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;list_entry&lt;/span&gt;  &lt;span class="c"&gt;// entrys in current table.&lt;/span&gt;
  &lt;span class="n"&gt;exValues&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// real values for types beyond size of 32bit(e.g. int64, complex128).&lt;/span&gt;
  &lt;span class="n"&gt;reserveTable&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// reserved space, used to align current table to block size.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c"&gt;// list entry:&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt;  &lt;span class="n"&gt;list_entry&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;valueTypeFlag&lt;/span&gt;     &lt;span class="kt"&gt;byte&lt;/span&gt;      &lt;span class="c"&gt;// specified valueType of current entry.&lt;/span&gt;
  &lt;span class="n"&gt;sonKeyTypeFlag&lt;/span&gt;    &lt;span class="kt"&gt;byte&lt;/span&gt;      &lt;span class="c"&gt;// this field only exist when valueTypeFlag is TYPE_MAP, this field specified keyType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;sonValueTypeFlag&lt;/span&gt;  &lt;span class="kt"&gt;byte&lt;/span&gt;      &lt;span class="c"&gt;// this field only exist when valueTypeFlag is TYPE_MAP or TYPE_ARRAY, this field specified valueType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt;             &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// the "value" of current entry.&lt;/span&gt;
  &lt;span class="n"&gt;reserveEntry&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// reserved space, used to align current entry to 5 bytes.&lt;/span&gt;
  &lt;span class="c"&gt;// according to valueTypeFlag：&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_ARRAY, TYPE_MAP, TYPE_LIST or TYPE_STRUCT，then value is uint16 type，specified son table's offset, relative to current table's end, block unit.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_STRING, then value is uint16 type, specified the index of string in *StrFile*.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's number type below size of 32bit(int8-32, uint8-32, float32), then value is the real value of current entry.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's number type beyond size of 32bit, then value is uint32 type, specified the offset of real value, relative to start of exValues, byte unit.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;//---------------------------------------------------------------------------------------&lt;/span&gt;









&lt;span class="c"&gt;//*******************************************************************************************&lt;/span&gt;
&lt;span class="c"&gt;// struct table:&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt;  &lt;span class="n"&gt;struct_table&lt;/span&gt;  &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;entryNum&lt;/span&gt;      &lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// number of entrys in current table.&lt;/span&gt;
  &lt;span class="n"&gt;entrys&lt;/span&gt;        &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entryNum&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;struct_entry&lt;/span&gt;  &lt;span class="c"&gt;// entrys of current table.&lt;/span&gt;
  &lt;span class="n"&gt;exValues&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;  &lt;span class="c"&gt;// real values for types beyond size of 32bit(e.g. int64, complex128).&lt;/span&gt;
  &lt;span class="n"&gt;reserveTable&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;  &lt;span class="c"&gt;// reserved space, used to align current table to block size.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c"&gt;// struct entry：&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt;  &lt;span class="n"&gt;struct_entry&lt;/span&gt;  &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;valueTypeFlag&lt;/span&gt;     &lt;span class="kt"&gt;byte&lt;/span&gt;      &lt;span class="c"&gt;// specified valueType of current entry.&lt;/span&gt;
  &lt;span class="n"&gt;key&lt;/span&gt;               &lt;span class="kt"&gt;uint16&lt;/span&gt;    &lt;span class="c"&gt;// index of string in *StrFile*.&lt;/span&gt;
  &lt;span class="n"&gt;sonKeyTypeFlag&lt;/span&gt;    &lt;span class="kt"&gt;byte&lt;/span&gt;      &lt;span class="c"&gt;// this field only exist when valueTypeFlag is TYPE_MAP, this field specified keyType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;sonValueTypeFlag&lt;/span&gt;  &lt;span class="kt"&gt;byte&lt;/span&gt;      &lt;span class="c"&gt;// this field only exist when valueTypeFlag is TYPE_MAP or TYPE_ARRAY, this field specified valueType of son table's all entrys.&lt;/span&gt;
  &lt;span class="n"&gt;value&lt;/span&gt;             &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// the "value" of current entry.&lt;/span&gt;
  &lt;span class="n"&gt;reserveEntry&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;    &lt;span class="c"&gt;// reserved space, used to align current entry to 7 bytes.&lt;/span&gt;
  &lt;span class="c"&gt;// according to valueTypeFlag：&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_ARRAY, TYPE_MAP, TYPE_LIST or TYPE_STRUCT，then value is uint16 type，specified son table's offset, relative to current table's end, block unit.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's TYPE_STRING, then value is uint16 type, specified the index of string in *StrFile*.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's number type below size of 32bit(int8-32, uint8-32, float32), then value is the real value of current entry.&lt;/span&gt;
  &lt;span class="c"&gt;// if it's number type beyond size of 32bit, then value is uint32 type, specified the offset of real value, relative to start of exValues, byte unit.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Module Management for Golang on Win10</title>
      <dc:creator>Plume</dc:creator>
      <pubDate>Wed, 15 Dec 2021 07:51:09 +0000</pubDate>
      <link>https://dev.to/chenganxu2014/module-management-for-golang-on-win10-dm4</link>
      <guid>https://dev.to/chenganxu2014/module-management-for-golang-on-win10-dm4</guid>
      <description>&lt;h1&gt;
  
  
  &lt;a href="https://dev.to/chenganxu2014/golang-install-and-config-on-win10-5cd1"&gt;Install and Config Golang on Win10&lt;/a&gt;
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Create a Module
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a new directory, in this example, I Created "A:/Learn/Go/Work".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;em&gt;cmd&lt;/em&gt; or &lt;em&gt;PowerShell&lt;/em&gt;, jump to the new directory.&lt;br&gt;
&lt;code&gt;cd /d A:/Learn/Go/Work&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;go mod init Aoi/Sola&lt;/code&gt; where &lt;code&gt;Aoi/Sola&lt;/code&gt; will be the new module's name. This will create a &lt;em&gt;go.mod&lt;/em&gt; File in "A:/Learn/Go/Work", make "A:/Learn/Go/Work" the new module's root directory.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;em&gt;go.mod&lt;/em&gt; file's content will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="n"&gt;Aoi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Sola&lt;/span&gt;

&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="m"&gt;1.17&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;Aoi/Sola&lt;/code&gt; is the new module's name, 1.17 is &lt;strong&gt;Golang&lt;/strong&gt;'s version number.&lt;/p&gt;

&lt;h1&gt;
  
  
  Hello World
&lt;/h1&gt;

&lt;p&gt;Create a source file in module's root directory(in this example "A:/Learn/Go/Work").&lt;/p&gt;

&lt;p&gt;In this example, I created &lt;em&gt;hello.go&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;hello.go&lt;/em&gt;'s content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="c"&gt;// "package main" specifies the package name: "main"&lt;/span&gt;

&lt;span class="c"&gt;// Golang's main func have no return no argument.&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c"&gt;// Output "Hello World" through standard error.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every source file's first line should be a &lt;code&gt;package &amp;lt;package_name&amp;gt;&lt;/code&gt; statement.&lt;br&gt;
A &lt;strong&gt;Golang&lt;/strong&gt; program can only have one "main" package.&lt;/p&gt;

&lt;p&gt;Jump to module's root directory(in this example "A:/Learn/Go/Work"), run &lt;code&gt;go run hello.go&lt;/code&gt;, you will see "Hello World" in standard error output.&lt;/p&gt;
&lt;h1&gt;
  
  
  Import Module
&lt;/h1&gt;
&lt;h3&gt;
  
  
  Import Remote Module
&lt;/h3&gt;

&lt;p&gt;Create another module in another directory, in this example I created a module named "remote" in "A:/Learn/Go/Remote".&lt;br&gt;
Create a source file in "A:/Learn/Go/Remote", I created &lt;em&gt;remote.go&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;remote.go&lt;/em&gt;'s content：&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt;  &lt;span class="c"&gt;// "hello.go" will refer variable Str with name "remote.Str", the package name "remote" is also used as namespace.&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;Str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"I Love Aoi Sola"&lt;/span&gt; &lt;span class="c"&gt;// Variable/Function name's first letter must be uppercase, or they can't be accessed out of current module.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then push "A:/Learn/Go/Remote" to a remote repository and change the module name to the repository's url:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xxau2et0y6y630u2tgn5.png"&gt;Change Module Name1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1dvunubbp6sshujjho0.png"&gt;Change Module Name2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change &lt;em&gt;hello.go&lt;/em&gt;'s content to：&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"github.com/ChengAnXu2014/GoModule"&lt;/span&gt;   &lt;span class="c"&gt;// module name is also remote repository's URL.&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remote&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c"&gt;// refer varialbe Str with "remote.Str".&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run &lt;code&gt;go mod tidy&lt;/code&gt; in "A:/Learn/Go/Work" to upgrade module &lt;code&gt;Aoi/Sola&lt;/code&gt;'s &lt;em&gt;go.mod&lt;/em&gt; file.&lt;br&gt;
&lt;strong&gt;Golang&lt;/strong&gt; will download module &lt;code&gt;github.com/ChengAnXu2014/GoModule&lt;/code&gt;'s content to the directory specified by environment variable &lt;strong&gt;GOPATH&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And module &lt;code&gt;Aoi/Sola&lt;/code&gt;'s &lt;em&gt;go.mod&lt;/em&gt; file's content will be like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="n"&gt;Aoi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Sola&lt;/span&gt;

&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="m"&gt;1.17&lt;/span&gt;

&lt;span class="n"&gt;require&lt;/span&gt; &lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ChengAnXu2014&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;GoModule&lt;/span&gt; &lt;span class="n"&gt;v0&lt;/span&gt;&lt;span class="m"&gt;.0.0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;20210624111742&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;626&lt;/span&gt;&lt;span class="n"&gt;d6b55d79e&lt;/span&gt; &lt;span class="c"&gt;// means current module require module `github.com/ChengAnXu2014/GoModule`.&lt;/span&gt;
&lt;span class="c"&gt;// if any tags is created, the most recent tag's commit will be used, vx.x.x will be the most recent tag number.&lt;/span&gt;
&lt;span class="c"&gt;// if no tag is created, the most recent commit is used, vx.x.x will be v0.0.0&lt;/span&gt;
&lt;span class="c"&gt;// 20210624111742 is the used commit's commit time(2021/06/24 11:17:42).&lt;/span&gt;
&lt;span class="c"&gt;// 626d6b55d79e is the used commit's name, and is also the used commit's checksum.&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For security, &lt;strong&gt;Golang&lt;/strong&gt; won't access third-party repository by default, to change that you must set the environment variable &lt;strong&gt;GOPRIVATE&lt;/strong&gt;(see below).&lt;/p&gt;

&lt;p&gt;Now run &lt;code&gt;go run hello.go&lt;/code&gt; in "A:/Learn/Go/Work", "I Love Aoi Sola" will be output through standard error.&lt;/p&gt;

&lt;p&gt;If you changed remote module, then delete "require ..." statement from module &lt;code&gt;Aoi/Sola&lt;/code&gt;'s &lt;em&gt;go.mod&lt;/em&gt; and run &lt;code&gt;go mod tidy&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Golang&lt;/strong&gt; will download from remote module and upgrade module &lt;code&gt;Aoi/Sola&lt;/code&gt;'s &lt;em&gt;go.mod&lt;/em&gt; again.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;GOPRIVATE&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For security, &lt;strong&gt;Golang&lt;/strong&gt; won't access third-party repository by default, to change that you must set the environment variable &lt;strong&gt;GOPRIVATE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4gqu3e3h49groaynhtc.png"&gt;Set &lt;strong&gt;GOPRIVATE&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Multiple URLs can be separated by &lt;code&gt;,&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Import Local Module
&lt;/h3&gt;

&lt;p&gt;Change "A:/Learn/Go/Remote/remote.go" to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;Str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"I'm Local Module!!!"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change module &lt;code&gt;Aoi/Sola&lt;/code&gt;'s &lt;em&gt;go.mod&lt;/em&gt; to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="n"&gt;Aoi&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Sola&lt;/span&gt;

&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="m"&gt;1.17&lt;/span&gt;

&lt;span class="n"&gt;replace&lt;/span&gt; &lt;span class="n"&gt;github&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ChengAnXu2014&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;GoModule&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="o"&gt;:/&lt;/span&gt;&lt;span class="n"&gt;Learn&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Go&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Remote&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;delete "require..." statement and add "replace..." statement to map &lt;code&gt;github.com/ChengAnXu2014/GoModule&lt;/code&gt; to local directory "A:/Learn/Go/Remote"&lt;/p&gt;

&lt;p&gt;Then run &lt;code&gt;go mod tidy&lt;/code&gt; in "A:/Learn/Go/Work" to upgrade module &lt;code&gt;Aoi/Sola&lt;/code&gt;'s &lt;em&gt;go.mod&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;go run hello.go&lt;/code&gt; in "A:/Learn/Go/Work", you will see "I'm Local Module!!!" in standard error output.&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>Install and Config Golang on Windows10</title>
      <dc:creator>Plume</dc:creator>
      <pubDate>Fri, 19 Nov 2021 06:42:29 +0000</pubDate>
      <link>https://dev.to/chenganxu2014/golang-install-and-config-on-win10-5cd1</link>
      <guid>https://dev.to/chenganxu2014/golang-install-and-config-on-win10-5cd1</guid>
      <description>&lt;h3&gt;
  
  
  Download Page: &lt;a href="https://golang.org.dl"&gt;https://golang.org.dl&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_CHeOj0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ozlbhdgx4uxrkwfi9ju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_CHeOj0T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ozlbhdgx4uxrkwfi9ju.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.msi&lt;/code&gt; is &lt;strong&gt;Windows&lt;/strong&gt;'s new install package file just double click it to install.&lt;/p&gt;

&lt;h3&gt;
  
  
  Environment Variable Config
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---mlKquW3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtfmhw9u8thd1zogmzno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---mlKquW3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtfmhw9u8thd1zogmzno.png" alt="Image description" width="800" height="780"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Variable &lt;strong&gt;GO111MODULE&lt;/strong&gt;'s value should be set to "on" to enable module control tools(&lt;code&gt;go mod&lt;/code&gt; tools).&lt;/p&gt;

&lt;p&gt;Variable &lt;strong&gt;GOBIN&lt;/strong&gt;'s value should be set to "$go/bin" where the "$go" is the directory where you installed &lt;strong&gt;Golang&lt;/strong&gt;.&lt;br&gt;
So that the &lt;strong&gt;Windows&lt;/strong&gt; system can find the &lt;code&gt;go&lt;/code&gt; tools in "$go/bin" when you perform them in &lt;strong&gt;cmd&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Variable &lt;strong&gt;GOPATH&lt;/strong&gt;'s value should be a path, which will be used to save the modules installed from the remote repository.&lt;/p&gt;

</description>
      <category>go</category>
      <category>windows</category>
    </item>
    <item>
      <title>LLVM-IR</title>
      <dc:creator>Plume</dc:creator>
      <pubDate>Sun, 14 Nov 2021 10:38:08 +0000</pubDate>
      <link>https://dev.to/chenganxu2014/llvm-ir-4mfg</link>
      <guid>https://dev.to/chenganxu2014/llvm-ir-4mfg</guid>
      <description>&lt;h1&gt;
  
  
  Navigation
&lt;/h1&gt;

&lt;p&gt;3 Equivalent Forms&lt;br&gt;
Infinite Virtual Register Set&lt;br&gt;
&lt;code&gt;load&lt;/code&gt; and &lt;code&gt;store&lt;/code&gt; Instruction&lt;br&gt;
Three Address Form Assignment&lt;br&gt;
Static Single Assignment&lt;br&gt;
Global and Local Identifiers&lt;br&gt;
&lt;code&gt;icmp&lt;/code&gt; Instruction&lt;/p&gt;

&lt;p&gt;To Be Continued...&lt;/p&gt;

&lt;h1 id="3-equ-forms"&gt;3 Equivalent Forms&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;LLVM-IR&lt;/strong&gt; have 3 equivalent forms:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;textual form&lt;/strong&gt; for developers to read and edit manually.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;binary form&lt;/strong&gt;(also called &lt;strong&gt;bitcode form&lt;/strong&gt;) for storing on disk(in &lt;em&gt;.o&lt;/em&gt; and &lt;em&gt;.exe&lt;/em&gt; files).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;in-memory form&lt;/strong&gt; for compilers and optimizers to use.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These 3 forms can be transformed between each other with no information lose.&lt;br&gt;
Since these 3 forms are equivalent and only the &lt;strong&gt;textual form&lt;/strong&gt; of them is readable, we only introduce the &lt;strong&gt;textual form&lt;/strong&gt; in this article.&lt;/p&gt;

&lt;h1 id="infinite-vir-reg"&gt;Infinite Virtual Register Set&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;LLVM-IR&lt;/strong&gt; use a &lt;strong&gt;Virtual Register Set&lt;/strong&gt; which have infinite virtual registers.&lt;br&gt;
When &lt;strong&gt;LLVM-IR&lt;/strong&gt; code is transformed to &lt;strong&gt;Native Code&lt;/strong&gt;, the virtual registers are maped to the real registers of the &lt;strong&gt;Host Machine&lt;/strong&gt;.&lt;br&gt;
Since the &lt;strong&gt;Host Machine&lt;/strong&gt;'s registers are finite, the used registers that are nolonger referenced will be reused to map new virtual registers.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code 1&lt;/em&gt; &lt;strong&gt;LLVM-IR&lt;/strong&gt; Code for Infinite Virtual Register Set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%a = add i64 9,  8      ; i64 is 64-bit integer type
%b = add i64 %a, 7      ; after ';' are Comments
%c = add i64 %b, %a     ; LLVM-IR's register name must have a prefix: "%"
%d = add i64 %c, %b
%e = add i64 %d, %c
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code 2&lt;/em&gt; Pseudo Code After Register Mapping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AX = add i64 9,  8
BX = add i64 AX, 7
CX = add i64 BX, AX
AX = add i64 CX, BX
BX = add i64 AX, CX
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Virtual Register&lt;/strong&gt;s can be used to hold scalar values: integers, floating-point numbers, pointers.&lt;/p&gt;

&lt;h1 id="load-store-ins"&gt;`load` and `store` Instruction&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;load&lt;/code&gt; instruction is used to "read" from memory, and is the only way to "read" from memory;&lt;br&gt;
&lt;code&gt;store&lt;/code&gt; instruction is used to "write" to memory, and is the only way to "write" to memory.&lt;br&gt;
&lt;code&gt;load&lt;/code&gt; and &lt;code&gt;store&lt;/code&gt; access memory with a pointer.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code 3&lt;/em&gt; &lt;strong&gt;LLVM-IR&lt;/strong&gt; Code for &lt;code&gt;load&lt;/code&gt; and &lt;code&gt;store&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%a = load i64, i64* %ptr      ; load i64 type value from memory pointed by i64* type pointer register %ptr
store  i64 99, i64* %ptr      ; store i64 type value 99 into memory pointed by i64* type pointer register %ptr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1 id="three-addr-form"&gt;Three Address Form Assignment&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;LLVM-IR&lt;/strong&gt;'s assignment-statements always have a &lt;code&gt;=&lt;/code&gt;, and there must be one and only one register at the left side of the &lt;code&gt;=&lt;/code&gt;.&lt;br&gt;
You can see that, the assignment-statements in &lt;em&gt;Code 1&lt;/em&gt;, &lt;em&gt;Code 2&lt;/em&gt; and &lt;em&gt;Code 3&lt;/em&gt; are all in Three Address Form.&lt;/p&gt;

&lt;h1 id="ssa"&gt;Static Single Assignment&lt;/h1&gt;

&lt;p&gt;In &lt;strong&gt;LLVM-IR&lt;/strong&gt; code, there can be only one assignment-statement for each register.&lt;br&gt;
Although loop code can perform one assignment-statement many times, &lt;code&gt;phi&lt;/code&gt; instruction can put many possible values at right side of a assignment-statement's &lt;code&gt;=&lt;/code&gt;, &lt;strong&gt;SSA&lt;/strong&gt;(Static Single Assignment) and &lt;strong&gt;TAF&lt;/strong&gt;(Three Adress Form) still significantly simplifies the data-flow of &lt;strong&gt;LLVM-IR&lt;/strong&gt; code, so that many analyses can get the data-flow information they need from &lt;strong&gt;LLVM-IR&lt;/strong&gt; code without any sophisticated data-flow analysis.&lt;/p&gt;

&lt;p&gt;But how can we transform non-&lt;strong&gt;SSA&lt;/strong&gt; source code to &lt;strong&gt;SSA LLVM-IR&lt;/strong&gt; code?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code 4&lt;/em&gt; non-&lt;strong&gt;SSA Go&lt;/strong&gt; Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;i64&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;99&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;88&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;77&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;66&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code 5&lt;/em&gt; Corresponding &lt;strong&gt;SSA LLVM-IR&lt;/strong&gt; Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%a = i64 99
%0 = i64 88
%1 = i64 77
%2 = i64 66
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When transform non-&lt;strong&gt;SSA&lt;/strong&gt; source code to &lt;strong&gt;SSA LLVM-IR&lt;/strong&gt; code, the compiler auto generate register names with &lt;code&gt;%&lt;/code&gt; prefix and numbers.&lt;/p&gt;

&lt;h1 id="glob-local-ident"&gt;Global and Local Identifiers&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;LLVM-IR&lt;/strong&gt; have two kinds of identifiers: &lt;strong&gt;Global Identifier&lt;/strong&gt; and &lt;strong&gt;Local Identifier&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;Global Identifier&lt;/strong&gt;s begin with the &lt;code&gt;@&lt;/code&gt; character, &lt;strong&gt;Local Identifier&lt;/strong&gt;s begin with the &lt;code&gt;%&lt;/code&gt; character.&lt;br&gt;
&lt;strong&gt;Global Identifier&lt;/strong&gt;s contain &lt;strong&gt;Global Variable&lt;/strong&gt; names and &lt;strong&gt;Function&lt;/strong&gt; names.&lt;br&gt;
&lt;strong&gt;Local Identifier&lt;/strong&gt;s contain &lt;strong&gt;Register&lt;/strong&gt; names, &lt;strong&gt;Label&lt;/strong&gt; names and &lt;strong&gt;User Defined Type&lt;/strong&gt; names.&lt;/p&gt;

&lt;p&gt;We'll illustrate &lt;strong&gt;Global Variable&lt;/strong&gt;s later, &lt;strong&gt;Label&lt;/strong&gt;s are similar to the labels in high-level languages.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code 6&lt;/em&gt; &lt;strong&gt;GO&lt;/strong&gt; Code for Label:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="n"&gt;i64&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;
&lt;span class="c"&gt;// 'loop' is a label&lt;/span&gt;
&lt;span class="n"&gt;loop&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;goto&lt;/span&gt; &lt;span class="n"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;// other code&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code 7&lt;/em&gt; &lt;strong&gt;LLVM-IR&lt;/strong&gt; Code for Label:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;; 'enter', 'loop', 'end' are labels
enter:
    %i = i64 0
loop:
    %i1   = phi i64 [ %i, %enter ], [ %i2, %loop ]     ; if dominated by label 'enter' %i1 = %i;     if dominated by label 'loop' %i1 = %i2.
    %i2   = add i64 %i1, 1
    %cond = icmp ne i64 %i2, 10      ; if %i2 != 10 %cond is "true";     otherwise %cond is "false"
    br i1 %cond, label %loop, label %end      ; if %cond is "true" jump to label 'loop';     otherwise jump to label 'end'
end:
    ;code for label 'end'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;icmp&lt;/code&gt;, &lt;code&gt;br&lt;/code&gt; and &lt;code&gt;phi&lt;/code&gt; instructions will be illustrated later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Struct&lt;/strong&gt; is a typical example of &lt;strong&gt;User Defined Type&lt;/strong&gt;s.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Code 8&lt;/em&gt; &lt;strong&gt;GO&lt;/strong&gt; Code for &lt;strong&gt;Struct&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// 'usertype' is a user defined type name&lt;/span&gt;
&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;usertype&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;i8&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;i16&lt;/span&gt;
    &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;i32&lt;/span&gt;
    &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="n"&gt;i64&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code 9&lt;/em&gt; &lt;strong&gt;LLVM-IR&lt;/strong&gt; Code for &lt;strong&gt;Struct&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%usertype = type { i8, i16, i32, i64 }      ; '%usertype' is a user defined type name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1 id="icmp"&gt;`icmp` Instruction&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;icmp&lt;/code&gt; is used to compare values, return a bool value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;result&amp;gt; = icmp &amp;lt;cond&amp;gt; &amp;lt;ty&amp;gt; &amp;lt;op1&amp;gt;, &amp;lt;op2&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;cond&amp;gt;&lt;/code&gt; is keyword that indicates witch kind of compare to perform.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;ty&amp;gt;&lt;/code&gt; is the type of &lt;code&gt;&amp;lt;op1&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;op2&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;op1&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;op2&amp;gt;&lt;/code&gt; are the values to be compared, they can be integer, float-pointing or pointer type, and they must be in the same type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;&amp;lt;cond&amp;gt;&lt;/code&gt;s&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;eq: equal&lt;/li&gt;
&lt;li&gt;ne: not equal&lt;/li&gt;
&lt;li&gt;ugt: unsigned greater than&lt;/li&gt;
&lt;li&gt;uge: unsigned greater or equal&lt;/li&gt;
&lt;li&gt;ult: unsigned less than&lt;/li&gt;
&lt;li&gt;ule: unsigned less or equal&lt;/li&gt;
&lt;li&gt;sgt: signed greater than&lt;/li&gt;
&lt;li&gt;sge: signed greater or equal&lt;/li&gt;
&lt;li&gt;slt: signed less than&lt;/li&gt;
&lt;li&gt;sle: signed less or equal&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Examples:
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Code 10&lt;/em&gt; Simple examples for &lt;code&gt;icmp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%result1 = icmp eq i32 4, 5          ; yields: %result1=false
%result2 = icmp ult i16  4, 5        ; yields: %result2=true
%result3 = icmp sgt i16  4, 5        ; yields: %result3=false
%result4 = icmp sge i16  4, 5        ; yields: %result4=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code 11&lt;/em&gt; Complicated examples for &lt;code&gt;icmp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;; Use &amp;lt;cond&amp;gt; ne(not equal) to compare float* type pointer %X and itself.
%result5 = icmp ne float* %X, %X     ; yields: %result5=false

; Use &amp;lt;cond&amp;gt; ule(unsigned less or equal) to compare -4 and 5
; first convert -4 to unsigned 252, then compare 252 and 5
; 252 &amp;gt; 5, so -4 ule 5 is false.
%result6 = icmp ule i16 -4, 5        ; yields: %result6=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Code 12&lt;/em&gt; Unsure examples for &lt;code&gt;icmp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;; These examples combine two compare operations in one instruction:
; 1. Use &amp;lt;cond&amp;gt; ugt(unsigned greater than) to compare i16 type values 0 and 1; 0 &amp;lt; 1, so 0 ugt 1 is false.
; 2. Use &amp;lt;cond&amp;gt; ugt to compare i16 type values 3 and 2; 3 &amp;gt; 2, so 3 ugt 2 is true.

&amp;lt;%result7, %result8&amp;gt; = icmp ugt &amp;lt;2 x i16&amp;gt; &amp;lt;i16 0, i16 3&amp;gt;, &amp;lt;i16 1, i16 2&amp;gt;    ; yields: %result7=false; %result8=true
%resultptr = icmp ugt &amp;lt;2 x i16&amp;gt; &amp;lt;i16 0, i16 3&amp;gt;, &amp;lt;i16 1, i16 2&amp;gt; ; %resultptr is a &amp;lt;2 x i1&amp;gt;* type pointer, the vector it points to is &amp;lt;i1 0, i1 1&amp;gt; where 'i1 0' represents false, 'i1 1' represents true.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no example for multiple compare in &lt;strong&gt;LLVM-IR&lt;/strong&gt;'s documentation so I make two by myself, I'm not sure which one is correct or they are all uncorrect.&lt;/p&gt;

&lt;h1 id="to-be-continued"&gt;To Be Continued...&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;br&lt;/code&gt; Instruction&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;phi&lt;/code&gt; Instruction&lt;/li&gt;
&lt;li&gt;Global Variable&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>llvm</category>
    </item>
    <item>
      <title>Overview of LLVM Architecture</title>
      <dc:creator>Plume</dc:creator>
      <pubDate>Mon, 01 Nov 2021 07:22:44 +0000</pubDate>
      <link>https://dev.to/chenganxu2014/overview-of-llvm-architecture-p8b</link>
      <guid>https://dev.to/chenganxu2014/overview-of-llvm-architecture-p8b</guid>
      <description>&lt;h1&gt;
  
  
  First of all, let's see a graph of LLVM Architecture.
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Picture 1:
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ro0EJEta--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ir080q7fyybkj4gp2ql.png" alt="Image description" width="880" height="195"&gt;
&lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ir080q7fyybkj4gp2ql.png"&gt;Click here to see HD picture&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As you can see in &lt;em&gt;Picture 1&lt;/em&gt;, &lt;strong&gt;source code&lt;/strong&gt; of arbitrary language(C, C++, Go, etc) are compiled by an appropriate compiler to &lt;strong&gt;LLVM-IR&lt;/strong&gt;(&lt;strong&gt;LLVM&lt;/strong&gt;'s Intermidiate code Representation) codes, these &lt;strong&gt;LLVM-IR&lt;/strong&gt; codes are saved in &lt;em&gt;.o&lt;/em&gt; files(object files).&lt;br&gt;
Then, an &lt;strong&gt;Optimizing Linker&lt;/strong&gt; is used to link the &lt;em&gt;.o&lt;/em&gt; files, libraries of the native system, and libraries of &lt;strong&gt;LLVM Architecture&lt;/strong&gt; into a &lt;em&gt;.exe&lt;/em&gt; file, the &lt;em&gt;.exe&lt;/em&gt; file contains both &lt;strong&gt;LLVM-IR&lt;/strong&gt; and &lt;strong&gt;native code&lt;/strong&gt;(&lt;strong&gt;Machine Code&lt;/strong&gt; which can run on the &lt;strong&gt;Host Machine&lt;/strong&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Now, let's have a break
&lt;/h3&gt;

&lt;p&gt;Before we continue describing &lt;em&gt;Picture 1&lt;/em&gt;, we'd better illustrate the meaning of &lt;em&gt;Offline&lt;/em&gt; and &lt;em&gt;Profile &amp;amp; Trace Info&lt;/em&gt; first.&lt;/p&gt;

&lt;h4&gt;
  
  
  According to the context, &lt;em&gt;Offline&lt;/em&gt; can mean:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;While &lt;em&gt;.exe&lt;/em&gt; file is not running(in idle time).&lt;/li&gt;
&lt;li&gt;After &lt;em&gt;.exe&lt;/em&gt; file is generated.&lt;/li&gt;
&lt;li&gt;After the program(&lt;em&gt;.exe&lt;/em&gt; file) is installed.&lt;/li&gt;
&lt;li&gt;On &lt;strong&gt;Host Machine&lt;/strong&gt;(User's Computer).&lt;/li&gt;
&lt;li&gt;Without &lt;strong&gt;source code&lt;/strong&gt;(.c, .cpp, .go, etc).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Profile&lt;/em&gt; means:
&lt;/h4&gt;

&lt;p&gt;Information about which regions of the &lt;em&gt;.exe&lt;/em&gt; file's code runs more frequently on &lt;strong&gt;Host Machine&lt;/strong&gt;, these frequently-run code regions are called &lt;strong&gt;Hot Code&lt;/strong&gt;s.&lt;/p&gt;

&lt;h3&gt;
  
  
  Continue
&lt;/h3&gt;

&lt;p&gt;After &lt;em&gt;.exe&lt;/em&gt; file is generated, the &lt;strong&gt;Run-time Optimizer&lt;/strong&gt; is used to capture &lt;em&gt;Profile &amp;amp; Trace Info&lt;/em&gt;, use the information contained by &lt;em&gt;Profile&lt;/em&gt; to find &lt;strong&gt;Hot Code&lt;/strong&gt;, optimize the &lt;strong&gt;LLVM-IR&lt;/strong&gt; contained by &lt;em&gt;.exe&lt;/em&gt; file to improve &lt;strong&gt;Hot Code&lt;/strong&gt;'s performance at the cost of &lt;strong&gt;Cold Code&lt;/strong&gt;'s performance. This kind of optimization is called &lt;strong&gt;Profile-guided Optimization&lt;/strong&gt;.&lt;br&gt;
Then, the &lt;strong&gt;Run-time Optimizer&lt;/strong&gt; passes the generated &lt;strong&gt;Native Code&lt;/strong&gt; to &lt;strong&gt;Host Machine&lt;/strong&gt; to run it.&lt;/p&gt;

&lt;p&gt;Sometimes, the &lt;strong&gt;Profile-guided Optimization&lt;/strong&gt; is too sophisticated to perform at run-time or the &lt;strong&gt;Profile-guided Optimization&lt;/strong&gt; is valuable enough to retain long-term, so the &lt;em&gt;Profile&lt;/em&gt; information is passed to the &lt;strong&gt;Offline Reoptimizer&lt;/strong&gt;, the &lt;strong&gt;Offline Reoptimizer&lt;/strong&gt; use the information contained by &lt;em&gt;Profile&lt;/em&gt; to find &lt;strong&gt;Hot Code&lt;/strong&gt;, optimize the &lt;strong&gt;LLVM-IR&lt;/strong&gt; contained by &lt;em&gt;.exe&lt;/em&gt; file to improve &lt;strong&gt;Hot Code&lt;/strong&gt;'s performance at the cost of &lt;strong&gt;Cold Code&lt;/strong&gt;'s performance.&lt;br&gt;
Then, the &lt;strong&gt;Offline Reoptimizer&lt;/strong&gt; passes the reoptimized &lt;strong&gt;LLVM-IR&lt;/strong&gt; and &lt;strong&gt;Native Code&lt;/strong&gt; to &lt;em&gt;.exe&lt;/em&gt; file to save them long-term.&lt;/p&gt;

</description>
      <category>llvm</category>
    </item>
  </channel>
</rss>
