📄 ghdldrv.adb
字号:
Init (Command_Comp (Cmd)); Cmd.Flag_Depend_Unit := False; Cmd.Flag_Force := False; end Init; procedure Decode_Option (Cmd : in out Command_Make; Option : String; Arg : String; Res : out Option_Res) is begin if Option = "-Mu" then Cmd.Flag_Depend_Unit := True; Res := Option_Ok; elsif Option = "-f" then Cmd.Flag_Force := True; Res := Option_Ok; else Decode_Option (Command_Comp (Cmd), Option, Arg, Res); end if; end Decode_Option; procedure Perform_Action (Cmd : in out Command_Make; Args : Argument_List) is use Configuration; File : Iir_Design_File; Unit : Iir; Lib_Unit : Iir; Lib : Iir_Library_Declaration; In_Work : Boolean; Files_List : Iir_List; -- Set when a design file has been compiled. Has_Compiled : Boolean; Need_Analyze : Boolean; Need_Elaboration : Boolean; Stamp : Time_Stamp_Id; File_Id : Name_Id; Nil_Args : Argument_List (2 .. 1); Success : Boolean; begin Set_Elab_Units ("-m", Args); Setup_Compiler (True); -- Create list of files. Files_List := Build_Dependence (Prim_Name, Sec_Name); if Cmd.Flag_Depend_Unit then Put_Line ("Units analysis order:"); for I in Design_Units.First .. Design_Units.Last loop Unit := Design_Units.Table (I); Put (" "); Disp_Library_Unit (Get_Library_Unit (Unit)); New_Line;-- Put (" file: ");-- File := Get_Design_File (Unit);-- Image (Get_Design_File_Filename (File));-- Put_Line (Name_Buffer (1 .. Name_Length)); end loop; end if; if Cmd.Flag_Depend_Unit then Put_Line ("File analysis order:"); for I in Natural loop File := Get_Nth_Element (Files_List, I); exit when File = Null_Iir; Image (Get_Design_File_Filename (File)); Put (" "); Put (Name_Buffer (1 .. Name_Length)); if Flag_Verbose then Put_Line (":"); declare Dep_List : Iir_List; Dep_File : Iir; begin Dep_List := Get_File_Dependence_List (File); if Dep_List /= Null_Iir_List then for J in Natural loop Dep_File := Get_Nth_Element (Dep_List, J); exit when Dep_File = Null_Iir; Image (Get_Design_File_Filename (Dep_File)); Put (" "); Put_Line (Name_Buffer (1 .. Name_Length)); end loop; end if; end; else New_Line; end if; end loop; end if; Has_Compiled := False; Last_Stamp := Null_Time_Stamp; for I in Natural loop File := Get_Nth_Element (Files_List, I); exit when File = Null_Iir; Need_Analyze := False; if Is_File_Outdated (File) then Need_Analyze := True; else Unit := Get_First_Design_Unit (File); while Unit /= Null_Iir loop Lib_Unit := Get_Library_Unit (Unit); if not (Get_Kind (Lib_Unit) = Iir_Kind_Configuration_Declaration and then Get_Identifier (Lib_Unit) = Null_Identifier) then if Is_Unit_Outdated (Unit) then Need_Analyze := True; exit; end if; end if; Unit := Get_Chain (Unit); end loop; end if; Lib := Get_Library (File); In_Work := Lib = Libraries.Work_Library; if Need_Analyze or else (Cmd.Flag_Force and In_Work) then File_Id := Get_Design_File_Filename (File); if not Flag_Verbose then Put ("analyze "); Put (Image (File_Id)); --Disp_Library_Unit (Get_Library_Unit (Unit)); New_Line; end if; if In_Work then Do_Compile (Nil_Args, Image (File_Id)); else declare use Libraries; Lib_Args : Argument_List (1 .. 2); Prev_Workdir : Name_Id; begin Prev_Workdir := Work_Directory; -- Must be set, since used to build the object filename. Work_Directory := Get_Library_Directory (Lib); -- Always overwrite --work and --workdir. Lib_Args (1) := new String' ("--work=" & Image (Get_Identifier (Lib))); if Work_Directory = Libraries.Local_Directory then Lib_Args (2) := new String'("--workdir=."); else Lib_Args (2) := new String' ("--workdir=" & Image (Work_Directory)); end if; Do_Compile (Lib_Args, Image (File_Id)); Work_Directory := Prev_Workdir; Free (Lib_Args (1)); Free (Lib_Args (2)); end; end if; Has_Compiled := True; -- Set the analysis time stamp since the file has just been -- analyzed. Set_Analysis_Time_Stamp (File, Files_Map.Get_Os_Time_Stamp); end if; end loop; Need_Elaboration := False; -- Elaboration. -- if libgrt is more recent than the executable (FIXME). if Has_Compiled then if Flag_Verbose then Put_Line ("link due to a file compilation"); end if; Need_Elaboration := True; else declare Exec_File : String := Output_File.all & Nul; begin Stamp := Files_Map.Get_File_Time_Stamp (Exec_File'Address); end; if Stamp = Null_Time_Stamp then if Flag_Verbose then Put_Line ("link due to no binary file"); end if; Need_Elaboration := True; else if Files_Map.Is_Gt (Last_Stamp, Stamp) then -- if a file is more recent than the executable. if Flag_Verbose then Put ("link due to outdated binary file: "); Put (Image (Get_Design_File_Filename (Last_Stamp_File))); Put (" ("); Put (Files_Map.Get_Time_Stamp_String (Last_Stamp)); Put (" > "); Put (Files_Map.Get_Time_Stamp_String (Stamp)); Put (")"); New_Line; end if; Need_Elaboration := True; end if; end if; end if; if Need_Elaboration then if not Flag_Verbose then Put ("elaborate "); Put (Prim_Name.all); --Disp_Library_Unit (Get_Library_Unit (Unit)); New_Line; end if; Bind; Link (Add_Std => True, Disp_Only => False); Delete_File (Filelist_Name.all, Success); end if; end Perform_Action; -- Command Gen_Makefile. type Command_Gen_Makefile is new Command_Comp with null record; function Decode_Command (Cmd : Command_Gen_Makefile; Name : String) return Boolean; function Get_Short_Help (Cmd : Command_Gen_Makefile) return String; procedure Perform_Action (Cmd : in out Command_Gen_Makefile; Args : Argument_List); function Decode_Command (Cmd : Command_Gen_Makefile; Name : String) return Boolean is pragma Unreferenced (Cmd); begin return Name = "--gen-makefile"; end Decode_Command; function Get_Short_Help (Cmd : Command_Gen_Makefile) return String is pragma Unreferenced (Cmd); begin return "--gen-makefile [OPTS] UNIT [ARCH] Generate a Makefile for UNIT"; end Get_Short_Help; function Is_Makeable_File (File : Iir_Design_File) return Boolean is begin if File = Std_Package.Std_Standard_File then return False; end if; return True; end Is_Makeable_File; procedure Perform_Action (Cmd : in out Command_Gen_Makefile; Args : Argument_List) is pragma Unreferenced (Cmd); HT : constant Character := Ada.Characters.Latin_1.HT; Files_List : Iir_List; File : Iir_Design_File; Lib : Iir_Library_Declaration; Dir_Id : Name_Id; Dep_List : Iir_List; Dep_File : Iir; begin Set_Elab_Units ("--gen-makefile", Args); Setup_Libraries (True); Files_List := Build_Dependence (Prim_Name, Sec_Name); Put_Line ("# Makefile automatically generated by ghdl"); Put ("# Version: "); Put (Version.Ghdl_Version); Put (" - "); if Version_String /= null then Put (Version_String.all); end if; New_Line; Put_Line ("# Command used to generate this makefile:"); Put ("# "); Put (Command_Name); for I in 1 .. Argument_Count loop Put (' '); Put (Argument (I)); end loop; New_Line; New_Line; Put ("GHDL="); Put_Line (Command_Name); -- Extract options for command line. Put ("GHDLFLAGS="); for I in 2 .. Argument_Count loop declare Arg : String := Argument (I); begin if Arg (1) = '-' then if (Arg'Length > 10 and then Arg (1 .. 10) = "--workdir=") or else (Arg'Length > 7 and then Arg (1 .. 7) = "--ieee=") or else (Arg'Length > 6 and then Arg (1 .. 6) = "--std=") or else (Arg'Length > 7 and then Arg (1 .. 7) = "--work=") or else (Arg'Length > 2 and then Arg (1 .. 2) = "-P") then Put (" "); Put (Arg); end if; end if; end; end loop; New_Line; New_Line; Put_Line ("# Default target"); Put ("all: "); Put_Line (Base_Name.all); New_Line; Put_Line ("# Elaboration target"); Put (Base_Name.all); Put (":"); for I in Natural loop File := Get_Nth_Element (Files_List, I); exit when File = Null_Iir; if Is_Makeable_File (File) then Put (" "); Put (Get_Object_Filename (File)); end if; end loop; New_Line; Put_Line (HT & "$(GHDL) -e $(GHDLFLAGS) $@"); New_Line; Put_Line ("# Run target"); Put_Line ("run: " & Base_Name.all); Put_Line (HT & "$(GHDL) -r " & Base_Name.all & " $(GHDLRUNFLAGS)"); New_Line; Put_Line ("# Targets to analyze files"); for I in Natural loop File := Get_Nth_Element (Files_List, I); exit when File = Null_Iir; Dir_Id := Get_Design_File_Directory (File); if not Is_Makeable_File (File) then -- Builtin file. null; else Put (Get_Object_Filename (File)); Put (": "); if Dir_Id /= Files_Map.Get_Home_Directory then Put (Image (Dir_Id)); Put (Image (Get_Design_File_Filename (File))); New_Line; Put_Line (HT & "@echo ""This file was not locally built ($<)"""); Put_Line (HT & "exit 1"); else Put (Image (Get_Design_File_Filename (File))); New_Line; Put (HT & "$(GHDL) -a $(GHDLFLAGS)"); Lib := Get_Library (File); if Lib /= Libraries.Work_Library then -- Overwrite some options. Put (" --work="); Put (Image (Get_Identifier (Lib))); Dir_Id := Get_Library_Directory (Lib); Put (" --workdir="); if Dir_Id = Libraries.Local_Directory then Put ("."); else Put (Image (Dir_Id)); end if; end if; Put_Line (" $<"); end if; end if; end loop; New_Line; Put_Line ("# Files dependences"); for I in Natural loop File := Get_Nth_Element (Files_List, I); exit when File = Null_Iir; if Is_Makeable_File (File) then Put (Get_Object_Filename (File)); Put (": "); Dep_List := Get_File_Dependence_List (File); if Dep_List /= Null_Iir_List then for J in Natural loop Dep_File := Get_Nth_Element (Dep_List, J); exit when Dep_File = Null_Iir; if Dep_File /= File and then Is_Makeable_File (Dep_File) then Put (" "); Put (Get_Object_Filename (Dep_File)); end if; end loop; end if; New_Line; end if; end loop; end Perform_Action; procedure Register_Commands is begin Register_Command (new Command_Analyze); Register_Command (new Command_Elab); Register_Command (new Command_Run); Register_Command (new Command_Elab_Run); Register_Command (new Command_Bind); Register_Command (new Command_Link); Register_Command (new Command_List_Link); Register_Command (new Command_Anaelab); Register_Command (new Command_Make); Register_Command (new Command_Gen_Makefile); Register_Command (new Command_Dispconfig); end Register_Commands;end Ghdldrv;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -