private Expression MakeValueExpression(Value value, DataType dt) { var c = value as Constant; if (c != null) { if (c.Value == null) { var w = PrimitiveType.CreateWord(dt.Size); var v = IrConstant.Create(w, 0); v.DataType = w; return(v); } else { return(IrConstant.Create(dt, Convert.ToInt64(c.Value))); } } var l = value as Literal; if (l != null) { if (l.Type == TokenType.HexInteger) { var ptr = dt as Pointer; var val = Convert.ToInt64(l.Value, 16); if (ptr != null) { return(Address.Create(ptr, (ulong)val)); } return(IrConstant.Create(dt, val)); } throw new NotImplementedException(); } var local = value as LocalId; if (local != null) { return(m.GetLocalId(local.Name)); } var global = value as GlobalId; if (global != null) { return(builder.Globals[global.Name]); } var get = value as GetElementPtrExpr; if (get != null) { return(GetElementPtr(get.PointerType, get.Pointer, get.Indices)); } throw new NotImplementedException(string.Format("MakeValueExpression: {0} {1}", value.GetType().Name, value.ToString() ?? "(null)")); }
private Expression MakeValueExpression(Value value, DataType dt) { switch (value) { case Constant c: if (c.Value == null) { var w = PrimitiveType.CreateWord(dt.BitSize); var v = IrConstant.Create(w, 0); v.DataType = w; return(v); } else { return(IrConstant.Create(dt, Convert.ToInt64(c.Value))); } case Literal l: if (l.Type == TokenType.HexInteger) { var val = Convert.ToInt64(l.Value, 16); if (dt is Pointer ptr) { return(Address.Create(ptr, (ulong)val)); } return(IrConstant.Create(dt, val)); } throw new NotImplementedException(); case LocalId local: return(m.GetLocalId(local.Name)); case GlobalId global: return(builder.Globals[global.Name]); case GetElementPtrExpr get: return(GetElementPtr(get.PointerType, get.Pointer, get.Indices)); } throw new NotImplementedException(string.Format("MakeValueExpression: {0} {1}", value.GetType().Name, value.ToString() ?? "(null)")); }
public Expression Ult(Expression a, int b) { return(new BinaryExpression(Operator.Ult, PrimitiveType.Bool, a, Constant.Create(PrimitiveType.CreateWord(a.DataType.Size), b))); }
public BinaryExpression Uge(Expression a, int n) { return(new BinaryExpression(Operator.Uge, PrimitiveType.Bool, a, Constant.Create(a.DataType, n))); }
public BinaryExpression IAdd(Expression left, int right) { return(new BinaryExpression(Operator.IAdd, left.DataType, left, Constant.Create(left.DataType, right))); }
public BinaryExpression ISub(Expression left, int right) { return(ISub(left, Constant.Create(left.DataType, right))); }
public BinaryExpression Sar(Expression e, int sh) { return(new BinaryExpression(Operator.Sar, e.DataType, e, Constant.Create(e.DataType, sh))); }
public Expression UMul(Expression left, int c) { return(new BinaryExpression(Operator.UMul, PrimitiveType.Create(Domain.UnsignedInt, left.DataType.Size), left, Constant.Create(left.DataType, c))); }
public Expression Or(Expression a, int b) { return(new BinaryExpression(Operator.Or, a.DataType, a, Constant.Create(a.DataType, b))); }
public BinaryExpression Ne0(Expression expr) { return(new BinaryExpression( Operator.Ne, PrimitiveType.Bool, expr, Constant.Create(expr.DataType, 0))); }
public BinaryExpression Lt(Expression a, int b) { return(Lt(a, Constant.Create(a.DataType, b))); }
public Expression Ge(Expression a, int b) { return(Ge(a, Constant.Create(a.DataType, b))); }
public BinaryExpression Eq0(Expression exp) { return(new BinaryExpression(Operator.Eq, PrimitiveType.Bool, exp, Constant.Create(exp.DataType, 0))); }
public BinaryExpression Eq(Expression a, int b) { return(new BinaryExpression(Operator.Eq, PrimitiveType.Bool, a, Constant.Create(a.DataType, b))); }
public BinaryExpression And(Expression left, ulong right) { return(And(left, Constant.Create(left.DataType, right))); }
public static Constant Zero(DataType dataType) { return(Constant.Create(dataType, 0)); }
public Expression IMul(Expression left, int c) { return(new BinaryExpression(Operator.IMul, left.DataType, left, Constant.Create(left.DataType, c))); }