Error - :near "(": syntax error, unexpected '(', expecting IDENTIFIER or '='

3.3k views Asked by At

I create my own macros file:

`ifndef MY_MACROS_SV
`define MY_MACROS_SV
 
// MACRO: 'my_fatal_err
// calls uvm_fatal in case the assertion is not correct
`define my_fatal(condition, msg)\
   assert (condition) else\
`uvm_fatal("FATAL ERROR", msg)
 
`define add_rand(mem_type, mem) \
  begin \
   case (mem_type) \
     "int": add_rand_int(mem); \
     "bit": add_rand_bit(mem); \
     default: `uvm_fatal("FATAL ERROR", "type is not supported") \
    endcase\
  end
 
`endif  //MY_MACROS_SV

I got the following error:

# ** at ..\sv\tx_transaction.sv(21): near "(": syntax error, unexpected '(', 
expecting IDENTIFIER or '='.

Line 21 in tx_transaction.sv:

  add_rand_macro();

add_rand is a function which defined in the base_transaction (tx_transaction extends it):

class base_transaction extends uvm_sequence_item();

   int rand_int_list [];   
   bit rand_bit_list [];

   
   bit [31:0] data [$];

   //add to list functions
   function void add_rand_int(int mem);
      rand_int_list.push_back(mem);      
   endfunction: add_rand_int
   ......
endclass: base_transaction

The code for tx_transaction:

class tx_transaction extends base_transaction;
   bit [15:0]  data_xi;
   bit [15:0]  data_xq;
   int mem_int;  //TODO- delete

   //uvm_object_utils\
   `uvm_object_utils(tx_transaction)

   //constructor
   function new(string name = "tx_transaction");
      super.new(name);
   endfunction: new

   function void add_rand_macro();
      `add_rand("int", mem_int)
   endfunction: add_rand_macro

   add_rand_macro();
     
   //TODO - DELETE
   function void foo();
      $display("rand mem int: %d", mem_int);
   endfunction: foo

endclass: tx_transaction
1

There are 1 answers

2
toolic On BEST ANSWER

Since the macro expands to a case statement, it must be called from inside a function in your class:

function ...

    ...
   `add_rand("int", mem_int)   
    ...

endfunction

UPDATED: Make sure you use a semicolon to end the function statement:

function void add_rand_macro();
    `add_rand("int", mem_int)
endfunction

UPDATED: You cannot call the add_rand_macro function in the body of a class; it must be called inside another function.