Pass in constraints
This commit is contained in:
@@ -20,11 +20,11 @@ i u32 <- 0, rep text[i] != 0:
|
|||||||
|
|
||||||
// text data<u8> <- "Hello world!"
|
// text data<u8> <- "Hello world!"
|
||||||
|
|
||||||
/*addStuff asm<+r, r>: num1 u32, num2 u32 -> u32
|
/*addStuff asm<"+r, r">: num1 u32, num2 u32 -> u32
|
||||||
add $1, $0
|
add $1, $0
|
||||||
;*/
|
;*/
|
||||||
|
|
||||||
rawAdd raw
|
rawAdd raw<"~{ebx}">
|
||||||
//push rbx
|
//push rbx
|
||||||
mov ebx, 5
|
mov ebx, 5
|
||||||
//pop rbx
|
//pop rbx
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ void ModuleBuilder::buildRawFunction(shared_ptr<StatementRawFunction> statement)
|
|||||||
vector<llvm::Type *> types;
|
vector<llvm::Type *> types;
|
||||||
|
|
||||||
llvm::FunctionType *funType = llvm::FunctionType::get(llvm::Type::getVoidTy(*context), types, false);
|
llvm::FunctionType *funType = llvm::FunctionType::get(llvm::Type::getVoidTy(*context), types, false);
|
||||||
llvm::InlineAsm *rawFun = llvm::InlineAsm::get(funType, statement->getRawSource(), "~{ebx}", false, false, llvm::InlineAsm::AsmDialect::AD_Intel);
|
llvm::InlineAsm *rawFun = llvm::InlineAsm::get(funType, statement->getRawSource(), statement->getConstraints(), false, false, llvm::InlineAsm::AsmDialect::AD_Intel);
|
||||||
if (!setRawFun(statement->getName(), rawFun))
|
if (!setRawFun(statement->getName(), rawFun))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -240,12 +240,26 @@ shared_ptr<Statement> Parser::matchStatementRawFunction() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
string constraints;
|
||||||
string rawSource;
|
string rawSource;
|
||||||
|
|
||||||
// name
|
// name
|
||||||
name = tokens.at(currentIndex++)->getLexme();
|
name = tokens.at(currentIndex++)->getLexme();
|
||||||
currentIndex++; // skip raw
|
currentIndex++; // skip raw
|
||||||
|
|
||||||
|
// constraints
|
||||||
|
|
||||||
|
if (tryMatchingTokenKinds({TokenKind::LESS}, true, true)) {
|
||||||
|
if (tokens.at(currentIndex)->isOfKind({TokenKind::STRING})) {
|
||||||
|
constraints = tokens.at(currentIndex++)->getLexme();
|
||||||
|
// remove enclosing quotes
|
||||||
|
if (constraints.length() >= 2)
|
||||||
|
constraints = constraints.substr(1, constraints.length() - 2);
|
||||||
|
}
|
||||||
|
if (!tryMatchingTokenKinds({TokenKind::GREATER}, true, true))
|
||||||
|
markError({TokenKind::GREATER}, {});
|
||||||
|
}
|
||||||
|
|
||||||
// consume new line
|
// consume new line
|
||||||
if (!tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true)) {
|
if (!tryMatchingTokenKinds({TokenKind::NEW_LINE}, true, true)) {
|
||||||
markError(TokenKind::NEW_LINE, {});
|
markError(TokenKind::NEW_LINE, {});
|
||||||
@@ -267,7 +281,7 @@ shared_ptr<Statement> Parser::matchStatementRawFunction() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_shared<StatementRawFunction>(name, rawSource);
|
return make_shared<StatementRawFunction>(name, constraints, rawSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<Statement> Parser::matchStatementBlock(vector<TokenKind> terminalTokenKinds) {
|
shared_ptr<Statement> Parser::matchStatementBlock(vector<TokenKind> terminalTokenKinds) {
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#include "StatementRawFunction.h"
|
#include "StatementRawFunction.h"
|
||||||
|
|
||||||
StatementRawFunction::StatementRawFunction(string name, string rawSource):
|
StatementRawFunction::StatementRawFunction(string name, string constraints, string rawSource):
|
||||||
Statement(StatementKind::RAW_FUNCTION), name(name), rawSource(rawSource) { }
|
Statement(StatementKind::RAW_FUNCTION), name(name), constraints(constraints), rawSource(rawSource) { }
|
||||||
|
|
||||||
string StatementRawFunction::getName() {
|
string StatementRawFunction::getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string StatementRawFunction::getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
string StatementRawFunction::getRawSource() {
|
string StatementRawFunction::getRawSource() {
|
||||||
return rawSource;
|
return rawSource;
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,12 @@ class Expression;
|
|||||||
class StatementRawFunction: public Statement {
|
class StatementRawFunction: public Statement {
|
||||||
private:
|
private:
|
||||||
string name;
|
string name;
|
||||||
|
string constraints;
|
||||||
string rawSource;
|
string rawSource;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StatementRawFunction(string name, string rawSource);
|
StatementRawFunction(string name, string constraints, string rawSource);
|
||||||
string getName();
|
string getName();
|
||||||
|
string getConstraints();
|
||||||
string getRawSource();
|
string getRawSource();
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user