Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ src/parseLEX.cpp
*.swp
*.eps
*.plt
.vscode/
33 changes: 21 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
LEX = flex
LEX = flex
YACC = bison
LEX_FLAG = -Pparse
YACC_FLAG = -d -p parse
LEX_FLAG = -Pparse
YACC_FLAG = -d -p parse

CXX = g++
#CFLAGS = -g -Iinclude
CFLAGS = -O3 -Iinclude -Wall
CSRCS = $(wildcard src/*.cpp)
CHDRS = $(wildcard include/*.h)
#COBJS = $(addsuffix .o, $(basename $(CSRCS)))
CXX = g++
CFLAGS = -O3 -Iinclude -Wall
CFLAGS_STFU = -Wno-unused-function -Wno-unneeded-internal-declaration
CSRCS = $(wildcard src/*.cpp)
CHDRS = $(wildcard include/*.h)

COBJS = obj/main.o obj/simulator.o obj/circuit.o obj/utils.o obj/parseLEX.o obj/parseYY.o
COBJS = obj/main.o obj/simulator.o obj/circuit.o obj/utils.o obj/parseLEX.o obj/parseYY.o

all : bin/cspice
.PHONY: create_dirs

all : create_dirs bin/cspice

create_dirs:
mkdir -p bin obj

src/parseLEX.cpp: src/parser.l src/parseYY.hpp
@echo "> lexing: $<"
Expand All @@ -25,6 +29,10 @@ src/parseYY.cpp src/parseYY.hpp: src/parser.y
@mv parseYY.hpp src/parseYY.hpp
@ln -sf src/parseYY.hpp include/parseYY.hpp

# Special rule for parseLEX.o to shut up warnings from autogenerated source
obj/parseLEX.o : src/parseLEX.cpp
$(CXX) $(CFLAGS) ${CFLAGS_STFU} -c -o $@ $<

obj/parseYY.o : src/parser.cpp

bin/cspice : $(COBJS)
Expand All @@ -39,5 +47,6 @@ obj/%.o : src/%.cpp
$(COBJS) : $(CHDRS)

clean:
-rm -f obj/* bin/* src/parseYY.cpp src/parseYY.hpp src/parseLEX.cpp
-rm -f obj/*.o bin/cspice src/parseYY.cpp src/parseYY.hpp src/parseLEX.cpp
-rm -rf bin obj

2 changes: 1 addition & 1 deletion include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std;

class Parser {
public:
Parser(const char *) ;
Parser(const char* fname = nullptr) ;
const Circuit& getCircuit() const { return circuit; }
const vector<SimulateConfig>& getConfig() const { return config; }
Circuit& getCircuit() { return circuit; }
Expand Down
4 changes: 2 additions & 2 deletions include/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Source {
_name() ,
_prevValue(0.0) ,
_nextValue(0.0) ,
_n1(NULL) ,
_n2(NULL) { }
_n1(0) ,
_n2(0) { }

Source(const char * name , const int n1 , const int n2 , const double pv , const double nv) :
_name(name) ,
Expand Down
2 changes: 1 addition & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern void printFormula(const vector<vector<const Element*> > & , ostream &) ;
extern complex<double> evalFormula(const vector<double> & , const double&);
extern vector<pair<int , double> > expandFormula(const vector<vector<const Element*> > &) ;
vector<double> numericalIntegration(const vector<double>& times,Simulator::TransferFunction& tf, unsigned shift = 8) ;
extern unsigned long long hash(const char *) ;
extern unsigned long long util_hash(const char *) ;

#endif /* __UTILS_H__ */

2 changes: 1 addition & 1 deletion src/circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void Circuit::dfs(
// Be ware that, we have to take the risk of
// hash(a) + hash(b) == hash(c) + hash(d),
// though I don't think it would happen so easily.
hashValue += hash(current_tree[i]->formula().c_str()) ;
hashValue += util_hash(current_tree[i]->formula().c_str()) ;

sign *= current_tree[i]->sign() ;
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Parser::Parser(const char * fname = NULL) {
Parser::Parser(const char * fname) {
extern FILE * yyin ;
extern int yyparse() ;

Expand Down
2 changes: 1 addition & 1 deletion src/parser.l
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ FNAME (([0-9a-zA-Z\.\-_])+\.eps)
. {
/* rest cases */
char msg[40] ;
sprintf(msg , "Unexpected character: '%s'" , escape(yytext)) ;
snprintf(msg , 40, "Unexpected character: '%s'" , escape(yytext)) ;
yyerror(msg) ;
return yytext[0] ;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ostream& operator<<(ostream& out , const Element& element) {
return out ;
}

unsigned long long hash(const char * p) {
unsigned long long util_hash(const char * p) {
// using FNV-1a hash algorithm
const unsigned long long prime = 1099511628211ull ;
unsigned long long result = 14695981039346656037ull ;
Expand Down