diff options
author | Tristan Gingold <tgingold@free.fr> | 2016-02-21 07:56:25 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2016-03-08 06:25:52 +0100 |
commit | 77f983ae738583dfce7c3c3aaab5efde16519af0 (patch) | |
tree | d7f17de16b115bfc3ff52ad0f6b04e840800dae8 /src/ortho/llvm | |
parent | a7bb5f6944b410d2b02b1ae5aa9fdc10c68d7519 (diff) | |
download | ghdl-77f983ae738583dfce7c3c3aaab5efde16519af0.tar.gz ghdl-77f983ae738583dfce7c3c3aaab5efde16519af0.tar.bz2 ghdl-77f983ae738583dfce7c3c3aaab5efde16519af0.zip |
ortho: add new_default_value to initialize a variable.
Diffstat (limited to 'src/ortho/llvm')
-rw-r--r-- | src/ortho/llvm/llvm-core.ads | 4 | ||||
-rw-r--r-- | src/ortho/llvm/ortho_code_main.adb | 17 | ||||
-rw-r--r-- | src/ortho/llvm/ortho_llvm.adb | 20 | ||||
-rw-r--r-- | src/ortho/llvm/ortho_llvm.ads | 4 |
4 files changed, 28 insertions, 17 deletions
diff --git a/src/ortho/llvm/llvm-core.ads b/src/ortho/llvm/llvm-core.ads index 4a72d5d19..7ec85c284 100644 --- a/src/ortho/llvm/llvm-core.ads +++ b/src/ortho/llvm/llvm-core.ads @@ -318,6 +318,9 @@ package LLVM.Core is function VoidType return TypeRef; function LabelType return TypeRef; + -- See Module::dump. + procedure DumpType(T : TypeRef); + -- Values ------------------------------------------------------------ -- The bulk of LLVM's object model consists of values, which comprise a very -- rich type hierarchy. @@ -998,6 +1001,7 @@ private pragma Import (C, VoidType, "LLVMVoidType"); pragma Import (C, LabelType, "LLVMLabelType"); + pragma Import (C, DumpType, "LLVMDumpType"); pragma Import (C, TypeOf, "LLVMTypeOf"); pragma Import (C, GetValueName, "LLVMGetValueName"); diff --git a/src/ortho/llvm/ortho_code_main.adb b/src/ortho/llvm/ortho_code_main.adb index b44081fe8..b84dfbbd2 100644 --- a/src/ortho/llvm/ortho_code_main.adb +++ b/src/ortho/llvm/ortho_code_main.adb @@ -72,19 +72,6 @@ procedure Ortho_Code_Main is Features : constant Cstring := Empty_Cstring; Reloc : constant RelocMode := RelocDefault; - procedure Dump_Llvm - is - use LLVM.Analysis; - Msg : aliased Cstring; - begin - DumpModule (Module); - if LLVM.Analysis.VerifyModule - (Module, PrintMessageAction, Msg'Access) /= 0 - then - null; - end if; - end Dump_Llvm; - function To_String (C : Cstring) return String is function Strlen (C : Cstring) return Natural; pragma Import (C, Strlen); @@ -296,7 +283,7 @@ begin -- Ortho_Mcode.Finish; if Flag_Dump_Llvm then - Dump_Llvm; + DumpModule (Module); end if; -- Verify module. @@ -391,7 +378,7 @@ begin end; else - Dump_Llvm; + DumpModule (Module); end if; Set_Exit_Status (Success); diff --git a/src/ortho/llvm/ortho_llvm.adb b/src/ortho/llvm/ortho_llvm.adb index 8106f9d7d..3075b8bca 100644 --- a/src/ortho/llvm/ortho_llvm.adb +++ b/src/ortho/llvm/ortho_llvm.adb @@ -946,9 +946,15 @@ package body Ortho_LLVM is (List : in out O_Record_Aggr_List; Res : out O_Cnode) is + V : ValueRef; begin - Res := (LLVM => ConstStruct (List.Vals.all, List.Len, 0), - Ctype => List.Atype); + if List.Atype.Kind = ON_Incomplete_Record_Type then + V := ConstNamedStruct (Get_LLVM_Type (List.Atype), + List.Vals.all, List.Len); + else + V := ConstStruct (List.Vals.all, List.Len, 0); + end if; + Res := (LLVM => V, Ctype => List.Atype); Free (List.Vals); end Finish_Record_Aggr; @@ -1028,6 +1034,16 @@ package body Ortho_LLVM is end if; end New_Union_Aggr; + ----------------------- + -- New_Default_Value -- + ----------------------- + + function New_Default_Value (Ltype : O_Tnode) return O_Cnode is + begin + return O_Cnode'(LLVM => ConstNull (Ltype.LLVM), + Ctype => Ltype); + end New_Default_Value; + ---------------- -- New_Sizeof -- ---------------- diff --git a/src/ortho/llvm/ortho_llvm.ads b/src/ortho/llvm/ortho_llvm.ads index 3f77a86b9..1dca66f4e 100644 --- a/src/ortho/llvm/ortho_llvm.ads +++ b/src/ortho/llvm/ortho_llvm.ads @@ -161,6 +161,10 @@ package Ortho_LLVM is -- Create a null access literal. function New_Null_Access (Ltype : O_Tnode) return O_Cnode; + -- Create a literal with default (null) values. Can only be used to + -- define the initial value of a static decalaration. + function New_Default_Value (Ltype : O_Tnode) return O_Cnode; + -- Build a record/array aggregate. -- The aggregate is constant, and therefore can be only used to initialize -- constant declaration. |