Skip to content

Commit

Permalink
Merge 64bd2b0 into 95a3c22
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt authored Dec 12, 2019
2 parents 95a3c22 + 64bd2b0 commit c179246
Show file tree
Hide file tree
Showing 8 changed files with 838 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ script:
- test -f /usr/local/include/verilogAST.hpp

after_success:
- coveralls --root .. -E ".*CMakeFiles.*" -E ".*googletest-src.*" -E ".*tests/.*.cpp.*"
- coveralls --root .. -E ".*CMakeFiles.*" -E ".*googletest-src.*" -E ".*tests/.*.cpp.*" -e miniconda
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include_directories(
${PROJECT_SOURCE_DIR}/include/
)

set(LIB_SOURCES src/verilogAST.cpp)
set(LIB_SOURCES src/verilogAST.cpp src/transformer.cpp)

set(LIBRARY_NAME verilogAST)
add_library(${LIBRARY_NAME} SHARED ${LIB_SOURCES})
Expand Down Expand Up @@ -57,6 +57,10 @@ if (VERILOGAST_BUILD_TESTS)
add_executable(parameterized_module tests/parameterized_module.cpp)
target_link_libraries(parameterized_module gtest_main ${LIBRARY_NAME})
add_test(NAME parameterized_module_tests COMMAND parameterized_module)

add_executable(transformer tests/transformer.cpp)
target_link_libraries(transformer gtest_main ${LIBRARY_NAME})
add_test(NAME transformer_tests COMMAND transformer)
endif()

install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
Expand Down
85 changes: 42 additions & 43 deletions include/verilogAST.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef VERILOGAST_H
#define VERILOGAST_H

