aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth/include
diff options
context:
space:
mode:
authorMichaƂ Kruszewski <mkru@protonmail.com>2021-03-05 19:17:57 +0100
committertgingold <tgingold@users.noreply.github.com>2021-03-07 21:10:05 +0100
commit66cd5e0aa897b947533d269535fde4c0852472c2 (patch)
treeeb6bb9932eb604b243aa0b2ba57c9faf1c1db883 /src/synth/include
parent80b41f38598931c14db30232b8b38b12186c156d (diff)
downloadghdl-66cd5e0aa897b947533d269535fde4c0852472c2.tar.gz
ghdl-66cd5e0aa897b947533d269535fde4c0852472c2.tar.bz2
ghdl-66cd5e0aa897b947533d269535fde4c0852472c2.zip
Include directory structure proposal.
Diffstat (limited to 'src/synth/include')
-rw-r--r--src/synth/include/synth.h174
-rw-r--r--src/synth/include/synth_gates.h124
2 files changed, 298 insertions, 0 deletions
diff --git a/src/synth/include/synth.h b/src/synth/include/synth.h
new file mode 100644
index 000000000..c89eab7fc
--- /dev/null
+++ b/src/synth/include/synth.h
@@ -0,0 +1,174 @@
+/* Ghdlsynth -*- C++ -*- interface
+
+ 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>.
+*/
+
+namespace GhdlSynth {
+ struct logic_32 {
+ unsigned int va;
+ unsigned int zx;
+ };
+
+ // Use struct wrappers for type safety.
+ // Convention: W for wrapped, D for direct, B for boolean.
+#define GHDLSYNTH_ADA_PREFIX(N) netlists__##N
+#define GHDLSYNTH_ADA_WRAPPER_WW(NAME, RESTYPE, ARGTYPE) \
+ extern "C" unsigned int GHDLSYNTH_ADA_PREFIX(NAME) (unsigned int); \
+ inline RESTYPE NAME(ARGTYPE arg) { \
+ RESTYPE res; \
+ res.id = GHDLSYNTH_ADA_PREFIX(NAME) (arg.id); \
+ return res; \
+ }
+
+#define GHDLSYNTH_ADA_WRAPPER_WWD(NAME, RESTYPE, ARGTYPE1, ARGTYPE2) \
+ extern "C" unsigned int GHDLSYNTH_ADA_PREFIX(NAME) (unsigned int, ARGTYPE2);\
+ inline RESTYPE NAME(ARGTYPE1 arg1, ARGTYPE2 arg2) { \
+ RESTYPE res; \
+ res.id = GHDLSYNTH_ADA_PREFIX(NAME) (arg1.id, arg2); \
+ return res; \
+ }
+
+#define GHDLSYNTH_ADA_WRAPPER_DWD(NAME, RESTYPE, ARGTYPE1, ARGTYPE2) \
+ extern "C" RESTYPE GHDLSYNTH_ADA_PREFIX(NAME) (unsigned int, ARGTYPE2);\
+ inline RESTYPE NAME(ARGTYPE1 arg1, ARGTYPE2 arg2) { \
+ return GHDLSYNTH_ADA_PREFIX(NAME) (arg1.id, arg2); \
+ }
+
+#define GHDLSYNTH_ADA_WRAPPER_DW(NAME, RESTYPE, ARGTYPE) \
+ extern "C" RESTYPE GHDLSYNTH_ADA_PREFIX(NAME) (unsigned int); \
+ inline RESTYPE NAME(ARGTYPE arg) { \
+ return GHDLSYNTH_ADA_PREFIX(NAME) (arg.id); \
+ }
+
+#define GHDLSYNTH_ADA_WRAPPER_BW(NAME, ARGTYPE) \
+ extern "C" unsigned int GHDLSYNTH_ADA_PREFIX(NAME) (unsigned int); \
+ inline bool NAME(ARGTYPE arg) { \
+ return (GHDLSYNTH_ADA_PREFIX(NAME) (arg.id) & 1); \
+ }
+
+#define GHDLSYNTH_ADA_WRAPPER_BWD(NAME, ARGTYPE1, ARGTYPE2) \
+ extern "C" unsigned int GHDLSYNTH_ADA_PREFIX(NAME) (unsigned, unsigned); \
+ inline bool NAME(ARGTYPE1 arg1, ARGTYPE2 arg2) { \
+ return (GHDLSYNTH_ADA_PREFIX(NAME) (arg1.id, arg2) & 1); \
+ }
+
+ struct Name_Id { unsigned int id; };
+ extern "C" const char *name_table__get_address (unsigned int);
+ inline const char *get_cstr(Name_Id n) {
+ return name_table__get_address (n.id);
+ }
+
+ extern "C" unsigned name_table__get_identifier_with_len(const char *s, unsigned l);
+ inline Name_Id get_identifier(const char *s) {
+ Name_Id n;
+ n.id = name_table__get_identifier_with_len(s, strlen(s));
+ return n;
+ }
+
+ struct Sname { unsigned int id; };
+ const Sname No_Sname = {0 };
+
+ enum Sname_Kind { Sname_User, Sname_Artificial, Sname_Version };
+ GHDLSYNTH_ADA_WRAPPER_DW(get_sname_kind, Sname_Kind, Sname);
+ inline bool is_valid(Sname l) { return l.id != 0; }
+
+ GHDLSYNTH_ADA_WRAPPER_WW(get_sname_prefix, Sname, Sname);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_sname_suffix, Name_Id, Sname);
+
+ GHDLSYNTH_ADA_WRAPPER_DW(get_sname_version, unsigned int, Sname);
+
+ typedef unsigned int Width;
+ typedef unsigned int Port_Idx;
+ typedef unsigned int Param_Idx;
+ struct Pval { unsigned int id; };
+
+#include "ghdl/synth_gates.h"
+
+ struct Module { unsigned int id; };
+ inline bool is_valid(Module m) { return m.id != 0; }
+ GHDLSYNTH_ADA_WRAPPER_WW(get_module_name, Sname, Module);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_first_sub_module, Module, Module);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_next_sub_module, Module, Module);
+ GHDLSYNTH_ADA_WRAPPER_DW(get_id, Module_Id, Module);
+ GHDLSYNTH_ADA_WRAPPER_DW(get_nbr_outputs, unsigned int, Module);
+ GHDLSYNTH_ADA_WRAPPER_DW(get_nbr_inputs, unsigned int, Module);
+ GHDLSYNTH_ADA_WRAPPER_DW(get_nbr_params, unsigned int, Module);
+
+ struct Net { unsigned int id; };
+ GHDLSYNTH_ADA_WRAPPER_DW(get_width, Width, Net);
+
+ struct Instance { unsigned int id; };
+ inline bool is_valid(Instance inst) { return inst.id != 0; }
+ GHDLSYNTH_ADA_WRAPPER_WW(get_self_instance, Instance, Module);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_first_instance, Instance, Module);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_next_instance, Instance, Instance);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_instance_name, Sname, Instance);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_module, Module, Instance);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_net_parent, Instance, Net);
+ GHDLSYNTH_ADA_WRAPPER_DWD(get_param_uns32, unsigned int, Instance, Param_Idx);
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_param_pval, Pval, Instance, Param_Idx);
+ GHDLSYNTH_ADA_WRAPPER_DW(get_pval_length, unsigned int, Pval);
+ GHDLSYNTH_ADA_WRAPPER_DWD(read_pval, struct logic_32, Pval, unsigned int);
+
+ struct Input { unsigned int id; };
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_input, Input, Instance, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_output, Net, Instance, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_driver, Net, Input);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_input_parent, Instance, Input);
+
+ GHDLSYNTH_ADA_WRAPPER_WW(get_first_sink, Input, Net);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_next_sink, Input, Input);
+
+ struct Attribute { unsigned int id; };
+ GHDLSYNTH_ADA_WRAPPER_WW(get_first_attribute, Attribute, Instance);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_attribute_name, Name_Id, Attribute);
+ GHDLSYNTH_ADA_WRAPPER_DW(get_attribute_type, Param_Type, Attribute);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_attribute_pval, Pval, Attribute);
+ GHDLSYNTH_ADA_WRAPPER_WW(get_attribute_next, Attribute, Attribute);
+
+ // Utils
+#undef GHDLSYNTH_ADA_PREFIX
+#define GHDLSYNTH_ADA_PREFIX(N) netlists__utils__##N
+ GHDLSYNTH_ADA_WRAPPER_DW(get_id, Module_Id, Instance);
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_input_name, Sname, Module, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_output_name, Sname, Module, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_DWD(get_input_width, Width, Module, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_DWD(get_output_width, Width, Module, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_BWD(get_inout_flag, Module, Port_Idx);
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_param_name, Sname, Module, Param_Idx);
+ GHDLSYNTH_ADA_WRAPPER_DWD(get_param_type, Param_Type, Module, Param_Idx);
+ GHDLSYNTH_ADA_WRAPPER_BW(has_one_connection, Net);
+
+ GHDLSYNTH_ADA_WRAPPER_WWD(get_input_net, Net, Instance, Port_Idx);
+
+
+ extern "C" unsigned int ghdlsynth__ghdl_synth(int init,
+ int argc, const char **argv);
+ inline Module ghdl_synth(int init, int argc, const char **argv) {
+ Module res;
+ res.id = ghdlsynth__ghdl_synth(init, argc, argv);
+ return res;
+ }
+
+ // Disp ghdl configuration.
+ extern "C" void ghdlcomp__disp_config (void);
+
+ // Initialize the whole library.
+ extern "C" void libghdl_init (void);
+
+ // More initialization for synthesis.
+ extern "C" void ghdlsynth__init_for_ghdl_synth (void);
+};
diff --git a/src/synth/include/synth_gates.h b/src/synth/include/synth_gates.h
new file mode 100644
index 000000000..78e4a6ef9
--- /dev/null
+++ b/src/synth/include/synth_gates.h
@@ -0,0 +1,124 @@
+/* DO NOT MODIFY
+ This file is automatically generated by Makefile. */
+enum Module_Id {
+ Id_None = 0,
+ Id_Free = 1,
+ Id_Design = 2,
+ Id_User_None = 128,
+ Id_User_Parameters = 129,
+ Id_User_First = Id_User_Parameters + 1,
+ Id_And = 3,
+ Id_Or = 4,
+ Id_Xor = 5,
+ Id_Nand = 6,
+ Id_Nor = 7,
+ Id_Xnor = 8,
+ Id_Add = 9,
+ Id_Sub = 10,
+ Id_Umin = 11,
+ Id_Smin = 12,
+ Id_Umax = 13,
+ Id_Smax = 14,
+ Id_Umul = 15,
+ Id_Smul = 16,
+ Id_Udiv = 17,
+ Id_Sdiv = 18,
+ Id_Umod = 19,
+ Id_Smod = 20,
+ Id_Srem = 21,
+ Id_Not = 22,
+ Id_Neg = 23,
+ Id_Abs = 24,
+ Id_Lsl = 25,
+ Id_Lsr = 26,
+ Id_Asr = 27,
+ Id_Rol = 28,
+ Id_Ror = 29,
+ Id_Eq = 30,
+ Id_Ne = 31,
+ Id_Ule = 32,
+ Id_Sle = 33,
+ Id_Ult = 34,
+ Id_Slt = 35,
+ Id_Uge = 36,
+ Id_Sge = 37,
+ Id_Ugt = 38,
+ Id_Sgt = 39,
+ Id_Red_And = 40,
+ Id_Red_Or = 41,
+ Id_Red_Xor = 42,
+ Id_Concat2 = 43,
+ Id_Concat3 = 44,
+ Id_Concat4 = 45,
+ Id_Concatn = 46,
+ Id_Mux2 = 47,
+ Id_Mux4 = 48,
+ Id_Pmux = 49,
+ Id_Signal = 52,
+ Id_Isignal = 53,
+ Id_Output = 54,
+ Id_Ioutput = 55,
+ Id_Port = 56,
+ Id_Inout = 57,
+ Id_Iinout = 58,
+ Id_Enable = 59,
+ Id_Nop = 60,
+ Id_Dff = 64,
+ Id_Adff = 65,
+ Id_Idff = 66,
+ Id_Iadff = 67,
+ Id_Mdff = 68,
+ Id_Midff = 69,
+ Id_Latch = 70,
+ Id_Tri = 72,
+ Id_Resolver = 73,
+ Id_Utrunc = 82,
+ Id_Strunc = 83,
+ Id_Uextend = 84,
+ Id_Sextend = 85,
+ Id_Extract = 86,
+ Id_Dyn_Extract = 87,
+ Id_Dyn_Insert = 88,
+ Id_Dyn_Insert_En = 89,
+ Id_Memidx = 90,
+ Id_Addidx = 91,
+
+ Id_Memory = 92,
+ Id_Memory_Init = 93,
+ Id_Mem_Rd = 94,
+ Id_Mem_Rd_Sync = 95,
+ Id_Mem_Wr_Sync = 96,
+ Id_Mem_Multiport = 97,
+ Id_Posedge = 100,
+ Id_Negedge = 101,
+ Id_Assert = 104,
+ Id_Assume = 105,
+ Id_Cover = 106,
+ Id_Assert_Cover = 107,
+ Id_Allconst = 108,
+ Id_Anyconst = 109,
+ Id_Allseq = 110,
+ Id_Anyseq = 111,
+ Id_Const_UB32 = 112,
+ Id_Const_SB32 = 113,
+ Id_Const_UL32 = 114,
+ Id_Const_UB64 = 115,
+ Id_Const_UL64 = 116,
+ Id_Const_X = 117,
+ Id_Const_Z = 118,
+ Id_Const_0 = 119,
+ Id_Const_1 = 120,
+ Id_Const_Bit = 121,
+ Id_Const_Log = 122,
+};
+
+enum Param_Type {
+ Param_Invalid,
+ Param_Uns32,
+ Param_Pval_Vector,
+ Param_Pval_String,
+ Param_Pval_Integer,
+ Param_Pval_Real,
+ Param_Pval_Time_Ps,
+ Param_Pval_Boolean
+};