Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding support for fxd-point arithmetic

  • Loading branch information...
commit e67ac77aaff51194fa7b776b038b59a7e1e16d8b 1 parent 99799d8
@mwolf76 authored
View
2  src/expr/expr.hh
@@ -55,6 +55,8 @@ typedef enum {
HCONST, // hex constants
OCONST, // octal constants
+ FCONST, // fract constant
+
IDENT, DOT,
NIL, // reserved
View
30 src/expr/expr_mgr.cc
@@ -36,14 +36,32 @@ ExprMgr::ExprMgr()
false_expr = make_identifier(FALSE_TOKEN);
true_expr = make_identifier(TRUE_TOKEN);
- // unsigned and signed base integer types identifiers
- unsigned_expr = make_identifier(UNSIGNED_TOKEN);
- signed_expr = make_identifier(SIGNED_TOKEN);
- fixed_expr = make_identifier(FIXED_TOKEN);
- integer_expr = make_identifier(INTEGER_TOKEN); // abstract
+ // integer types identifiers
+ {
+ ostringstream oss; oss << UNSIGNED_TOKEN << " " << INT_TOKEN;
+ unsigned_int_expr = make_identifier(oss.str());
+ }
+ {
+ ostringstream oss; oss << SIGNED_TOKEN << " " << INT_TOKEN;
+ signed_int_expr = make_identifier(oss.str());
+ }
+ int_expr = make_identifier(INT_TOKEN);
+
+ // fixed-point real types identifiers
+ {
+ ostringstream oss; oss << UNSIGNED_TOKEN << " " << FXD_TOKEN;
+ unsigned_fxd_expr = make_identifier(oss.str());
+ }
+ {
+ ostringstream oss; oss << SIGNED_TOKEN << " " << FXD_TOKEN;
+ signed_fxd_expr = make_identifier(oss.str());
+ }
+ fxd_expr = make_identifier(FXD_TOKEN);
- // main module identifier
main_expr = make_identifier(MAIN_TOKEN);
+ enum_expr = make_identifier(ENUM_TOKEN);
+ inst_expr = make_identifier(INST_TOKEN);
+ array_expr = make_identifier (ARRAY_TOKEN);
DEBUG << "ExprMgr @" << this << " initialized" << endl;
}
View
111 src/expr/expr_mgr.hh
@@ -204,31 +204,84 @@ public:
inline Expr_ptr make_boolean_type() const
{ return bool_expr; }
- inline Expr_ptr make_integer_type() const
- { return integer_expr; }
+ inline Expr_ptr make_int_const_type() const
+ { return int_expr; }
+
+ inline Expr_ptr make_fxd_const_type() const
+ { return fxd_expr; }
inline Expr_ptr make_range_type(Expr_ptr a, Expr_ptr b)
{
- assert(is_numeric(a));
- assert(is_numeric(b));
+ assert(is_int_numeric(a));
+ assert(is_int_numeric(b));
return make_expr(RANGE, a, b);
}
- inline Expr_ptr make_unsigned_type(unsigned bits)
- { return make_params(unsigned_expr, make_iconst((value_t) bits)); }
+ inline Expr_ptr make_abstract_unsigned_int_type()
+ {
+ return unsigned_int_expr;
+ }
+
+ inline Expr_ptr make_unsigned_int_type(unsigned digits)
+ {
+ return make_params(unsigned_int_expr,
+ make_iconst((value_t) digits));
+ }
+
+ inline Expr_ptr make_abstract_signed_int_type()
+ {
+ return signed_int_expr;
+ }
+
+ inline Expr_ptr make_signed_int_type(unsigned digits)
+ {
+ return make_params(signed_int_expr,
+ make_iconst((value_t) digits));
+ }
+
+ inline Expr_ptr make_abstract_unsigned_fxd_type()
+ {
+ return unsigned_fxd_expr;
+ }
+
+ inline Expr_ptr make_unsigned_fxd_type(unsigned int_digits,
+ unsigned fract_digits)
+ {
+ return make_params(unsigned_fxd_expr,
+ make_comma(make_iconst((value_t) int_digits),
+ make_iconst((value_t) fract_digits)));
+ }
- inline Expr_ptr make_signed_type(unsigned bits)
- { return make_params(signed_expr, make_iconst((value_t) bits)); }
+ inline Expr_ptr make_abstract_signed_fxd_type()
+ {
+ return signed_fxd_expr;
+ }
- inline Expr_ptr make_fixed_type(unsigned int_digits, unsigned fract_digits)
+ inline Expr_ptr make_signed_fxd_type(unsigned int_digits,
+ unsigned fract_digits)
{
- return make_params(fixed_expr,
+ return make_params(signed_fxd_expr,
make_comma(make_iconst((value_t) int_digits),
make_iconst((value_t) fract_digits)));
}
+ inline Expr_ptr make_abstract_enum_type()
+ {
+ return enum_expr;
+ }
+
Expr_ptr make_enum_type(ExprSet& literals);
+ inline Expr_ptr make_abstract_inst_type()
+ {
+ return inst_expr;
+ }
+
+ inline Expr_ptr make_abstract_array_type()
+ {
+ return array_expr;
+ }
+
/* builtin identifiers */
inline Expr_ptr make_main() const
{ return main_expr; }
@@ -282,13 +335,18 @@ public:
return expr->f_symb == NEXT;
}
- inline bool is_numeric(const Expr_ptr expr) const {
+ inline bool is_int_numeric(const Expr_ptr expr) const {
assert(expr);
return (expr->f_symb == ICONST)
|| (expr->f_symb == HCONST)
|| (expr->f_symb == OCONST) ;
}
+ inline bool is_fxd_numeric(const Expr_ptr expr) const {
+ assert(expr);
+ return (expr->f_symb == FCONST);
+ }
+
// expr inspectors, used by compiler as helpers to determine operands type
inline bool is_unary_logical(const Expr_ptr expr) const {
assert(expr);
@@ -402,22 +460,35 @@ private:
/* -- data ------------------------------------------------------------- */
- // temporal exprs type
- Expr_ptr temporal_expr;
+ // // temporal exprs type
+ // Expr_ptr temporal_expr;
- // boolean exprs type and constants
+ /* boolean exprs type and constants */
Expr_ptr bool_expr;
Expr_ptr false_expr;
Expr_ptr true_expr;
- // main module
+ /* main module */
Expr_ptr main_expr;
- // base for (un-)signed integer
- Expr_ptr unsigned_expr;
- Expr_ptr signed_expr;
- Expr_ptr fixed_expr;
- Expr_ptr integer_expr; // reserved for abstract integer-type
+ /* reserved for abstract enum types */
+ Expr_ptr enum_expr;
+
+ /* reserved for abstract instance types */
+ Expr_ptr inst_expr;
+
+ /* reserved for abstract array types */
+ Expr_ptr array_expr;
+
+ /* integers */
+ Expr_ptr unsigned_int_expr;
+ Expr_ptr signed_int_expr;
+ Expr_ptr int_expr;
+
+ /* fixed-point reals */
+ Expr_ptr unsigned_fxd_expr;
+ Expr_ptr signed_fxd_expr;
+ Expr_ptr fxd_expr;
/* shared pools */
ExprPool f_expr_pool;
View
6 src/expr/tests/test_expr.cc
@@ -73,11 +73,11 @@ BOOST_AUTO_TEST_CASE(expr_makers)
BOOST_CHECK (x_ite_y->f_symb == ITE && x_ite_y->u.f_lhs == x && x_ite_y->u.f_rhs == y);
Expr_ptr iconst_42 = em.make_iconst(42);
- BOOST_CHECK (em.is_numeric(iconst_42) && iconst_42->value() == 42);
+ BOOST_CHECK (em.is_int_numeric(iconst_42) && iconst_42->value() == 42);
Expr_ptr hconst_42 = em.make_hconst(0x2a);
- BOOST_CHECK (em.is_numeric(hconst_42) && hconst_42->value() == 42);
+ BOOST_CHECK (em.is_int_numeric(hconst_42) && hconst_42->value() == 42);
Expr_ptr oconst_42 = em.make_oconst(052);
- BOOST_CHECK (em.is_numeric(oconst_42) && oconst_42->value() == 42);
+ BOOST_CHECK (em.is_int_numeric(oconst_42) && oconst_42->value() == 42);
Expr_ptr x_dot_y = em.make_dot(x, y);
BOOST_CHECK (x_dot_y->f_symb == DOT && x_dot_y->u.f_lhs == x && x_dot_y->u.f_rhs == y);
Please sign in to comment.
Something went wrong with that request. Please try again.