예제 #1
0
        public static LLVMValueRef Literal(TokenType tokenType, string value, Type type)
        {
            // Token value is an integer.
            if (tokenType == TokenType.LiteralInteger)
            {
                return(LLVM.ConstInt(type.Emit(), ulong.Parse(value), false));
            }
            // Token value is a decimal.
            else if (tokenType == TokenType.LiteralDecimal)
            {
                return(LLVM.ConstReal(type.Emit(), double.Parse(value)));
            }
            // Token value is a string.
            else if (tokenType == TokenType.LiteralString)
            {
                return(LLVM.ConstString(value, (uint)value.Length, false));
            }

            throw new Exception("Cannot resolve unsupported type");
        }
예제 #2
0
 public static LLVMValueRef Literal(Token token, Type type)
 {
     return(Literal(token.Type, token.Value, type));
 }