編譯器開發系列--Ocelot語言7.中間代碼,編譯器--ocelot

來源:互聯網
上載者:User

編譯器開發系列--Ocelot語言7.中間代碼,編譯器--ocelot

Ocelot的中間代碼是仿照國外編譯器相關圖書Modern Compiler Implementation 中所使用的名為Tree 的中間代碼設計的。顧名思義,Tree 是一種樹形結構,其特徵是簡單,而且方便轉換為機器語言。

例如以下代碼:

int main(int argc, char** argv){return ++argc;}

會被轉換成如下的中間代碼:

<<IR>> (G:\編譯原理\自製編譯器\源碼\test\hello_ir.cb:1)variables:functions:    <<DefinedFunction>> (G:\編譯原理\自製編譯器\源碼\test\hello_ir.cb:1)    name: main    isPrivate: false    type: int(int, char**)    body:        <<Assign>> (G:\編譯原理\自製編譯器\源碼\test\hello_ir.cb:3)        lhs:            <<Addr>>            type: INT32            entity: argc        rhs:            <<Bin>>            type: INT32            op: ADD            left:                <<Var>>                type: INT32                entity: argc            right:                <<Int>>                type: INT32                value: 1        <<Return>> (G:\編譯原理\自製編譯器\源碼\test\hello_ir.cb:3)        expr:            <<Var>>            type: INT32            entity: argc

組成中間代碼的類如表11.1 所示。

所有語句的節點都繼承自Stmt 類,運算式的節點繼承自Expr 類。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.