1 // add another interface to vvp compiler
5 #include "vvp/compile.h"
10 #include "vvp/codes.h"
11 // #include <iostream>
12 #define sd(a) strdup(a)
13 #define none (const char*)0
18 virtual operator string() const=0;
19 // needed to circumvent temporary address warning
20 ARG_BASE
* operator &(){ return(this); }
22 /*-----------------------------------------------------*/
23 class ARG_I
: public ARG_BASE
{
27 ARG_I(intptr_t x
): ARG_BASE(),i(x
){}
28 operator string() const{
34 /*-----------------------------------------------------*/
35 class ARG_E
: public ARG_BASE
{
39 static intptr_t offset
;
41 ARG_E(intptr_t x
): ARG_BASE(),i(x
)
43 operator string() const{
45 x
<< "E_0x" << hex
<< (i
-offset
);
49 /*-----------------------------------------------------*/
50 class ARG_O
: public ARG_BASE
{
54 static intptr_t offset
;
56 ARG_O(intptr_t x
): ARG_BASE(),i(x
){}
57 operator string() const{
59 x
<< "oo" << hex
<< (void*)(i
-offset
);
62 /*-----------------------------------------------*/
64 /*-----------------------------------------------------*/
65 class ARG_RAW
: public ARG_BASE
{
69 ARG_RAW(string x
): ARG_BASE(),s(x
){}
70 ARG_RAW(const char* x
): ARG_BASE(),s(x
){}
71 operator string() const{
78 /*-----------------------------------------------------*/
79 class ARG_S
: public ARG_BASE
{
83 static intptr_t offset
;
85 ARG_S(intptr_t x
): ARG_BASE(),i(x
){}
86 operator string() const;
88 /*-----------------------------------------------------*/
89 class ARG_T
: public ARG_BASE
{
95 static intptr_t offset
;
97 ARG_T(intptr_t x
): ARG_BASE(),i(x
),apped(false){}
98 ARG_T(intptr_t x
, unsigned y
): ARG_BASE(),i(x
),app(y
),apped(true){}
99 operator string() const{
101 x
<< "T_" << i
- offset
;
107 /*-----------------------------------------------------*/
108 class ARG_C4
: public ARG_BASE
{
115 // just reproduce the string...
116 // obsolete at the end??
117 ARG_C4(const char* x
): ARG_BASE(),s(strdup(x
)),type(0){}
119 ARG_C4(unsigned x
): ARG_BASE(),i(x
),type(1){}
120 ARG_C4(char x
, unsigned wid
): ARG_BASE(),i(wid
),c(x
),type(2){}
122 operator string() const;
124 /*------------------------------------------------*/
125 class ARG_P
: public ARG_BASE
{
129 static intptr_t offset
;
131 ARG_P(intptr_t x
): ARG_BASE(),i(x
){}
132 operator string() const{
134 x
<< "P_" << hex
<< i
- offset
;
138 /*------------------------------------------------*/
139 class ARG_V
: public ARG_BASE
{
144 static intptr_t offset
;
146 ARG_V(intptr_t x
, int y
): ARG_BASE(),i(x
), app(y
){}
147 operator string() const{
149 x
<< "v0x" << hex
<< i
- offset
<< "_" << app
;
153 /*------------------------------------------------*/
155 // compile iverilogish argument list from ARG_BASE va_list...
156 symb_s
* arg_symbols( unsigned argc
, va_list argv
);
158 inline symb_s
* arg_symbols( unsigned argc
, ... ){
159 trace0("arg_sybbols ... ");
161 va_start ( arguments
, argc
);
162 return arg_symbols(argc
,arguments
);
166 class COMPILE_WRAP
: public COMPILE
{
168 intptr_t param_offset
;
170 intptr_t signal_offset
;
178 void param_logic(ARG_BASE
* label
, char* name
, char*value
, bool signed_flag
,
179 long file_idx
, long lineno
);
181 // this is a READ ONLY pointer. so it is ok.
182 void param_real(ARG_BASE
*label
, char*name
, const double* value
,
183 long file_idx
, long lineno
);
185 void variable(intptr_t, int app
, char*name
,
186 int msb
, int lsb
, int vpi_type_code
,
187 bool signed_flag
, bool local_flag
);
188 void variable(ARG_BASE
* label
, char*name
,
189 int msb
, int lsb
, int vpi_type_code
,
190 bool signed_flag
, bool local_flag
);
194 void code( intptr_t label, const char *mnem );
195 void code( intptr_t label, const char *mnem,
197 void code( intptr_t label, const char *mnem,
199 void code( intptr_t label, const char *mnem,
200 unsigned long l, unsigned long m);
201 void code( intptr_t label, const char *mnem,
202 unsigned long l, const char* m, unsigned long n);
203 void code( intptr_t label, const char *mnem,
204 unsigned long l, unsigned long m, unsigned long n);
205 void code( intptr_t label, const char *mnem,
206 const char * l, unsigned long m, unsigned long n);
209 void vpi_call( const char* label
, const char* cmd
, bool b0
, bool
210 b1
, long l0
, long l1
, ... );
213 void net( intptr_t label
, int app
, char*name
, int msb
, int lsb
,
214 int vpi_type_code
, bool signed_flag
, bool local_flag
,
215 unsigned argc
, ... );
216 void net( ARG_BASE
* label
, char*name
, int msb
, int lsb
,
217 int vpi_type_code
, bool signed_flag
, bool local_flag
,
218 unsigned argc
, ... );
220 void functor(const char*label
, const char*type
, unsigned width
,
221 unsigned ostr0
, unsigned ostr1
,
222 unsigned argc
, ...) {
223 va_list arguments
,argv
;
224 va_start ( arguments
, argc
);
225 va_copy(argv
,arguments
);
228 // ARG_BASE* w = va_arg ( arguments, ARG_BASE* );
229 // trace0("passing arguments 1, "+ string(*w) );
232 COMPILE::functor(label
, type
, width
,
234 argc
, arg_symbols( argc
, argv
));
236 // compile->functor( &ARG_O(0), s("BUFZ"), 1, 6, 6, 1, &ARG_RAW("C4<z>") ); // o0x2b9ed4fce018
237 void functor(const ARG_BASE
* label
, const char*type
, unsigned width
,
238 unsigned ostr0
, unsigned ostr1
,
239 unsigned argc
, va_list argv
) {
241 const char* l
= strdup(string(*label
).c_str());
242 trace0("calling arg_symbols");
243 struct symb_s
*args
= arg_symbols(argc
, argv
);
244 COMPILE::functor(l
, type
, width
,
248 void functor(const ARG_BASE
* label
, const char*type
, unsigned width
,
249 unsigned ostr0
, unsigned ostr1
,
250 unsigned argc
, ...) {
252 va_start( argv
, argc
);
254 functor(label
, type
, width
,
258 void event(int l
, char* t
, int argc
, ... ){
261 COMPILE::event(strdup(string(ARG_E(l
)).c_str()), t
, argc
, arg_symbols(argc
, argv
));
263 void event(ARG_BASE
* l
, char* t
, int argc
, ... ){
266 COMPILE::event(strdup(string(*l
).c_str()), t
, argc
, arg_symbols(argc
, argv
));
269 /*---------------------------*/
270 inline void code( const char *label
, const char *mnem
){
271 comp_operands_s
*opa
= 0;
272 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
274 inline void code( const char *label
, const char *mnem
, unsigned long l
){
275 comp_operands_s
*opa
= (comp_operands_t
) calloc(1, sizeof(comp_operands_s
));
278 opa
->argv
[0].ltype
= L_NUMB
;
279 opa
->argv
[0].numb
= l
;
281 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
283 inline void code( const char *label
, const char *mnem
, const char* cc
){
284 comp_operands_s
*opa
= (comp_operands_t
) calloc(1, sizeof(comp_operands_s
));
285 //= new comp_operands_s();
288 symb_s s
;// = new symb_s();
291 opa
->argv
[0].ltype
= L_SYMB
;
292 opa
->argv
[0].symb
= s
;
294 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
298 inline void code( const char *label
, const char *mnem
,
301 comp_operands_s
*opa
= (comp_operands_t
) calloc(1, sizeof(comp_operands_s
));
304 opa
->argv
[0].ltype
= L_NUMB
;
305 opa
->argv
[0].numb
= l
;
306 opa
->argv
[1].ltype
= L_NUMB
;
307 opa
->argv
[1].numb
= m
;
310 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
313 /*inline void code( const char *label, const char *mnem,
317 comp_operands_s *opa = (comp_operands_t) calloc(1, sizeof(comp_operands_s));
323 opa->argv[0].ltype = L_NUMB;
324 opa->argv[0].numb = l;
325 opa->argv[1].ltype = L_SYMB;
326 opa->argv[1].symb = M;
327 opa->argv[2].ltype = L_NUMB;
328 opa->argv[2].numb = n;
330 COMPILE::code(label?sd(label):0, sd(mnem), opa);
333 inline void code( const char *label
, const char *mnem
,
337 comp_operands_s
*opa
= (comp_operands_t
) calloc(1, sizeof(comp_operands_s
));
340 opa
->argv
[0].ltype
= L_NUMB
;
341 opa
->argv
[0].numb
= l
;
342 opa
->argv
[1].ltype
= L_NUMB
;
343 opa
->argv
[1].numb
= m
;
344 opa
->argv
[2].ltype
= L_NUMB
;
345 opa
->argv
[2].numb
= n
;
347 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
350 // compile->code( 0, "\%set/v", &ARG_V(0,0), 0, 32);
351 inline void code( const char *label
, const char *mnem
,
356 trace0("COMPILE_WRAP::code " + string(*l
) );
357 char *ll
= strdup(string(*l
).c_str());
359 comp_operands_s
*opa
= (comp_operands_t
) calloc(1, sizeof(comp_operands_s
));
365 opa
->argv
[0].ltype
= L_SYMB
;
366 opa
->argv
[0].symb
= L
;
367 opa
->argv
[1].ltype
= L_NUMB
;
368 opa
->argv
[1].numb
= m
;
369 opa
->argv
[2].ltype
= L_NUMB
;
370 opa
->argv
[2].numb
= n
;
372 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
375 void thread( const ARG_BASE
* l
, char* c
){
376 return COMPILE::thread ( strdup(string(*l
).c_str()), c
);
378 void scope_recall( const ARG_BASE
* l
){
379 return COMPILE::scope_recall ( strdup(string(*l
).c_str()));
381 void code( const char*label
, const char *mnem
,
383 return code (label
, mnem
, strdup(string(*l
).c_str()));
386 void code( const char*label
, const char *mnem
,
390 char *mm
= strdup(string(*m
).c_str());
392 comp_operands_s
*opa
= (comp_operands_t
) calloc(1, sizeof(comp_operands_s
));
398 opa
->argv
[0].ltype
= L_NUMB
;
399 opa
->argv
[0].numb
= l
;
400 opa
->argv
[1].ltype
= L_SYMB
;
401 opa
->argv
[1].symb
= M
;
402 opa
->argv
[2].ltype
= L_NUMB
;
403 opa
->argv
[2].numb
= n
;
405 COMPILE::code(label
?sd(label
):0, sd(mnem
), opa
);
408 void scope_decl(ARG_BASE
*typ
, char*lab
, char*nam
, char*tnam
,
409 ARG_BASE
* par
, long file_idx
, long lineno
,
410 long def_file_idx
, long def_lineno
,
412 char * p
= (par
)? strdup(string(*par
).c_str()):0;
414 COMPILE::scope_decl(strdup(string(*typ
).c_str()), lab
, nam
, tnam
,
416 def_file_idx
, def_lineno
,
420 void notify_i( const ARG_BASE
* l
,
422 uint32_t n
, COMPONENT
* daport
);
423 void notify( const ARG_BASE
* l
,
425 uint32_t n
, COMPONENT
* daport
);
428 void notify_i ( uint32_t delay
, uint32_t bit
, COMPONENT
* daport
);
429 void notify ( uint32_t delay
, uint32_t bit
, COMPONENT
* daport
);
430 void load_real_parameter( const double*, unsigned reg
);
431 void load_number_parameter( const int64_t*, unsigned reg
);
432 void load_number_parameter( const int32_t*, unsigned reg
, unsigned wid
=32 );
433 void codelabel( ARG_BASE
* label
);
443 //#define OPERAND_MAX 3
444 //enum ltype_e { L_NUMB, L_SYMB };
446 //struct comp_operands_s {
449 // enum ltype_e ltype;
451 // unsigned long numb;
452 // struct symb_s symb;
454 // } argv[OPERAND_MAX];
457 // void compile_code(char*label, char*mnem, va_list a);
462 symb_s* operands_wrap( unsigned argc, ... ){
464 va_start ( arguments, argc );
470 for(unsigned i=0; i<argc; i++){
471 const char* w = va_arg ( arguments, const char* );
473 comp_operands_s* opa = (comp_operands_s*)
474 calloc(1, sizeof(struct comp_operands_s));
482 void compile_vpi_call(COMPILE
* c
, const char* label
, const char* cmd
, bool b0
, bool b1
, long l0
, long l1
, ... );
485 inline symb_s
* symbols_wrap( unsigned argc
, ... ){
486 trace0("symbols_wrap");
488 va_start ( arguments
, argc
);
494 for(unsigned i
=0; i
<argc
; i
++){
495 const char* w
= va_arg ( arguments
, const char* );
498 trace0("wrapping" + string(w
));
506 trace0("wrapped " + string(obj
.vect
[0].text
));