summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPrashanth Mundkur2018-08-30 14:05:54 -0700
committerPrashanth Mundkur2018-08-30 14:19:34 -0700
commit2dd89e3b26cbf4c31d47aa4a978ade28914acb24 (patch)
tree9ef8737844bbfe8333328e3f3b50a27863e67292 /lib
parentdee068786b2ef0b0d57fc02ca042e176c74db9b0 (diff)
Annotate the RISC-V prelude for C builtins.
Add some builtins to the C sail lib. Enable some gcc warnings.
Diffstat (limited to 'lib')
-rw-r--r--lib/sail.c21
-rw-r--r--lib/sail.h6
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/sail.c b/lib/sail.c
index 3c0b0dac..c702455c 100644
--- a/lib/sail.c
+++ b/lib/sail.c
@@ -132,6 +132,27 @@ void concat_str(sail_string *stro, const sail_string str1, const sail_string str
strcat(*stro, str2);
}
+bool string_startswith(sail_string s, sail_string prefix)
+{
+ return strstr(s, prefix) == s;
+}
+
+void string_length(sail_int *len, sail_string s)
+{
+ mpz_set_ui(*len, strlen(s));
+}
+
+void string_drop(sail_string *dst, sail_string s, sail_int ns)
+{
+ size_t len = strlen(s);
+ mach_int n = CREATE_OF(mach_int, sail_int)(ns);
+ if (len >= n) {
+ *dst = realloc(*dst, (len - n) + 1);
+ memcpy(*dst, s + n, len - n);
+ (*dst)[len - n] = '\0';
+ }
+}
+
/* ***** Sail integers ***** */
inline
diff --git a/lib/sail.h b/lib/sail.h
index 37b6b685..8533cd21 100644
--- a/lib/sail.h
+++ b/lib/sail.h
@@ -77,6 +77,7 @@ bool eq_string(const sail_string, const sail_string);
bool EQUAL(sail_string)(const sail_string, const sail_string);
void concat_str(sail_string *stro, const sail_string str1, const sail_string str2);
+bool string_startswith(sail_string s, sail_string prefix);
/* ***** Sail integers ***** */
@@ -319,6 +320,11 @@ unit prerr_real(const sail_string, const real);
void random_real(real *rop, unit);
+/* ***** String utilities ***** */
+
+void string_length(sail_int *len, sail_string s);
+void string_drop(sail_string *dst, sail_string s, sail_int len);
+
/* ***** Printing ***** */
void string_of_int(sail_string *str, const sail_int i);