Updates hehe :)
This commit is contained in:
parent
19b32214a4
commit
7a320fb70a
16
core/init.sp
Normal file
16
core/init.sp
Normal file
@ -0,0 +1,16 @@
|
||||
import core/flow;
|
||||
|
||||
namespace init {
|
||||
|
||||
i32 _libcore_Argc;
|
||||
i8** _libcore_Argv;
|
||||
|
||||
@__libcore_call_init (i32 _Argc, i8** _Argv) {
|
||||
_libcore_Argc = _Argc;
|
||||
_libcore_Argv = _Argv;
|
||||
|
||||
main();
|
||||
|
||||
flow.exit(0);
|
||||
}
|
||||
}
|
@ -1,19 +1,25 @@
|
||||
#include "Arguments.h"
|
||||
#include "Error.h"
|
||||
#include "tclap/CmdLine.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
|
||||
std::string Arguments::input_fname;
|
||||
std::string Arguments::output_fname;
|
||||
bool Arguments::wimport;
|
||||
llvm::Triple Arguments::TargetTriple;
|
||||
std::string Arguments::cpu;
|
||||
|
||||
void Arguments::parse(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
TCLAP::CmdLine command_line("The Sapphire compiler.",' ',"0.1");
|
||||
|
||||
TCLAP::UnlabeledValueArg<std::string> input_fname_arg("file","Input file.",true,"test.sp","filename");
|
||||
TCLAP::UnlabeledValueArg<std::string> input_fname_arg("file","Input file.",true,"test.sp","string");
|
||||
|
||||
TCLAP::ValueArg<std::string> output_fname_arg("o","output","Output file.",false,"sp-output","output");
|
||||
TCLAP::ValueArg<std::string> output_fname_arg("o","output","Output file.",false,"sp-output","string");
|
||||
TCLAP::ValueArg<std::string> march_arg("","march","Architecture to compile for.",false,"native","string");
|
||||
TCLAP::ValueArg<std::string> mcpu_arg("","mcpu","CPU to compile for.",false,"generic","string");
|
||||
TCLAP::ValueArg<std::string> msystem_arg("","msystem","Operating System to compile for.",false,"native","string");
|
||||
|
||||
TCLAP::SwitchArg wimport_arg("","wimport","Show a warning when trying to import an already imported file.");
|
||||
|
||||
@ -22,13 +28,40 @@ void Arguments::parse(int argc, char **argv)
|
||||
command_line.add(input_fname_arg);
|
||||
command_line.add(output_fname_arg);
|
||||
|
||||
command_line.add(march_arg);
|
||||
command_line.add(mcpu_arg);
|
||||
command_line.add(msystem_arg);
|
||||
|
||||
command_line.parse(argc,argv);
|
||||
|
||||
input_fname = input_fname_arg.getValue();
|
||||
output_fname = output_fname_arg.getValue();
|
||||
wimport = wimport_arg.getValue();
|
||||
|
||||
cpu = mcpu_arg.getValue();
|
||||
|
||||
setTriple(march_arg.getValue(),msystem_arg.getValue());
|
||||
|
||||
} catch (TCLAP::ArgException &e) {
|
||||
Error::throw_error_without_location(e.error());
|
||||
}
|
||||
}
|
||||
|
||||
void Arguments::setTriple(const std::string& arch, const std::string& system)
|
||||
{
|
||||
std::string triple = llvm::sys::getDefaultTargetTriple();
|
||||
llvm::Triple tgTriple(triple);
|
||||
|
||||
if(arch != "native")
|
||||
{
|
||||
tgTriple.setArchName(arch);
|
||||
}
|
||||
if(system != "native")
|
||||
{
|
||||
tgTriple.setOSAndEnvironmentName(system);
|
||||
}
|
||||
|
||||
tgTriple.setVendor(llvm::Triple::VendorType::UnknownVendor); // let's leave it like that
|
||||
|
||||
TargetTriple = tgTriple;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <llvm/ADT/Triple.h>
|
||||
|
||||
struct Arguments
|
||||
{
|
||||
@ -9,4 +10,10 @@ struct Arguments
|
||||
static std::string output_fname;
|
||||
|
||||
static bool wimport;
|
||||
|
||||
static std::string cpu;
|
||||
|
||||
static llvm::Triple TargetTriple;
|
||||
private:
|
||||
static void setTriple(const std::string& arch, const std::string& system);
|
||||
};
|
||||
|
@ -233,6 +233,7 @@ Token Lexer::create_identifier()
|
||||
if (identifier == "syscall3") return Token::make_with_line({TT_Syscall3,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
if (identifier == "syscall4") return Token::make_with_line({TT_Syscall4,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
if (identifier == "syscall5") return Token::make_with_line({TT_Syscall5,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
if( identifier == "compmacro" ) return Token::make_with_line({TT_CompilerMacro,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
return Token::make_with_line({TT_Identifier,identifier,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
}
|
||||
}
|
||||
@ -251,6 +252,7 @@ Token Lexer::create_identifier()
|
||||
if (identifier == "syscall3") return Token::make_with_line({TT_Syscall3,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
if (identifier == "syscall4") return Token::make_with_line({TT_Syscall4,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
if (identifier == "syscall5") return Token::make_with_line({TT_Syscall5,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
if( identifier == "compmacro" ) return Token::make_with_line({TT_CompilerMacro,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
return Token::make_with_line({TT_Identifier,identifier,{prev_line,prev_column,loc.fname}},current_line_text);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "Lexer.h"
|
||||
#include "AST/ASTNode.h"
|
||||
|
||||
class Parser
|
||||
{
|
||||
@ -7,4 +10,7 @@ private:
|
||||
public:
|
||||
Parser(/* args */);
|
||||
~Parser();
|
||||
|
||||
static std::shared_ptr<Parser> new_parser(const TokenStream& tokens);
|
||||
std::shared_ptr<ASTNode> parse();
|
||||
};
|
||||
|
@ -42,7 +42,8 @@ const std::string token_strings[] = {
|
||||
"TT_SYSCALL2",
|
||||
"TT_SYSCALL3",
|
||||
"TT_SYSCALL4",
|
||||
"TT_SYSCALL5"
|
||||
"TT_SYSCALL5",
|
||||
"TT_COMPILERMACRO"
|
||||
};
|
||||
|
||||
Token::Token(const TokenType& type)
|
||||
@ -186,6 +187,8 @@ std::string Token::to_string() const
|
||||
return "SYSCALL4 " + details;
|
||||
case TT_Syscall5:
|
||||
return "SYSCALL5 " + details;
|
||||
case TT_CompilerMacro:
|
||||
return "COMPMACRO " + details;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ enum TokenType
|
||||
TT_Syscall2,
|
||||
TT_Syscall3,
|
||||
TT_Syscall4,
|
||||
TT_Syscall5
|
||||
TT_Syscall5,
|
||||
TT_CompilerMacro
|
||||
};
|
||||
|
||||
extern const std::string token_strings[];
|
||||
|
@ -22,4 +22,6 @@ int main(int argc, char** argv)
|
||||
}
|
||||
|
||||
std::cout << "Output filename: " << Arguments::output_fname << std::endl;
|
||||
|
||||
std::cout << "Output target triple: " << Arguments::TargetTriple.getTriple() << std::endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user