aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/xilinx/brams_init.py
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2017-03-18 15:00:03 +0100
committerClifford Wolf <clifford@clifford.at>2017-03-18 15:00:03 +0100
commit1390e9a0a7d4872e24a9fe53e258b8097932392a (patch)
treeb9f474c9f230a0595deddf4478de1d18d2a84806 /techlibs/xilinx/brams_init.py
parent088f9c9cab8db27076385e6f3242369499247b9f (diff)
downloadyosys-1390e9a0a7d4872e24a9fe53e258b8097932392a.tar.gz
yosys-1390e9a0a7d4872e24a9fe53e258b8097932392a.tar.bz2
yosys-1390e9a0a7d4872e24a9fe53e258b8097932392a.zip
Add simple EDIF test case generator and checker
Diffstat (limited to 'techlibs/xilinx/brams_init.py')
0 files changed, 0 insertions, 0 deletions
' href='#n118'>118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
--  Synthesis context.
--  Copyright (C) 2017 Tristan Gingold
--
--  This file is part of GHDL.
--
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation, either version 2 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <gnu.org/licenses>.

with Ada.Unchecked_Deallocation;

with Tables;

with Vhdl.Errors; use Vhdl.Errors;
with Vhdl.Utils;

package body Elab.Vhdl_Context is

   Sig_Nbr : Signal_Index_Type := No_Signal_Index;

   function Get_Nbr_Signal return Signal_Index_Type is
   begin
      return Sig_Nbr;
   end Get_Nbr_Signal;

   package Inst_Tables is new Tables
     (Table_Component_Type => Synth_Instance_Acc,
      Table_Index_Type => Instance_Id_Type,
      Table_Low_Bound => First_Instance_Id,
      Table_Initial => 16);

   function Get_Instance_Id (Inst : Synth_Instance_Acc)
                            return Instance_Id_Type is
   begin
      return Inst.Id;
   end Get_Instance_Id;

   procedure Make_Root_Instance is
   begin
      --  Allow multiple elaborations
      --  pragma Assert (Root_Instance = null);

      Root_Instance :=
        new Synth_Instance_Type'(Max_Objs => Global_Info.Nbr_Objects,
                                 Is_Const => False,
                                 Is_Error => False,
                                 Id => Inst_Tables.Last + 1,
                                 Block_Scope => Global_Info,
                                 Up_Block => null,
                                 Uninst_Scope => null,
                                 Source_Scope => Null_Node,
                                 Caller       => null,
                                 Config       => Null_Node,
                                 Foreign      => 0,
                                 Extra_Units  => null,
                                 Extra_Link   => null,
                                 Elab_Objects => 0,
                                 Objects => (others => (Kind => Obj_None)));
      Inst_Tables.Append (Root_Instance);
   end Make_Root_Instance;

   procedure Free_Base_Instance is
   begin
      --  TODO: really free.
      null;
   end Free_Base_Instance;

   function Make_Elab_Instance
     (Parent : Synth_Instance_Acc; Blk : Node; Config : Node)
     return Synth_Instance_Acc
   is
      Info : constant Sim_Info_Acc := Get_Info (Blk);
      Scope : Sim_Info_Acc;
      Nbr_Objs : Object_Slot_Type;
      Res : Synth_Instance_Acc;
   begin
      if Get_Kind (Blk) = Iir_Kind_Architecture_Body then
         --  Architectures are extensions of entities.
         Scope := Get_Info (Vhdl.Utils.Get_Entity (Blk));
      else
         Scope := Info;
      end if;

      if Scope = null then
         --  Foreign modules are not annotated.
         pragma Assert (Get_Kind (Blk) = Iir_Kind_Foreign_Module);
         Nbr_Objs := 0;
      else
         Nbr_Objs := Info.Nbr_Objects;
      end if;

      Res := new Synth_Instance_Type'(Max_Objs => Nbr_Objs,
                                      Is_Const => False,
                                      Is_Error => False,
                                      Id => Inst_Tables.Last + 1,
                                      Block_Scope => Scope,
                                      Up_Block => Parent,
                                      Uninst_Scope => null,
                                      Source_Scope => Blk,
                                      Caller       => null,
                                      Config       => Config,
                                      Foreign      => 0,
                                      Extra_Units  => null,
                                      Extra_Link   => null,
                                      Elab_Objects => 0,
                                      Objects => (others =>
                                                    (Kind => Obj_None)));
      Inst_Tables.Append (Res);
      return Res;
   end Make_Elab_Instance;

   procedure Free_Elab_Instance (Synth_Inst : in out Synth_Instance_Acc)
   is
      procedure Deallocate is new Ada.Unchecked_Deallocation
        (Synth_Instance_Type, Synth_Instance_Acc);
      Id : constant Instance_Id_Type := Synth_Inst.Id;
   begin
      Deallocate (Synth_Inst);
      if Id = Inst_Tables.Last then
         Inst_Tables.Decrement_Last;
      else
         Inst_Tables.Table (Id) := null;
      end if;
   end Free_Elab_Instance;

   function Make_Elab_Generate_Instance
     (Parent : Synth_Instance_Acc; Blk : Node; Config : Node; Len : Natural)
     return Synth_Instance_Acc
   is
      Info : constant Sim_Info_Acc := Get_Info (Blk);
      Res : Synth_Instance_Acc;
   begin
      Res := new Synth_Instance_Type'(Max_Objs => Object_Slot_Type (Len),
                                      Is_Const => False,
                                      Is_Error => False,
                                      Id => Inst_Tables.Last + 1,
                                      Block_Scope => Info,
                                      Up_Block => Parent,
                                      Uninst_Scope => null,
                                      Source_Scope => Blk,
                                      Caller       => null,
                                      Config       => Config,
                                      Foreign      => 0,
                                      Extra_Units  => null,
                                      Extra_Link   => null,
                                      Elab_Objects => 0,
                                      Objects => (others =>
                                                    (Kind => Obj_None)));
      Inst_Tables.Append (Res);
      return Res;
   end Make_Elab_Generate_Instance;

   function Get_Generate_Sub_Instance
     (Parent : Synth_Instance_Acc; Idx : Positive) return Synth_Instance_Acc is
   begin
      return Parent.Objects (Object_Slot_Type (Idx)).I_Inst;
   end Get_Generate_Sub_Instance;

   procedure Set_Generate_Sub_Instance
     (Parent : Synth_Instance_Acc; Idx : Positive; Child : Synth_Instance_Acc)
   is
   begin
      Parent.Objects (Object_Slot_Type (Idx)) := (Obj_Instance, Child);
   end Set_Generate_Sub_Instance;

   function Is_Error (Inst : Synth_Instance_Acc) return Boolean is
   begin
      return Inst.Is_Error;
   end Is_Error;

   procedure Set_Error (Inst : Synth_Instance_Acc) is
   begin
      Inst.Is_Error := True;
   end Set_Error;

   function Get_Source_Scope (Inst : Synth_Instance_Acc) return Node is
   begin
      return Inst.Source_Scope;
   end Get_Source_Scope;

   function Get_Instance_Parent (Inst : Synth_Instance_Acc)
                                return Synth_Instance_Acc is
   begin
      return Inst.Up_Block;
   end Get_Instance_Parent;

   function Get_Instance_Const (Inst : Synth_Instance_Acc) return Boolean is
   begin
      return Inst.Is_Const;
   end Get_Instance_Const;

   function Check_Set_Instance_Const (Inst : Synth_Instance_Acc)
                                     return Boolean is
   begin
      for I in 1 .. Inst.Elab_Objects loop
         if Inst.Objects (I).Kind /= Obj_Subtype then
            return False;
         end if;
      end loop;
      return True;
   end Check_Set_Instance_Const;

   procedure Set_Instance_Const (Inst : Synth_Instance_Acc; Val : Boolean) is
   begin
      pragma Assert (not Val or else Check_Set_Instance_Const (Inst));
      Inst.Is_Const := Val;
   end Set_Instance_Const;

   procedure Set_Instance_Config (Inst : Synth_Instance_Acc; Config : Node) is
   begin
      pragma Assert (Inst.Config = Null_Node);
      Inst.Config := Config;
   end Set_Instance_Config;

   function Get_Instance_Config (Inst : Synth_Instance_Acc) return Node is
   begin
      return Inst.Config;
   end Get_Instance_Config;

   procedure Set_Instance_Foreign (Inst : Synth_Instance_Acc; N : Int32) is
   begin
      pragma Assert (Inst.Foreign = 0);
      Inst.Foreign := N;
   end Set_Instance_Foreign;

   function Get_Instance_Foreign (Inst : Synth_Instance_Acc) return Int32 is
   begin
      return Inst.Foreign;
   end Get_Instance_Foreign;

   procedure Add_Extra_Instance (Inst : Synth_Instance_Acc;
                                 Extra : Synth_Instance_Acc) is
   begin
      pragma Assert (Extra.Extra_Link = null);
      Extra.Extra_Link := Inst.Extra_Units;
      Inst.Extra_Units := Extra;
   end Add_Extra_Instance;

   function Get_First_Extra_Instance (Inst : Synth_Instance_Acc)
                                     return Synth_Instance_Acc is
   begin
      return Inst.Extra_Units;
   end Get_First_Extra_Instance;

   function Get_Next_Extra_Instance (Inst : Synth_Instance_Acc)
                                    return Synth_Instance_Acc is
   begin
      return Inst.Extra_Link;
   end Get_Next_Extra_Instance;

   procedure Create_Object (Syn_Inst : Synth_Instance_Acc;
                            Slot : Object_Slot_Type;
                            Num : Object_Slot_Type := 1) is
   begin
      --  Check elaboration order.
      --  Note: this is not done for package since objects from package are
      --  commons (same scope), and package annotation order can be different
      --  from package elaboration order (eg: body).
      if Slot /= Syn_Inst.Elab_Objects + 1
        or else Syn_Inst.Objects (Slot).Kind /= Obj_None
      then
         Error_Msg_Elab ("synth: bad elaboration order of objects");
         raise Internal_Error;
      end if;
      Syn_Inst.Elab_Objects := Slot + Num - 1;
   end Create_Object;

   procedure Create_Object_Force
     (Syn_Inst : Synth_Instance_Acc; Decl : Node; Vt : Valtyp)
   is
      Info : constant Sim_Info_Acc := Get_Info (Decl);
   begin
      pragma Assert
        (Syn_Inst.Objects (Info.Slot).Kind = Obj_None
           or else Vt = (null, null)
           or else Syn_Inst.Objects (Info.Slot) = (Kind => Obj_Object,
                                                   Obj => No_Valtyp));
      Syn_Inst.Objects (Info.Slot) := (Kind => Obj_Object, Obj => Vt);
   end Create_Object_Force;

   procedure Create_Object
     (Syn_Inst : Synth_Instance_Acc; Decl : Node; Vt : Valtyp)
   is
      Info : constant Sim_Info_Acc := Get_Info (Decl);
   begin
      Create_Object (Syn_Inst, Info.Slot, 1);
      Create_Object_Force (Syn_Inst, Decl, Vt);
   end Create_Object;

   procedure Create_Signal (Syn_Inst : Synth_Instance_Acc;
                            Decl : Node;
                            Typ : Type_Acc;
                            Init : Value_Acc)
   is
      Info : constant Sim_Info_Acc := Get_Info (Decl);
      Vt : Valtyp;
   begin
      Create_Object (Syn_Inst, Info.Slot, 1);
      Sig_Nbr := Sig_Nbr + 1;
      Vt := (Typ, Create_Value_Signal (Sig_Nbr, Init));
      Syn_Inst.Objects (Info.Slot) := (Kind => Obj_Object, Obj => Vt);
   end Create_Signal;

   procedure Replace_Signal
     (Syn_Inst : Synth_Instance_Acc; Decl : Node; Vt : Valtyp)
   is
      Info : constant Sim_Info_Acc := Get_Info (Decl);
      Obj : Obj_Type renames Syn_Inst.Objects (Info.Slot);
   begin
      pragma Assert (Obj.Kind = Obj_Object);
      pragma Assert (Obj.Obj.Typ = Vt.Typ);
      pragma Assert (Obj.Obj.Val.Kind = Value_Signal);

      Obj.Obj := Vt;

      --  TODO: free old signal ?
   end Replace_Signal;

   procedure Mutate_Object
     (Syn_Inst : Synth_Instance_Acc; Decl : Node; Vt : Valtyp)
   is
      Info : constant Sim_Info_Acc := Get_Info (Decl);
      Obj : Obj_Type renames Syn_Inst.Objects (Info.Slot);