Commit 55863184 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Prepare for code generation

parent 6e3fa960
with "ocarina/ocarina"; with "ocarina/ocarina";
with "templates_parser"; with "templates-parser/templates_parser";
project AADL_Parser is project AADL_Parser is
......
...@@ -13,7 +13,8 @@ with System.Assertions, ...@@ -13,7 +13,8 @@ with System.Assertions,
Ocarina.Configuration, Ocarina.Configuration,
Ocarina.Files, Ocarina.Files,
Ocarina.Parser, Ocarina.Parser,
TASTE.Backend.Build_Script; TASTE.Backend.Build_Script,
TASTE.Backend.Skeletons;
use Ada.Text_IO, use Ada.Text_IO,
Ada.Exceptions, Ada.Exceptions,
...@@ -205,4 +206,9 @@ package body TASTE.AADL_Parser is ...@@ -205,4 +206,9 @@ package body TASTE.AADL_Parser is
TASTE.Backend.Build_Script.Generate (Model); TASTE.Backend.Build_Script.Generate (Model);
end Generate_Build_Script; end Generate_Build_Script;
procedure Generate_Skeletons (Model : TASTE_Model) is
begin
TASTE.Backend.Skeletons.Generate (Model);
end Generate_Skeletons;
end TASTE.AADL_Parser; end TASTE.AADL_Parser;
...@@ -32,6 +32,7 @@ package TASTE.AADL_Parser is ...@@ -32,6 +32,7 @@ package TASTE.AADL_Parser is
procedure Dump (Model : TASTE_Model); procedure Dump (Model : TASTE_Model);
procedure Generate_Build_Script (Model : TASTE_Model); procedure Generate_Build_Script (Model : TASTE_Model);
procedure Generate_Skeletons (Model : TASTE_Model);
private private
function Initialize return Taste_Configuration; function Initialize return Taste_Configuration;
......
with Text_IO,
Templates_Parser;
use Text_IO,
Templates_Parser;
package body TASTE.Backend.Skeletons.C is
procedure Generate (Config : Taste_Configuration;
Template : Translate_Set) is
dummy_Prefix : constant String := Config.Binary_Path.all
& "templates/skeletons/c";
begin
null;
end Generate;
end TASTE.Backend.Skeletons.C;
with TASTE.Interface_View,
TASTE.Parser_Utils;
use TASTE.Interface_View,
TASTE.Parser_Utils;
package TASTE.Backend.Skeletons.C is
procedure Generate (Config : Taste_Configuration;
Func : Taste_Terminal_Function);
pragma Unreferenced (Generate);
end TASTE.Backend.Skeletons.C;
with Text_IO; use Text_IO;
-- with TASTE.Backend.Skeletons.C;
package body TASTE.Backend.Skeletons is
procedure Generate (Model : TASTE_Model) is
dummy_Template : constant IV_As_Template :=
Interface_View_Template (Model.Interface_View);
begin
Put_Line ("=== Generate skeletons ===");
-- case Each.Language is
-- when Language_C =>
-- TASTE.Backend.Skeletons.C.Generate (Model.Configuration,
-- Template);
-- when others =>
-- Put_Line (Each.Language'Img & "Not supported yet");
-- end case;
-- end;
-- end loop;
end Generate;
function Parameter_Template (Param : ASN1_Parameter) return Translate_Set is
(+Assoc ("Type", Param.Sort) & Assoc ("Name", Param.Name)
& Assoc ("Direction", Param.Direction'Img));
function Interface_Template (TI : Taste_Interface)
return Interface_As_Template
is
use Template_Vectors;
Result : Interface_As_Template;
begin
Result.Header := +Assoc ("Name", TI.Name)
& Assoc ("Parent_Function", TI.Parent_Function);
for Each of TI.Params loop
Result.Params := Result.Params & Parameter_Template (Each);
end loop;
return Result;
end Interface_Template;
function Func_Template (F : Taste_Terminal_Function) return Func_As_Template
is
use Interface_Vectors;
Result : Func_As_Template;
begin
Result.Header := +Assoc ("Name", F.Name)
& Assoc ("Language", F.Language'Img);
for Each of F.Provided loop
Result.Provided := Result.Provided & Interface_Template (Each);
end loop;
for Each of F.Required loop
Result.Required := Result.Required & Interface_Template (Each);
end loop;
return Result;
end Func_Template;
function Interface_View_Template (IV : Complete_Interface_View)
return IV_As_Template is
use Func_Vectors;
Result : IV_As_Template;
begin
for Each of IV.Flat_Functions loop
Result.Funcs := Result.Funcs & Func_Template (Each);
end loop;
return Result;
end Interface_View_Template;
end TASTe.Backend.Skeletons;
with Ada.Containers.Indefinite_Vectors,
Templates_Parser,
TASTE.AADL_Parser;
use Ada.Containers,
Templates_Parser,
TASTE.AADL_Parser;
package TASTE.Backend.Skeletons is
procedure Generate (Model : TASTE_Model);
private
package Template_Vectors is new Indefinite_Vectors (Natural, Translate_Set);
type Interface_As_Template is
record
Header : Translate_Set;
Params : Template_Vectors.Vector;
end record;
package Interface_Vectors is new Indefinite_Vectors (Natural,
Interface_As_Template);
type Func_As_Template is
record
Header : Translate_set;
Provided : Interface_Vectors.Vector;
Required : Interface_Vectors.Vector;
end record;
package Func_Vectors is new Indefinite_Vectors (Natural, Func_As_Template);
type IV_As_Template is
record
Funcs : Func_Vectors.Vector;
end record;
-- Set of functions translating the AST into Templates_Parser mappings
function Parameter_Template (Param : ASN1_Parameter) return Translate_Set;
function Interface_Template (TI : Taste_Interface)
return Interface_As_Template;
function Func_Template (F : Taste_Terminal_Function)
return Func_As_Template;
function Interface_View_Template (IV : Complete_Interface_View)
return IV_As_Template;
end TASTE.Backend.Skeletons;
package TASTE.Parser_Version is package TASTE.Parser_Version is
Parser_Release : constant String := Parser_Release : constant String :=
"b207577 ; Commit Date: Tue Jan 16 15:55:38 2018 "; "6e3fa96 ; Commit Date: Fri Jan 19 17:21:22 2018 ";
Ocarina_Version : constant String := Ocarina_Version : constant String :=
"Ocarina 2017.x (Working Copy from r0b92ed3)"; "Ocarina 2017.x (Working Copy from r0b92ed3)";
end TASTE.Parser_Version; end TASTE.Parser_Version;
\ No newline at end of file
/* Body file for function @_Name_@
* Generated by TASTE on @_Now_@
* You can edit this file, it will not be overwritten
*/
#include "@_LOWER:Name_@.h"
@@IF@@ @_Has_Context_@
/* Include Context Parameters (constants defined in the Interface View) */
#include "Context-@_REPLACE((_)/(-)):LOWER:Name_@.h"
@@END_IF@@
void @_LOWER:Name_@_startup()
{
// Write your initialisation code, but DO NOT CALL REQUIRED INTERFACES
// puts ("[@_Name_@] Startup");
}
@@TABLE@@
void @_LOWER:Name_@_PI_@_Provided_Interfaces_@
{
/* Write your code here */
}
@@END_TABLE@@
@@TABLE@@
void @_LOWER:Name_@_PI_@_Timers_@
{
/* This function is called when the timer expires */
}
@@END_TABLE@@
/* Header file for function @_Name_@
* Generated by TASTE on @_Now_@
* DO NOT EDIT THIS FILE, IT WILL BE OVERWRITTEN DURING THE BUILD
*/
#ifndef __USER_CODE_H_@_UPPER:Name_@
#define __USER_CODE_H_@_UPPER:Name_@
#include "C_ASN1_Types.h"
#ifdef __cplusplus
extern "C" {
#endif
void @_LOWER:Name_@_startup();
@@TABLE@@
void @_LOWER:Name_@_PI_@_Provided_Interfaces_@;
@@END_TABLE@@
@@TABLE@@
void @_LOWER:Name_@_RI_@_Required_Interfaces_@;
@@END_TABLE@@
@@TABLE@@
@_Timers_@
@@END_TABLE@@
#ifdef __cplusplus
extern "C" {
#endif
#endif /* __USER_CODE_H_@_UPPER:Name_@
const asn1Scc@_Type_@ *IN_@_LOWER:Name_@
@_LOWER:Name_@(@@TABLE['TERSE]@@
@_Parameters_@,
@@END_TABLE@@
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment