Skip to content

Commit

Permalink
vhdl: fix termification of bit strings
Browse files Browse the repository at this point in the history
Termification mistakes bit strings for operator symbol names. Fix this
by intercepting the bit string case and generating an explicit literal.
Emit the corresponding expression.
  • Loading branch information
fabianschuiki committed Feb 24, 2018
1 parent f86c43d commit 17b6108
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/vhdl/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ pub enum ExprData {
Select(ExprRef, Spanned<ResolvableName>),
/// An attribute selection, e.g. `a'b`.
Attr(ExprRef, Spanned<ResolvableName>),
/// A bit string literal.
StringLiteral(Name),
/// An integer literal.
IntegerLiteral(ConstInt),
/// A float literal.
Expand Down
13 changes: 10 additions & 3 deletions src/vhdl/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::collections::HashMap;

use num::BigInt;

use common::name::Name;
use common::errors::*;
use common::source::*;
use common::util::*;
Expand Down Expand Up @@ -39,6 +40,8 @@ pub enum Term {
Default,
/// An integer literal.
IntLit(BigInt),
/// A bit string literal.
StrLit(Name),
/// An unresolved name.
Unresolved(ResolvableName),
/// A term that refers to a definition.
Expand Down Expand Up @@ -251,9 +254,10 @@ impl<'sbc, 'lazy, 'sb, 'ast, 'ctx> TermContext<'sbc, 'lazy, 'sb, 'ast, 'ctx> {
/// Map an AST compound name to a term.
pub fn termify_compound_name(&self, ast: &'ast ast::CompoundName) -> Result<Spanned<Term>> {
// Map the primary name.
let mut term = self.fold(self.termify_name(
self.ctx.resolvable_from_primary_name(&ast.primary)?
)?);
let mut term = self.fold(match ast.primary.kind {
ast::PrimaryNameKind::String(s) => Spanned::new(Term::StrLit(s), ast.primary.span),
_ => self.termify_name(self.ctx.resolvable_from_primary_name(&ast.primary)?)?,
});

// For each name part, wrap the term in another layer. Like an onion.
for part in &ast.parts {
Expand Down Expand Up @@ -411,6 +415,9 @@ impl<'sbc, 'lazy, 'sb, 'ast, 'ctx> TermContext<'sbc, 'lazy, 'sb, 'ast, 'ctx> {
Term::IntLit(value) => {
hir::ExprData::IntegerLiteral(ConstInt::new(None, value))
}
Term::StrLit(value) => {
hir::ExprData::StringLiteral(value)
}
Term::Unary(op, arg) => {
hir::ExprData::Unary(op, self.term_to_expr(*arg)?)
}
Expand Down

0 comments on commit 17b6108

Please sign in to comment.