Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
Showing with 126 additions and 57 deletions.
  1. +13 −9 src/cgen.c
  2. +79 −36 src/elab.c
  3. +2 −1 src/link.c
  4. +14 −3 src/rt/rtkern.c
  5. +4 −0 src/sem.c
  6. +3 −0 test/regress/elab3.vhd
  7. +3 −0 test/regress/gold/elab3.txt
  8. +7 −7 test/run_regr.rb
  9. +1 −1 test/test_elab.c
View
22 src/cgen.c
@@ -1055,19 +1055,20 @@ static LLVMValueRef cgen_agg_bound(tree_t t, bool low, int32_t def,
return result;
}
-static LLVMValueRef cgen_instance_name(tree_t ref)
+static LLVMValueRef cgen_name_attr(tree_t ref, int which)
{
tree_t decl = tree_ref(ref);
LLVMValueRef signal = tree_attr_ptr(decl, sig_struct_i);
LLVMValueRef res = LLVMBuildAlloca(builder,
llvm_uarray_type(LLVMInt8Type()),
- "inst_name");
+ "name_attr");
LLVMValueRef args[] = {
llvm_void_cast(signal),
- res
+ llvm_int32(which),
+ res,
};
- LLVMBuildCall(builder, llvm_fn("_inst_name"), args, ARRAY_LEN(args), "");
+ LLVMBuildCall(builder, llvm_fn("_name_attr"), args, ARRAY_LEN(args), "");
return LLVMBuildLoad(builder, res, "");
}
@@ -1092,7 +1093,9 @@ static LLVMValueRef cgen_fcall(tree_t t, cgen_ctx_t *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);
+ return cgen_name_attr(tree_param(t, 0).value, 1);
+ else if (icmp(builtin, "path_name"))
+ return cgen_name_attr(tree_param(t, 0).value, 0);
}
LLVMValueRef args[tree_params(t)];
@@ -3084,14 +3087,15 @@ static void cgen_support_fns(void)
false));
}
- LLVMTypeRef _inst_name_args[] = {
+ LLVMTypeRef _name_attr_args[] = {
llvm_void_ptr(),
+ LLVMInt32Type(),
LLVMPointerType(llvm_uarray_type(LLVMInt8Type()), 0)
};
- LLVMAddFunction(module, "_inst_name",
+ LLVMAddFunction(module, "_name_attr",
LLVMFunctionType(LLVMVoidType(),
- _inst_name_args,
- ARRAY_LEN(_inst_name_args),
+ _name_attr_args,
+ ARRAY_LEN(_name_attr_args),
false));
}
View
115 src/elab.c
@@ -23,8 +23,14 @@
#include <string.h>
#include <stdarg.h>
-static void elab_arch(tree_t t, tree_t out, ident_t path);
-static void elab_block(tree_t t, tree_t out, ident_t path);
+typedef struct {
+ tree_t out;
+ ident_t path; // Current 'PATH_NAME
+ ident_t inst; // Current 'INSTANCE_NAME
+} elab_ctx_t;
+
+static void elab_arch(tree_t t, const elab_ctx_t *ctx);
+static void elab_block(tree_t t, const elab_ctx_t *ctx);
static ident_t hpathf(ident_t path, char sep, const char *fmt, ...)
{
@@ -253,48 +259,63 @@ static void elab_map(tree_t t, tree_t arch,
}
}
-static void elab_instance(tree_t t, tree_t out, ident_t path)
+static void elab_instance(tree_t t, const elab_ctx_t *ctx)
{
// Default binding indication is described in LRM 93 section 5.2.2
- tree_t arch = tree_copy(pick_arch(tree_loc(t), tree_ident2(t)));
+ if ((tree_class(t) == C_COMPONENT) || (tree_class(t) == C_CONFIGURATION))
+ fatal_at(tree_loc(t), "sorry, instantiating components or configurations "
+ "is not supported yet");
- ident_t npath = hpathf(path, '@', "%s(%s)",
- simple_name(istr(tree_ident2(arch))),
- simple_name(istr(tree_ident(arch))));
+ tree_t arch = tree_copy(pick_arch(tree_loc(t), tree_ident2(t)));
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, npath);
+ elab_copy_context(ctx->out, tree_ref(t));
+
+ ident_t ninst = hpathf(ctx->inst, '@', "%s(%s)",
+ simple_name(istr(tree_ident2(arch))),
+ simple_name(istr(tree_ident(arch))));
+
+ elab_ctx_t new_ctx = {
+ .out = ctx->out,
+ .path = ctx->path,
+ .inst = ninst
+ };
+ elab_arch(arch, &new_ctx);
}
-static void elab_decls(tree_t t, tree_t out, ident_t path)
+static void elab_decls(tree_t t, const elab_ctx_t *ctx)
{
+ ident_t inst_name_i = ident_new("INSTANCE_NAME");
+
for (unsigned i = 0; i < tree_decls(t); i++) {
tree_t d = tree_decl(t, i);
- ident_t pn = hpathf(path, ':', "%s",
- simple_name(istr(tree_ident(d))));
+ const char *label = simple_name(istr(tree_ident(d)));
+ ident_t ninst = hpathf(ctx->inst, ':', "%s", label);
+ ident_t npath = hpathf(ctx->path, ':', "%s", label);
switch (tree_kind(d)) {
case T_SIGNAL_DECL:
case T_FUNC_BODY:
case T_PROC_BODY:
case T_ALIAS:
- tree_set_ident(d, pn);
- tree_add_decl(out, d);
+ tree_set_ident(d, npath);
+ tree_add_decl(ctx->out, d);
+ tree_add_attr_str(d, inst_name_i, ninst);
break;
case T_FUNC_DECL:
case T_PROC_DECL:
- tree_set_ident(d, pn);
+ tree_set_ident(d, npath);
break;
case T_CONST_DECL:
if (type_kind(tree_type(d)) == T_CARRAY) {
- tree_set_ident(d, pn);
- tree_add_decl(out, d);
+ tree_set_ident(d, npath);
+ tree_add_attr_str(d, inst_name_i, ninst);
+ tree_add_decl(ctx->out, d);
}
break;
default:
@@ -303,40 +324,49 @@ static void elab_decls(tree_t t, tree_t out, ident_t path)
}
}
-static void elab_stmts(tree_t t, tree_t out, ident_t path)
+static void elab_stmts(tree_t t, const elab_ctx_t *ctx)
{
for (unsigned i = 0; i < tree_stmts(t); i++) {
tree_t s = tree_stmt(t, i);
- ident_t npath = hpathf(path, ':', "%s", istr(tree_ident(s)));
+ const char *label = istr(tree_ident(s));
+ ident_t npath = hpathf(ctx->path, ':', "%s", label);
+ ident_t ninst = hpathf(ctx->inst, ':', "%s", label);
+
tree_set_ident(s, npath);
+ elab_ctx_t new_ctx = {
+ .out = ctx->out,
+ .path = npath,
+ .inst = ninst
+ };
+
switch (tree_kind(s)) {
case T_INSTANCE:
- elab_instance(s, out, npath);
+ elab_instance(s, &new_ctx);
break;
case T_BLOCK:
- elab_block(s, out, npath);
+ elab_block(s, &new_ctx);
break;
default:
- tree_add_stmt(out, s);
+ tree_add_stmt(ctx->out, s);
}
}
}
-static void elab_block(tree_t t, tree_t out, ident_t path)
+static void elab_block(tree_t t, const elab_ctx_t *ctx)
{
- elab_decls(t, out, path);
- elab_stmts(t, out, path);
+ elab_decls(t, ctx);
+ elab_stmts(t, ctx);
}
-static void elab_arch(tree_t t, tree_t out, ident_t path)
+static void elab_arch(tree_t t, const elab_ctx_t *ctx)
{
- elab_copy_context(out, t);
- elab_decls(t, out, path);
- elab_stmts(t, out, path);
+ elab_copy_context(ctx->out, t);
+ elab_decls(t, ctx);
+ elab_stmts(t, ctx);
}
-static void elab_entity(tree_t t, tree_t out, ident_t path)
+static void elab_entity(tree_t t, const elab_ctx_t *ctx)
{
if (tree_ports(t) > 0 || tree_generics(t) > 0) {
// LRM 93 section 12.1 says implementation may allow this but
@@ -345,12 +375,19 @@ static void elab_entity(tree_t t, tree_t out, ident_t path)
}
tree_t arch = pick_arch(NULL, tree_ident(t));
- ident_t new_path = hpathf(path, ':', ":%s(%s)",
- simple_name(istr(tree_ident(t))),
- simple_name(istr(tree_ident(arch))));
+ const char *name = simple_name(istr(tree_ident(t)));
+ ident_t ninst = hpathf(ctx->inst, ':', ":%s(%s)", name,
+ simple_name(istr(tree_ident(arch))));
+ ident_t npath = hpathf(ctx->path, ':', ":%s", name);
- elab_copy_context(out, t);
- elab_arch(arch, out, new_path);
+ elab_copy_context(ctx->out, t);
+
+ elab_ctx_t new_ctx = {
+ .out = ctx->out,
+ .path = npath,
+ .inst = ninst,
+ };
+ elab_arch(arch, &new_ctx);
}
tree_t elab(tree_t top)
@@ -361,9 +398,15 @@ tree_t elab(tree_t top)
tree_set_ident(e, ident_prefix(tree_ident(top),
ident_new("elab"), '.'));
+ elab_ctx_t ctx = {
+ .out = e,
+ .path = NULL,
+ .inst = NULL
+ };
+
switch (tree_kind(top)) {
case T_ENTITY:
- elab_entity(top, e, NULL);
+ elab_entity(top, &ctx);
break;
default:
fatal("%s is not a suitable top-level unit", istr(tree_ident(top)));
View
3 src/link.c
@@ -151,9 +151,10 @@ static void link_shared(tree_t top)
link_arg_f("%s", SYSTEM_CC);
link_arg_f("-shared");
link_arg_f("-o");
- // TODO: different on OS X, etc.
#if defined __CYGWIN__
link_output(top, "dll");
+#elif defined __APPLE__
+ link_output(top, "dylib");
#else
link_output(top, "so");
#endif
View
17 src/rt/rtkern.c
@@ -460,11 +460,22 @@ void _debug_dump(const uint8_t *ptr, int32_t len)
printf("\n");
}
-void _inst_name(void *_sig, struct uarray *u)
+void _name_attr(void *_sig, int which, struct uarray *u)
{
struct signal *sig = _sig;
+ ident_t inst_name_i = ident_new("INSTANCE_NAME");
- const char *str = istr(tree_ident(sig->decl));
+ const char *str;
+ switch (which) {
+ case 0: // PATH_NAME
+ str = istr(tree_ident(sig->decl));
+ break;
+ case 1: // INSTANCE_NAME
+ str = istr(tree_attr_str(sig->decl, inst_name_i));
+ break;
+ default:
+ assert(false);
+ }
size_t len = strlen(str) + 1;
char *buf = rt_tmp_alloc(len);
@@ -973,7 +984,7 @@ static void rt_one_time_init(void)
jit_bind_fn("_array_reverse", _array_reverse);
jit_bind_fn("_image", _image);
jit_bind_fn("_debug_out", _debug_out);
- jit_bind_fn("_inst_name", _inst_name);
+ jit_bind_fn("_name_attr", _name_attr);
trace_on = opt_get_int("rt_trace_en");
View
4 src/sem.c
@@ -1357,6 +1357,7 @@ static void sem_add_attributes(tree_t decl)
ident_t last_value_i = ident_new("LAST_VALUE");
ident_t active_i = ident_new("ACTIVE");
ident_t inst_name_i = ident_new("INSTANCE_NAME");
+ ident_t path_name_i = ident_new("PATH_NAME");
tree_add_attr_tree(decl, event_i,
sem_builtin_fn(event_i, std_bool, "event",
@@ -1370,6 +1371,9 @@ static void sem_add_attributes(tree_t decl)
tree_add_attr_tree(decl, inst_name_i,
sem_builtin_fn(inst_name_i, std_string,
"instance_name", type, NULL));
+ tree_add_attr_tree(decl, path_name_i,
+ sem_builtin_fn(path_name_i, std_string,
+ "path_name", type, NULL));
}
}
View
3 test/regress/elab3.vhd
@@ -9,6 +9,7 @@ begin
begin
wait for 2 ns;
report p'instance_name;
+ report p'path_name;
wait;
end process;
@@ -33,6 +34,7 @@ begin
begin
wait for 1 ns;
report y'instance_name;
+ report y'path_name;
wait;
end process;
@@ -41,6 +43,7 @@ begin
process is
begin
report x'instance_name;
+ report x'path_name;
wait;
end process;
View
3 test/regress/gold/elab3.txt
@@ -1,3 +1,6 @@
0ms+0: Report Note: :elab3(test):x
+0ms+0: Report Note: :elab3:x
1ns+0: Report Note: :elab3(test):b:y
+1ns+0: Report Note: :elab3:b:y
2ns+0: Report Note: :elab3(test):s@sub(test):p
+2ns+0: Report Note: :elab3:s:p
View
14 test/run_regr.rb
@@ -9,7 +9,7 @@
TestDir = Pathname.new(__FILE__).realpath.dirname
BuildDir = Pathname.new(ENV['BUILD_DIR'] || Dir.pwd).realpath
LibPath = "#{BuildDir}/lib/std:#{BuildDir}/lib/ieee"
-Opts = Getopt::Std.getopts('v')
+Opts = Getopt::Std.getopts('vn')
def read_tests
tests = []
@@ -24,11 +24,11 @@ def read_tests
end
def valgrind
- if Opts['v'] then
- 'valgrind '
- else
- ''
- end
+ Opts['v'] ? 'valgrind ' : ''
+end
+
+def native
+ Opts['n'] ? '--native' : ''
end
def nvc
@@ -58,7 +58,7 @@ def analyse(t)
end
def elaborate(t)
- run_cmd "#{nvc} -e #{t[:name]} --disable-opt"
+ run_cmd "#{nvc} -e #{t[:name]} --disable-opt #{native}"
end
def run(t)
View
2 test/test_elab.c
@@ -77,7 +77,7 @@ START_TEST(test_drivers)
fail_unless(input_from_file(TESTDIR "/elab/drivers.vhd"));
const error_t expect[] = {
- { 5, "signal :drivers(a):y has multiple drivers" },
+ { 5, "signal :drivers:y has multiple drivers" },
{ -1, NULL }
};
expect_errors(expect);

No commit comments for this range

Something went wrong with that request. Please try again.