Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add 'INSTANCE_NAME attribute

  • Loading branch information...
commit 421751cc9c5cacdcae5ce5653ca3befebc25fd3a 1 parent 59b2f61
Nick Gasson authored
20 src/cgen.c
View
@@ -898,6 +898,15 @@ static LLVMValueRef cgen_agg_bound(tree_t t, bool low, int32_t def,
return result;
}
+static LLVMValueRef cgen_instance_name(tree_t ref)
+{
+ tree_t decl = tree_ref(ref);
+
+ LLVMValueRef signal = tree_attr_ptr(decl, sig_struct_i);
+ LLVMValueRef cast = llvm_void_cast(signal);
+ return LLVMBuildCall(builder, llvm_fn("_inst_name"), &cast, 1, "");
+}
+
static LLVMValueRef cgen_fcall(tree_t t, struct cgen_ctx *ctx)
{
tree_t decl = tree_ref(t);
@@ -918,6 +927,8 @@ static LLVMValueRef cgen_fcall(tree_t t, struct cgen_ctx *ctx)
return cgen_agg_bound(tree_param(t, 0).value, true, INT32_MAX, ctx);
else if (icmp(builtin, "agg_high"))
return cgen_agg_bound(tree_param(t, 0).value, false, INT32_MIN, ctx);
+ else if (icmp(builtin, "instance_name"))
+ return cgen_instance_name(tree_param(t, 0).value);
}
LLVMValueRef args[tree_params(t)];
@@ -2807,6 +2818,15 @@ static void cgen_support_fns(void)
_iexp_args,
ARRAY_LEN(_iexp_args),
false));
+
+ LLVMTypeRef _inst_name_args[] = {
+ llvm_void_ptr()
+ };
+ LLVMAddFunction(module, "_inst_name",
+ LLVMFunctionType(llvm_uarray_type(LLVMInt8Type()),
+ _inst_name_args,
+ ARRAY_LEN(_inst_name_args),
+ false));
}
static void cgen_module_name(tree_t top)
6 src/elab.c
View
@@ -209,13 +209,17 @@ static void elab_instance(tree_t t, tree_t out, ident_t path)
{
tree_t arch = tree_copy(pick_arch(tree_ident2(t)));
+ ident_t npath = hpathf(path, '@', "%s(%s)",
+ simple_name(istr(tree_ident2(arch))),
+ simple_name(istr(tree_ident(arch))));
+
elab_map(t, arch, tree_ports, tree_port,
tree_params, tree_param);
elab_map(t, arch, tree_generics, tree_generic,
tree_genmaps, tree_genmap);
elab_copy_context(out, tree_ref(t));
- elab_arch(arch, out, path);
+ elab_arch(arch, out, npath);
}
static void elab_decls(tree_t t, tree_t out, ident_t path)
19 src/rt/rtkern.c
View
@@ -433,6 +433,24 @@ int32_t _iexp(int32_t n, int32_t v)
return (int32_t)pow(n, v);
}
+struct uarray _inst_name(void *_sig)
+{
+ struct signal *sig = _sig;
+
+ const char *str = istr(tree_ident(sig->decl));
+
+ size_t len = strlen(str) + 1;
+ char *buf = rt_tmp_alloc(len);
+ strncpy(buf, str, len);
+
+ struct uarray u;
+ u.ptr = buf;
+ u.left = 0;
+ u.right = len - 1;
+ u.dir = RANGE_TO;
+ return u;
+}
+
////////////////////////////////////////////////////////////////////////////////
// Simulation kernel
@@ -879,6 +897,7 @@ static void rt_one_time_init(void)
jit_bind_fn("_image", _image);
jit_bind_fn("_debug_out", _debug_out);
jit_bind_fn("_iexp", _iexp);
+ jit_bind_fn("_inst_name", _inst_name);
event_stack = rt_alloc_stack_new(sizeof(struct event));
waveform_stack = rt_alloc_stack_new(sizeof(struct waveform));
11 src/sem.c
View
@@ -1258,9 +1258,13 @@ static void sem_add_attributes(tree_t decl)
if ((tree_kind(decl) == T_PORT_DECL && tree_class(decl) == C_SIGNAL)
|| (tree_kind(decl) == T_SIGNAL_DECL)) {
- ident_t event_i = ident_new("EVENT");
+ type_t std_string = sem_std_type("STRING");
+
+ ident_t event_i = ident_new("EVENT");
ident_t last_value_i = ident_new("LAST_VALUE");
- ident_t active_i = ident_new("ACTIVE");
+ ident_t active_i = ident_new("ACTIVE");
+ ident_t inst_name_i = ident_new("INSTANCE_NAME");
+
tree_add_attr_tree(decl, event_i,
sem_builtin_fn(event_i, std_bool, "event",
type, NULL));
@@ -1270,6 +1274,9 @@ static void sem_add_attributes(tree_t decl)
tree_add_attr_tree(decl, last_value_i,
sem_builtin_fn(last_value_i, type, "last_value",
type, NULL));
+ tree_add_attr_tree(decl, inst_name_i,
+ sem_builtin_fn(inst_name_i, std_string,
+ "instance_name", type, NULL));
}
}
48 test/regress/elab3.vhd
View
@@ -0,0 +1,48 @@
+entity sub is
+end entity;
+
+architecture test of sub is
+ signal p : integer;
+begin
+
+ process is
+ begin
+ wait for 2 ns;
+ report p'instance_name;
+ wait;
+ end process;
+
+end architecture;
+
+-------------------------------------------------------------------------------
+
+entity elab3 is
+end entity;
+
+architecture test of elab3 is
+ signal x : integer;
+begin
+
+ s: entity work.sub;
+
+ b: block is
+ signal y : integer;
+ begin
+
+ process is
+ begin
+ wait for 1 ns;
+ report y'instance_name;
+ wait;
+ end process;
+
+ end block;
+
+ process is
+ begin
+ report x'instance_name;
+ wait;
+ end process;
+
+end architecture;
+
3  test/regress/gold/elab3.txt
View
@@ -0,0 +1,3 @@
+0ms+0: Report Note: :elab3(test):x
+1ns+0: Report Note: :elab3(test):b:y
+2ns+0: Report Note: :elab3(test):s@sub(test):p
1  test/regress/testlist.txt
View
@@ -61,3 +61,4 @@ generic1 normal
signal7 normal
synopsys1 normal
block1 normal
+elab3 normal,gold
Please sign in to comment.
Something went wrong with that request. Please try again.