private PhiInstruction ParsePhi(LocalId result) { Expect(TokenType.phi); //sExp = "%15 = phi i1 [false, %5], [%13, %8]"; var type = ParseType(); var args = new List <Tuple <Value, LocalId> >(); Expect(TokenType.LBRACKET); var value = ParseValue(); Expect(TokenType.COMMA); var label = ParseLocalId(); Expect(TokenType.RBRACKET); var arg = Tuple.Create(value !, label !); args.Add(arg); while (PeekAndDiscard(TokenType.COMMA)) { Expect(TokenType.LBRACKET); value = ParseValue(); Expect(TokenType.COMMA); label = ParseLocalId(); Expect(TokenType.RBRACKET); arg = Tuple.Create(value !, label !); args.Add(arg); } return(new PhiInstruction { Result = result, Type = type, Arguments = args, }); }
private Select ParseSelect(LocalId result) { Expect(TokenType.select); var condType = ParseType(); var cond = ParseValue(); Expect(TokenType.COMMA); var trueType = ParseType(); var trueValue = ParseValue(); Expect(TokenType.COMMA); var falseType = ParseType(); var falseValue = ParseValue(); return(new Select { Result = result, CondType = condType, Cond = cond, TrueType = trueType, TrueValue = trueValue, FalseType = falseType, FalseValue = falseValue, }); }
private Instruction ParseLoad(LocalId result) { Expect(TokenType.load); if (PeekAndDiscard(TokenType.@volatile)) { } var dstType = ParseType(); Expect(TokenType.COMMA); var srcType = ParseType(); var src = ParseValue(); int alignment = 0; if (PeekAndDiscard(TokenType.COMMA)) { Expect(TokenType.align); alignment = Convert.ToInt32(ParseInteger().Value); } return(new Load { DstType = dstType, Dst = result, SrcType = srcType, Src = src, Alignment = alignment }); }
private Instruction ParseAlloca(LocalId result) { Expect(TokenType.alloca); LLVMType type = ParseType(); LLVMType?elcType = null; Value? elc = null; int alignment = 0; while (PeekAndDiscard(TokenType.COMMA)) { if (Type_FIRST.Contains(Peek().Type)) { elcType = ParseType(); elc = ParseValue(); } else if (PeekAndDiscard(TokenType.align)) { alignment = int.Parse(Expect(TokenType.Integer)); } } return(new Alloca { Result = result, Type = type, ElCountType = elcType, ElementCount = elc, Alignment = alignment, }); }
private Instruction ParseFcmp(LocalId result) { Expect(TokenType.fcmp); var cc = Get(); if (!fconditionCodes.Contains(cc.Type)) { Unexpected(cc); } var type = ParseType(); var op1 = ParseValue(); Expect(TokenType.COMMA); var op2 = ParseValue(); return(new CmpInstruction { Result = result, Operator = TokenType.fcmp, ConditionCode = cc.Type, Type = type, Op1 = op1, Op2 = op2, }); }
private Instruction ParseGetElementPtr(LocalId result) { Expect(TokenType.getelementptr); PeekAndDiscard(TokenType.inbounds); //$REVIEW: use this? var baseType = ParseType(); Expect(TokenType.COMMA); var ptrType = ParseType(); var ptrVal = ParseValue(); var indices = new List <Tuple <LLVMType, Value> >(); while (PeekAndDiscard(TokenType.COMMA)) { PeekAndDiscard(TokenType.inrange); //$REVIEW: use this? var type = ParseType(); var idxVal = ParseValue(); indices.Add(Tuple.Create(type, idxVal !)); } return(new GetElementPtr { Result = result, BaseType = baseType, PtrType = ptrType, PtrValue = ptrVal, Indices = indices, }); }
private Instruction ParseConversion(LocalId result) { var op = Get().Type; var typeFrom = ParseType(); var value = ParseValue(); Expect(TokenType.to); var typeTo = ParseType(); return(new Conversion { Operator = op, Result = result, TypeFrom = typeFrom, Value = value, TypeTo = typeTo, }); }
private Instruction ParseCall(LocalId result) { //$TODO: tail Expect(TokenType.call); var attrs = ParseParameterAttributes(); var ret = ParseType(); var fnPtr = ParseValue(); var args = ParseArgumentList(); ParseFunctionAttributes(); return(new LLVMCall { Result = result, res_attrs = attrs, FnType = ret, FnPtr = fnPtr, Arguments = args, }); }
private Instruction ParseExtractvalue(LocalId result) { Expect(TokenType.extractvalue); var aggregateType = ParseType(); var val = ParseValue(); var indices = new List <int>(); Expect(TokenType.COMMA); do { var idx = Convert.ToInt32(ParseInteger().Value); indices.Add(idx); } while (PeekAndDiscard(TokenType.COMMA)); return(new Extractvalue { Result = result, AggregateType = aggregateType, Value = val, Indices = indices, }); }
private Instruction ParseBinBitOp(LocalId result) { var op = Get().Type; var nuw = PeekAndDiscard(TokenType.nuw); var nsw = PeekAndDiscard(TokenType.nsw); var type = ParseType(); var op1 = ParseValue(); Expect(TokenType.COMMA); var op2 = ParseValue(); return(new BitwiseBinary { Result = result, Operator = op, NoUnsignedWrap = nuw, NoSignedWrap = nsw, Type = type, Left = op1, Right = op2, }); }
public TypeReference(LocalId name) { this.TypeName = name; }