public static LLVMTypeRef ToLLVMTy(TyRef ty, LLVMContextRef context) { if (ty is TyInt) return IntTypeInContext(context, (ty as TyInt).BitWidth); else if (ty is TyUint) return IntTypeInContext(context, (ty as TyUint).BitWidth); else if (ty is TyFloat) { switch ((ty as TyFloat).BitWidth) { case 16: return HalfTypeInContext(context); case 32: return FloatTypeInContext(context); case 64: return DoubleTypeInContext(context); // EW default: throw new ArgumentException("ty"); } } else if (ty is TyBool) return Int1TypeInContext(context); else if (ty is TyVoid) return VoidTypeInContext(context); else if (ty is PointerTyRef) return PointerType(ToLLVMTy((ty as PointerTyRef).ty.Raw, context), 0); else if (ty is FnTyRef) { var fnTy = ty as FnTyRef; var llvmTyParams = fnTy.parameterTys.Select(param => ToLLVMTy(param.Raw, context)).ToArray(); var llvmTyReturn = ToLLVMTy(fnTy.returnTy.Raw, context); return FunctionType(llvmTyReturn, llvmTyParams, false); } // TODO(kai): structs and things go here pls else throw new ArgumentException("ty"); }
private TyRef[] PopCount(int count) { if (count > stack.Count) throw new ArgumentException(string.Format("Cannot pop {0} values from the stack, only {1} values are present.", count, stack.Count), "count"); var result = new TyRef[count]; for (int i = count; i-- > 0;) result[i] = stack.Pop(); return result; }
private void ErrNoSuchFunction(Spanned<string> spName, TyRef[] args) { var builder = new StringBuilder().Append('|'); for (int i = 0; i < args.Length; i++) { if (i > 0) builder.Append(", "); builder.Append(args[i]); } builder.Append('|'); log.Error(spName.span, "No method \"{0}\" with parameter types {1} exists.", spName.value, builder.ToString()); }
private static string GetTyName(TyRef ty) { if (ty is TyInt) { switch ((ty as TyInt).BitWidth) { case 8: return "x"; case 16: return "s"; case 32: return "i"; case 64: return "l"; default: return "NO PLS"; } } else if (ty is TyUint) { switch ((ty as TyUint).BitWidth) { case 8: return "c"; case 16: return "j"; case 32: return "u"; case 64: return "w"; default: return "NO PLS"; } } else if (ty is TyFloat) { switch ((ty as TyFloat).BitWidth) { case 16: return "h"; case 32: return "f"; case 64: return "d"; default: return "NO PLS"; } } else if (ty is TyBool) return "b"; else if (ty is TyVoid) return "v"; else if (ty is PointerTyRef) return "P" + GetTyName((ty as PointerTyRef).ty.Raw); // TODO(kai): structs and things go here pls else return "FAK"; }
public PointerTyRef(TyRef ty, bool isMut) { this.ty = ty; this.isMut = isMut; }
public FnTyRef(List<TyRef> parameterTys, TyRef returnTy) { this.parameterTys = parameterTys; this.returnTy = returnTy; }
public void Resolve(TyRef ty) { if (ty is PathTyRef) { var path = ty as PathTyRef; if (!path.Resolved) throw new ArgumentException("Cannot resolve this type with an unresolved path type."); Resolve(path.Ty); } else Ty = ty; }
public void InsertVar(string varName, TyRef ty) => current.InsertVar(varName, ty, false);
public void InsertType(string typeName, Modifiers mods, TyRef ty) => current.InsertType(typeName, mods, ty);
public void InsertVar(string varName, TyRef ty, bool isMut) => symbols[varName] = new VarSymbol(varName, ty, isMut);
public void InsertType(string typeName, Modifiers mods, TyRef ty) => symbols[typeName] = new TypeSymbol(typeName, mods, ty);
public ScoreVal(Span span, TyRef ty, LLVMValueRef value) { this.ty = ty; this.value = value; }
private void Push(TyRef ty) => stack.Push(ty.Raw);
private ScoreVal Push(Span span, TyRef ty, LLVMValueRef value) { var val = new ScoreVal(span, ty, value); stack.Push(val); return val; }
public VarSymbol(string name, TyRef ty, bool isMut) : base(name, SymbolKind.VAR) { this.ty = ty; this.isMut = isMut; }
public TypeSymbol(string name, Modifiers mods, TyRef ty) : base(name, SymbolKind.TYPE) { this.mods = mods; this.ty = ty; }