📄 llvm.g
字号:
{ iList = null; }: (iList=branchI | iList=retI) { };branchI returns [ LinkedList iList ] { iList = new LinkedList(); Instruction inst = null; Operand condOperand, iftrueOperand, iffalseOperand, dstOperand = null; }: (BR BOOL condOperand=value[Type.Bool, false] COMMA LABEL iftrueOperand=value[Type.Label, false] COMMA LABEL iffalseOperand=value[Type.Label, false] { inst = Branch.create(Operators.BR, (BooleanOperand)condOperand, (LabelOperand)iftrueOperand, (LabelOperand)iffalseOperand); iList.addLast(inst); }) | (BR LABEL dstOperand=value[Type.Label, false] { inst = Goto.create(Operators.GOTO, (LabelOperand)dstOperand); iList.addLast(inst); }) { };retI returns [ LinkedList iList ] { iList = new LinkedList(); Instruction inst = null; Type t = null; Operand o = null; }: ((RET t=type o=value[t, false] { if (!(t.isFirstClass())) { System.err.println("Error: Type for return instruction must be first class on line: " + LT(0).getLine()); System.exit(-1); } inst = Return.create(Operators.RET, t, o); }) | (RET VOID { inst = Return.create(Operators.RET); })) { iList.addLast(inst); };binaryI returns [ LinkedList iList ] { iList = new LinkedList(); Instruction inst = null; Type t = null; Operand resOperand, val1Operand, val2Operand = null; Operator op = null; Varid resVarid = null; }: resVarid=varid EQUAL op=binaryOp t=type val1Operand=value[t, false] COMMA val2Operand=value[t, false] { if (!(t.isInteger() || t.isFloat() || t.isDouble())) { System.err.println("Error: Type for binary operation must be integer, float or double on line: " + LT(0).getLine()); System.exit(-1); } try { if (resVarid.isVersioned()) { resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBlock(resVarid.getBasename()); } } catch (IllegalOperand e) { System.err.println("Error creating block operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } inst = Binary.create(op, t, resOperand, val1Operand, val2Operand); iList.addLast(inst); }; bitwiseBinaryI returns [ LinkedList iList ] { iList = new LinkedList(); Instruction inst = null; Type t = null; Operand resOperand, val1Operand, val2Operand = null; Operator op = null; Varid resVarid = null; }: resVarid=varid EQUAL op=bitwiseBinaryOp t=type val1Operand=value[t, false] COMMA val2Operand=value[t, false] { if (!(t.isIntegral())) { System.err.println("Error: Type for bitwise binary operation must be integral on line: " + LT(0).getLine()); System.exit(-1); } try { if (t == Type.Bool) { if (resVarid.isVersioned()) { resOperand = Operand.newBoolean(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBoolean(resVarid.getBasename()); } } else { if (resVarid.isVersioned()) { resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBlock(resVarid.getBasename()); } } } catch (IllegalOperand e) { System.err.println("Error creating result operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } inst = Binary.create(op, t, resOperand, val1Operand, val2Operand); iList.addLast(inst); }; shiftI returns [ LinkedList iList ] { iList = new LinkedList(); Instruction inst = null; Type t = null; Operand resOperand, val1Operand, val2Operand = null; Operator op = null; Varid resVarid = null; }: // Second value type should really be a ubyte, but we don't handle those yet. resVarid=varid EQUAL op=shiftOp t=type val1Operand=value[t, false] COMMA UBYTE val2Operand=value[t, false] { if (!t.isInteger()){ System.err.println("Error: First type argument to shift instruction must be integer on line: " + LT(0).getLine()); System.exit(-1); } try { if (resVarid.isVersioned()) { resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBlock(resVarid.getBasename()); } } catch (IllegalOperand e) { System.err.println("Error creating block operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } inst = Binary.create(op, t, resOperand, val1Operand, val2Operand); iList.addLast(inst); }; binaryOp returns [ Operator op ] { op = null; }: (ADD {op = Operators.ADD;} | SUB {op = Operators.SUB;} | MUL {op = Operators.MUL;} | DIV {op = Operators.DIV;} | REM {op = Operators.REM;} );bitwiseBinaryOp returns [ Operator op ] { op = null; }: ( AND {op = Operators.AND;} | OR {op = Operators.OR;} | XOR {op = Operators.XOR;} );shiftOp returns [Operator op] { op = null; }: ( SHL {op = Operators.SHL;} | SHR {op = Operators.SHR; });setccI returns [LinkedList iList ] { iList = new LinkedList(); Instruction inst = null; Type t = null; Operand resOperand, val1Operand, val2Operand = null; Operator op = null; }: resOperand=value[Type.Bool, false] EQUAL op=setccOp t=type val1Operand=value[t, false] COMMA val2Operand=value[t, false] { if (!t.isFirstClass()){ System.err.println("Error: Type argument to setcc instruction must be first class on line: " + LT(0).getLine()); System.exit(-1); } inst = Test.create(op, t, (BooleanOperand)resOperand, val1Operand, val2Operand); iList.addLast(inst); };setccOp returns [ Operator op ] { op = null; }: (SETGT {op = Operators.SETGT;} | SETGE {op = Operators.SETGE;} | SETLT {op = Operators.SETLT;} | SETLE {op = Operators.SETLE;} | SETNE {op = Operators.SETNE;} | SETEQ {op = Operators.SETEQ;});phiI returns [LinkedList iList] { iList = new LinkedList(); Instruction inst = null; Type t = null; LinkedList values = new LinkedList(); Operand resOperand, val, lab = null; Varid resVarid = null; int index = 0; LinkedList phiInfoList = new LinkedList(); GepInfo gepInfo = null; Operand srcOperand = null; String addrOpName = null; }: resVarid=varid EQUAL PHI t=type (LBRACKET (val=value[t, true] { if (val.isUnknown()) { phiInfoList.add(new PhiInfo(index, ((UnknownOperand)val).getOrigName(), val.getName(), val.getAssignment())); } values.addLast(val); } | GETELEMENTPTR LPAREN gepInfo=getelementptrInfo RPAREN { addrOpName = GepInfo.names.getUniqueName("%phi_addr"); try { srcOperand = Operand.newAddr(addrOpName);System.out.println("creating phi address: " + addrOpName); } catch (IllegalOperand e) { System.err.println("Error creating addr operand: " + addrOpName + " on line: " + LT(0).getLine()); throw(e); } inst = Getelementptr.create(Operators.GETELEMENTPTR, srcOperand, gepInfo.type, gepInfo.operand, gepInfo.pairs); iList.addLast(inst); values.addLast(srcOperand); } ) COMMA lab=value[Type.Label, false] RBRACKET { values.addLast(lab); if (!t.isFirstClass()){ System.err.println("Error: Type argument to phi instruction must be first class on line: " + LT(0).getLine()); System.exit(-1); } index++; } ) (COMMA LBRACKET (val=value[t, true] { if (val.isUnknown()) { phiInfoList.add(new PhiInfo(index, ((UnknownOperand)val).getOrigName(), val.getName(), val.getAssignment())); } values.addLast(val); } | GETELEMENTPTR LPAREN gepInfo=getelementptrInfo RPAREN { addrOpName = GepInfo.names.getUniqueName("%phi_addr");System.out.println("creating phi address: " + addrOpName); try { srcOperand = Operand.newAddr(addrOpName); } catch (IllegalOperand e) { System.err.println("Error creating addr operand: " + addrOpName + " on line: " + LT(0).getLine()); throw(e); } inst = Getelementptr.create(Operators.GETELEMENTPTR, srcOperand, gepInfo.type, gepInfo.operand, gepInfo.pairs); iList.addLast(inst); values.addLast(srcOperand); } ) COMMA lab=value[Type.Label, false] RBRACKET { values.addLast(lab); index++; } )* { try { if (t.isPointer()) { resOperand = Operand.newPrimal(resVarid.getBasename() + "." + resVarid.getVersion()); } else if (t == Type.Bool) { if (resVarid.isVersioned()) { resOperand = Operand.newBoolean(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBoolean(resVarid.getBasename()); } } else { if (resVarid.isVersioned()) { resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBlock(resVarid.getBasename()); } } } catch (IllegalOperand e) { System.err.println("Error creating result operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } inst = Phi.create(Operators.PHI, t, resOperand, values); iList.addLast(inst); PhiInfo.patchList.addLast(inst); PhiInfo.patchList.addLast(phiInfoList); };callI returns [LinkedList iList] { iList = new LinkedList(); Instruction inst = null; Varid resVarid = null; Type retType = null; Varid funcVarid = null; int numArgs = 0; LinkedList args = new LinkedList(); Type argType = null; Operand argOperand = null; Operand resOperand = null; LabelOperand funcOperand = null; }: resVarid=varid EQUAL (TAIL)? CALL retType=type funcVarid=varid LPAREN (RPAREN | ((argType=type argOperand=value[argType, false] { numArgs++; args.addLast(new TypeOperand(argType)); args.addLast(argOperand); } ) (COMMA argType=type argOperand=value[argType, false] { numArgs++; args.addLast(new TypeOperand(argType)); args.addLast(argOperand); })* RPAREN) ) { try { if (resVarid.isVersioned()) { resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBlock(resVarid.getBasename()); } } catch (IllegalOperand e) { System.err.println("Error creating result operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } try { if (funcVarid.isVersioned()) { funcOperand = Operand.newLabel(funcVarid.getBasename(), funcVarid.getVersion()); } else { funcOperand = Operand.newLabel(funcVarid.getBasename()); } } catch (IllegalOperand e) { System.err.println("Error creating function operand: " + funcVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } inst = Call.create(Operators.CALL, retType, resOperand, funcOperand, args); iList.addLast(inst); };castI returns [LinkedList iList] { iList = new LinkedList(); Instruction inst = null; Type fromType, toType = null; Operand resOperand, val = null; Varid resVarid = null; }: resVarid=varid EQUAL CAST fromType=type val=value[fromType, false] TO toType=type { if (!fromType.isFirstClass()){ System.err.println("Error: From type argument to cast instruction must be first class on line: " + LT(0).getLine()); System.exit(-1); } if (!toType.isFirstClass()){ System.err.println("Error: To type argument to cast instruction must be first class on line: " + LT(0).getLine()); System.exit(-1); } try { if (toType == Type.Bool) { if (resVarid.isVersioned()) { resOperand = Operand.newBoolean(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBoolean(resVarid.getBasename()); } } else { if (resVarid.isVersioned()) { resOperand = Operand.newBlock(resVarid.getBasename(), resVarid.getVersion()); } else { resOperand = Operand.newBlock(resVarid.getBasename()); } } } catch (IllegalOperand e) { System.err.println("Error creating result operand: " + resVarid.getBasename() + " on line: " + LT(0).getLine()); throw(e); } inst = Cast.create(Operators.CAST, resOperand, fromType, val, toType); iList.addLast(inst); };selectI returns [LinkedList iList] { iList = new LinkedList(); Instruction inst = null; Type t1, t2 = null; Operand resOperand, cond, op1, op2 = null; Varid resVarid = null; }: resVarid=varid EQUAL SELECT BOOL cond=value[Type.Bool, false] COMMA t1=type op1=value[t1, false] COMMA t2=type op2=value[t2, false] { if (t1 != t2) { System.err.println("Error: Both type arguments to select instruction must be the same, on line: " + LT(0).getLine()); System.exit(-1); } if (!t1.isFirstClass()){ System.err.println("Error: Type arguments to select instruction must be first class on line: " + LT(0).getLine()); System.exit(-1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -