Esempio n. 1
0
 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");
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
 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";
 }
Esempio n. 5
0
 public PointerTyRef(TyRef ty, bool isMut)
 {
     this.ty = ty;
     this.isMut = isMut;
 }
Esempio n. 6
0
 public FnTyRef(List<TyRef> parameterTys, TyRef returnTy)
 {
     this.parameterTys = parameterTys;
     this.returnTy = returnTy;
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 public void InsertVar(string varName, TyRef ty) =>
     current.InsertVar(varName, ty, false);
Esempio n. 9
0
 public void InsertType(string typeName, Modifiers mods, TyRef ty) =>
     current.InsertType(typeName, mods, ty);
Esempio n. 10
0
 public void InsertVar(string varName, TyRef ty, bool isMut) =>
     symbols[varName] = new VarSymbol(varName, ty, isMut);
Esempio n. 11
0
 public void InsertType(string typeName, Modifiers mods, TyRef ty) =>
     symbols[typeName] = new TypeSymbol(typeName, mods, ty);
Esempio n. 12
0
 public ScoreVal(Span span, TyRef ty, LLVMValueRef value)
 {
     this.ty = ty;
     this.value = value;
 }
Esempio n. 13
0
 private void Push(TyRef ty) => stack.Push(ty.Raw);
Esempio n. 14
0
 private ScoreVal Push(Span span, TyRef ty, LLVMValueRef value)
 {
     var val = new ScoreVal(span, ty, value);
     stack.Push(val);
     return val;
 }
Esempio n. 15
0
 public VarSymbol(string name, TyRef ty, bool isMut)
     : base(name, SymbolKind.VAR)
 {
     this.ty = ty;
     this.isMut = isMut;
 }
Esempio n. 16
0
 public TypeSymbol(string name, Modifiers mods, TyRef ty)
     : base(name, SymbolKind.TYPE)
 {
     this.mods = mods;
     this.ty = ty;
 }