Skip to content
Snippets Groups Projects
Commit 84b8efb2 authored by Peter Matta's avatar Peter Matta
Browse files

[CLI][Feature] Updated CLI interfaces for duckc and dusk-format

parent d825109c
No related branches found
No related tags found
No related merge requests found
//===--- main.cpp - Dusk source compiler ------------------------*- C++ -*-===//
//
// dusk-lang
// This source file is part of a dusk-lang project, which is a semestral
// assignement for BI-PJP course at Czech Technical University in Prague.
// The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND.
//
//===----------------------------------------------------------------------===//
#include "dusk/Basic/LLVM.h"
#include "dusk/Frontend/CompilerInvocation.h"
#include "dusk/Frontend/CompilerInstance.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include <string>
#include <iostream>
 
#include "dusk/AST/ASTContext.h"
#include "dusk/AST/Type.h"
......@@ -15,14 +25,23 @@ cl::opt<std::string> InFile(cl::Positional, cl::Required,
cl::desc("<input file>"), cl::init("-"));
 
cl::opt<std::string> OutFile("o", cl::desc("Specify output filename"),
cl::value_desc("<filename>"));
cl::value_desc("<filename>"), cl::init("a.out"));
cl::opt<bool> IsQuiet("quiet", cl::desc("Suppress diagnostics"));
cl::alias IsQuiet2("q", cl::desc("Suppress diagnostics"),
cl::aliasopt(IsQuiet));
 
cl::opt<bool> OnlyCompile("c",
cl::desc("Run parser, type checker as well as LLVM "
"IR generation and create an object file."
"Does not perform linkage of binary"));
cl::opt<bool> PrintIR("S",
cl::desc("Print outputed IR of compilation"));
void initCompilerInstance(CompilerInstance &C) {
CompilerInvocation Inv;
Inv.setArgs(C.getSourceManager(), C.getDiags(), InFile, OutFile, IsQuiet);
Inv.setArgs(C.getSourceManager(), C.getDiags(), InFile, OutFile, IsQuiet,
PrintIR);
C.reset(std::move(Inv));
}
 
......@@ -33,5 +52,12 @@ int main(int argc, const char *argv[]) {
 
Compiler.performCompilation();
if (!OnlyCompile && !Compiler.getContext().isError()) {
auto Cmd = "clang++ "
+ Compiler.getInputFile()->file() + ".o "
+ "-L$DUSK_STDLIB_PATH -lstddusk -o" + OutFile;
system(Cmd.c_str());
}
return 0;
}
//===--- main.cpp - Dusk source formatter -----------------------*- C++ -*-===//
//
// dusk-lang
// This source file is part of a dusk-lang project, which is a semestral
// assignement for BI-PJP course at Czech Technical University in Prague.
// The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND.
//
//===----------------------------------------------------------------------===//
#include "dusk/Basic/LLVM.h"
#include "dusk/Frontend/CompilerInvocation.h"
#include "dusk/Frontend/CompilerInstance.h"
#include "dusk/AST/ASTPrinter.h"
#include "dusk/Frontend/Formatter.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_os_ostream.h"
#include <iostream>
#include <string>
 
......@@ -15,15 +26,29 @@ using namespace llvm;
cl::opt<std::string> InFile(cl::Positional, cl::Required,
cl::desc("<input file>"), cl::init("-"));
 
cl::opt<std::string> OutFile("o", cl::desc("Specify output filename"),
cl::value_desc("<filename>"));
cl::opt<unsigned> SpaceLen("indent-size",
cl::desc("Indenetation size. Aplicable only when "
"idending with spaces. Default indentation"
"is 4 spaces."),
cl::init(4));
cl::opt<IndKind>
IndentationType("indent-type",
cl::desc("Indentation type. Choose wheather to ident with "
"spaces or tabs. By default formatter indent with"
"spaces."),
cl::values(clEnumVal(IndKind::Space, "Indent with spaces."),
clEnumVal(IndKind::Tab, "Indent with tabs.")),
cl::init(IndKind::Space));
cl::opt<bool> IsQuiet("quiet", cl::desc("Suppress diagnostics"));
cl::alias IsQuiet2("q", cl::desc("Suppress diagnostics"),
cl::aliasopt(IsQuiet));
 
void initCompilerInstance(CompilerInstance &C) {
CompilerInvocation Inv;
Inv.setArgs(C.getSourceManager(), C.getDiags(), InFile, OutFile, IsQuiet);
Inv.setArgs(C.getSourceManager(), C.getDiags(), InFile, "", IsQuiet,
false);
C.reset(std::move(Inv));
}
 
......@@ -34,7 +59,10 @@ int main(int argc, const char *argv[]) {
 
Compiler.performParseOnly();
if (Compiler.hasASTContext() && !Compiler.getContext().isError()) {
Formatter F(Compiler.getContext(), llvm::errs());
llvm::raw_os_ostream OS(std::cout);
Formatter F(Compiler.getContext(), OS);
F.setIndentSize(SpaceLen);
F.setIndentType(IndentationType);
F.format();
return 0;
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment