1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00
llvm-mirror/test/MC/WebAssembly/globals.s
Wouter van Oortmerssen 538b137e0b [WebAssembly] Added initial type checker to MC Assembler
This to protect against non-sensical instruction sequences being assembled,
which would either cause asserts/crashes further down, or a Wasm module being output that doesn't validate.

Unlike a validator, this type checker is able to give type-errors as part of the parsing process, which makes the assembler much friendlier to be used by humans writing manual input.

Because the MC system is single pass (instructions aren't even stored in MC format, they are directly output) the type checker has to be single pass as well, which means that from now on .globaltype and .functype decls must come before their use. An extra pass is added to Codegen to collect information for this purpose, since AsmPrinter is normally single pass / streaming as well, and would otherwise generate this information on the fly.

A `-no-type-check` flag was added to llvm-mc (and any other tools that take asm input) that surpresses type errors, as a quick escape hatch for tests that were not intended to be type correct.

This is a first version of the type checker that ignores control flow, i.e. it checks that types are correct along the linear path, but not the branch path. This will still catch most errors. Branch checking could be added in the future.

Differential Revision: https://reviews.llvm.org/D104945
2021-07-09 14:07:25 -07:00

89 lines
2.7 KiB
ArmAsm

# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj < %s | obj2yaml | FileCheck -check-prefix=BIN %s
# Tests creating an accessing actual wasm globals
.globl read_global
.globl write_global
.globaltype foo_global, i32
.globaltype global2, i64, immutable
.globaltype global3, f32
.globaltype global4, f64
read_global:
.functype read_global () -> (i32)
global.get foo_global
end_function
write_global:
.functype write_global (i32, i64, f32, f64) -> ()
local.get 0
global.set foo_global
local.get 1
global.set global2
local.get 2
global.set global3
local.get 3
global.set global4
end_function
foo_global:
global2:
global3:
global4:
# CHECK: .globl read_global
# CNEXT: .globl write_global
# CHECK: .globaltype foo_global, i32
# CHECK: foo_global:
# BIN: - Type: GLOBAL
# BIN-NEXT: Globals:
# BIN-NEXT: - Index: 0
# BIN-NEXT: Type: I32
# BIN-NEXT: Mutable: true
# BIN-NEXT: InitExpr:
# BIN-NEXT: Opcode: I32_CONST
# BIN-NEXT: Value: 0
# BIN-NEXT: - Index: 1
# BIN-NEXT: Type: I64
# BIN-NEXT: Mutable: false
# BIN-NEXT: InitExpr:
# BIN-NEXT: Opcode: I64_CONST
# BIN-NEXT: Value: 0
# BIN: - Type: CUSTOM
# BIN-NEXT: Name: linking
# BIN-NEXT: Version: 2
# BIN-NEXT: SymbolTable:
# BIN-NEXT: - Index: 0
# BIN-NEXT: Kind: FUNCTION
# BIN-NEXT: Name: read_global
# BIN-NEXT: Flags: [ ]
# BIN-NEXT: Function: 0
# BIN-NEXT: - Index: 1
# BIN-NEXT: Kind: FUNCTION
# BIN-NEXT: Name: write_global
# BIN-NEXT: Flags: [ ]
# BIN-NEXT: Function: 1
# BIN-NEXT: - Index: 2
# BIN-NEXT: Kind: GLOBAL
# BIN-NEXT: Name: foo_global
# BIN-NEXT: Flags: [ BINDING_LOCAL ]
# BIN-NEXT: Global: 0
# BIN-NEXT: - Index: 3
# BIN-NEXT: Kind: GLOBAL
# BIN-NEXT: Name: global2
# BIN-NEXT: Flags: [ BINDING_LOCAL ]
# BIN-NEXT: Global: 1
# BIN-NEXT: - Index: 4
# BIN-NEXT: Kind: GLOBAL
# BIN-NEXT: Name: global3
# BIN-NEXT: Flags: [ BINDING_LOCAL ]
# BIN-NEXT: Global: 2
# BIN-NEXT: - Index: 5
# BIN-NEXT: Kind: GLOBAL
# BIN-NEXT: Name: global4
# BIN-NEXT: Flags: [ BINDING_LOCAL ]
# BIN-NEXT: Global: 3