diff sema/DType.d @ 27:9031487e97d7 new_gen

Various changes related to DType * Drop the typeToLLVM table from LLVMGen * Removed circular dependency * Added basic types to DType
author Anders Halager <halager@gmail.com>
date Sun, 20 Apr 2008 01:08:50 +0200
parents b4dc2b2c0e38
children 69464d465284
line wrap: on
line diff
--- a/sema/DType.d	Sat Apr 19 22:19:14 2008 +0200
+++ b/sema/DType.d	Sun Apr 20 01:08:50 2008 +0200
@@ -2,21 +2,32 @@
 
 import tango.text.Util : jhash;
 
-import sema.SymbolTable;
+import LLVM = llvm.llvm;
+
+import lexer.Token,
+       ast.Exp;
 
 class DType
 {
-    Identifier id;
-    Scope sc;
-    DType actual;
+    private char[] id;
+    private Location loc;
+    public DType actual;
+    private LLVM.Type llvmType;
 
-    this(Identifier id, Scope sc, DType actual = null)
+    this(Identifier id, DType actual = null)
+    {
+        Token temp = id.token;
+        this.id = temp.get;
+        this.loc = temp.location;
+        if (actual !is null)
+            this.actual = this;
+    }
+
+    this(char[] id, DType actual = null)
     {
         this.id = id;
-        this.sc = sc;
-        if (actual is null)
+        if (actual !is null)
             this.actual = this;
-        _name = id.get;
     }
 
     int opEquals(Object o)
@@ -38,26 +49,60 @@
         return cast(hash_t)(cast(void*)this);
     }
 
-    char[] name() { return _name; }
+    char[] name() { return id; }
+    LLVM.Type llvm() { return llvmType; }
+
+    static DInteger
+        Bool,
+        Byte, UByte, Short, UShort,
+        Int, UInt, Long, ULong;
+
+    static DType Void;
+
+    static this()
+    {
+        Void   = new DType("void");
 
-private:
-    char[] _name;
+        Bool   = new DInteger("bool",    1, false);
+        Byte   = new DInteger("byte",    8, false);
+        UByte  = new DInteger("ubyte",   8, true);
+        Short  = new DInteger("short",  16, false);
+        UShort = new DInteger("ushort", 16, true);
+        Int    = new DInteger("int",    32, false);
+        UInt   = new DInteger("uint",   32, true);
+        Long   = new DInteger("long",   64, false);
+        ULong  = new DInteger("ulong",  64, true);
+    }
+}
+
+class DInteger : DType
+{
+    this(char[] name, int bits, bool unsigned)
+    {
+        super(name, null);
+        this.bits = bits;
+        this.unsigned = unsigned;
+        llvmType = LLVM.IntegerType.Get(bits);
+    }
+
+    int bits;
+    bool unsigned;
 }
 
 class DStruct : DType
 {
-    this(Identifier id, Scope sc, DType actual = null)
+    this(Identifier id, DType actual = null)
     {
-        super(id, sc, actual);
+        super(id, actual);
     }
     DType[] members;
 }
 
 class DFunction : DType
 {
-    this(Identifier id, Scope sc, DType actual = null)
+    this(Identifier id, DType actual = null)
     {
-        super(id, sc, actual);
+        super(id, actual);
     }
     DType[] params;
     DType return_type;