import{_ as r}from"./plugin-vue_export-helper-DlAUqK2U.js";import{c as t,d as a,a as Q,b as V,o as H}from"./app-BNrZTL3A.js";const n="/assets/TAC_Code1-C2mEW6js.png",d="/assets/TAC_Instruction-D1KCt5bE.png",m="/assets/TAC_Code2-RAZ95TV7.png",l="/assets/TAC_Code3-CG_E8cM4.png",s="/assets/TAC_Code4-D_gYuQBk.png",e="/assets/%E7%BB%BC%E5%90%88%E5%B1%9E%E6%80%A7%E8%AF%AD%E4%B9%89%E8%A7%84%E5%88%991-Ca21N-fK.png",o="/assets/%E7%BB%BC%E5%90%88%E5%B1%9E%E6%80%A7%E8%AF%AD%E4%B9%89%E8%A7%84%E5%88%992-CYak_ZHl.png",h="/assets/%E7%BB%BC%E5%90%88%E5%B1%9E%E6%80%A7%E8%AF%AD%E4%B9%89%E5%88%86%E6%9E%90-BAyRBjmb.png",p="/assets/if%E7%BB%93%E6%9E%84-Cwu-2cdU.png",L="/assets/if-else%E7%BB%93%E6%9E%84-CMsB7ZkG.png",g="/assets/while%E7%BB%93%E6%9E%84-CPJhMSik.png",M="/assets/or%E7%BB%93%E6%9E%84-CrZK_PpT.png",c="/assets/and%E7%BB%93%E6%9E%84-FwaaYcAw.png",f="/assets/%E5%B8%83%E5%B0%94%E8%A1%A8%E8%BE%BE%E5%BC%8F%E4%BE%8B%E5%AD%90-_P-vmz_f.png",Z="/assets/%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6%E7%A4%BA%E4%BE%8B%E5%9B%BE-DvxXxgMM.png",i="/assets/%E5%B0%BE%E9%80%92%E5%BD%92%E4%BC%98%E5%8C%96-0pAHL3hw.png",u="/assets/%E4%BB%A3%E7%A0%81%E7%A7%BB%E5%8A%A8-D9Pw_n9A.png",x="/assets/%E5%88%A0%E9%99%A4-BVHrrRLi.png",w="/assets/flowgraph-B1PphNbH.png",b="/assets/DAG1-laYv4mNL.png",y="/assets/DAG2-CScncBsr.png",v="/assets/DAG3-DXC38M6j.png",C={},E={class:"MathJax",jax:"SVG",style:{position:"relative"}},D={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"34.529ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 15262 1000","aria-hidden":"true"},B={class:"MathJax",jax:"SVG",style:{position:"relative"}},k={style:{"vertical-align":"-0.14ex"},xmlns:"http://www.w3.org/2000/svg",width:"1.131ex",height:"0.084ex",role:"img",focusable:"false",viewBox:"0 25 500 37","aria-hidden":"true"},j={class:"MathJax",jax:"SVG",style:{position:"relative"}},A={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"33.497ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 14805.6 1000","aria-hidden":"true"},F={class:"MathJax",jax:"SVG",style:{position:"relative"}},S={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"23.945ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 10583.6 1000","aria-hidden":"true"},z={class:"MathJax",jax:"SVG",style:{position:"relative"}},G={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"32.303ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 14277.9 1000","aria-hidden":"true"},_={class:"MathJax",jax:"SVG",style:{position:"relative"}},J={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"30.13ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 13317.4 1000","aria-hidden":"true"},R={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},I={style:{"vertical-align":"-3.733ex"},xmlns:"http://www.w3.org/2000/svg",width:"27.794ex",height:"8.597ex",role:"img",focusable:"false",viewBox:"0 -2150 12285.1 3800","aria-hidden":"true"},O={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},P={style:{"vertical-align":"-2.036ex"},xmlns:"http://www.w3.org/2000/svg",width:"28.14ex",height:"5.204ex",role:"img",focusable:"false",viewBox:"0 -1400 12438 2300","aria-hidden":"true"},N={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},X={style:{"vertical-align":"-9.389ex"},xmlns:"http://www.w3.org/2000/svg",width:"26.554ex",height:"19.91ex",role:"img",focusable:"false",viewBox:"0 -4650 11737 8800","aria-hidden":"true"},q={id:"",tabindex:"-1"},Y={class:"header-anchor",href:"#"},K={class:"MathJax",jax:"SVG",style:{position:"relative"}},W={style:{"vertical-align":"-0.05ex"},xmlns:"http://www.w3.org/2000/svg",width:"16.327ex",height:"1.645ex",role:"img",focusable:"false",viewBox:"0 -705 7216.6 727","aria-hidden":"true"},U={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},$={style:{"vertical-align":"-3.507ex"},xmlns:"http://www.w3.org/2000/svg",width:"44.539ex",height:"8.145ex",role:"img",focusable:"false",viewBox:"0 -2050 19686.4 3600","aria-hidden":"true"},Q1={id:"-1",tabindex:"-1"},T1={class:"header-anchor",href:"#-1"},a1={class:"MathJax",jax:"SVG",style:{position:"relative"}},t1={style:{"vertical-align":"-0.05ex"},xmlns:"http://www.w3.org/2000/svg",width:"23.377ex",height:"1.645ex",role:"img",focusable:"false",viewBox:"0 -705 10332.6 727","aria-hidden":"true"},H1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},V1={style:{"vertical-align":"-4.977ex"},xmlns:"http://www.w3.org/2000/svg",width:"63.033ex",height:"11.086ex",role:"img",focusable:"false",viewBox:"0 -2700 27860.8 4900","aria-hidden":"true"},r1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},n1={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"28.87ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 12760.6 1000","aria-hidden":"true"},d1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},m1={style:{"vertical-align":"-7.919ex"},xmlns:"http://www.w3.org/2000/svg",width:"26.554ex",height:"16.968ex",role:"img",focusable:"false",viewBox:"0 -4000 11737 7500","aria-hidden":"true"},l1={id:"-2",tabindex:"-1"},s1={class:"header-anchor",href:"#-2"},e1={class:"MathJax",jax:"SVG",style:{position:"relative"}},o1={style:{"vertical-align":"-0.05ex"},xmlns:"http://www.w3.org/2000/svg",width:"17.947ex",height:"1.645ex",role:"img",focusable:"false",viewBox:"0 -705 7932.6 727","aria-hidden":"true"},h1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},p1={style:{"vertical-align":"-4.977ex"},xmlns:"http://www.w3.org/2000/svg",width:"62.865ex",height:"11.086ex",role:"img",focusable:"false",viewBox:"0 -2700 27786.3 4900","aria-hidden":"true"},L1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},g1={style:{"vertical-align":"-3.733ex"},xmlns:"http://www.w3.org/2000/svg",width:"35.534ex",height:"8.597ex",role:"img",focusable:"false",viewBox:"0 -2150 15705.9 3800","aria-hidden":"true"},M1={class:"MathJax",jax:"SVG",style:{position:"relative"}},c1={style:{"vertical-align":"-0.025ex"},xmlns:"http://www.w3.org/2000/svg",width:"15.156ex",height:"1.595ex",role:"img",focusable:"false",viewBox:"0 -694 6699 705","aria-hidden":"true"},f1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},Z1={style:{"vertical-align":"-3.507ex"},xmlns:"http://www.w3.org/2000/svg",width:"14.207ex",height:"8.145ex",role:"img",focusable:"false",viewBox:"0 -2050 6279.6 3600","aria-hidden":"true"},i1={id:"-3",tabindex:"-1"},u1={class:"header-anchor",href:"#-3"},x1={class:"MathJax",jax:"SVG",style:{position:"relative"}},w1={style:{"vertical-align":"-0.025ex"},xmlns:"http://www.w3.org/2000/svg",width:"13.553ex",height:"1.563ex",role:"img",focusable:"false",viewBox:"0 -680 5990.6 691","aria-hidden":"true"},b1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},y1={style:{"vertical-align":"-6.448ex"},xmlns:"http://www.w3.org/2000/svg",width:"43.633ex",height:"14.027ex",role:"img",focusable:"false",viewBox:"0 -3350 19286 6200","aria-hidden":"true"},v1={id:"-4",tabindex:"-1"},C1={class:"header-anchor",href:"#-4"},E1={class:"MathJax",jax:"SVG",style:{position:"relative"}},D1={style:{"vertical-align":"-0.025ex"},xmlns:"http://www.w3.org/2000/svg",width:"15.182ex",height:"1.595ex",role:"img",focusable:"false",viewBox:"0 -694 6710.6 705","aria-hidden":"true"},B1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},k1={style:{"vertical-align":"-6.448ex"},xmlns:"http://www.w3.org/2000/svg",width:"45.231ex",height:"14.027ex",role:"img",focusable:"false",viewBox:"0 -3350 19992 6200","aria-hidden":"true"},j1={id:"-5",tabindex:"-1"},A1={class:"header-anchor",href:"#-5"},F1={class:"MathJax",jax:"SVG",style:{position:"relative"}},S1={style:{"vertical-align":"-0.025ex"},xmlns:"http://www.w3.org/2000/svg",width:"11.567ex",height:"1.563ex",role:"img",focusable:"false",viewBox:"0 -680 5112.6 691","aria-hidden":"true"},z1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},G1={style:{"vertical-align":"-3.507ex"},xmlns:"http://www.w3.org/2000/svg",width:"16.656ex",height:"8.145ex",role:"img",focusable:"false",viewBox:"0 -2050 7362 3600","aria-hidden":"true"},_1={class:"MathJax",jax:"SVG",style:{position:"relative"}},J1={style:{"vertical-align":"0"},xmlns:"http://www.w3.org/2000/svg",width:"1.729ex",height:"1.538ex",role:"img",focusable:"false",viewBox:"0 -680 764 680","aria-hidden":"true"},R1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},I1={style:{"vertical-align":"-3.507ex"},xmlns:"http://www.w3.org/2000/svg",width:"23.943ex",height:"8.145ex",role:"img",focusable:"false",viewBox:"0 -2050 10582.8 3600","aria-hidden":"true"},O1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},P1={style:{"vertical-align":"-6.586ex"},xmlns:"http://www.w3.org/2000/svg",width:"27.914ex",height:"14.302ex",role:"img",focusable:"false",viewBox:"0 -3410.8 12337.8 6321.6","aria-hidden":"true"},N1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},X1={style:{"vertical-align":"-9.447ex"},xmlns:"http://www.w3.org/2000/svg",width:"19.718ex",height:"20.025ex",role:"img",focusable:"false",viewBox:"0 -4675.5 8715.6 8850.9","aria-hidden":"true"},q1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},Y1={style:{"vertical-align":"-4.977ex"},xmlns:"http://www.w3.org/2000/svg",width:"20.41ex",height:"11.086ex",role:"img",focusable:"false",viewBox:"0 -2700 9021.1 4900","aria-hidden":"true"},K1={class:"MathJax",jax:"SVG",display:"true",style:{position:"relative"}},W1={style:{"vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"12.679ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 5604 1000","aria-hidden":"true"},U1={class:"MathJax",jax:"SVG",style:{position:"relative"}},$1={style:{"vertical-align":"0"},xmlns:"http://www.w3.org/2000/svg",width:"1.729ex",height:"1.538ex",role:"img",focusable:"false",viewBox:"0 -680 764 680","aria-hidden":"true"},Q2={class:"MathJax",jax:"SVG",style:{position:"relative"}},T2={style:{"vertical-align":"-0.025ex"},xmlns:"http://www.w3.org/2000/svg",width:"4.348ex",height:"1.62ex",role:"img",focusable:"false",viewBox:"0 -705 1922 716","aria-hidden":"true"},a2={class:"MathJax",jax:"SVG",style:{position:"relative"}},t2={style:{"vertical-align":"-0.025ex"},xmlns:"http://www.w3.org/2000/svg",width:"4.536ex",height:"1.416ex",role:"img",focusable:"false",viewBox:"0 -615 2005 626","aria-hidden":"true"},H2={class:"MathJax",jax:"SVG",style:{position:"relative"}},V2={style:{"vertical-align":"-0.186ex"},xmlns:"http://www.w3.org/2000/svg",width:"18.107ex",height:"1.692ex",role:"img",focusable:"false",viewBox:"0 -666 8003.1 748","aria-hidden":"true"},r2={class:"MathJax",jax:"SVG",style:{position:"relative"}},n2={style:{"vertical-align":"-0.439ex"},xmlns:"http://www.w3.org/2000/svg",width:"30.053ex",height:"2.009ex",role:"img",focusable:"false",viewBox:"0 -694 13283.6 888","aria-hidden":"true"};function d2(m2,T){return H(),t("div",null,[T[91]||(T[91]=a('

介绍

  1. 生成中间代码(IR Iermediate code 码)
  2. 生成某种汇编形式的代码,而不是真正的可执行代码
  3. 优化目标代码

中间代码

生成三地址码

运算

[TAC_Code1.png]
[TAC_Code1.png]

变量赋值

[TAC_Instruction.png]
[TAC_Instruction.png]

布尔值

[TAC_Code2.png]
[TAC_Code2.png]

流程控制语句

[TAC_Code3.png]
[TAC_Code4.png]

三地址码的实现

四元组实现

',17)),Q("ul",null,[Q("li",null,[T[4]||(T[4]=V("用")),Q("mjx-container",E,[(H(),t("svg",D,T[0]||(T[0]=[a('',1)]))),T[1]||(T[1]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mo",{stretchy:"false"},"("),Q("mi",null,"o"),Q("mi",null,"p"),Q("mo",null,","),Q("mi",null,"o"),Q("mi",null,"p"),Q("mi",null,"e"),Q("mi",null,"r"),Q("mi",null,"a"),Q("mi",null,"n"),Q("mi",null,"d"),Q("mn",null,"1"),Q("mo",null,","),Q("mi",null,"o"),Q("mi",null,"p"),Q("mi",null,"e"),Q("mi",null,"r"),Q("mi",null,"a"),Q("mi",null,"n"),Q("mi",null,"d"),Q("mn",null,"2"),Q("mo",null,","),Q("mi",null,"o"),Q("mi",null,"p"),Q("mi",null,"e"),Q("mi",null,"r"),Q("mi",null,"a"),Q("mi",null,"n"),Q("mi",null,"d"),Q("mn",null,"3"),Q("mo",{stretchy:"false"},")")])],-1))]),T[5]||(T[5]=V("来表示一个三地址指令,用")),Q("mjx-container",B,[(H(),t("svg",k,T[2]||(T[2]=[Q("g",{stroke:"currentColor",fill:"currentColor","stroke-width":"0",transform:"scale(1,-1)"},[Q("g",{"data-mml-node":"math"},[Q("g",{"data-mml-node":"mi"},[Q("path",{"data-c":"5F",d:"M0 -62V-25H499V-62H0Z"})])])],-1)]))),T[3]||(T[3]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",{mathvariant:"normal"},"_")])],-1))]),T[6]||(T[6]=V("来表示缺省的操作数"))]),Q("li",null,[T[11]||(T[11]=V("例如")),Q("mjx-container",j,[(H(),t("svg",A,T[7]||(T[7]=[a('',1)]))),T[8]||(T[8]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"t"),Q("mn",null,"2"),Q("mo",null,"="),Q("mi",null,"f"),Q("mi",null,"a"),Q("mi",null,"c"),Q("mi",null,"t"),Q("mo",null,"∗"),Q("mi",null,"x"),Q("mo",{stretchy:"false"},"→"),Q("mo",{stretchy:"false"},"("),Q("mi",null,"m"),Q("mi",null,"u"),Q("mi",null,"l"),Q("mo",null,","),Q("mi",null,"f"),Q("mi",null,"a"),Q("mi",null,"c"),Q("mi",null,"t"),Q("mo",null,","),Q("mi",null,"x"),Q("mo",null,","),Q("mi",{mathvariant:"normal"},"_"),Q("mi",null,"t"),Q("mn",null,"2"),Q("mo",{stretchy:"false"},")")])],-1))]),T[12]||(T[12]=V(" ,")),Q("mjx-container",F,[(H(),t("svg",S,T[9]||(T[9]=[a('',1)]))),T[10]||(T[10]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"l"),Q("mi",null,"a"),Q("mi",null,"b"),Q("mi",null,"e"),Q("mi",null,"l"),Q("mstyle",{scriptlevel:"0"},[Q("mspace",{width:"0.278em"})]),Q("mi",null,"L"),Q("mn",null,"2"),Q("mo",{stretchy:"false"},"→"),Q("mo",{stretchy:"false"},"("),Q("mi",null,"l"),Q("mi",null,"a"),Q("mi",null,"b"),Q("mo",null,","),Q("mi",null,"L"),Q("mn",null,"2"),Q("mo",null,","),Q("mi",{mathvariant:"normal"},"_"),Q("mo",null,","),Q("mi",{mathvariant:"normal"},"_"),Q("mo",{stretchy:"false"},")")])],-1))])])]),T[92]||(T[92]=Q("h4",{id:"三元组实现",tabindex:"-1"},[Q("a",{class:"header-anchor",href:"#三元组实现"},[Q("span",null,"三元组实现")])],-1)),Q("ul",null,[T[18]||(T[18]=Q("li",null,"用指令的地址来替换掉一个返回值变量来压缩掉一个变量",-1)),Q("li",null,[T[17]||(T[17]=V("例如")),Q("mjx-container",z,[(H(),t("svg",G,T[13]||(T[13]=[a('',1)]))),T[14]||(T[14]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"t"),Q("mn",null,"2"),Q("mo",null,"="),Q("mi",null,"f"),Q("mi",null,"a"),Q("mi",null,"c"),Q("mi",null,"t"),Q("mo",null,"∗"),Q("mi",null,"x"),Q("mo",{stretchy:"false"},"→"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"4"),Q("mo",{stretchy:"false"},")"),Q("mo",{stretchy:"false"},"("),Q("mi",null,"m"),Q("mi",null,"u"),Q("mi",null,"l"),Q("mo",null,","),Q("mi",null,"f"),Q("mi",null,"a"),Q("mi",null,"c"),Q("mi",null,"t"),Q("mo",null,","),Q("mi",null,"x"),Q("mo",{stretchy:"false"},")")])],-1))]),Q("mjx-container",_,[(H(),t("svg",J,T[15]||(T[15]=[a('',1)]))),T[16]||(T[16]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"f"),Q("mi",null,"a"),Q("mi",null,"c"),Q("mi",null,"t"),Q("mo",null,"="),Q("mi",null,"t"),Q("mn",null,"2"),Q("mo",{stretchy:"false"},"→"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"5"),Q("mo",{stretchy:"false"},")"),Q("mo",{stretchy:"false"},"("),Q("mi",null,"a"),Q("mi",null,"s"),Q("mi",null,"n"),Q("mo",null,","),Q("mo",{stretchy:"false"},"("),Q("mn",null,"4"),Q("mo",{stretchy:"false"},")"),Q("mo",null,","),Q("mi",null,"f"),Q("mi",null,"a"),Q("mi",null,"c"),Q("mi",null,"t"),Q("mo",{stretchy:"false"},")")])],-1))])])]),T[93]||(T[93]=a('

区别

生成三地址码的细节

综合属性

',4)),Q("mjx-container",R,[(H(),t("svg",I,T[19]||(T[19]=[a('',1)]))),T[20]||(T[20]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"exp"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"id"),Q("mo",null,"="),Q("mtext",null,"exp"),Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mo",{minsize:"1.2em",maxsize:"1.2em"},"|")]),Q("mtext",null,"aexp")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"aexp"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"aexp+factor"),Q("mo",null,"∣"),Q("mtext",null,"factor")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"factor"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"(exp)"),Q("mo",null,"∣"),Q("mtext",null,"num"),Q("mo",null,"∣"),Q("mtext",null,"id")])])])])],-1))]),T[94]||(T[94]=a('

[综合属性语义规则1.png]
[综合属性语义规则2.png]
[综合属性语义分析.png]

语言结构

If
',3)),Q("mjx-container",O,[(H(),t("svg",P,T[21]||(T[21]=[a('',1)]))),T[22]||(T[22]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd",null,[Q("mtext",null,"if-stmt")]),Q("mtd",null,[Q("mi"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"if"),Q("mtext",null,"(exp)"),Q("mstyle",{scriptlevel:"0"},[Q("mspace",{width:"0.278em"})]),Q("mtext",null,"stmt")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mi"),Q("mo",{"data-mjx-texclass":"ORD",stretchy:"false"},"|"),Q("mtext",null,"if"),Q("mo",{stretchy:"false"},"("),Q("mtext",null,"exp"),Q("mo",{stretchy:"false"},")"),Q("mstyle",{scriptlevel:"0"},[Q("mspace",{width:"0.278em"})]),Q("mtext",null,"stmt else stmt")])])])])],-1))]),Q("mjx-container",N,[(H(),t("svg",X,T[23]||(T[23]=[a('',1)]))),T[24]||(T[24]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"if"),Q("mi",{mathvariant:"normal"},"_"),Q("mtext",null,"false t1 goto L1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"goto L2")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"label L1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"label L2")])])])])],-1))]),Q("h6",q,[Q("a",Y,[Q("span",null,[Q("mjx-container",K,[(H(),t("svg",W,T[25]||(T[25]=[a('',1)]))),T[26]||(T[26]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"S"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"if E then S1")])],-1))])])])]),T[95]||(T[95]=Q("figure",null,[Q("img",{src:p,alt:"[if结构.png]",tabindex:"0",loading:"lazy"}),Q("figcaption",null,"[if结构.png]")],-1)),Q("mjx-container",U,[(H(),t("svg",$,T[27]||(T[27]=[a('',1)]))),T[28]||(T[28]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E.true"),Q("mo",null,"="),Q("mtext",null,"newlabel ();")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E.false"),Q("mo",null,"="),Q("mtext",null,"S.next;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"S.code"),Q("mo",null,"="),Q("mtext",null,"E.code"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"Label E.true"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"S1.code")])])])])],-1))]),Q("h6",Q1,[Q("a",T1,[Q("span",null,[Q("mjx-container",a1,[(H(),t("svg",t1,T[29]||(T[29]=[a('',1)]))),T[30]||(T[30]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"S"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"if E then S1 else S2")])],-1))])])])]),T[96]||(T[96]=Q("figure",null,[Q("img",{src:L,alt:"[if-else结构.png]",tabindex:"0",loading:"lazy"}),Q("figcaption",null,"[if-else结构.png]")],-1)),Q("mjx-container",H1,[(H(),t("svg",V1,T[31]||(T[31]=[a('',1)]))),T[32]||(T[32]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E.true=newlabel"),Q("mo",null,";"),Q("mtext",null,"E.false=newlabel"),Q("mo",null,";")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"S1.next=S.next"),Q("mo",null,";"),Q("mtext",null,"S2.next=S.next;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"S.code=E.code"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"LabelE.true"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mi",null,"S"),Q("mn",null,"1."),Q("mtext",null,"code"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"goto S.next"),Q("mo",null,"+"),Q("mo",null,"+")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"Label E.false++S2.code")])])])])],-1))]),T[97]||(T[97]=Q("h5",{id:"while",tabindex:"-1"},[Q("a",{class:"header-anchor",href:"#while"},[Q("span",null,"While")])],-1)),Q("mjx-container",r1,[(H(),t("svg",n1,T[33]||(T[33]=[a('',1)]))),T[34]||(T[34]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtext",null,"while-stmt"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"while"),Q("mo",{stretchy:"false"},"("),Q("mi",null,"exp"),Q("mo",{stretchy:"false"},")"),Q("mtext",null,"stmt")])],-1))]),Q("mjx-container",d1,[(H(),t("svg",m1,T[35]||(T[35]=[a('',1)]))),T[36]||(T[36]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"label L1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"if"),Q("mi",{mathvariant:"normal"},"_"),Q("mtext",null,"false t1 goto L2")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"goto L1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"label L2")])])])])],-1))]),Q("h6",l1,[Q("a",s1,[Q("span",null,[Q("mjx-container",e1,[(H(),t("svg",o1,T[37]||(T[37]=[a('',1)]))),T[38]||(T[38]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"S"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"while E do S1")])],-1))])])])]),T[98]||(T[98]=Q("figure",null,[Q("img",{src:g,alt:"[while结构.png]",tabindex:"0",loading:"lazy"}),Q("figcaption",null,"[while结构.png]")],-1)),Q("mjx-container",h1,[(H(),t("svg",p1,T[39]||(T[39]=[a('',1)]))),T[40]||(T[40]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"S.begin=newlabel"),Q("mo",null,";"),Q("mtext",null,"E.true=newlabel"),Q("mo",null,";"),Q("mtext",null,"E.false=S.next;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"S1.next=S.begin;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"S.code=Label S.beginin"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"E.code"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"Label E.true"),Q("mo",null,"+"),Q("mo",null,"+"),Q("mtext",null,"S1.code")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"++goto S.begin")])])])])],-1))]),T[99]||(T[99]=Q("h5",{id:"布尔表达式",tabindex:"-1"},[Q("a",{class:"header-anchor",href:"#布尔表达式"},[Q("span",null,"布尔表达式")])],-1)),Q("ul",null,[Q("li",null,[T[43]||(T[43]=V("布尔表达式有两个主要作用,一个是用来计算逻辑值,另一个是用在 if 或 while 等语句中作为条件控制。")),Q("mjx-container",L1,[(H(),t("svg",g1,T[41]||(T[41]=[a('',1)]))),T[42]||(T[42]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnspacing:"1em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd",null,[Q("mtext",null,"E"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"E or E"),Q("mo",null,"∣"),Q("mtext",null,"E and E"),Q("mo",null,"∣"),Q("mtext",null,"not E"),Q("mo",null,"∣"),Q("mtext",null,"(E)")])]),Q("mtr",null,[Q("mtd",null,[Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mo",{minsize:"1.2em",maxsize:"1.2em"},"|")]),Q("mtext",null,"id relop id"),Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mo",{minsize:"1.2em",maxsize:"1.2em"},"|")]),Q("mtext",null,"true"),Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mo",{minsize:"1.2em",maxsize:"1.2em"},"|")]),Q("mtext",null,"false")])]),Q("mtr",null,[Q("mtd",null,[Q("mi",null,"r"),Q("mi",null,"e"),Q("mi",null,"l"),Q("mi",null,"o"),Q("mi",null,"p"),Q("mo",null,":"),Q("mi",{mathvariant:"normal"},"关"),Q("mi",{mathvariant:"normal"},"系"),Q("mi",{mathvariant:"normal"},"运"),Q("mi",{mathvariant:"normal"},"算"),Q("mi",{mathvariant:"normal"},"符"),Q("mo",{stretchy:"false"},"("),Q("mo",null,"≥"),Q("mo",null,","),Q("mo",null,"≤"),Q("mo",null,","),Q("mo",null,"<"),Q("mo",null,","),Q("mo",null,">"),Q("mo",null,","),Q("mo",null,"="),Q("mo",null,","),Q("mo",null,"≠"),Q("mo",{stretchy:"false"},")")])])])])],-1))])]),Q("li",null,[T[48]||(T[48]=V("例如")),Q("mjx-container",M1,[(H(),t("svg",c1,T[44]||(T[44]=[a('',1)]))),T[45]||(T[45]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"a or b and not c")])],-1))]),T[49]||(T[49]=V(" 就会被翻译成")),Q("mjx-container",f1,[(H(),t("svg",Z1,T[46]||(T[46]=[a('',1)]))),T[47]||(T[47]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"_t1"),Q("mo",null,"="),Q("mtext",null,"not c")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"_t2"),Q("mo",null,"="),Q("mtext",null,"b and t1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"_t3"),Q("mo",null,"="),Q("mtext",null,"a or t2")])])])])],-1))])])]),Q("h6",i1,[Q("a",u1,[Q("span",null,[Q("mjx-container",x1,[(H(),t("svg",w1,T[50]||(T[50]=[a('',1)]))),T[51]||(T[51]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"E"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"E1 or E2")])],-1))])])])]),T[100]||(T[100]=Q("figure",null,[Q("img",{src:M,alt:"[or结构.png]",tabindex:"0",loading:"lazy"}),Q("figcaption",null,"[or结构.png]")],-1)),Q("mjx-container",b1,[(H(),t("svg",y1,T[52]||(T[52]=[a('',1)]))),T[53]||(T[53]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E1.true=E.true;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E1.false=newlabel;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E2.true=E.true;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E2.false=E.false;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E.code=E1.code++label E1.false++E2.code")])])])])],-1))]),Q("h6",v1,[Q("a",C1,[Q("span",null,[Q("mjx-container",E1,[(H(),t("svg",D1,T[54]||(T[54]=[a('',1)]))),T[55]||(T[55]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"E"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"E1 and E2")])],-1))])])])]),T[101]||(T[101]=Q("figure",null,[Q("img",{src:c,alt:"[and结构.png]",tabindex:"0",loading:"lazy"}),Q("figcaption",null,"[and结构.png]")],-1)),Q("mjx-container",B1,[(H(),t("svg",k1,T[56]||(T[56]=[a('',1)]))),T[57]||(T[57]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E1.true=newlabel;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E1.false=E.false;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E2.true=E.true;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E2.false=E.false;")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"E.code=E1.code++ Label E1.true++ E2.code")])])])])],-1))]),Q("h6",j1,[Q("a",A1,[Q("span",null,[Q("mjx-container",F1,[(H(),t("svg",S1,T[58]||(T[58]=[a('',1)]))),T[59]||(T[59]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"E"),Q("mo",{accent:"false",stretchy:"false"},"→"),Q("mtext",null,"not E1")])],-1))])])])]),Q("mjx-container",z1,[(H(),t("svg",G1,T[60]||(T[60]=[a('',1)]))),T[61]||(T[61]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnspacing:"1em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd",null,[Q("mtext",null,"E1.true="),Q("mtext",null,"E.false;")])]),Q("mtr",null,[Q("mtd",null,[Q("mtext",null,"E1.false="),Q("mtext",null,"E.true;")])]),Q("mtr",null,[Q("mtd",null,[Q("mtext",null,"E.code=E1.code;")])])])])],-1))]),T[102]||(T[102]=a('
布尔表达式示例
[布尔表达式例子.png]
[布尔表达式例子.png]
流程控制与布尔表达式翻译
',3)),Q("ul",null,[Q("li",null,[T[66]||(T[66]=V("流程控制的语法(其中")),Q("mjx-container",_1,[(H(),t("svg",J1,T[62]||(T[62]=[Q("g",{stroke:"currentColor",fill:"currentColor","stroke-width":"0",transform:"scale(1,-1)"},[Q("g",{"data-mml-node":"math"},[Q("g",{"data-mml-node":"mi"},[Q("path",{"data-c":"1D438",d:"M492 213Q472 213 472 226Q472 230 477 250T482 285Q482 316 461 323T364 330H312Q311 328 277 192T243 52Q243 48 254 48T334 46Q428 46 458 48T518 61Q567 77 599 117T670 248Q680 270 683 272Q690 274 698 274Q718 274 718 261Q613 7 608 2Q605 0 322 0H133Q31 0 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q146 66 215 342T285 622Q285 629 281 629Q273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H757Q764 676 764 669Q764 664 751 557T737 447Q735 440 717 440H705Q698 445 698 453L701 476Q704 500 704 528Q704 558 697 578T678 609T643 625T596 632T532 634H485Q397 633 392 631Q388 629 386 622Q385 619 355 499T324 377Q347 376 372 376H398Q464 376 489 391T534 472Q538 488 540 490T557 493Q562 493 565 493T570 492T572 491T574 487T577 483L544 351Q511 218 508 216Q505 213 492 213Z"})])])],-1)]))),T[63]||(T[63]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"E")])],-1))]),T[67]||(T[67]=V("为布尔表达式):")),Q("mjx-container",R1,[(H(),t("svg",I1,T[64]||(T[64]=[a('',1)]))),T[65]||(T[65]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd",null,[Q("mi",null,"S"),Q("mo",{accent:"false",stretchy:"false"},"→")]),Q("mtd",null,[Q("mtext",null,"if E then S1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"| if E then S1 else S2")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"| while E do S1")])])])])],-1))])]),T[68]||(T[68]=Q("li",null,"在流程控制中,布尔表达式的值不再是由临时变量来表示并存储,而是用程序跳转的位置来表示。",-1))]),T[103]||(T[103]=a(`
流程控制示例
while a<b do
  if c<d then
    x=y+z
  else
    x=y-z
[流程控制示例图.png]
[流程控制示例图.png]

代码优化

常见的优化

寄存器优化

  • 通过提高程序运行时的缓存命中率来提高运行速度

冗余的操作

相同的子表达式
',9)),Q("mjx-container",O1,[(H(),t("svg",P1,T[69]||(T[69]=[a('',1)]))),T[70]||(T[70]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd",null,[Q("msub",null,[Q("mtext",null,"(1)T"),Q("mn",null,"1")])]),Q("mtd",null,[Q("mi"),Q("mo",null,"="),Q("mn",null,"4"),Q("mo",null,"∗"),Q("mtext",null,"I")])]),Q("mtr",null,[Q("mtd",null,[Q("mtext",null,"(2)"),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"2")])]),Q("mtd",null,[Q("mi"),Q("mo",null,"="),Q("mtext",null,"addr(A)-4")])]),Q("mtr",null,[Q("mtd",null,[Q("msub",null,[Q("mtext",null,"(3)T"),Q("mn",null,"3")])]),Q("mtd",null,[Q("mi"),Q("mo",null,"="),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"2")]),Q("mo",{stretchy:"false"},"["),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"1")]),Q("mo",{stretchy:"false"},"]")])]),Q("mtr",null,[Q("mtd",null,[Q("msub",null,[Q("mtext",null,"(4)T"),Q("mn",null,"4")])]),Q("mtd",null,[Q("mi"),Q("mo",null,"="),Q("mn",null,"4"),Q("mo",null,"∗"),Q("mtext",null,"I"),Q("mo",{stretchy:"false"},"→"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"4"),Q("mo",{stretchy:"false"},")"),Q("msub",null,[Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mi",{mathvariant:"normal"},"T")]),Q("mn",null,"4")]),Q("mo",null,":="),Q("msub",null,[Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mi",{mathvariant:"normal"},"T")]),Q("mn",null,"1")])])]),Q("mtr",null,[Q("mtd")])])])],-1))]),T[104]||(T[104]=Q("h5",{id:"没有用到的变量",tabindex:"-1"},[Q("a",{class:"header-anchor",href:"#没有用到的变量"},[Q("span",null,"没有用到的变量")])],-1)),Q("mjx-container",N1,[(H(),t("svg",X1,T[71]||(T[71]=[a('',1)]))),T[72]||(T[72]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"(1)I"),Q("mo",null,"="),Q("mn",null,"1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"(2)"),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"1")]),Q("mo",null,"="),Q("mn",null,"4")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("msub",null,[Q("mtext",null,"(3)T"),Q("mn",null,"3")]),Q("mo",null,"="),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"2")]),Q("mo",{stretchy:"false"},"["),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"1")]),Q("mo",{stretchy:"false"},"]")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"(4)"),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"4")]),Q("mo",null,"="),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"1")])])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"(5)I"),Q("mo",null,"="),Q("mtext",null,"I"),Q("mo",null,"+"),Q("mn",null,"1")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mrow",{"data-mjx-texclass":"ORD"},[Q("mo",{stretchy:"false"},"("),Q("mn",null,"6"),Q("mo",{stretchy:"false"},")"),Q("msub",null,[Q("mi",{mathvariant:"normal"},"T"),Q("mn",null,"1")]),Q("mo",null,"="),Q("msub",null,[Q("mi",{mathvariant:"normal"},"T"),Q("mn",null,"1")]),Q("mo",null,"+"),Q("mn",null,"4")])])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mi"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"7"),Q("mo",{stretchy:"false"},")"),Q("msub",null,[Q("mtext",null,"if T"),Q("mn",null,"1")]),Q("mtext",null,"≤80 goto (3)")])])])])],-1))]),T[105]||(T[105]=Q("ul",null,[Q("li",null,"(1)、(4)、(5)都是无用代码,于是可以化简成")],-1)),Q("mjx-container",q1,[(H(),t("svg",Y1,T[73]||(T[73]=[a('',1)]))),T[74]||(T[74]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtable",{displaystyle:"true",columnalign:"right left",columnspacing:"0em",rowspacing:"3pt"},[Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mtext",null,"(2)"),Q("msub",null,[Q("mtext",null,"T"),Q("mn",null,"1")]),Q("mo",null,":="),Q("mn",null,"4")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mi"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"3"),Q("mo",{stretchy:"false"},")"),Q("msub",null,[Q("mi",null,"T"),Q("mn",null,"3")]),Q("mo",null,":="),Q("msub",null,[Q("mi",null,"T"),Q("mn",null,"2")]),Q("mo",{stretchy:"false"},"["),Q("msub",null,[Q("mi",null,"T"),Q("mn",null,"1")]),Q("mo",{stretchy:"false"},"]")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mi"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"6"),Q("mo",{stretchy:"false"},")"),Q("msub",null,[Q("mi",null,"T"),Q("mn",null,"1")]),Q("mo",null,":="),Q("msub",null,[Q("mi",null,"T"),Q("mn",null,"1")]),Q("mo",null,"+"),Q("mn",null,"4")])]),Q("mtr",null,[Q("mtd"),Q("mtd",null,[Q("mi"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"7"),Q("mo",{stretchy:"false"},")"),Q("msub",null,[Q("mtext",null,"if T"),Q("mn",null,"1")]),Q("mo",null,"≤"),Q("mn",null,"80"),Q("mtext",null," goto"),Q("mo",{stretchy:"false"},"("),Q("mn",null,"3"),Q("mo",{stretchy:"false"},")")])])])])],-1))]),T[106]||(T[106]=Q("h5",{id:"消除死代码",tabindex:"-1"},[Q("a",{class:"header-anchor",href:"#消除死代码"},[Q("span",null,"消除死代码")])],-1)),Q("mjx-container",K1,[(H(),t("svg",W1,T[75]||(T[75]=[a('',1)]))),T[76]||(T[76]=Q("mjx-assistive-mml",{unselectable:"on",display:"block"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML",display:"block"},[Q("mtext",null,"if(E) do stmt")])],-1))]),Q("ul",null,[Q("li",null,[T[83]||(T[83]=V("如果")),Q("mjx-container",U1,[(H(),t("svg",$1,T[77]||(T[77]=[Q("g",{stroke:"currentColor",fill:"currentColor","stroke-width":"0",transform:"scale(1,-1)"},[Q("g",{"data-mml-node":"math"},[Q("g",{"data-mml-node":"mi"},[Q("path",{"data-c":"1D438",d:"M492 213Q472 213 472 226Q472 230 477 250T482 285Q482 316 461 323T364 330H312Q311 328 277 192T243 52Q243 48 254 48T334 46Q428 46 458 48T518 61Q567 77 599 117T670 248Q680 270 683 272Q690 274 698 274Q718 274 718 261Q613 7 608 2Q605 0 322 0H133Q31 0 31 11Q31 13 34 25Q38 41 42 43T65 46Q92 46 125 49Q139 52 144 61Q146 66 215 342T285 622Q285 629 281 629Q273 632 228 634H197Q191 640 191 642T193 659Q197 676 203 680H757Q764 676 764 669Q764 664 751 557T737 447Q735 440 717 440H705Q698 445 698 453L701 476Q704 500 704 528Q704 558 697 578T678 609T643 625T596 632T532 634H485Q397 633 392 631Q388 629 386 622Q385 619 355 499T324 377Q347 376 372 376H398Q464 376 489 391T534 472Q538 488 540 490T557 493Q562 493 565 493T570 492T572 491T574 487T577 483L544 351Q511 218 508 216Q505 213 492 213Z"})])])],-1)]))),T[78]||(T[78]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"E")])],-1))]),T[84]||(T[84]=V("的值恒为")),Q("mjx-container",Q2,[(H(),t("svg",T2,T[79]||(T[79]=[a('',1)]))),T[80]||(T[80]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"false")])],-1))]),T[85]||(T[85]=V(" ,那么")),Q("mjx-container",a2,[(H(),t("svg",t2,T[81]||(T[81]=[a('',1)]))),T[82]||(T[82]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mtext",null,"stmt")])],-1))]),T[86]||(T[86]=V("将永远不会执行,也就是所说的死代码"))])]),T[107]||(T[107]=a('

耗时的操作

乘法与移位
  • 把乘二优化成向左移位

常量优化

常量折叠
',5)),Q("p",null,[Q("mjx-container",H2,[(H(),t("svg",V2,T[87]||(T[87]=[a('',1)]))),T[88]||(T[88]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"a"),Q("mo",null,"="),Q("mn",null,"2"),Q("mo",null,"+"),Q("mn",null,"3"),Q("mo",{stretchy:"false"},"→"),Q("mi",null,"a"),Q("mo",null,"="),Q("mn",null,"5")])],-1))])]),T[108]||(T[108]=Q("h5",{id:"常量传播",tabindex:"-1"},[Q("a",{class:"header-anchor",href:"#常量传播"},[Q("span",null,"常量传播")])],-1)),Q("p",null,[Q("mjx-container",r2,[(H(),t("svg",n2,T[89]||(T[89]=[a('',1)]))),T[90]||(T[90]=Q("mjx-assistive-mml",{unselectable:"on",display:"inline"},[Q("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[Q("mi",null,"a"),Q("mo",null,"="),Q("mn",null,"2"),Q("mo",null,";"),Q("mi",null,"b"),Q("mo",null,"="),Q("mn",null,"3"),Q("mo",null,";"),Q("mi",null,"c"),Q("mo",null,"="),Q("mi",null,"a"),Q("mo",null,"+"),Q("mi",null,"b"),Q("mo",{stretchy:"false"},"→"),Q("mi",null,"c"),Q("mo",null,"="),Q("mn",null,"5")])],-1))])]),T[109]||(T[109]=a('

内联展开和尾递归

[尾递归优化.png]
[尾递归优化.png]

优化的时期

  • 三地址码生成时:直接优化语义树,可能对某个子树进行删除或者替换
  • 三地址码生成后:很多时候,从语法树上获取不到足够的信息来进行优化,这时候就要在中间代码上进行优化
  • 目标代码生成时:有可能要对某个特定的指令集进行优化又被称为窥孔优化(peephole optimization),在编译器理论中,窥孔优化是一种在生成的代码段中对非常小的指令集合执行的优化。该集合称为“窥孔”或“窗口”

优化的范围

局部优化(Local Optimizations)

  • 局部优化适用于直线代码段,即没有跳入或跳出序列的代码序列。一个最大的直线代码序列被称为一个基本块(basic block)。局部优化就是被限制在一个基本块中

全局优化(Global Optimizations)

  • 优化超出了基本块的范围,但仅限于单个过程。
  • 循环是很重要的优化位置,尤其是内部循环。
Code motion
  • 代码移动减少了循环中的代码量,就是把循环内的和循环无关的代码移动到循环外
    [代码移动.png]
Induction variables deletion
  • 归纳变量(Induction Variable)是指在循环的每次迭代中都会增加或减少固定数量的变量,或者是另一个归纳变量的线性函数。归纳变量通常用于循环优化中,例如循环展开和代码移动。
[删除.png]
[删除.png]

线程间优化(Interprocedural optimization)

  • 超出单个线程的范围,对整个程序进行优化

优化的工具

Flow graph

  1. 第一个指令是一个 basic block 的开始
  2. 每个作为 jump 的目标的 label 的语句是一个新的 basic block 的开始
  3. 每个跟着有条件跳转的指令都会开启一个新的 basic block (跟 2 差不多)
    [flowgraph.png]

DAG(directed acyclic graph)

  • DAG 跟踪在 basic block 中发生的计算和重新赋值

  • 叶子节点是从这个 block 之外来的变量和值

  • 内部节点都是对值的操作

  • 赋值被表现为把目标变量或临时变量 attach 到这个节点上
    [DAG1.png]

  • 基本块的开始标签和最后的跳转标签不被包括在 DAG 中

  • 复制操作不会增加新的节点,誓师会把新的标签添加到被复制值的节点上

  • 对相同值的重复使用也会被体现在 DAG 中

几种情况
  • 对于 x=y+z,如果 y 和 z 不变,则+的内部节点不需要创建,而是执行 y+z (常量折叠)
  • 对于 x=y+z,如果已经存在一个与 y+z 具有相同值的节点,我们不会创建新节点,而是给现有节点附加标签 x。 (局部公共子表达式消除)
  • 如果 x 之前标记过其他节点,我们删除该标签,因为 x 的“当前”值是刚刚创建的节点(消除不必要的分配)
    [DAG2.png]
    [DAG3.png]
',23))])}const e2=r(C,[["render",d2]]),o2=JSON.parse(`{"path":"/notes/Compile-Principles/Chapter5-Code-Generation.html","title":"Chapter5 语法生成","lang":"zh-CN","frontmatter":{"title":"Chapter5 语法生成","icon":"page","order":1,"author":"chiichen","date":"2023-10-11T00:00:00.000Z","category":["课程笔记"],"tag":["编译原理"],"sticky":true,"star":false,"footer":null,"copyright":"转载请注明出处","isOriginal":true,"description":"介绍 代码生成取决于:源代码、目标系统体系结构、运行时环境 代码生成可以被划分为三步: 生成中间代码(IR Iermediate code 码) 生成某种汇编形式的代码,而不是真正的可执行代码 优化目标代码 中间代码 以三地址码(TAC Three Address code)为例 生成三地址码 运算 [TAC_Code1.png][TAC_Code1....","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"Chapter5 语法生成\\",\\"image\\":[\\"\\"],\\"datePublished\\":\\"2023-10-11T00:00:00.000Z\\",\\"dateModified\\":\\"2025-01-30T06:51:55.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"chiichen\\"}]}"],["meta",{"property":"og:url","content":"https://chiichen.github.io/notes/Compile-Principles/Chapter5-Code-Generation.html"}],["meta",{"property":"og:site_name","content":"chiichen's Blog"}],["meta",{"property":"og:title","content":"Chapter5 语法生成"}],["meta",{"property":"og:description","content":"介绍 代码生成取决于:源代码、目标系统体系结构、运行时环境 代码生成可以被划分为三步: 生成中间代码(IR Iermediate code 码) 生成某种汇编形式的代码,而不是真正的可执行代码 优化目标代码 中间代码 以三地址码(TAC Three Address code)为例 生成三地址码 运算 [TAC_Code1.png][TAC_Code1...."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2025-01-30T06:51:55.000Z"}],["meta",{"property":"article:author","content":"chiichen"}],["meta",{"property":"article:tag","content":"编译原理"}],["meta",{"property":"article:published_time","content":"2023-10-11T00:00:00.000Z"}],["meta",{"property":"article:modified_time","content":"2025-01-30T06:51:55.000Z"}]]},"git":{"createdTime":1696994087000,"updatedTime":1738219915000,"contributors":[{"name":"Chi_Laptop","username":"","email":"2531693734@qq.com","commits":1},{"name":"ChiChen","username":"ChiChen","email":"2531693734@qq.com","commits":4,"url":"https://github.com/ChiChen"},{"name":"chiichen","username":"chiichen","email":"chiichen@qq.com","commits":4,"url":"https://github.com/chiichen"},{"name":"Chiichen","username":"Chiichen","email":"chiichen@qq.com","commits":1,"url":"https://github.com/Chiichen"}]},"readingTime":{"minutes":7.65,"words":2294},"filePathRelative":"notes/Compile-Principles/Chapter5-Code-Generation.md","excerpt":"

介绍

\\n
    \\n
  • 代码生成取决于:源代码、目标系统体系结构、运行时环境
  • \\n
  • 代码生成可以被划分为三步:
  • \\n
\\n
    \\n
  1. 生成中间代码(IR Iermediate code 码)
  2. \\n
  3. 生成某种汇编形式的代码,而不是真正的可执行代码
  4. \\n
  5. 优化目标代码
  6. \\n
\\n

中间代码

\\n
    \\n
  • 以三地址码(TAC Three Address code)为例
  • \\n
\\n

生成三地址码

\\n

运算

\\n
[TAC_Code1.png]
","autoDesc":true}`);export{e2 as comp,o2 as data};