#include <algorithm>
#include <map>
#include <memory>
#include <string>
Expand All @@ -26,6 +27,7 @@ class Expression : public Node {
enum Radix { BINARY, OCTAL, HEX, DECIMAL };

class NumericLiteral : public Expression {
public:
/// For now, we model values as strings because it depends on their radix
// (alternatively, we could store an unsigned integer representation and
// convert it during code generation)
Expand All @@ -38,7 +40,6 @@ class NumericLiteral : public Expression {
bool _signed; // default false
Radix radix; // default decimal

public:
NumericLiteral(std::string value, unsigned int size, bool _signed,
Radix radix)
: value(value), size(size), _signed(_signed), radix(radix){};
Expand All @@ -60,42 +61,42 @@ class NumericLiteral : public Expression {
// TODO also need a string literal, as strings can be used as parameter values

class Identifier : public Expression {
public:
std::string value;

public:
Identifier(std::string value) : value(value){};

std::string toString() override;
~Identifier(){};
};

class String : public Expression {
public:
std::string value;

public:
String(std::string value) : value(value){};

std::string toString() override;
~String(){};
};

class Index : public Expression {
public:
std::unique_ptr<Identifier> id;
std::unique_ptr<Expression> index;

public:
Index(std::unique_ptr<Identifier> id, std::unique_ptr<Expression> index)
: id(std::move(id)), index(std::move(index)){};
std::string toString() override;
~Index(){};
};

class Slice : public Expression {
public:
std::unique_ptr<Identifier> id;
std::unique_ptr<Expression> high_index;
std::unique_ptr<Expression> low_index;

public:
Slice(std::unique_ptr<Identifier> id, std::unique_ptr<Expression> high_index,
std::unique_ptr<Expression> low_index)
: id(std::move(id)),
Expand Down Expand Up @@ -132,11 +133,11 @@ enum BinOp {
}

class BinaryOp : public Expression {
public:
std::unique_ptr<Expression> left;
BinOp::BinOp op;
std::unique_ptr<Expression> right;

public:
BinaryOp(std::unique_ptr<Expression> left, BinOp::BinOp op,
std::unique_ptr<Expression> right)
: left(std::move(left)), op(op), right(std::move(right)){};
Expand All @@ -161,23 +162,23 @@ enum UnOp {
}

class UnaryOp : public Expression {
public:
std::unique_ptr<Expression> operand;

UnOp::UnOp op;

public:
UnaryOp(std::unique_ptr<Expression> operand, UnOp::UnOp op)
: operand(std::move(operand)), op(op){};
std::string toString();
~UnaryOp(){};
};

class TernaryOp : public Expression {
public:
std::unique_ptr<Expression> cond;
std::unique_ptr<Expression> true_value;
std::unique_ptr<Expression> false_value;

public:
TernaryOp(std::unique_ptr<Expression> cond,
std::unique_ptr<Expression> true_value,
std::unique_ptr<Expression> false_value)
Expand All @@ -189,47 +190,47 @@ class TernaryOp : public Expression {
};

class Concat : public Expression {
public:
std::vector<std::unique_ptr<Expression>> args;

public:
Concat(std::vector<std::unique_ptr<Expression>> args)
: args(std::move(args)){};
std::string toString();
};

class Replicate : public Expression {
std::unique_ptr<Expression> num;
std::unique_ptr<Expression> value;

public:
std::unique_ptr<Expression> num;
std::unique_ptr<Expression> value;

Replicate(std::unique_ptr<Expression> num, std::unique_ptr<Expression> value)
: num(std::move(num)), value(std::move(value)){};
std::string toString();
};

class NegEdge : public Expression {
std::unique_ptr<Expression> value;

class NegEdge : public Node {
public:
NegEdge(std::unique_ptr<Expression> value) : value(std::move(value)){};
std::unique_ptr<Identifier> value;

NegEdge(std::unique_ptr<Identifier> value) : value(std::move(value)){};
std::string toString();
~NegEdge(){};
};

class PosEdge : public Expression {
std::unique_ptr<Expression> value;

class PosEdge : public Node {
public:
PosEdge(std::unique_ptr<Expression> value) : value(std::move(value)){};
std::unique_ptr<Identifier> value;

PosEdge(std::unique_ptr<Identifier> value) : value(std::move(value)){};
std::string toString();
~PosEdge(){};
};

class Call {
public:
std::string func;
std::vector<std::unique_ptr<Expression>> args;

public:
Call(std::string func, std::vector<std::unique_ptr<Expression>> args)
: func(func), args(std::move(args)){};
std::string toString();
Expand All @@ -251,11 +252,11 @@ enum PortType { WIRE, REG };
class AbstractPort : public Node {};

class Vector : public Node {
public:
std::unique_ptr<Identifier> id;
std::unique_ptr<Expression> msb;
std::unique_ptr<Expression> lsb;

public:
Vector(std::unique_ptr<Identifier> id, std::unique_ptr<Expression> msb,
std::unique_ptr<Expression> lsb)
: id(std::move(id)), msb(std::move(msb)), lsb(std::move(lsb)){};
Expand All @@ -264,6 +265,7 @@ class Vector : public Node {
};

class Port : public AbstractPort {
public:
// Required
// `<name>` or `<name>[n]` or `name[n:m]`
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Vector>> value;
Expand All @@ -275,7 +277,6 @@ class Port : public AbstractPort {
Direction direction;
PortType data_type;

public:
Port(std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Vector>> value,
Direction direction, PortType data_type)
: value(std::move(value)),
Expand All @@ -286,42 +287,44 @@ class Port : public AbstractPort {
};

class StringPort : public AbstractPort {
public:
std::string value;

public:
StringPort(std::string value) : value(value){};
std::string toString() { return value; };
~StringPort(){};
};

class Statement : public Node {};

class SingleLineComment : public Statement {
std::string value;
class BehavioralStatement : public Statement {};
class StructuralStatement : public Statement {};

class SingleLineComment : public StructuralStatement,
public BehavioralStatement {
public:
std::string value;

SingleLineComment(std::string value) : value(value){};
std::string toString() { return "// " + value; };
~SingleLineComment(){};
};

class BlockComment : public Statement {
class BlockComment : public StructuralStatement, public BehavioralStatement {
public:
std::string value;

public:
BlockComment(std::string value) : value(value){};
std::string toString() { return "/*\n" + value + "\n*/"; };
~BlockComment(){};
};

class BehavioralStatement : public Statement {};
class StructuralStatement : public Statement {};

typedef std::vector<
std::pair<std::unique_ptr<Identifier>, std::unique_ptr<Expression>>>
Parameters;

class ModuleInstantiation : public StructuralStatement {
public:
std::string module_name;

// parameter,value
Expand All @@ -336,7 +339,6 @@ class ModuleInstantiation : public StructuralStatement {
std::unique_ptr<Slice>, std::unique_ptr<Concat>>>
connections;

public:
// TODO Need to make sure that the instance parameters are a subset of the
// module parameters
ModuleInstantiation(
Expand All @@ -354,7 +356,7 @@ class ModuleInstantiation : public StructuralStatement {
};

class Declaration : public Node {
protected:
public:
std::string decl;
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Index>,
std::unique_ptr<Slice>, std::unique_ptr<Vector>>
Expand All @@ -366,7 +368,6 @@ class Declaration : public Node {
std::string decl)
: decl(decl), value(std::move(value)){};

public:
std::string toString();
virtual ~Declaration() = default;
};
Expand All @@ -390,7 +391,7 @@ class Reg : public Declaration {
};

class Assign : public Node {
protected:
public:
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<Index>,
std::unique_ptr<Slice>>
target;
Expand All @@ -416,7 +417,6 @@ class Assign : public Node {
prefix(prefix),
symbol(symbol){};

public:
std::string toString();
virtual ~Assign() = default;
};
Expand Down Expand Up @@ -473,6 +473,7 @@ class Star : Node {
};

class Always : public StructuralStatement {
public:
std::vector<
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<PosEdge>,
std::unique_ptr<NegEdge>, std::unique_ptr<Star>>>
Expand All @@ -481,7 +482,6 @@ class Always : public StructuralStatement {
std::unique_ptr<Declaration>>>
body;

public:
Always(std::vector<
std::variant<std::unique_ptr<Identifier>, std::unique_ptr<PosEdge>,
std::unique_ptr<NegEdge>, std::unique_ptr<Star>>>
Expand All @@ -503,7 +503,7 @@ class Always : public StructuralStatement {
class AbstractModule : public Node {};

class Module : public AbstractModule {
protected:
public:
std::string name;
std::vector<std::unique_ptr<AbstractPort>> ports;
std::vector<std::variant<std::unique_ptr<StructuralStatement>,
Expand All @@ -519,7 +519,6 @@ class Module : public AbstractModule {
ports(std::move(ports)),
parameters(std::move(parameters)){};

public:
Module(std::string name, std::vector<std::unique_ptr<AbstractPort>> ports,
std::vector<std::variant<std::unique_ptr<StructuralStatement>,
std::unique_ptr<Declaration>>>
Expand All @@ -535,9 +534,9 @@ class Module : public AbstractModule {
};

class StringBodyModule : public Module {
public:
std::string body;

public:
StringBodyModule(std::string name,
std::vector<std::unique_ptr<AbstractPort>> ports,
std::string body, Parameters parameters)
Expand All @@ -547,19 +546,19 @@ class StringBodyModule : public Module {
};

class StringModule : public AbstractModule {
public:
std::string definition;

public:
StringModule(std::string definition) : definition(definition){};
std::string toString() { return definition; };
~StringModule(){};
};

class File : public Node {
public:
std::vector<std::unique_ptr<AbstractModule>> modules;

public:
File(std::vector<std::unique_ptr<AbstractModule>> &modules)
File(std::vector<std::unique_ptr<AbstractModule>>& modules)
: modules(std::move(modules)){};
std::string toString();
~File(){};
Expand Down
Loading

0 comments on commit c179246

Please sign in to comment.