ACT Library
Loading...
Searching...
No Matches
act.h
Go to the documentation of this file.
1/*************************************************************************
2 *
3 * This file is part of the ACT library
4 *
5 * Copyright (c) 2018-2019 Rajit Manohar
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 **************************************************************************
23 */
24#ifndef __ACT_H__
25#define __ACT_H__
26
27#include <act/types.h>
28#include <act/lang.h>
29#include <act/body.h>
30#include <act/value.h>
31#include <common/config.h>
32#include <map>
33#include <unordered_set>
34
310#define ACT_MODEL_CHP 0
311#define ACT_MODEL_HSE 1
312#define ACT_MODEL_PRS 2
313#define ACT_MODEL_DEVICE 3
314#define ACT_MODEL_TOTAL 4
315
316
321extern const char *act_model_names[];
322
323class ActPass;
324class Log;
325
334class Act {
335 public:
351 static void Init (int *argc, char ***argv, const char *optional_conf);
352
366 static void Init (int *argc, char ***argv, list_t *multi_conf = NULL);
367
382 static int getOptions (int *argc, char ***argv);
383
391 static void setOptionString (char *str);
392
397
402
403#define WARNING_FLAG(x,y) \
404 static int x ;
405#include "warn.def"
406
411 static list_t *cmdline_args;
412
418 static int emit_depend;
419
423 static void config_info (const char *s);
424 static void generic_msg (const char *s);
425
426
434 Act (const char *s = NULL);
436
442 void Merge (const char *s);
443
444
452 bool LocalizeGlobal (const char *s);
453
458 void Expand ();
459
460
467 void mangle (char *s);
468
475 int mangle_set_char (unsigned char c);
476
477 int mangle_active() { return any_mangling; }
488 int mangle_string (const char *src, char *dst, int sz);
489
497 int unmangle_string (const char *src, char *dst, int sz);
498
507 void mfprintf (FILE *fp, const char *s, ...);
508
517 void ufprintf (FILE *fp, const char *s, ...);
518
529 int msnprintf (char *fp, int sz, const char *s, ...);
530
541 int usnprintf (char *fp, int sz, const char *s, ...);
542
552 void msnprintfproc (char *fp, int sz, UserDef *u, int omit_ns = 0);
553
561 void mfprintfproc (FILE *fp, UserDef *u, int omit_ns = 0);
562
568 int unmangle_stringproc (const char *src, char *dst, int sz);
569
570 /*
571 API functions
572 */
573
581 Process *findProcess (const char *s, bool allow_expand = false);
582
591 Process *findProcess (ActNamespace *ns, const char *s, bool allow_expand = false);
592
598 UserDef *findUserdef (const char *s);
599
605 ActNamespace *findNamespace (const char *s);
606
614
615
619 ActNamespace *Global() { return gns; }
620
626 void Print (FILE *fp);
627
634 void pass_register (const char *name, ActPass *p);
635
643 ActPass *pass_find (const char *name);
644
650 void pass_unregister (const char *name);
651
658 const char *pass_name (const char *name);
659
671 list_t *getDecomp (Process *p);
672
677 list_t *getDecompTypes ();
678
684
685 /*
686 Get modeling level of detail and refinement steps.
687 */
688 int getLevel ();
689 int getLevel (Process *p);
690 int getLevel (ActId *id);
691
692 int getRefSteps() { return refine_steps; }
696
699
700private:
703
704
706 int inv_map[256];
708
709#if 0
710 int mangle_langle_idx; /* index of '<' */
711 int mangle_min_idx; /* index of the min of , . { } */
712 int mangle_mode;
713#endif
714
715 static Log *L;
716
717 struct Hashtable *passes;
718
721
726
730
735
740
742
743 static char *_getopt_string;
744
749 static int _process_act_arg (const char *argvp, int *tech_specified, char **conf);
750};
751
791class ActPass {
792protected:
794
809
812
813 list_t *deps;
816
817 list_t *fwdeps;
821
822 const char *name;
823
828
835
837
841
842
848 virtual void _actual_update (Process *p);
849
860 int AddDependency (const char *pass);
861
862public:
874 ActPass (Act *_a, const char *name, int doroot = 0);
875
876 virtual ~ActPass ();
877
878
888 void update (Process *p);
889
898 int rundeps (Process *p = NULL);
899
904 const char *getName();
905
913 virtual int run(Process *p = NULL); // run pass on a process; NULL =
914 // top level
915
916
920 int completed() { return (_finished == 2) ? 1 : 0; }
921
925 int pending() { return (_finished == 1) ? 1 : 0; }
926
934 void *getMap (UserDef *u);
935
939 void *getGlobalInfo () { return _global_info; }
940
944 Act *getAct () { return a; }
945
949 ActPass *getPass (const char *name) { return a->pass_find (name); }
950
954 Process *getRoot() { return _root; }
955
956
973 virtual void run_recursive (Process *p = NULL, int mode = 0);
974
979
984
989
994
1002 static void refreshAll (Act *a, Process *p = NULL);
1003
1004private:
1015 virtual void *pre_op (Process *p, int mode = 0);
1016
1025 virtual void *pre_op (Channel *c, int mode = 0);
1026
1035 virtual void *pre_op (Data *d, int mode = 0);
1036
1047 virtual void *local_op (Process *p, int mode = 0);
1048
1049
1058 virtual void *local_op (Channel *c, int mode = 0);
1059
1068 virtual void *local_op (Data *d, int mode = 0);
1069
1073 virtual void free_local (void *);
1074
1075 int init ();
1076
1077 void recursive_op (UserDef *p, int mode = 0);
1079
1080 void init_map ();
1083
1084 void free_map ();
1086
1087 std::map<UserDef *, void *> *pmap;
1091
1092 std::unordered_set<UserDef *> *visited_flag;
1095};
1096
1097class Technology;
1098class ActDynamicPass;
1099
1115class ActDynamicPass : public ActPass {
1116
1122 char *lib;
1123 void *lib_ptr;
1124 int refs;
1126 };
1127
1135
1142 void (*_init) (ActPass *ap);
1143
1144
1152 void (*_run) (ActPass *ap, Process *p);
1153
1160 void (*_recursive) (ActPass *ap, Process *p, int mode);
1161
1169 void *(*_proc) (ActPass *ap, Process *p, int mode);
1170
1178 void *(*_chan) (ActPass *ap, Channel *c, int mode);
1179
1187 void *(*_data) (ActPass *ap, Data *d, int mode);
1188
1194 void (*_free) (ActPass *ap, void *v);
1195
1196 /*
1197 * This called prior to the pass being destroyed
1198 * @param ap is the pass
1199 */
1200 void (*_done) (ActPass *ap);
1201
1202 /*
1203 * A pass-specific function that can be defined to run arbitrary
1204 * commands associated with a pass.
1205 * @param ap is the pass
1206 * @param name is the name of the command to run
1207 * @return return value of the command (-1 is reserved to mean the
1208 * command does not exist).
1209 */
1210 int (*_runcmd) (ActPass *ap, const char *name);
1211 };
1212
1213
1214public:
1225 ActDynamicPass (Act *_a, const char *name, const char *lib, const char *prefix);
1226
1228
1232 int run (Process *p = NULL);
1233
1237 void run_recursive (Process *p = NULL, int mode = 0);
1238
1247 void setParam (const char *name, void *v);
1248
1257 void setParam (const char *name, int v);
1258
1267 void setParam (const char *name, double v);
1268
1274 int getIntParam (const char *name);
1275
1281 void *getPtrParam (const char *name);
1282
1288 double getRealParam (const char *name);
1289
1294 bool hasParam (const char *name);
1295
1302 int runcmd (const char *name);
1303
1309 struct Hashtable *getConfig ();
1310
1315 Technology *getTech () { return T; }
1316
1320 bool loaded() { return _load_success; }
1321
1330 int addDependency (const char *name) { return AddDependency (name); }
1331
1332private:
1333
1337 virtual void *local_op (Process *, int = 0);
1341 virtual void *local_op (Channel *, int = 0);
1345 virtual void *local_op (Data *, int = 0);
1349 virtual void free_local (void *);
1350
1352
1353 char *_libused;
1354
1356
1357 struct Hashtable *_params;
1359
1360 struct Hashtable *_config_state;
1362
1364
1370 static list_t *_sh_libs;
1371};
1372
1373
1374/* this should be elsewhere */
1375
1384Expr *const_expr (long val);
1385
1396
1406
1407
1418void act_add_global_pint (const char *name, int val);
1419
1420
1431void act_add_global_pbool (const char *name, int val);
1432
1433#endif /* __ACT_H__ */
Expr * const_expr_real(double v)
#define ACT_MODEL_TOTAL
The total number of modeling levels (used for error checking)
Definition: act.h:314
Expr * const_expr(long val)
void act_add_global_pbool(const char *name, int val)
Expr * const_expr_bool(int v)
const char * act_model_names[]
void act_add_global_pint(const char *name, int val)
This is an ActPass that is dynamically loaded in at run-time via a shared object library....
Definition: act.h:1115
void setParam(const char *name, int v)
Technology * T
the technology pointer for the library
Definition: act.h:1363
int getIntParam(const char *name)
virtual void * local_op(Channel *, int=0)
struct Hashtable * _config_state
Definition: act.h:1360
bool _load_success
flag set when the pass is loaded
Definition: act.h:1351
void setParam(const char *name, void *v)
act_sh_dispatch_table _d
dispatch table for this pass
Definition: act.h:1355
~ActDynamicPass()
release storage
virtual void free_local(void *)
void run_recursive(Process *p=NULL, int mode=0)
virtual void * local_op(Data *, int=0)
struct Hashtable * getConfig()
void * getPtrParam(const char *name)
void setParam(const char *name, double v)
char * _libused
library used by this pass
Definition: act.h:1353
bool hasParam(const char *name)
Technology * getTech()
Definition: act.h:1315
int addDependency(const char *name)
Definition: act.h:1330
double getRealParam(const char *name)
struct Hashtable * _params
Definition: act.h:1357
bool loaded()
Definition: act.h:1320
int run(Process *p=NULL)
ActDynamicPass(Act *_a, const char *name, const char *lib, const char *prefix)
virtual void * local_op(Process *, int=0)
int runcmd(const char *name)
static list_t * _sh_libs
Definition: act.h:1370
The main Act class used to read in an ACT file and create basic data structures. All design informati...
Definition: act.h:334
char ** inst_levels[ACT_MODEL_TOTAL]
Definition: act.h:736
Act(const char *s=NULL)
static void generic_msg(const char *s)
static int getOptions(int *argc, char ***argv)
int default_level
the default modeling level
Definition: act.h:741
const char * pass_name(const char *name)
static void Init(int *argc, char ***argv, list_t *multi_conf=NULL)
list_t * getDecompTypes()
bool LocalizeGlobal(const char *s)
char ** type_levels[ACT_MODEL_TOTAL]
Definition: act.h:727
int mangle_characters[256]
which characters do we mangle?
Definition: act.h:705
void Merge(const char *s)
int num_type_levels[ACT_MODEL_TOTAL]
Definition: act.h:722
void mangle(char *s)
int msnprintf(char *fp, int sz, const char *s,...)
int refine_steps
Definition: act.h:719
int usnprintf(char *fp, int sz, const char *s,...)
void pass_unregister(const char *name)
void mfprintfproc(FILE *fp, UserDef *u, int omit_ns=0)
int mangle_active()
Definition: act.h:477
static list_t * cmdline_args
Definition: act.h:411
ActNamespace * Global()
Definition: act.h:619
void pass_register(const char *name, ActPass *p)
static int _process_act_arg(const char *argvp, int *tech_specified, char **conf)
list_t * getDecomp(Process *p)
void msnprintfproc(char *fp, int sz, UserDef *u, int omit_ns=0)
int getRefSteps()
Definition: act.h:692
void decRefSteps()
Definition: act.h:694
static int max_loop_iterations
Definition: act.h:401
void mfprintf(FILE *fp, const char *s,...)
void incRefSteps()
Definition: act.h:697
ActPass * pass_find(const char *name)
int inv_map[256]
map used for inverse lookup
Definition: act.h:706
int mangle_string(const char *src, char *dst, int sz)
UserDef * findUserdef(const char *s)
int getLevel(ActId *id)
get level for this instance
int getLevel(Process *p)
get level for this type
int getLevel()
get default level
static int emit_depend
Definition: act.h:418
static void Init(int *argc, char ***argv, const char *optional_conf)
int unmangle_stringproc(const char *src, char *dst, int sz)
int num_inst_levels[ACT_MODEL_TOTAL]
Definition: act.h:731
TypeFactory * getTypeFactory()
Definition: act.h:683
void Expand()
static int max_recurse_depth
Definition: act.h:396
ActNamespace * findNamespace(ActNamespace *ns, const char *s)
ActNamespace * gns
the global namespace pointer
Definition: act.h:702
~Act()
Process * findProcess(const char *s, bool allow_expand=false)
TypeFactory * tf
type factory for the Act instance
Definition: act.h:701
static void setOptionString(char *str)
int any_mangling
1 if there is any name mangling, 0 otherwise
Definition: act.h:707
void Print(FILE *fp)
Process * findProcess(ActNamespace *ns, const char *s, bool allow_expand=false)
int mangle_set_char(unsigned char c)
struct Hashtable * passes
Table of any ActPass-es.
Definition: act.h:717
static Log * L
Used for log messages.
Definition: act.h:715
static char * _getopt_string
the string used for getopt
Definition: act.h:743
int unmangle_string(const char *src, char *dst, int sz)
ActNamespace * findNamespace(const char *s)
static void config_info(const char *s)
void ufprintf(FILE *fp, const char *s,...)
This class is used to store Act identifiers that correspond to instances. Identifiers have an optiona...
Definition: act_id.h:56
The ActNamespace class holds all the information about a namespace.
Definition: namespaces.h:469
The main ActPass class used to implement an ACT analysis/synthesis pass. All the core tools use this ...
Definition: act.h:791
void enableUpdate()
Definition: act.h:983
void clrStickyVisited()
Definition: act.h:993
int _update_propagate
Definition: act.h:824
Act * a
Definition: act.h:810
list_t * fwdeps
Definition: act.h:817
const char * name
the name for the pass
Definition: act.h:822
int rundeps(Process *p=NULL)
static void refreshAll(Act *a, Process *p=NULL)
void free_map()
const char * getName()
void update(Process *p)
int _finished
has the pass finished execution?
Definition: act.h:793
int init()
initialize or re-initialize
Process * getRoot()
Definition: act.h:954
void recursive_op(UserDef *p, int mode=0)
void * getMap(UserDef *u)
virtual void * local_op(Process *p, int mode=0)
std::map< UserDef *, void * > * pmap
Definition: act.h:1087
void * getGlobalInfo()
Definition: act.h:939
ActPass * getPass(const char *name)
Definition: act.h:949
void * _global_info
Definition: act.h:838
virtual void * pre_op(Channel *c, int mode=0)
Act * getAct()
Definition: act.h:944
Process * _root
the root of the design
Definition: act.h:836
virtual void * local_op(Channel *c, int mode=0)
int _root_dirty
Definition: act.h:829
virtual ~ActPass()
release storage
list_t * deps
Definition: act.h:813
int _sticky_visited
Definition: act.h:795
virtual int run(Process *p=NULL)
virtual void run_recursive(Process *p=NULL, int mode=0)
void disableUpdate()
Definition: act.h:978
ActPass(Act *_a, const char *name, int doroot=0)
virtual void _actual_update(Process *p)
void mkStickyVisited()
Definition: act.h:988
void init_map()
int AddDependency(const char *pass)
virtual void free_local(void *)
virtual void * local_op(Data *d, int mode=0)
int completed()
Definition: act.h:920
virtual void * pre_op(Data *d, int mode=0)
std::unordered_set< UserDef * > * visited_flag
Definition: act.h:1092
int pending()
Definition: act.h:925
virtual void * pre_op(Process *p, int mode=0)
User-defined channel type. Channels can be unidirectional or bi-directional (sometimes called exchang...
Definition: types.h:1215
A user-defined data types.
Definition: types.h:1062
User-defined processes.
Definition: types.h:750
This holds all the technology design rules (or at least the approximate ones) used by the ACT library...
Definition: tech.h:820
This is the class used to create all instance types. It also caches types to reduce memory usage.
Definition: types.h:1415
UserDef stores information that is common to all user-defined types. User-defined types are more comp...
Definition: types.h:310
Contains the data structures for each ACT sub-language.
These are the C function pointers extracted from the shared library used to execute the various metho...
Definition: act.h:1134
void(* _run)(ActPass *ap, Process *p)
Definition: act.h:1152
int(* _runcmd)(ActPass *ap, const char *name)
Definition: act.h:1210
void(* _init)(ActPass *ap)
Definition: act.h:1142
void(* _recursive)(ActPass *ap, Process *p, int mode)
Definition: act.h:1160
void(* _free)(ActPass *ap, void *v)
Definition: act.h:1194
void(* _done)(ActPass *ap)
Definition: act.h:1200
This holds information about the shared object file.
Definition: act.h:1121
int refs
Definition: act.h:1124
void * lib_ptr
this is the open library pointer, if any
Definition: act.h:1123
char * lib
this is the file name of the shared object library
Definition: act.h:1122
Definition: expr.h:79