Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,825 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
**/_*.json | ||
*.pyc | ||
\#*\# | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore everything in this directory | ||
* | ||
#except this file | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.SUFFIXES: | ||
COREIRCONFIG ?= g++ | ||
CXX ?= g++ | ||
|
||
ifeq ($(COREIRCONFIG),g++) | ||
CXX = g++ | ||
endif | ||
|
||
ifeq ($(COREIRCONFIG),g++-4.9) | ||
CXX = g++-4.9 | ||
endif | ||
|
||
CXXFLAGS = -std=c++11 -Wall -fPIC -Werror | ||
|
||
ifdef COREDEBUG | ||
CXXFLAGS += -O0 -g3 -D_GLIBCXX_DEBUG | ||
endif | ||
|
||
|
||
HOME = ../.. | ||
INCS = -I$(HOME)/include -I. | ||
LPATH = -L$(HOME)/lib | ||
LIBS = -Wl,-rpath,$(HOME)/lib -lcoreir-passes -lcoreir | ||
SRCFILES = $(wildcard [^_]*.cpp) | ||
OBJS = $(patsubst %.cpp,build/%.o,$(SRCFILES)) | ||
EXES = $(patsubst %.cpp,build/%,$(SRCFILES)) | ||
|
||
all: $(EXES) | ||
|
||
clean: | ||
rm -rf build/* | ||
|
||
build/%: build/%.o | ||
$(CXX) $(CXXFLAGS) $(INCS) -o $@ $< $(LPATH) $(LIBS) | ||
cp $@ $(HOME)/bin | ||
|
||
build/%.o: %.cpp | ||
$(CXX) $(CXXFLAGS) $(INCS) -c -o $@ $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore everything in this directory | ||
* | ||
#except this file | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "coreir.h" | ||
#include "cxxopts.hpp" | ||
|
||
#include "coreir-passes/firrtl.hpp" | ||
|
||
using namespace CoreIR; | ||
|
||
string getExt(string s) { | ||
auto split = splitString(s,'.'); | ||
ASSERT(split.size()==2,"File needs extention: " + s); | ||
return split[1]; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
cxxopts::Options options("coreir", "a simple hardware compiler"); | ||
options.add_options() | ||
("i,input","input: <file>.json",cxxopts::value<std::string>()) | ||
("o,output","output: <file>.<json|txt|firrtl|v>",cxxopts::value<std::string>()) | ||
; | ||
//Do the parsing of the arguments | ||
options.parse(argc,argv); | ||
|
||
ASSERT(options.count("i"),"No input specified") | ||
ASSERT(options.count("o"),"No output specified") | ||
string infileName; | ||
string outfileName; | ||
try { | ||
infileName = options["i"].as<string>(); | ||
outfileName = options["o"].as<string>(); | ||
//string topRef = a.get<string>("top"); | ||
//bool userTop = topRef != ""; | ||
} catch(cxxopts::option_requires_argument_exception& exc) { | ||
cout << exc.what() << endl; | ||
exit(1); | ||
} | ||
string inExt = getExt(infileName); | ||
ASSERT(inExt=="json","Input needs to be json"); | ||
string outExt = getExt(outfileName); | ||
ASSERT(outExt == "json" | ||
|| outExt == "txt" | ||
|| outExt == "firrtl" | ||
|| outExt == "v", "Cannot support out extention: " + outExt); | ||
|
||
cout << "in: " << infileName << endl; | ||
cout << "out: " << outfileName << endl; | ||
|
||
//Load input | ||
Context* c = newContext(); | ||
Module* top; | ||
if (!loadFromFile(c,infileName,&top)) { | ||
c->die(); | ||
} | ||
cout << "Loaded succesffully" << endl; | ||
//if (userTop) { | ||
// auto tref = splitString(topRef,"."); | ||
// ASSERT(c->hasNamespace(tref[0]),"Missing top : " + topRef); | ||
// ASSERT(c->getNamespace(tref[0])->hasModule(tref[1]),"Missing top : " + topRef); | ||
// Module* uTop = c->getNamespace(tref[0])->getModule(tref[1]); | ||
// if (uTop != top) { | ||
// cout << "WARNING: Overriding top="+uTop->getNamespace()->getName() + "." + uTop->getName() + " with top=" + topRef; | ||
// } | ||
// top = uTop; | ||
//} | ||
|
||
|
||
PassManager* pm = new PassManager(c->getGlobal()); | ||
|
||
if (outExt=="firrtl") { | ||
Firrtl* fpass = new Firrtl(); | ||
pm->addPass(fpass,5); | ||
pm->run(); | ||
fpass->writeToFile(outfileName); | ||
} | ||
//Get Namespace | ||
//Namespace* ns = top->getNamespace(); | ||
////Write out to a file | ||
//if (outExt == "json") { | ||
// if (!saveToFile(ns,outfileName,top)) { | ||
// c->die(); | ||
// } | ||
//} | ||
//else { | ||
// cout << "NYI" << endl; | ||
//} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.