diff options
author | jistone <jistone> | 2006-12-22 02:34:05 +0000 |
---|---|---|
committer | jistone <jistone> | 2006-12-22 02:34:05 +0000 |
commit | ef474d24145b85f933d06a1648b0d9cbf6695fe5 (patch) | |
tree | 4025671f55ad05735ad61d94cca720aa33c4d65e /translate.cxx | |
parent | 9c66f4e068e743727dfec5acec6547cd18a4030c (diff) | |
download | systemtap-steved-ef474d24145b85f933d06a1648b0d9cbf6695fe5.tar.gz systemtap-steved-ef474d24145b85f933d06a1648b0d9cbf6695fe5.tar.xz systemtap-steved-ef474d24145b85f933d06a1648b0d9cbf6695fe5.zip |
2006-12-21 Josh Stone <joshua.i.stone@intel.com>
PR 3671
* parse.cxx (parser::parse_global): Allow a maxsize on global arrays.
* staptree.h (struct vardecl): Add the maxsize field.
* staptree.cxx (vardecl::vardecl): Init. maxsize.
(vardecl::set_arity): Don't allow arity 0 when there's a maxsize.
(vardecl::compatible_arity): Ditto.
(vardecl::print): Include maxsize in output.
(target_symbol::print): Ditto.
* translate.cxx (struct mapvar, mapvar::mapvar): Add maxsize.
(mapvar::init): Init maps with the given maxsize if specified, else
keep using MAXMAPENTRIES.
(mapvar::set): Make the error message give the maxsize.
(mapvar::add): Ditto, and check for overflow on pmap add.
(c_unparser::getmap): Pass the maxsize from the vardecl to mapvar.
Diffstat (limited to 'translate.cxx')
-rw-r--r-- | translate.cxx | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/translate.cxx b/translate.cxx index d37600da..c20cde8d 100644 --- a/translate.cxx +++ b/translate.cxx @@ -435,12 +435,15 @@ struct mapvar : public var { vector<exp_type> index_types; + int maxsize; mapvar (bool local, exp_type ty, statistic_decl const & sd, string const & name, - vector<exp_type> const & index_types) + vector<exp_type> const & index_types, + int maxsize) : var (local, ty, sd, name), - index_types (index_types) + index_types (index_types), + maxsize (maxsize) {} static string shortname(exp_type e); @@ -547,11 +550,20 @@ struct mapvar string add (vector<tmpvar> const & indices, tmpvar const & val) const { + string res = "{ int rc = "; + // impedance matching: empty strings -> NULL if (type() == pe_stats) - return (call_prefix("add", indices) + ", " + val.qname() + ")"); + res += (call_prefix("add", indices) + ", " + val.qname() + ")"); else throw semantic_error("adding a value of an unsupported map type"); + + res += "; if (unlikely(rc)) c->last_error = \"Array overflow, check " + + stringify(maxsize > 0 ? + "size limit (" + stringify(maxsize) + ")" : "MAXMAPENTRIES") + + "\"; }"; + + return res; } string set (vector<tmpvar> const & indices, tmpvar const & val) const @@ -567,7 +579,10 @@ struct mapvar else throw semantic_error("setting a value of an unsupported map type"); - res += "; if (unlikely(rc)) c->last_error = \"Array overflow, check MAXMAPENTRIES\"; }"; + res += "; if (unlikely(rc)) c->last_error = \"Array overflow, check " + + stringify(maxsize > 0 ? + "size limit (" + stringify(maxsize) + ")" : "MAXMAPENTRIES") + + "\"; }"; return res; } @@ -589,7 +604,8 @@ struct mapvar string init () const { string mtype = is_parallel() ? "pmap" : "map"; - string prefix = qname() + " = _stp_" + mtype + "_new_" + keysym() + " (MAXMAPENTRIES" ; + string prefix = qname() + " = _stp_" + mtype + "_new_" + keysym() + " (" + + (maxsize > 0 ? stringify(maxsize) : "MAXMAPENTRIES") ; // Check for errors during allocation. string suffix = "if (" + qname () + " == NULL) rc = -ENOMEM;"; @@ -1905,7 +1921,8 @@ c_unparser::getmap(vardecl *v, token const *tok) i = session->stat_decls.find(v->name); if (i != session->stat_decls.end()) sd = i->second; - return mapvar (is_local (v, tok), v->type, sd, v->name, v->index_types); + return mapvar (is_local (v, tok), v->type, sd, + v->name, v->index_types, v->maxsize); } |