nightshade

The nightshade programming language, compiler and tools (WIP)
Log | Files | Refs | README

ast_lower.ads (1899B)



with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Types;                 use Types;

package AST_Lower is

   type IR_Type is (IR_VOID, IR_STR, IR_I64, IR_BOOL);

   type IR_Value is record
      Id  : Positive;
      Typ : IR_Type;
   end record;

   type IR_Inst_Kind is (CONST_STR, RET, CALL);

   package IR_Values_Vector is new Ada.Containers.Vectors (Index_Type => Natural, Element_Type => IR_Value);

   type IR_Instruction (Kind : IR_Inst_Kind := CONST_STR) is record
      case Kind is
         when CONST_STR =>
            Const_Str_Value : Unbounded_String;

         when RET =>
            Ret_Value : IR_Value;
            Has_Value : Boolean;

         when CALL =>
            Call_Name     : Unbounded_String;
            Call_Has_Dest : Boolean;
            Call_Dest     : IR_Value;
            Call_Args     : IR_Values_Vector.Vector;
      end case;
   end record;

   package Instructions_Vector is new
     Ada.Containers.Vectors (Index_Type => Natural, Element_Type => IR_Instruction);

   type IR_Function is record
      Name         : Unbounded_String;
      Instructions : Instructions_Vector.Vector;
      Return_Type  : IR_Type;
   end record;

   package Functions_Vector is new
     Ada.Containers.Vectors (Index_Type => Natural, Element_Type => IR_Function);

   type IR_Module is record
      Functions : Functions_Vector.Vector;
   end record;

   type IR_Module_Ref is access IR_Module;

   type Lowerer is record
      File_Name : File_Name_Ref;
      Source    : Source_Ref;
      AST       : Declaration_Vectors.Vector;
      Module    : IR_Module_Ref;
      Pos       : Natural;
   end record;

   function Init
     (File_Name : File_Name_Ref; Source : Source_Ref; AST : Declaration_Vectors.Vector) return Lowerer;

   procedure Lower (LL : in out Lowerer);
   procedure Print_IR (LL : in out Lowerer);
end AST_Lower;