Skip to content

Commit

Permalink
Actually adding all the new files
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaly525 committed Aug 14, 2017
1 parent 4ece7f6 commit 170313a
Show file tree
Hide file tree
Showing 6 changed files with 1,825 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,3 @@
**/_*.json
*.pyc
\#*\#
bin/
4 changes: 4 additions & 0 deletions bin/.gitignore
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
#except this file
!.gitignore
38 changes: 38 additions & 0 deletions src/binary/Makefile
@@ -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 $@ $<
4 changes: 4 additions & 0 deletions src/binary/build/.gitignore
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
#except this file
!.gitignore
88 changes: 88 additions & 0 deletions src/binary/coreir.cpp
@@ -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;
}

0 comments on commit 170313a

Please sign in to comment.