Skip to content

Commit fa46afe

Browse files
Merge pull request #97 from Bo-Yuan-Huang/dev
Dev.
2 parents 27b6af9 + eb03851 commit fa46afe

30 files changed

+17745
-172
lines changed

.lgtm.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ path_classifiers:
1111
script:
1212
- scripts
1313

14-
example:
14+
application:
1515
- apps
16-
- examples
1716

1817
extraction:
1918
cpp:
@@ -30,7 +29,7 @@ extraction:
3029
command:
3130
- mkdir -p build
3231
- cd build
33-
- cmake ..
32+
- cmake .. -DILANG_STATIC=ON
3433

3534
index:
3635
build_command:

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ project(ilang VERSION 0.9.0
2020
# OPTION
2121
# build configuration
2222
# ---------------------------------------------------------------------------- #
23+
option(ILANG_STATIC "Build static libraries." OFF)
2324
option(ILANG_FETCH_DEPS "Fetch source of dependencies at config time." ON)
2425
option(ILANG_BUILD_DOCS "Build documentations." OFF)
2526
option(ILANG_BUILD_SYNTH "Build the synthesis engine." ON)

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019
3+
Copyright (c) 2019 Princeton University ILA Team
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

extern/vlog-parser

include/ilang/ila/ast/expr_op.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,15 @@ class ExprOpSub : public ExprOp {
185185

186186
// TODO ExprOpMod
187187

188-
// TODO ExprOpMul
188+
/// \brief The wrapper for unsigned multiplication.
189+
class ExprOpMul : public ExprOp {
190+
public:
191+
/// Constructor for MUL operation.
192+
ExprOpMul(const ExprPtr arg0, const ExprPtr arg1);
193+
std::string op_name() const { return "MUL"; }
194+
z3::expr GetZ3Expr(z3::context& ctx, const Z3ExprVec& expr_vec,
195+
const std::string& suffix = "") const;
196+
}; // class ExprOpMul
189197

190198
/******************************************************************************/
191199
// Binary comparison

include/ilang/ila/ast_fuse.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ enum AST_UID_EXPR_OP {
3030
LSHR,
3131
ADD,
3232
SUB,
33+
MUL,
3334
EQ,
3435
LT,
3536
GT,

include/ilang/ila/expr_fuse.h

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ ExprPtr Lshr(const ExprPtr l, const int& r);
101101
ExprPtr Add(const ExprPtr l, const int& r);
102102
/// Arithmetic subtraction with int.
103103
ExprPtr Sub(const ExprPtr l, const int& r);
104+
/// Arithmetic unsigned multiply with int (bv only).
105+
ExprPtr Mul(const ExprPtr l, const int& r);
104106

105107
/******************************************************************************/
106108
// Comparison
@@ -163,6 +165,11 @@ ExprPtr Load(const ExprPtr mem, const int& addr);
163165
/// Memory store to constant address and data
164166
ExprPtr Store(const ExprPtr mem, const int& addr, const int& data);
165167

168+
/// Set memory size.
169+
bool SetMemSize(const ExprPtr mem, const int& size = 0);
170+
/// Get memory size.
171+
int GetMemSize(const ExprPtr mem);
172+
166173
/******************************************************************************/
167174
// Bit manipulation
168175
/******************************************************************************/

include/ilang/ilang++.h

+22-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ class ExprRef {
137137
/// \brief Replace the original argument (must exist) with the new argument.
138138
void ReplaceArg(const ExprRef& org_arg, const ExprRef& new_arg);
139139

140+
/// \brief Set the entry number of the memory (size regardless of bit-width).
141+
bool SetEntryNum(const int& num);
142+
/// \brief GEt the entry number of the memory (size regardless of bit-width).
143+
int GetEntryNum();
144+
140145
}; // class ExprRef
141146

142147
/******************************************************************************/
@@ -168,6 +173,8 @@ ExprRef Lshr(const ExprRef& a, const ExprRef& b);
168173
ExprRef operator+(const ExprRef& a, const ExprRef& b);
169174
/// Unsigned subtraction for bit-vectors.
170175
ExprRef operator-(const ExprRef& a, const ExprRef& b);
176+
/// Unsigned multiply for bit-vectors.
177+
ExprRef operator*(const ExprRef& a, const ExprRef& b);
171178

172179
/// Logical AND with Boolean constant.
173180
ExprRef operator&(const ExprRef& a, const bool& b);
@@ -185,6 +192,8 @@ ExprRef Lshr(const ExprRef& a, const int& b);
185192
ExprRef operator+(const ExprRef& a, const int& b);
186193
/// Unsigned subtraction with int constant.
187194
ExprRef operator-(const ExprRef& a, const int& b);
195+
/// Unsigned multiply with int constant.
196+
ExprRef operator*(const ExprRef& a, const int& b);
188197

189198
/******************************************************************************/
190199
// Binary comparison
@@ -485,7 +494,7 @@ class Ila {
485494

486495
// ------------------------- GENERATORS --------------------------------- //
487496
/// \brief Export an ILA as Verilog
488-
/// \param[in] filename the file name of the generated Verilog source
497+
/// \param[in] fout the output stream of the generated Verilog source.
489498
void ExportToVerilog(std::ostream& fout) const;
490499

491500
// ------------------------- ACCESSORS/MUTATORS --------------------------- //
@@ -542,6 +551,18 @@ std::ostream& operator<<(std::ostream& out, const InstrRef& instr);
542551
/// Print out the ILA.
543552
std::ostream& operator<<(std::ostream& out, const Ila& ila);
544553

554+
/******************************************************************************/
555+
// Converters
556+
/******************************************************************************/
557+
/// \brief Export the ILA portable to file.
558+
/// \param[in] ila the source ILA model to export.
559+
/// \param[in] file_name the name of the exported ILA portable (JSON) file.
560+
bool ExportIlaPortable(const Ila& ila, const std::string& file_name);
561+
562+
/// \brief Import the ILA portable from file.
563+
/// \param[in] file_name the name of the ILA portable (JSON) file to import.
564+
Ila ImportIlaPortable(const std::string& file_name);
565+
545566
/******************************************************************************/
546567
// Verification.
547568
/******************************************************************************/

include/ilang/portable/ila_to_json_serializer.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,31 @@ class I2JSer {
3636
json SerExpr(const ExprPtr& i_expr);
3737
/// \brief Serialize Instr to JSON.
3838
json SerInstr(const InstrPtr& i_instr);
39-
/// \brief Serialize InstrLvlAbs to JSON.
39+
/// \brief Serialize InstrLvlAbs, including its children, to JSON.
4040
json SerInstrLvlAbs(const InstrLvlAbsPtr& i_ila);
4141

4242
private:
4343
// ------------------------- MEMBERS -------------------------------------- //
4444
/// A map from visited i_expr id to j_expr array index.
4545
std::unordered_map<size_t, size_t> id_idx_map_;
46+
/// A map from visited i_func id to j_func array index.
47+
std::unordered_map<size_t, size_t> func_id_idx_map_;
4648
/// The list of all serialized expressions (j_expr array).
4749
json j_expr_arr_;
50+
/// The list of all serialized functions (j_func array).
51+
json j_func_arr_;
4852

4953
// ------------------------- METHODS -------------------------------------- //
5054
/// Serialize Sort to JSON.
5155
json SerSort(const SortPtr& i_sort) const;
56+
/// Serialize Func to JSON.
57+
json SerFunc(const FuncPtr& i_func);
5258
/// Serialize constant value to JSON.
5359
json SerConstVal(const ExprPtr& i_expr) const;
5460
/// Serialize one single Expr.
5561
json SerExprUnit(const ExprPtr& i_expr);
62+
/// Serialize InstrLvlAbs and its children, excluding the AST list.
63+
json SerInstrLvlAbsNoAst(const InstrLvlAbsPtr& i_ila);
5664

5765
}; // class I2JSer
5866

include/ilang/portable/interface.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class IlaSerDesMngr {
3030
/// \brief Serialize the ILA model to the given file.
3131
/// \param[in] m the ILA model to serialize.
3232
/// \param[in] file_name the output file name.
33+
/// \param[in] indent the number of space to indent.
3334
/// \return Return true if complete sucessfully.
34-
static bool SerToFile(const InstrLvlAbsPtr& m, const std::string& file_name);
35+
static bool SerToFile(const InstrLvlAbsPtr& m, const std::string& file_name,
36+
const int& indent = -1);
3537

3638
/// \brief Deserialize the ILA model from the given file.
3739
/// \param[in] file_name the input file name.

include/ilang/portable/json_to_ila_deserializer.h

+27-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <memory>
99
#include <nlohmann/json.hpp>
1010
#include <unordered_map>
11-
#include <unordered_set>
1211

1312
using json = nlohmann::json;
1413

@@ -33,21 +32,25 @@ class J2IDes {
3332
static J2IDesPtr New();
3433

3534
// ------------------------- METHODS -------------------------------------- //
35+
/// Deserialize Sort from JSON.
36+
SortPtr DesSort(const json& j_sort);
37+
/// Deserialize Func from JSON.
38+
FuncPtr DesFunc(const json& j_func);
3639
/// \brief Deserialize Expr from JSON.
37-
ExprPtr DesExpr(const json& j_expr, const InstrLvlAbsPtr& i_host);
40+
ExprPtr DesExpr(const json& j_expr);
3841
/// \brief Deserialize Instr from JSON.
3942
InstrPtr DesInstr(const json& j_instr, const InstrLvlAbsPtr& i_host) const;
4043
/// \brief Deserialize InstrLvlAbs from JSON.
41-
InstrLvlAbsPtr DesInstrLvlAbs(const json& j_ila);
44+
InstrLvlAbsPtr DesInstrLvlAbs(const json& j_global);
4245

4346
private:
4447
// ------------------------- MEMBERS -------------------------------------- //
45-
/// A mapping from id to expressions.
48+
/// A mapping from id to expression.
4649
std::unordered_map<size_t, ExprPtr> id_expr_map_;
47-
/// The set of state variables.
48-
std::unordered_set<size_t> state_id_set_;
49-
/// The set of input variables.
50-
std::unordered_set<size_t> input_id_set_;
50+
/// A mapping from id to function.
51+
std::unordered_map<size_t, FuncPtr> id_func_map_;
52+
/// The mapping from ila name to pointer.
53+
std::unordered_map<std::string, const InstrLvlAbsPtr> ila_name_ptr_map_;
5154

5255
// ------------------------- METHODS -------------------------------------- //
5356
/// Deserialize ExprVar into state from JSON.
@@ -61,6 +64,22 @@ class J2IDes {
6164
/// Deserialize ExprOp from JSON.
6265
ExprPtr DesExprOp(const unsigned& ast_expr_op_uid, const json& j_arg_arr,
6366
const json& j_param_arr) const;
67+
/// Deserialize ExprOpAppFunc from JSON.
68+
ExprPtr DesExprOpAppFunc(const json& j_func_id, const json& j_arg_arr) const;
69+
70+
/// Deserialize state/input variables. Note: the ILA model will be
71+
/// constructed on-the-fly.
72+
void DesVarUnit(const json& j_ila, const json& j_ast_list,
73+
const InstrLvlAbsPtr& i_parent);
74+
/// Deserialize state/input variables hierarchically. Note: ILA model will be
75+
/// constructed on-the-fly.
76+
void DesVarHier(const json& j_ila, const json& j_ast_list,
77+
const InstrLvlAbsPtr& i_parent);
78+
79+
/// Deserialize ILA info, e.g., fetch, valid, instructions, etc.
80+
void DesIlaUnit(const json& j_ila);
81+
/// Deserialize ILA info hierarchically.
82+
void DesIlaHier(const json& j_ila);
6483

6584
}; // class J2IDes
6685

include/ilang/portable/serdes_config.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ namespace ilang {
1313
#define SERDES_SORT_ADDR_WIDTH "a"
1414
#define SERDES_SORT_DATA_WIDTH "d"
1515

16+
// Func
17+
#define SERDES_FUNC_ID "i"
18+
#define SERDES_FUNC_NAME "n"
19+
#define SERDES_FUNC_OUT "o"
20+
#define SERDES_FUNC_ARGS "a"
21+
1622
// Expr
1723
#define SERDES_EXPR_ID "i"
1824
#define SERDES_EXPR_UID "u"
@@ -22,6 +28,7 @@ namespace ilang {
2228
#define SERDES_EXPR_OP "o"
2329
#define SERDES_EXPR_ARGS "a"
2430
#define SERDES_EXPR_PARAMS "p"
31+
#define SERDES_EXPR_FUNC "f"
2532

2633
// Instr
2734
#define SERDES_INSTR_NAME "n"
@@ -36,13 +43,18 @@ namespace ilang {
3643
#define SERDES_ILA_VALID "v"
3744
#define SERDES_ILA_INSTR "instr"
3845
#define SERDES_ILA_INIT "init"
39-
#define SERDES_ILA_AST "a"
46+
#define SERDES_ILA_CHILD "c"
4047

4148
// ConstVal
4249
#define SERDES_CONST_VAL "v"
4350
#define SERDES_CONST_DEF "d"
4451
#define SERDES_CONST_MAP "m"
4552

53+
// Global
54+
#define SERDES_GLOBAL_AST "a"
55+
#define SERDES_GLOBAL_FUNC "f"
56+
#define SERDES_GLOBAL_TOP "t"
57+
4658
}; // namespace ilang
4759

4860
#endif // ILANG_PORTABLE_SERDES_CONFIG_H__

include/ilang/target-c/ila_to_c.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// \file
2+
/// ILA to C target generator..
3+
4+
#ifndef ILANG_TARGET_I2C_H__
5+
#define ILANG_TARGET_I2C_H__
6+
7+
#include <ilang/ila/instr_lvl_abs.h>
8+
#include <memory>
9+
#include <unordered_map>
10+
11+
/// \namespace ilang
12+
namespace ilang {
13+
14+
/// \brief The calss for converting an ILA model to a C target.
15+
class I2CMngr {
16+
public:
17+
/// Pointer type for normal use of I2CMngr.
18+
typedef std::shared_ptr<I2CMngr> I2CMngrPtr;
19+
20+
// ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
21+
/// Default constructor.
22+
I2CMngr();
23+
/// Default destructor.
24+
~I2CMngr();
25+
26+
// ------------------------- HELPERS -------------------------------------- //
27+
/// \brief Create a new I2CMngr. Used for hiding implementation specific type
28+
/// details.
29+
static I2CMngrPtr New();
30+
31+
// ------------------------- METHODS -------------------------------------- //
32+
/// \brief Generate a C target of the given ILA model.
33+
/// \param[in] ila The top-level ILA model to generate the C target for.
34+
/// \param[out] C intermediate representation.
35+
void GenerateCTarget(const InstrLvlAbsPtr& ila);
36+
37+
private:
38+
// ------------------------- MEMBERS -------------------------------------- //
39+
/// A map from visited i_expr id to c_var array index.
40+
std::unordered_map<size_t, size_t> id_var_map_;
41+
42+
// ------------------------- METHODS -------------------------------------- //
43+
/// Convert constant node to c contant.
44+
void ConvertConst(const ExprPtr& expr) const;
45+
46+
}; // class I2CMngr
47+
48+
/// Pointer type for normal use of I2CMngr.
49+
typedef I2CMngr::I2CMngrPtr I2CMngrPtr;
50+
51+
}; // namespace ilang
52+
53+
#endif // ILANG_TARGET_I2C_H__
54+

src/CMakeLists.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
# TARGET
33
# archive library
44
# ---------------------------------------------------------------------------- #
5-
add_library(${ILANG_LIB_NAME} ilang++.cc)
5+
if(${ILANG_STATIC})
6+
add_library(${ILANG_LIB_NAME} STATIC ilang++.cc)
7+
else()
8+
add_library(${ILANG_LIB_NAME} SHARED ilang++.cc)
9+
endif()
10+
611
add_library(${PROJECT_NAME}::${ILANG_LIB_NAME} ALIAS ${ILANG_LIB_NAME})
712

813
##
914
## source files
1015
##
11-
add_subdirectory(util)
1216
add_subdirectory(ila)
17+
add_subdirectory(mcm)
18+
add_subdirectory(portable)
19+
add_subdirectory(target-c)
20+
add_subdirectory(util)
1321
add_subdirectory(verification)
1422
add_subdirectory(verilog-in)
1523
add_subdirectory(verilog-out)
1624
add_subdirectory(vtarget-out)
17-
add_subdirectory(mcm)
18-
add_subdirectory(portable)
1925

2026
if(${ILANG_BUILD_SYNTH})
2127
add_subdirectory(synth-interface)

src/ila/ast/expr_op.cc

+13
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ z3::expr ExprOpSub::GetZ3Expr(z3::context& ctx, const Z3ExprVec& expr_vec,
263263
return expr_vec[0] - expr_vec[1];
264264
}
265265

266+
// ------------------------- Class ExprOpMul ------------------------------- //
267+
ExprOpMul::ExprOpMul(const ExprPtr arg0, const ExprPtr arg1)
268+
: ExprOp(arg0, arg1) {
269+
set_sort(GetSortBinaryOperation(arg0, arg1));
270+
}
271+
272+
z3::expr ExprOpMul::GetZ3Expr(z3::context& ctx, const Z3ExprVec& expr_vec,
273+
const std::string& suffix) const {
274+
ILA_ASSERT(expr_vec.size() == 2) << "Mul is binary operation.";
275+
ILA_ASSERT(is_bv()) << "Mul can only be applied to bv.";
276+
return expr_vec[0] * expr_vec[1];
277+
}
278+
266279
// ------------------------- Class ExprOpEq --------------------------------- //
267280
ExprOpEq::ExprOpEq(const ExprPtr arg0, const ExprPtr arg1)
268281
: ExprOp(arg0, arg1) {

0 commit comments

Comments
 (0)