def METHOD_NAME(prim, prefix, location):
    assert not isdefinition(prim)
    def arg(k,v): # helper function to format arg
        if not isinstance(v, str): v = str(v)
        return '%s=%s' % (k, v)
    # collect args
    args = []
    for k, v in prim.interface.ports.items():
        if v.is_input() or v.is_inout():
            # connect input to an output by tracing the net
            w = v.value()
            if w:
                w = fullinputname(prefix, w)
                args.append( arg(k,w) )
        elif v.is_output() or v.is_inout():
            # connect output to a wire with a fully qualified name
            w = fullqualifiedname(prefix, v)
            args.append( arg(k,w) )
    s  = '.gate ' + str(prim.__class__.__name__) + ' ' + ' '.join(args) + '\n'
    # parameters
    for k, v in prim.kwargs.items():
        if k == 'LUT_INIT':
            if isinstance(v, tuple):
                v = v[0]
            #v = int('0x'+v[4:], 0) # convert from verilog hex
            v = bin(v)[2:]         # convert to binary, skipping 0b
            s += '.param %s %s\n' % (k, v)
    # attributes - only location for now
    if location:
        s += '.attr loc "%d,%d/%d"\n' % location
    return s