Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxxrtl: export wire attributes through the C API #3994

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

whitequark
Copy link
Member

@whitequark whitequark commented Oct 9, 2023

Among other things this allows retrieving source locations for wires in the simulation, e.g.:

void print_location_cb(void *, const char *name, struct cxxrtl_object *object, size_t parts) {
	printf("%s:\n", name);
	cxxrtl_attr_set attrs = object->attrs;
	if (cxxrtl_attr_type(attrs, "src") == CXXRTL_ATTR_STRING) {
		const char *src = cxxrtl_attr_get_string(attrs, "src");
		while (src) {
			char buf[256] = {0};
			const char *next = strchr(src, '|');
			if (!next) {
				printf("\t%s\n", src);
				src = NULL;
			} else {
				strncpy(buf, src, next - src);
				printf("\t%s\n", buf);
				src = next + 1;
			}
		}
	} else {
		printf("(missing!)\n");
	}
}

int main() {
	cxxrtl_handle top = cxxrtl_create_at(cxxrtl_design_create(), "toplevel");
	cxxrtl_reset(top);

	printf("Source location information for this simulation:\n");
	cxxrtl_enum(top, NULL, print_location_cb);

	return 0;
}

@whitequark whitequark marked this pull request as draft October 9, 2023 15:38
backends/cxxrtl/cxxrtl_capi.h Outdated Show resolved Hide resolved
@whitequark whitequark marked this pull request as ready for review October 25, 2023 11:24
@whitequark whitequark requested a review from mwkmwkmwk October 25, 2023 11:24
@whitequark whitequark merged commit 6ffc315 into YosysHQ:master Oct 25, 2023
7 checks passed
@whitequark whitequark deleted the cxxrtl-wire-attrs branch October 25, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant