Commit aeb86d57 authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque]: Add constexpr keyword/types for compile-time evaluation

Torque expressions of type constexpr are evaluated at compile-time
rather than runtime. They are backed by C++ types rather than
TNode<X> types, so the macro functions that are called by generated
C++ code expect values to be computed when the snapshot is generated
rather than by TurboFan-generated code.

Specifically, "if" statements can have a constexpr modifier. With this
modifier, a type of "constexpr bool" is expected rather than "bool",
and in that case instead of generating a CSA BranchIf, it generates
a C++ "if (<bool expression>)" that generates code for only the true or
false path based on the bool value at torque-execution (compile time)
rather than generating both paths (including inserting phi nodes
for variables modified on either branch at the re-merge at the end
of the if) and dynamically dispatching to the true or false path
during d8/Chrome/node.js execution (runtime) using a CSA BranchIf.

Change-Id: I8238e25aaadbfc618847e04556e96a3949ea5a8d
Reviewed-on: https://chromium-review.googlesource.com/1042085
Commit-Queue: Daniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53001}
parent 40a95443
...@@ -23,7 +23,7 @@ module array { ...@@ -23,7 +23,7 @@ module array {
if (IsArraySpeciesProtectorCellInvalid()) goto Bailout; if (IsArraySpeciesProtectorCellInvalid()) goto Bailout;
// Fast path only works on fast elements kind and with writable length. // Fast path only works on fast elements kind and with writable length.
let elementsKind: int32 = EnsureArrayPushable(map) otherwise Bailout; let elementsKind: ElementsKind = EnsureArrayPushable(map) otherwise Bailout;
if (!IsFastElementsKind(elementsKind)) goto Bailout; if (!IsFastElementsKind(elementsKind)) goto Bailout;
// For now, only support non-double fast elements // For now, only support non-double fast elements
......
This diff is collapsed.
...@@ -14,7 +14,7 @@ module typed_array { ...@@ -14,7 +14,7 @@ module typed_array {
extern builtin TypedArrayStoreElementFromTagged( extern builtin TypedArrayStoreElementFromTagged(
Context, JSTypedArray, Smi, Smi, Object); Context, JSTypedArray, Smi, Smi, Object);
extern macro NumberIsNaN(Number): bit; extern macro NumberIsNaN(Number): bool;
macro CallCompareWithDetachedCheck( macro CallCompareWithDetachedCheck(
context: Context, array: JSTypedArray, comparefn: Callable, a: Object, context: Context, array: JSTypedArray, comparefn: Callable, a: Object,
...@@ -164,7 +164,7 @@ module typed_array { ...@@ -164,7 +164,7 @@ module typed_array {
Store(context, array, kind, low_end, element); Store(context, array, kind, low_end, element);
low_end++; low_end++;
} else if (order > 0) { } else if (order > 0) {
let break_for: bit = no; let break_for: bool = no;
while (order > 0) { while (order > 0) {
high_start--; high_start--;
......
...@@ -223,6 +223,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler { ...@@ -223,6 +223,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
TNode<Int32T> HashSeed(); TNode<Int32T> HashSeed();
Node* IntPtrOrSmiConstant(int value, ParameterMode mode); Node* IntPtrOrSmiConstant(int value, ParameterMode mode);
TNode<BoolT> BoolConstant(bool value) {
return value ? Int32TrueConstant() : Int32FalseConstant();
}
TNode<Smi> LanguageModeConstant(LanguageMode mode) {
return SmiConstant(static_cast<int>(mode));
}
bool IsIntPtrOrSmiConstantZero(Node* test, ParameterMode mode); bool IsIntPtrOrSmiConstantZero(Node* test, ParameterMode mode);
bool TryGetIntPtrOrSmiConstantValue(Node* maybe_constant, int* value, bool TryGetIntPtrOrSmiConstantValue(Node* maybe_constant, int* value,
......
...@@ -22,6 +22,7 @@ CONVERT_KEYWORD: 'convert'; ...@@ -22,6 +22,7 @@ CONVERT_KEYWORD: 'convert';
FOR: 'for'; FOR: 'for';
WHILE: 'while'; WHILE: 'while';
RETURN: 'return'; RETURN: 'return';
CONSTEXPR: 'constexpr';
CONTINUE: 'continue'; CONTINUE: 'continue';
BREAK: 'break'; BREAK: 'break';
GOTO: 'goto'; GOTO: 'goto';
...@@ -81,7 +82,7 @@ DECREMENT: '--'; ...@@ -81,7 +82,7 @@ DECREMENT: '--';
NOT: '!'; NOT: '!';
STRING_LITERAL : ('"' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) * '"') STRING_LITERAL : ('"' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) * '"')
| ('\'' ( ESCAPE | ~('"' | '\\' | '\n' | '\r') ) * '\''); | ('\'' ( ESCAPE | ~('\'' | '\\' | '\n' | '\r') ) * '\'');
fragment ESCAPE : '\\' ( '\'' | '\\' | '"' ); fragment ESCAPE : '\\' ( '\'' | '\\' | '"' );
IDENTIFIER : [A-Za-z][0-9A-Za-z_]* ; IDENTIFIER : [A-Za-z][0-9A-Za-z_]* ;
...@@ -115,7 +116,7 @@ DECIMAL_LITERAL ...@@ -115,7 +116,7 @@ DECIMAL_LITERAL
| MINUS? DECIMAL_INTEGER_LITERAL EXPONENT_PART? | MINUS? DECIMAL_INTEGER_LITERAL EXPONENT_PART?
; ;
type : IDENTIFIER; type : CONSTEXPR? IDENTIFIER;
typeList : '(' type? (',' type)* ')'; typeList : '(' type? (',' type)* ')';
typeListMaybeVarArgs: '(' type? (',' type)* (',' VARARGS)? ')' typeListMaybeVarArgs: '(' type? (',' type)* (',' VARARGS)? ')'
...@@ -225,7 +226,7 @@ variableDeclaration: LET IDENTIFIER ':' type; ...@@ -225,7 +226,7 @@ variableDeclaration: LET IDENTIFIER ':' type;
variableDeclarationWithInitialization: variableDeclaration ('=' expression)?; variableDeclarationWithInitialization: variableDeclaration ('=' expression)?;
helperCallStatement: (TAIL)? helperCall; helperCallStatement: (TAIL)? helperCall;
expressionStatement: assignment; expressionStatement: assignment;
ifStatement: IF '(' expression ')' statementBlock ('else' statementBlock)?; ifStatement: IF CONSTEXPR? '(' expression ')' statementBlock ('else' statementBlock)?;
whileLoop: WHILE '(' expression ')' statementBlock; whileLoop: WHILE '(' expression ')' statementBlock;
returnStatement: RETURN expression?; returnStatement: RETURN expression?;
breakStatement: BREAK; breakStatement: BREAK;
...@@ -259,9 +260,10 @@ statementBlock ...@@ -259,9 +260,10 @@ statementBlock
helperBody : statementScope; helperBody : statementScope;
generatesDeclaration: 'generates' STRING_LITERAL;
extendsDeclaration: 'extends' IDENTIFIER; extendsDeclaration: 'extends' IDENTIFIER;
typeDeclaration : 'type' IDENTIFIER extendsDeclaration? generatesDeclaration? ';'; generatesDeclaration: 'generates' STRING_LITERAL;
constexprDeclaration: 'constexpr' STRING_LITERAL;
typeDeclaration : 'type' IDENTIFIER extendsDeclaration? generatesDeclaration? constexprDeclaration?';';
externalBuiltin : 'extern' JAVASCRIPT? BUILTIN IDENTIFIER typeList optionalType ';'; externalBuiltin : 'extern' JAVASCRIPT? BUILTIN IDENTIFIER typeList optionalType ';';
externalMacro : 'extern' (IMPLICIT? 'operator' STRING_LITERAL)? MACRO IDENTIFIER typeListMaybeVarArgs optionalType optionalLabelList ';'; externalMacro : 'extern' (IMPLICIT? 'operator' STRING_LITERAL)? MACRO IDENTIFIER typeListMaybeVarArgs optionalType optionalLabelList ';';
......
...@@ -251,15 +251,20 @@ class TorqueBaseListener : public TorqueListener { ...@@ -251,15 +251,20 @@ class TorqueBaseListener : public TorqueListener {
void enterHelperBody(TorqueParser::HelperBodyContext* /*ctx*/) override {} void enterHelperBody(TorqueParser::HelperBodyContext* /*ctx*/) override {}
void exitHelperBody(TorqueParser::HelperBodyContext* /*ctx*/) override {} void exitHelperBody(TorqueParser::HelperBodyContext* /*ctx*/) override {}
void enterExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* /*ctx*/) override {}
void exitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* /*ctx*/) override {}
void enterGeneratesDeclaration( void enterGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* /*ctx*/) override {} TorqueParser::GeneratesDeclarationContext* /*ctx*/) override {}
void exitGeneratesDeclaration( void exitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* /*ctx*/) override {} TorqueParser::GeneratesDeclarationContext* /*ctx*/) override {}
void enterExtendsDeclaration( void enterConstexprDeclaration(
TorqueParser::ExtendsDeclarationContext* /*ctx*/) override {} TorqueParser::ConstexprDeclarationContext* /*ctx*/) override {}
void exitExtendsDeclaration( void exitConstexprDeclaration(
TorqueParser::ExtendsDeclarationContext* /*ctx*/) override {} TorqueParser::ConstexprDeclarationContext* /*ctx*/) override {}
void enterTypeDeclaration( void enterTypeDeclaration(
TorqueParser::TypeDeclarationContext* /*ctx*/) override {} TorqueParser::TypeDeclarationContext* /*ctx*/) override {}
......
...@@ -270,13 +270,18 @@ class TorqueBaseVisitor : public TorqueVisitor { ...@@ -270,13 +270,18 @@ class TorqueBaseVisitor : public TorqueVisitor {
return visitChildren(ctx); return visitChildren(ctx);
} }
antlrcpp::Any visitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) override {
return visitChildren(ctx);
}
antlrcpp::Any visitGeneratesDeclaration( antlrcpp::Any visitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* ctx) override { TorqueParser::GeneratesDeclarationContext* ctx) override {
return visitChildren(ctx); return visitChildren(ctx);
} }
antlrcpp::Any visitExtendsDeclaration( antlrcpp::Any visitConstexprDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) override { TorqueParser::ConstexprDeclarationContext* ctx) override {
return visitChildren(ctx); return visitChildren(ctx);
} }
......
This diff is collapsed.
...@@ -47,53 +47,54 @@ class TorqueLexer : public antlr4::Lexer { ...@@ -47,53 +47,54 @@ class TorqueLexer : public antlr4::Lexer {
FOR = 32, FOR = 32,
WHILE = 33, WHILE = 33,
RETURN = 34, RETURN = 34,
CONTINUE = 35, CONSTEXPR = 35,
BREAK = 36, CONTINUE = 36,
GOTO = 37, BREAK = 37,
OTHERWISE = 38, GOTO = 38,
TRY = 39, OTHERWISE = 39,
CATCH = 40, TRY = 40,
LABEL = 41, CATCH = 41,
LABELS = 42, LABEL = 42,
TAIL = 43, LABELS = 43,
ISNT = 44, TAIL = 44,
IS = 45, ISNT = 45,
LET = 46, IS = 46,
ASSERT = 47, LET = 47,
UNREACHABLE_TOKEN = 48, ASSERT = 48,
DEBUG_TOKEN = 49, UNREACHABLE_TOKEN = 49,
ASSIGNMENT = 50, DEBUG_TOKEN = 50,
ASSIGNMENT_OPERATOR = 51, ASSIGNMENT = 51,
EQUAL = 52, ASSIGNMENT_OPERATOR = 52,
PLUS = 53, EQUAL = 53,
MINUS = 54, PLUS = 54,
MULTIPLY = 55, MINUS = 55,
DIVIDE = 56, MULTIPLY = 56,
MODULO = 57, DIVIDE = 57,
BIT_OR = 58, MODULO = 58,
BIT_AND = 59, BIT_OR = 59,
BIT_NOT = 60, BIT_AND = 60,
MAX = 61, BIT_NOT = 61,
MIN = 62, MAX = 62,
NOT_EQUAL = 63, MIN = 63,
LESS_THAN = 64, NOT_EQUAL = 64,
LESS_THAN_EQUAL = 65, LESS_THAN = 65,
GREATER_THAN = 66, LESS_THAN_EQUAL = 66,
GREATER_THAN_EQUAL = 67, GREATER_THAN = 67,
SHIFT_LEFT = 68, GREATER_THAN_EQUAL = 68,
SHIFT_RIGHT = 69, SHIFT_LEFT = 69,
SHIFT_RIGHT_ARITHMETIC = 70, SHIFT_RIGHT = 70,
VARARGS = 71, SHIFT_RIGHT_ARITHMETIC = 71,
EQUALITY_OPERATOR = 72, VARARGS = 72,
INCREMENT = 73, EQUALITY_OPERATOR = 73,
DECREMENT = 74, INCREMENT = 74,
NOT = 75, DECREMENT = 75,
STRING_LITERAL = 76, NOT = 76,
IDENTIFIER = 77, STRING_LITERAL = 77,
WS = 78, IDENTIFIER = 78,
BLOCK_COMMENT = 79, WS = 79,
LINE_COMMENT = 80, BLOCK_COMMENT = 80,
DECIMAL_LITERAL = 81 LINE_COMMENT = 81,
DECIMAL_LITERAL = 82
}; };
explicit TorqueLexer(antlr4::CharStream* input); explicit TorqueLexer(antlr4::CharStream* input);
......
...@@ -236,15 +236,20 @@ class TorqueListener : public antlr4::tree::ParseTreeListener { ...@@ -236,15 +236,20 @@ class TorqueListener : public antlr4::tree::ParseTreeListener {
virtual void enterHelperBody(TorqueParser::HelperBodyContext* ctx) = 0; virtual void enterHelperBody(TorqueParser::HelperBodyContext* ctx) = 0;
virtual void exitHelperBody(TorqueParser::HelperBodyContext* ctx) = 0; virtual void exitHelperBody(TorqueParser::HelperBodyContext* ctx) = 0;
virtual void enterExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) = 0;
virtual void exitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) = 0;
virtual void enterGeneratesDeclaration( virtual void enterGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* ctx) = 0; TorqueParser::GeneratesDeclarationContext* ctx) = 0;
virtual void exitGeneratesDeclaration( virtual void exitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* ctx) = 0; TorqueParser::GeneratesDeclarationContext* ctx) = 0;
virtual void enterExtendsDeclaration( virtual void enterConstexprDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) = 0; TorqueParser::ConstexprDeclarationContext* ctx) = 0;
virtual void exitExtendsDeclaration( virtual void exitConstexprDeclaration(
TorqueParser::ExtendsDeclarationContext* ctx) = 0; TorqueParser::ConstexprDeclarationContext* ctx) = 0;
virtual void enterTypeDeclaration( virtual void enterTypeDeclaration(
TorqueParser::TypeDeclarationContext* ctx) = 0; TorqueParser::TypeDeclarationContext* ctx) = 0;
......
This diff is collapsed.
...@@ -47,53 +47,54 @@ class TorqueParser : public antlr4::Parser { ...@@ -47,53 +47,54 @@ class TorqueParser : public antlr4::Parser {
FOR = 32, FOR = 32,
WHILE = 33, WHILE = 33,
RETURN = 34, RETURN = 34,
CONTINUE = 35, CONSTEXPR = 35,
BREAK = 36, CONTINUE = 36,
GOTO = 37, BREAK = 37,
OTHERWISE = 38, GOTO = 38,
TRY = 39, OTHERWISE = 39,
CATCH = 40, TRY = 40,
LABEL = 41, CATCH = 41,
LABELS = 42, LABEL = 42,
TAIL = 43, LABELS = 43,
ISNT = 44, TAIL = 44,
IS = 45, ISNT = 45,
LET = 46, IS = 46,
ASSERT = 47, LET = 47,
UNREACHABLE_TOKEN = 48, ASSERT = 48,
DEBUG_TOKEN = 49, UNREACHABLE_TOKEN = 49,
ASSIGNMENT = 50, DEBUG_TOKEN = 50,
ASSIGNMENT_OPERATOR = 51, ASSIGNMENT = 51,
EQUAL = 52, ASSIGNMENT_OPERATOR = 52,
PLUS = 53, EQUAL = 53,
MINUS = 54, PLUS = 54,
MULTIPLY = 55, MINUS = 55,
DIVIDE = 56, MULTIPLY = 56,
MODULO = 57, DIVIDE = 57,
BIT_OR = 58, MODULO = 58,
BIT_AND = 59, BIT_OR = 59,
BIT_NOT = 60, BIT_AND = 60,
MAX = 61, BIT_NOT = 61,
MIN = 62, MAX = 62,
NOT_EQUAL = 63, MIN = 63,
LESS_THAN = 64, NOT_EQUAL = 64,
LESS_THAN_EQUAL = 65, LESS_THAN = 65,
GREATER_THAN = 66, LESS_THAN_EQUAL = 66,
GREATER_THAN_EQUAL = 67, GREATER_THAN = 67,
SHIFT_LEFT = 68, GREATER_THAN_EQUAL = 68,
SHIFT_RIGHT = 69, SHIFT_LEFT = 69,
SHIFT_RIGHT_ARITHMETIC = 70, SHIFT_RIGHT = 70,
VARARGS = 71, SHIFT_RIGHT_ARITHMETIC = 71,
EQUALITY_OPERATOR = 72, VARARGS = 72,
INCREMENT = 73, EQUALITY_OPERATOR = 73,
DECREMENT = 74, INCREMENT = 74,
NOT = 75, DECREMENT = 75,
STRING_LITERAL = 76, NOT = 76,
IDENTIFIER = 77, STRING_LITERAL = 77,
WS = 78, IDENTIFIER = 78,
BLOCK_COMMENT = 79, WS = 79,
LINE_COMMENT = 80, BLOCK_COMMENT = 80,
DECIMAL_LITERAL = 81 LINE_COMMENT = 81,
DECIMAL_LITERAL = 82
}; };
enum { enum {
...@@ -150,18 +151,19 @@ class TorqueParser : public antlr4::Parser { ...@@ -150,18 +151,19 @@ class TorqueParser : public antlr4::Parser {
RuleStatementScope = 50, RuleStatementScope = 50,
RuleStatementBlock = 51, RuleStatementBlock = 51,
RuleHelperBody = 52, RuleHelperBody = 52,
RuleGeneratesDeclaration = 53, RuleExtendsDeclaration = 53,
RuleExtendsDeclaration = 54, RuleGeneratesDeclaration = 54,
RuleTypeDeclaration = 55, RuleConstexprDeclaration = 55,
RuleExternalBuiltin = 56, RuleTypeDeclaration = 56,
RuleExternalMacro = 57, RuleExternalBuiltin = 57,
RuleExternalRuntime = 58, RuleExternalMacro = 58,
RuleBuiltinDeclaration = 59, RuleExternalRuntime = 59,
RuleMacroDeclaration = 60, RuleBuiltinDeclaration = 60,
RuleConstDeclaration = 61, RuleMacroDeclaration = 61,
RuleDeclaration = 62, RuleConstDeclaration = 62,
RuleModuleDeclaration = 63, RuleDeclaration = 63,
RuleFile = 64 RuleModuleDeclaration = 64,
RuleFile = 65
}; };
explicit TorqueParser(antlr4::TokenStream* input); explicit TorqueParser(antlr4::TokenStream* input);
...@@ -228,8 +230,9 @@ class TorqueParser : public antlr4::Parser { ...@@ -228,8 +230,9 @@ class TorqueParser : public antlr4::Parser {
class StatementScopeContext; class StatementScopeContext;
class StatementBlockContext; class StatementBlockContext;
class HelperBodyContext; class HelperBodyContext;
class GeneratesDeclarationContext;
class ExtendsDeclarationContext; class ExtendsDeclarationContext;
class GeneratesDeclarationContext;
class ConstexprDeclarationContext;
class TypeDeclarationContext; class TypeDeclarationContext;
class ExternalBuiltinContext; class ExternalBuiltinContext;
class ExternalMacroContext; class ExternalMacroContext;
...@@ -246,6 +249,7 @@ class TorqueParser : public antlr4::Parser { ...@@ -246,6 +249,7 @@ class TorqueParser : public antlr4::Parser {
TypeContext(antlr4::ParserRuleContext* parent, size_t invokingState); TypeContext(antlr4::ParserRuleContext* parent, size_t invokingState);
size_t getRuleIndex() const override; size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* IDENTIFIER(); antlr4::tree::TerminalNode* IDENTIFIER();
antlr4::tree::TerminalNode* CONSTEXPR();
void enterRule(antlr4::tree::ParseTreeListener* listener) override; void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override; void exitRule(antlr4::tree::ParseTreeListener* listener) override;
...@@ -916,6 +920,7 @@ class TorqueParser : public antlr4::Parser { ...@@ -916,6 +920,7 @@ class TorqueParser : public antlr4::Parser {
ExpressionContext* expression(); ExpressionContext* expression();
std::vector<StatementBlockContext*> statementBlock(); std::vector<StatementBlockContext*> statementBlock();
StatementBlockContext* statementBlock(size_t i); StatementBlockContext* statementBlock(size_t i);
antlr4::tree::TerminalNode* CONSTEXPR();
void enterRule(antlr4::tree::ParseTreeListener* listener) override; void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override; void exitRule(antlr4::tree::ParseTreeListener* listener) override;
...@@ -1147,6 +1152,21 @@ class TorqueParser : public antlr4::Parser { ...@@ -1147,6 +1152,21 @@ class TorqueParser : public antlr4::Parser {
HelperBodyContext* helperBody(); HelperBodyContext* helperBody();
class ExtendsDeclarationContext : public antlr4::ParserRuleContext {
public:
ExtendsDeclarationContext(antlr4::ParserRuleContext* parent,
size_t invokingState);
size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* IDENTIFIER();
void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override;
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
};
ExtendsDeclarationContext* extendsDeclaration();
class GeneratesDeclarationContext : public antlr4::ParserRuleContext { class GeneratesDeclarationContext : public antlr4::ParserRuleContext {
public: public:
GeneratesDeclarationContext(antlr4::ParserRuleContext* parent, GeneratesDeclarationContext(antlr4::ParserRuleContext* parent,
...@@ -1162,12 +1182,12 @@ class TorqueParser : public antlr4::Parser { ...@@ -1162,12 +1182,12 @@ class TorqueParser : public antlr4::Parser {
GeneratesDeclarationContext* generatesDeclaration(); GeneratesDeclarationContext* generatesDeclaration();
class ExtendsDeclarationContext : public antlr4::ParserRuleContext { class ConstexprDeclarationContext : public antlr4::ParserRuleContext {
public: public:
ExtendsDeclarationContext(antlr4::ParserRuleContext* parent, ConstexprDeclarationContext(antlr4::ParserRuleContext* parent,
size_t invokingState); size_t invokingState);
size_t getRuleIndex() const override; size_t getRuleIndex() const override;
antlr4::tree::TerminalNode* IDENTIFIER(); antlr4::tree::TerminalNode* STRING_LITERAL();
void enterRule(antlr4::tree::ParseTreeListener* listener) override; void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override; void exitRule(antlr4::tree::ParseTreeListener* listener) override;
...@@ -1175,7 +1195,7 @@ class TorqueParser : public antlr4::Parser { ...@@ -1175,7 +1195,7 @@ class TorqueParser : public antlr4::Parser {
antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override; antlrcpp::Any accept(antlr4::tree::ParseTreeVisitor* visitor) override;
}; };
ExtendsDeclarationContext* extendsDeclaration(); ConstexprDeclarationContext* constexprDeclaration();
class TypeDeclarationContext : public antlr4::ParserRuleContext { class TypeDeclarationContext : public antlr4::ParserRuleContext {
public: public:
...@@ -1185,6 +1205,7 @@ class TorqueParser : public antlr4::Parser { ...@@ -1185,6 +1205,7 @@ class TorqueParser : public antlr4::Parser {
antlr4::tree::TerminalNode* IDENTIFIER(); antlr4::tree::TerminalNode* IDENTIFIER();
ExtendsDeclarationContext* extendsDeclaration(); ExtendsDeclarationContext* extendsDeclaration();
GeneratesDeclarationContext* generatesDeclaration(); GeneratesDeclarationContext* generatesDeclaration();
ConstexprDeclarationContext* constexprDeclaration();
void enterRule(antlr4::tree::ParseTreeListener* listener) override; void enterRule(antlr4::tree::ParseTreeListener* listener) override;
void exitRule(antlr4::tree::ParseTreeListener* listener) override; void exitRule(antlr4::tree::ParseTreeListener* listener) override;
......
...@@ -177,11 +177,14 @@ class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor { ...@@ -177,11 +177,14 @@ class TorqueVisitor : public antlr4::tree::AbstractParseTreeVisitor {
virtual antlrcpp::Any visitHelperBody( virtual antlrcpp::Any visitHelperBody(
TorqueParser::HelperBodyContext* context) = 0; TorqueParser::HelperBodyContext* context) = 0;
virtual antlrcpp::Any visitExtendsDeclaration(
TorqueParser::ExtendsDeclarationContext* context) = 0;
virtual antlrcpp::Any visitGeneratesDeclaration( virtual antlrcpp::Any visitGeneratesDeclaration(
TorqueParser::GeneratesDeclarationContext* context) = 0; TorqueParser::GeneratesDeclarationContext* context) = 0;
virtual antlrcpp::Any visitExtendsDeclaration( virtual antlrcpp::Any visitConstexprDeclaration(
TorqueParser::ExtendsDeclarationContext* context) = 0; TorqueParser::ConstexprDeclarationContext* context) = 0;
virtual antlrcpp::Any visitTypeDeclaration( virtual antlrcpp::Any visitTypeDeclaration(
TorqueParser::TypeDeclarationContext* context) = 0; TorqueParser::TypeDeclarationContext* context) = 0;
......
...@@ -13,10 +13,17 @@ namespace torque { ...@@ -13,10 +13,17 @@ namespace torque {
namespace { namespace {
std::string GetType(TorqueParser::TypeContext* context) {
if (!context) return "void";
std::string result(context->CONSTEXPR() == nullptr ? ""
: CONSTEXPR_TYPE_PREFIX);
result += context->IDENTIFIER()->getSymbol()->getText();
return result;
}
std::string GetOptionalType(TorqueParser::OptionalTypeContext* context) { std::string GetOptionalType(TorqueParser::OptionalTypeContext* context) {
if (!context) return ""; if (!context) return "";
if (!context->type()) return "void"; return GetType(context->type());
return context->type()->IDENTIFIER()->getSymbol()->getText();
} }
LabelAndTypesVector GetOptionalLabelAndTypeList( LabelAndTypesVector GetOptionalLabelAndTypeList(
...@@ -28,8 +35,7 @@ LabelAndTypesVector GetOptionalLabelAndTypeList( ...@@ -28,8 +35,7 @@ LabelAndTypesVector GetOptionalLabelAndTypeList(
new_label.name = label->IDENTIFIER()->getSymbol()->getText(); new_label.name = label->IDENTIFIER()->getSymbol()->getText();
if (label->typeList() != nullptr) { if (label->typeList() != nullptr) {
for (auto& type : label->typeList()->type()) { for (auto& type : label->typeList()->type()) {
new_label.types.emplace_back( new_label.types.emplace_back(GetType(type));
type->IDENTIFIER()->getSymbol()->getText());
} }
} }
labels.emplace_back(new_label); labels.emplace_back(new_label);
...@@ -95,8 +101,7 @@ antlrcpp::Any AstGenerator::visitParameterList( ...@@ -95,8 +101,7 @@ antlrcpp::Any AstGenerator::visitParameterList(
for (auto* parameter : context->parameter()) { for (auto* parameter : context->parameter()) {
parameter->accept(this); parameter->accept(this);
result.names.push_back(parameter->IDENTIFIER()->getSymbol()->getText()); result.names.push_back(parameter->IDENTIFIER()->getSymbol()->getText());
result.types.push_back( result.types.push_back(GetType(parameter->type()));
parameter->type()->IDENTIFIER()->getSymbol()->getText());
} }
return std::move(result); return std::move(result);
} }
...@@ -106,7 +111,7 @@ antlrcpp::Any AstGenerator::visitTypeList( ...@@ -106,7 +111,7 @@ antlrcpp::Any AstGenerator::visitTypeList(
ParameterList result{{}, {}, false, {}}; ParameterList result{{}, {}, false, {}};
result.types.reserve(context->type().size()); result.types.reserve(context->type().size());
for (auto* type : context->type()) { for (auto* type : context->type()) {
result.types.push_back(type->IDENTIFIER()->getSymbol()->getText()); result.types.push_back(GetType(type));
} }
return std::move(result); return std::move(result);
} }
...@@ -116,7 +121,7 @@ antlrcpp::Any AstGenerator::visitTypeListMaybeVarArgs( ...@@ -116,7 +121,7 @@ antlrcpp::Any AstGenerator::visitTypeListMaybeVarArgs(
ParameterList result{{}, {}, context->VARARGS(), {}}; ParameterList result{{}, {}, context->VARARGS(), {}};
result.types.reserve(context->type().size()); result.types.reserve(context->type().size());
for (auto* type : context->type()) { for (auto* type : context->type()) {
result.types.push_back(type->IDENTIFIER()->getSymbol()->getText()); result.types.push_back(GetType(type));
} }
return std::move(result); return std::move(result);
} }
...@@ -193,7 +198,7 @@ antlrcpp::Any AstGenerator::visitConstDeclaration( ...@@ -193,7 +198,7 @@ antlrcpp::Any AstGenerator::visitConstDeclaration(
TorqueParser::ConstDeclarationContext* context) { TorqueParser::ConstDeclarationContext* context) {
return implicit_cast<Declaration*>(RegisterNode(new ConstDeclaration{ return implicit_cast<Declaration*>(RegisterNode(new ConstDeclaration{
Pos(context), context->IDENTIFIER()->getSymbol()->getText(), Pos(context), context->IDENTIFIER()->getSymbol()->getText(),
context->type()->IDENTIFIER()->getSymbol()->getText(), GetType(context->type()),
StringLiteralUnquote( StringLiteralUnquote(
context->STRING_LITERAL()->getSymbol()->getText())})); context->STRING_LITERAL()->getSymbol()->getText())}));
} }
...@@ -211,16 +216,23 @@ antlrcpp::Any AstGenerator::visitTypeDeclaration( ...@@ -211,16 +216,23 @@ antlrcpp::Any AstGenerator::visitTypeDeclaration(
->getSymbol() ->getSymbol()
->getText()); ->getText());
} }
if (context->constexprDeclaration()) {
result->constexpr_generates =
StringLiteralUnquote(context->constexprDeclaration()
->STRING_LITERAL()
->getSymbol()
->getText());
}
return implicit_cast<Declaration*>(result); return implicit_cast<Declaration*>(result);
} }
antlrcpp::Any AstGenerator::visitVariableDeclaration( antlrcpp::Any AstGenerator::visitVariableDeclaration(
TorqueParser::VariableDeclarationContext* context) { TorqueParser::VariableDeclarationContext* context) {
return RegisterNode(new VarDeclarationStatement{ return RegisterNode(
Pos(context), new VarDeclarationStatement{Pos(context),
context->IDENTIFIER()->getSymbol()->getText(), context->IDENTIFIER()->getSymbol()->getText(),
context->type()->IDENTIFIER()->getSymbol()->getText(), GetType(context->type()),
{}}); {}});
} }
antlrcpp::Any AstGenerator::visitVariableDeclarationWithInitialization( antlrcpp::Any AstGenerator::visitVariableDeclarationWithInitialization(
...@@ -327,6 +339,7 @@ antlrcpp::Any AstGenerator::visitIfStatement( ...@@ -327,6 +339,7 @@ antlrcpp::Any AstGenerator::visitIfStatement(
IfStatement* result = RegisterNode(new IfStatement{ IfStatement* result = RegisterNode(new IfStatement{
Pos(context), Pos(context),
std::move(context->expression()->accept(this).as<Expression*>()), std::move(context->expression()->accept(this).as<Expression*>()),
context->CONSTEXPR() != nullptr,
std::move(context->statementBlock(0)->accept(this).as<Statement*>()), std::move(context->statementBlock(0)->accept(this).as<Statement*>()),
{}}); {}});
if (context->statementBlock(1)) if (context->statementBlock(1))
...@@ -425,11 +438,11 @@ antlrcpp::Any AstGenerator::visitPrimaryExpression( ...@@ -425,11 +438,11 @@ antlrcpp::Any AstGenerator::visitPrimaryExpression(
new StringLiteralExpression{Pos(context), e->getSymbol()->getText()})); new StringLiteralExpression{Pos(context), e->getSymbol()->getText()}));
if (context->CONVERT_KEYWORD()) if (context->CONVERT_KEYWORD())
return implicit_cast<Expression*>(RegisterNode(new ConvertExpression{ return implicit_cast<Expression*>(RegisterNode(new ConvertExpression{
Pos(context), context->type()->IDENTIFIER()->getSymbol()->getText(), Pos(context), GetType(context->type()),
context->expression()->accept(this).as<Expression*>()})); context->expression()->accept(this).as<Expression*>()}));
if (context->CAST_KEYWORD()) if (context->CAST_KEYWORD())
return implicit_cast<Expression*>(RegisterNode(new CastExpression{ return implicit_cast<Expression*>(RegisterNode(new CastExpression{
Pos(context), context->type()->IDENTIFIER()->getSymbol()->getText(), Pos(context), GetType(context->type()),
context->IDENTIFIER()->getSymbol()->getText(), context->IDENTIFIER()->getSymbol()->getText(),
context->expression()->accept(this).as<Expression*>()})); context->expression()->accept(this).as<Expression*>()}));
return context->expression()->accept(this); return context->expression()->accept(this);
......
...@@ -334,10 +334,15 @@ struct ExpressionStatement : Statement { ...@@ -334,10 +334,15 @@ struct ExpressionStatement : Statement {
struct IfStatement : Statement { struct IfStatement : Statement {
DEFINE_AST_NODE_LEAF_BOILERPLATE(IfStatement) DEFINE_AST_NODE_LEAF_BOILERPLATE(IfStatement)
IfStatement(SourcePosition p, Expression* c, Statement* t, IfStatement(SourcePosition p, Expression* c, bool cexpr, Statement* t,
base::Optional<Statement*> f) base::Optional<Statement*> f)
: Statement(kKind, p), condition(c), if_true(t), if_false(f) {} : Statement(kKind, p),
condition(c),
is_constexpr(cexpr),
if_true(t),
if_false(f) {}
Expression* condition; Expression* condition;
bool is_constexpr;
Statement* if_true; Statement* if_true;
base::Optional<Statement*> if_false; base::Optional<Statement*> if_false;
}; };
...@@ -501,6 +506,7 @@ struct TypeDeclaration : Declaration { ...@@ -501,6 +506,7 @@ struct TypeDeclaration : Declaration {
std::string name; std::string name;
base::Optional<std::string> extends; base::Optional<std::string> extends;
base::Optional<std::string> generates; base::Optional<std::string> generates;
base::Optional<std::string> constexpr_generates;
}; };
struct LabelAndTypes { struct LabelAndTypes {
......
...@@ -72,10 +72,19 @@ class DeclarationVisitor : public FileVisitor { ...@@ -72,10 +72,19 @@ class DeclarationVisitor : public FileVisitor {
void Visit(TailCallStatement* stmt) { Visit(stmt->call); } void Visit(TailCallStatement* stmt) { Visit(stmt->call); }
void Visit(TypeDeclaration* decl) { void Visit(TypeDeclaration* decl) {
std::string generates_class_name = std::string extends = decl->extends ? *decl->extends : std::string("");
decl->generates ? *decl->generates : decl->name; std::string* extends_ptr = decl->extends ? &extends : nullptr;
declarations()->DeclareType(decl->pos, decl->name, generates_class_name,
decl->extends ? &*decl->extends : nullptr); std::string generates =
decl->generates ? *decl->generates : std::string("");
declarations()->DeclareType(decl->pos, decl->name, generates, extends_ptr);
if (decl->constexpr_generates) {
std::string constexpr_name =
std::string(CONSTEXPR_TYPE_PREFIX) + decl->name;
declarations()->DeclareType(decl->pos, constexpr_name,
*decl->constexpr_generates, &(decl->name));
}
} }
void Visit(ExternalBuiltinDeclaration* decl) { void Visit(ExternalBuiltinDeclaration* decl) {
...@@ -125,6 +134,7 @@ class DeclarationVisitor : public FileVisitor { ...@@ -125,6 +134,7 @@ class DeclarationVisitor : public FileVisitor {
std::cout << "found declaration of external runtime " << decl->name std::cout << "found declaration of external runtime " << decl->name
<< " with signature "; << " with signature ";
} }
Type return_type = declarations()->LookupType(decl->pos, decl->return_type); Type return_type = declarations()->LookupType(decl->pos, decl->return_type);
TypeVector parameter_types = TypeVector parameter_types =
GetTypeVector(decl->pos, decl->parameters.types); GetTypeVector(decl->pos, decl->parameters.types);
...@@ -260,12 +270,16 @@ class DeclarationVisitor : public FileVisitor { ...@@ -260,12 +270,16 @@ class DeclarationVisitor : public FileVisitor {
} }
void Visit(IfStatement* stmt) { void Visit(IfStatement* stmt) {
PushControlSplit(); if (!stmt->is_constexpr) {
PushControlSplit();
}
DeclareExpressionForBranch(stmt->condition); DeclareExpressionForBranch(stmt->condition);
Visit(stmt->if_true); Visit(stmt->if_true);
if (stmt->if_false) Visit(*stmt->if_false); if (stmt->if_false) Visit(*stmt->if_false);
auto changed_vars = PopControlSplit(); if (!stmt->is_constexpr) {
global_context_.AddControlSplitChangedVariables(stmt, changed_vars); auto changed_vars = PopControlSplit();
global_context_.AddControlSplitChangedVariables(stmt, changed_vars);
}
} }
void Visit(WhileStatement* stmt) { void Visit(WhileStatement* stmt) {
......
...@@ -341,7 +341,7 @@ VisitResult ImplementationVisitor::Visit(LogicalOrExpression* expr) { ...@@ -341,7 +341,7 @@ VisitResult ImplementationVisitor::Visit(LogicalOrExpression* expr) {
Label::cast(declarations()->LookupValue(expr->pos, kFalseLabelName)); Label::cast(declarations()->LookupValue(expr->pos, kFalseLabelName));
GenerateLabelDefinition(false_label); GenerateLabelDefinition(false_label);
VisitResult left_result = Visit(expr->left); VisitResult left_result = Visit(expr->left);
if (left_result.type().IsBit()) { if (left_result.type().IsBool()) {
Label* true_label = Label* true_label =
Label::cast(declarations()->LookupValue(expr->pos, kTrueLabelName)); Label::cast(declarations()->LookupValue(expr->pos, kTrueLabelName));
GenerateIndent(); GenerateIndent();
...@@ -361,7 +361,7 @@ VisitResult ImplementationVisitor::Visit(LogicalAndExpression* expr) { ...@@ -361,7 +361,7 @@ VisitResult ImplementationVisitor::Visit(LogicalAndExpression* expr) {
Label::cast(declarations()->LookupValue(expr->pos, kTrueLabelName)); Label::cast(declarations()->LookupValue(expr->pos, kTrueLabelName));
GenerateLabelDefinition(true_label); GenerateLabelDefinition(true_label);
VisitResult left_result = Visit(expr->left); VisitResult left_result = Visit(expr->left);
if (left_result.type().IsBit()) { if (left_result.type().IsBool()) {
Label* false_label = Label* false_label =
Label::cast(declarations()->LookupValue(expr->pos, kFalseLabelName)); Label::cast(declarations()->LookupValue(expr->pos, kFalseLabelName));
GenerateIndent(); GenerateIndent();
...@@ -484,38 +484,70 @@ Type ImplementationVisitor::Visit(IfStatement* stmt) { ...@@ -484,38 +484,70 @@ Type ImplementationVisitor::Visit(IfStatement* stmt) {
bool has_else = stmt->if_false.has_value(); bool has_else = stmt->if_false.has_value();
Label* true_label = nullptr; if (stmt->is_constexpr) {
Label* false_label = nullptr; VisitResult expression_result = Visit(stmt->condition);
{
Declarations::NodeScopeActivator scope(declarations(), &*stmt->condition);
true_label =
Label::cast(declarations()->LookupValue(stmt->pos, kTrueLabelName));
GenerateLabelDefinition(true_label);
false_label =
Label::cast(declarations()->LookupValue(stmt->pos, kFalseLabelName));
GenerateLabelDefinition(false_label, !has_else ? stmt : nullptr);
}
Label* done_label = nullptr; if (!expression_result.type().Is(GetTypeOracle().GetConstexprBoolType())) {
bool live = false; std::stringstream stream;
if (has_else) { stream
done_label = << "expression should return type \"constexpr bool\" but doesn't at"
declarations()->DeclarePrivateLabel(stmt->pos, "if_done_label"); << PositionAsString(stmt->pos);
GenerateLabelDefinition(done_label, stmt); ReportError(stream.str());
}
{
GenerateIndent();
source_out() << "if ((" << expression_result.variable() << ")) ";
ScopedIndent indent(this, false);
source_out() << std::endl;
Visit(stmt->if_true);
}
if (has_else) {
source_out() << " else ";
ScopedIndent indent(this, false);
source_out() << std::endl;
Visit(*stmt->if_false);
}
source_out() << std::endl;
return GetTypeOracle().GetVoidType();
} else { } else {
done_label = false_label; Label* true_label = nullptr;
live = true; Label* false_label = nullptr;
} {
std::vector<Statement*> blocks = {stmt->if_true}; Declarations::NodeScopeActivator scope(declarations(), &*stmt->condition);
std::vector<Label*> labels = {true_label, false_label}; true_label =
if (has_else) blocks.push_back(*stmt->if_false); Label::cast(declarations()->LookupValue(stmt->pos, kTrueLabelName));
if (GenerateExpressionBranch(stmt->condition, labels, blocks, done_label)) { GenerateLabelDefinition(true_label);
live = true; false_label =
} Label::cast(declarations()->LookupValue(stmt->pos, kFalseLabelName));
if (live) { GenerateLabelDefinition(false_label, !has_else ? stmt : nullptr);
GenerateLabelBind(done_label); }
Label* done_label = nullptr;
bool live = false;
if (has_else) {
done_label =
declarations()->DeclarePrivateLabel(stmt->pos, "if_done_label");
GenerateLabelDefinition(done_label, stmt);
} else {
done_label = false_label;
live = true;
}
std::vector<Statement*> blocks = {stmt->if_true};
std::vector<Label*> labels = {true_label, false_label};
if (has_else) blocks.push_back(*stmt->if_false);
if (GenerateExpressionBranch(stmt->condition, labels, blocks, done_label)) {
live = true;
}
if (live) {
GenerateLabelBind(done_label);
}
return live ? GetTypeOracle().GetVoidType()
: GetTypeOracle().GetNeverType();
} }
return live ? GetTypeOracle().GetVoidType() : GetTypeOracle().GetNeverType();
} }
Type ImplementationVisitor::Visit(WhileStatement* stmt) { Type ImplementationVisitor::Visit(WhileStatement* stmt) {
...@@ -605,7 +637,7 @@ Type ImplementationVisitor::Visit(AssertStatement* stmt) { ...@@ -605,7 +637,7 @@ Type ImplementationVisitor::Visit(AssertStatement* stmt) {
Expression* expression = stmt->expression; Expression* expression = stmt->expression;
VisitResult expression_result = Visit(stmt->expression); VisitResult expression_result = Visit(stmt->expression);
if (expression_result.type() == GetTypeOracle().GetBitType()) { if (expression_result.type() == GetTypeOracle().GetBoolType()) {
GenerateBranch(expression_result, true_label, false_label); GenerateBranch(expression_result, true_label, false_label);
} else { } else {
if (expression_result.type() != GetTypeOracle().GetNeverType()) { if (expression_result.type() != GetTypeOracle().GetNeverType()) {
...@@ -1009,7 +1041,8 @@ VisitResult ImplementationVisitor::GenerateOperation( ...@@ -1009,7 +1041,8 @@ VisitResult ImplementationVisitor::GenerateOperation(
} }
} }
if (!return_type || (return_type->IsSubclass(handler.result_type))) { if (!return_type || (GetTypeOracle().IsAssignableFrom(
*return_type, handler.result_type))) {
return GenerateCall(pos, handler.macro_name, arguments, false); return GenerateCall(pos, handler.macro_name, arguments, false);
} }
} }
...@@ -1362,7 +1395,7 @@ bool ImplementationVisitor::GenerateExpressionBranch( ...@@ -1362,7 +1395,7 @@ bool ImplementationVisitor::GenerateExpressionBranch(
Declarations::NodeScopeActivator scope(declarations(), expression); Declarations::NodeScopeActivator scope(declarations(), expression);
VisitResult expression_result = Visit(expression); VisitResult expression_result = Visit(expression);
if (expression_result.type() == GetTypeOracle().GetBitType()) { if (expression_result.type() == GetTypeOracle().GetBoolType()) {
GenerateBranch(expression_result, statement_labels[0], statement_labels[1]); GenerateBranch(expression_result, statement_labels[0], statement_labels[1]);
} else { } else {
if (expression_result.type() != GetTypeOracle().GetNeverType()) { if (expression_result.type() != GetTypeOracle().GetNeverType()) {
......
...@@ -25,7 +25,11 @@ class TypeOracle { ...@@ -25,7 +25,11 @@ class TypeOracle {
Type GetArgumentsType() { return GetBuiltinType(ARGUMENTS_TYPE_STRING); } Type GetArgumentsType() { return GetBuiltinType(ARGUMENTS_TYPE_STRING); }
Type GetBitType() { return GetBuiltinType(BIT_TYPE_STRING); } Type GetBoolType() { return GetBuiltinType(BOOL_TYPE_STRING); }
Type GetConstexprBoolType() {
return GetBuiltinType(CONSTEXPR_BOOL_TYPE_STRING);
}
Type GetVoidType() { return GetBuiltinType(VOID_TYPE_STRING); } Type GetVoidType() { return GetBuiltinType(VOID_TYPE_STRING); }
...@@ -40,7 +44,8 @@ class TypeOracle { ...@@ -40,7 +44,8 @@ class TypeOracle {
Type GetConstInt31Type() { return GetBuiltinType(CONST_INT31_TYPE_STRING); } Type GetConstInt31Type() { return GetBuiltinType(CONST_INT31_TYPE_STRING); }
bool IsAssignableFrom(Type to, Type from) { bool IsAssignableFrom(Type to, Type from) {
if (to.IsSubclass(from)) return true; if (to == from) return true;
if (to.IsSubclass(from) && !from.IsConstexpr()) return true;
return IsImplicitlyConverableFrom(to, from); return IsImplicitlyConverableFrom(to, from);
} }
......
...@@ -14,9 +14,11 @@ namespace v8 { ...@@ -14,9 +14,11 @@ namespace v8 {
namespace internal { namespace internal {
namespace torque { namespace torque {
static const char* const CONSTEXPR_TYPE_PREFIX = "constexpr ";
static const char* const NEVER_TYPE_STRING = "never"; static const char* const NEVER_TYPE_STRING = "never";
static const char* const BRANCH_TYPE_STRING = "branch"; static const char* const BRANCH_TYPE_STRING = "branch";
static const char* const BIT_TYPE_STRING = "bit"; static const char* const CONSTEXPR_BOOL_TYPE_STRING = "constexpr bool";
static const char* const BOOL_TYPE_STRING = "bool";
static const char* const VOID_TYPE_STRING = "void"; static const char* const VOID_TYPE_STRING = "void";
static const char* const ARGUMENTS_TYPE_STRING = "Arguments"; static const char* const ARGUMENTS_TYPE_STRING = "Arguments";
static const char* const TAGGED_TYPE_STRING = "tagged"; static const char* const TAGGED_TYPE_STRING = "tagged";
...@@ -25,9 +27,9 @@ static const char* const EXCEPTION_TYPE_STRING = "Exception"; ...@@ -25,9 +27,9 @@ static const char* const EXCEPTION_TYPE_STRING = "Exception";
static const char* const OBJECT_TYPE_STRING = "Object"; static const char* const OBJECT_TYPE_STRING = "Object";
static const char* const STRING_TYPE_STRING = "String"; static const char* const STRING_TYPE_STRING = "String";
static const char* const INTPTR_TYPE_STRING = "intptr"; static const char* const INTPTR_TYPE_STRING = "intptr";
static const char* const CONST_INT31_TYPE_STRING = "const_int31"; static const char* const CONST_INT31_TYPE_STRING = "constexpr int31";
static const char* const CONST_INT32_TYPE_STRING = "const_int32"; static const char* const CONST_INT32_TYPE_STRING = "constexpr int32";
static const char* const CONST_FLOAT64_TYPE_STRING = "const_float64"; static const char* const CONST_FLOAT64_TYPE_STRING = "constexpr float64";
class Label; class Label;
...@@ -47,9 +49,14 @@ typedef struct Type { ...@@ -47,9 +49,14 @@ typedef struct Type {
bool IsException() const { return name() == EXCEPTION_TYPE_STRING; } bool IsException() const { return name() == EXCEPTION_TYPE_STRING; }
bool IsVoid() const { return name() == VOID_TYPE_STRING; } bool IsVoid() const { return name() == VOID_TYPE_STRING; }
bool IsNever() const { return name() == NEVER_TYPE_STRING; } bool IsNever() const { return name() == NEVER_TYPE_STRING; }
bool IsBit() const { return name() == BIT_TYPE_STRING; } bool IsBool() const { return name() == BOOL_TYPE_STRING; }
bool IsVoidOrNever() const { return IsVoid() || IsNever(); } bool IsVoidOrNever() const { return IsVoid() || IsNever(); }
bool IsConstexpr() const {
return name().substr(0, strlen(CONSTEXPR_TYPE_PREFIX)) ==
CONSTEXPR_TYPE_PREFIX;
}
const std::string& name() const; const std::string& name() const;
const std::string& GetGeneratedTypeName() const; const std::string& GetGeneratedTypeName() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment